|
@@ -8,6 +8,7 @@ import cn.reghao.dfs.store.model.dto.ContentRange;
|
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
import cn.reghao.dfs.store.model.po.FileMeta;
|
|
|
import cn.reghao.dfs.store.util.JwtUtil;
|
|
import cn.reghao.dfs.store.util.JwtUtil;
|
|
|
import cn.reghao.dfs.store.util.UserContext;
|
|
import cn.reghao.dfs.store.util.UserContext;
|
|
|
|
|
+import cn.reghao.oss.api.constant.ObjectScope;
|
|
|
import cn.reghao.oss.api.constant.UploadChannel;
|
|
import cn.reghao.oss.api.constant.UploadChannel;
|
|
|
import cn.reghao.oss.api.dto.ObjectMeta;
|
|
import cn.reghao.oss.api.dto.ObjectMeta;
|
|
|
import cn.reghao.jutil.web.ServletUtil;
|
|
import cn.reghao.jutil.web.ServletUtil;
|
|
@@ -67,10 +68,12 @@ public class GetObjectService {
|
|
|
|
|
|
|
|
ObjectMeta objectMeta = objectRepository.getObjectMeta(objectName);
|
|
ObjectMeta objectMeta = objectRepository.getObjectMeta(objectName);
|
|
|
if (objectMeta == null) {
|
|
if (objectMeta == null) {
|
|
|
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
|
|
- OutputStream outputStream = response.getOutputStream();
|
|
|
|
|
- outputStream.flush();
|
|
|
|
|
- outputStream.close();
|
|
|
|
|
|
|
+ writeResponse(HttpServletResponse.SC_NOT_FOUND);
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!checkPermission(objectMeta.getScope(), objectMeta.getUploadBy())) {
|
|
|
|
|
+ writeResponse(HttpServletResponse.SC_UNAUTHORIZED);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -119,16 +122,26 @@ public class GetObjectService {
|
|
|
|
|
|
|
|
ObjectMeta objectMeta = objectRepository.getObjectMeta(objectName);
|
|
ObjectMeta objectMeta = objectRepository.getObjectMeta(objectName);
|
|
|
if (objectMeta == null) {
|
|
if (objectMeta == null) {
|
|
|
- response.setStatus(HttpServletResponse.SC_NOT_FOUND);
|
|
|
|
|
- OutputStream outputStream = response.getOutputStream();
|
|
|
|
|
- outputStream.flush();
|
|
|
|
|
- outputStream.close();
|
|
|
|
|
|
|
+ writeResponse(HttpServletResponse.SC_NOT_FOUND);
|
|
|
return;
|
|
return;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
writeDownloadContent(objectMeta);
|
|
writeDownloadContent(objectMeta);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private boolean checkPermission(int scope, long uploadBy) {
|
|
|
|
|
+ if (scope == ObjectScope.PRIVATE.getCode()) {
|
|
|
|
|
+ long userId = UserContext.getUser();
|
|
|
|
|
+ return userId == uploadBy;
|
|
|
|
|
+ } else if (scope == ObjectScope.FRIEND.getCode()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ } else if (scope == ObjectScope.PROTECT.getCode()) {
|
|
|
|
|
+ return false;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ return true;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private void writeResponse(int statusCode) throws IOException {
|
|
private void writeResponse(int statusCode) throws IOException {
|
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
HttpServletResponse response = ServletUtil.getResponse();
|
|
|
response.setStatus(statusCode);
|
|
response.setStatus(statusCode);
|