mirror of
https://gitee.com/dromara/Jpom.git
synced 2024-12-04 12:58:24 +08:00
fix 获取工作空间 id 统一
This commit is contained in:
parent
3ba48b0946
commit
663e2d26e3
@ -37,6 +37,7 @@ import io.jpom.model.user.UserBindWorkspaceModel;
|
||||
import io.jpom.model.user.UserModel;
|
||||
import io.jpom.permission.*;
|
||||
import io.jpom.service.h2db.BaseNodeService;
|
||||
import io.jpom.service.h2db.BaseWorkspaceService;
|
||||
import io.jpom.service.node.NodeService;
|
||||
import io.jpom.service.user.UserBindWorkspaceService;
|
||||
import io.jpom.system.AgentException;
|
||||
@ -129,10 +130,7 @@ public class PermissionInterceptor extends BaseJpomInterceptor {
|
||||
}
|
||||
// 判断功能权限
|
||||
if (method != MethodFeature.LIST) {
|
||||
String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
if (StrUtil.isEmpty(workspaceId)) {
|
||||
workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER);
|
||||
}
|
||||
String workspaceId = BaseWorkspaceService.getWorkspaceId(request);
|
||||
UserBindWorkspaceModel.PermissionResult permissionResult = userBindWorkspaceService.checkPermission(userModel, workspaceId + StrUtil.DASHED + method.name());
|
||||
if (!permissionResult.isSuccess()) {
|
||||
this.errorMsg(response, permissionResult.errorMsg("对应功能【" + classFeature.getName() + StrUtil.DASHED + method.getName() + "】"));
|
||||
@ -201,7 +199,7 @@ public class PermissionInterceptor extends BaseJpomInterceptor {
|
||||
}
|
||||
} else {
|
||||
// 判断节点管理权限
|
||||
String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
String workspaceId = BaseWorkspaceService.getWorkspaceId(request);
|
||||
UserBindWorkspaceModel.PermissionResult permissionResult = userBindWorkspaceService.checkPermission(userModel, workspaceId + UserBindWorkspaceService.SYSTEM_USER);
|
||||
if (!permissionResult.isSuccess()) {
|
||||
this.errorMsg(response, permissionResult.errorMsg("节点管理"));
|
||||
|
@ -44,6 +44,7 @@ import io.jpom.common.interceptor.BaseJpomInterceptor;
|
||||
import io.jpom.common.interceptor.NotLogin;
|
||||
import io.jpom.model.data.NodeModel;
|
||||
import io.jpom.model.user.UserModel;
|
||||
import io.jpom.service.h2db.BaseWorkspaceService;
|
||||
import io.jpom.service.system.SystemParametersServer;
|
||||
import io.jpom.service.user.UserBindWorkspaceService;
|
||||
import io.jpom.service.user.UserService;
|
||||
@ -335,7 +336,7 @@ public class IndexControl extends BaseServerController {
|
||||
if (userModel.isSuperSystemUser()) {
|
||||
return true;
|
||||
}
|
||||
String workspaceId = ServletUtil.getHeader(getRequest(), Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
String workspaceId = BaseWorkspaceService.getWorkspaceId(getRequest());
|
||||
return userBindWorkspaceService.exists(userModel, workspaceId + UserBindWorkspaceService.SYSTEM_USER);
|
||||
}
|
||||
}
|
||||
|
@ -228,10 +228,11 @@ public class LoginControl extends BaseServerController {
|
||||
// 判断工作空间
|
||||
List<WorkspaceModel> bindWorkspaceModels = userBindWorkspaceService.listUserWorkspaceInfo(userModel);
|
||||
Assert.notEmpty(bindWorkspaceModels, "当前账号没有绑定任何工作空间,请联系管理员处理");
|
||||
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
|
||||
UserLoginDto userLoginDto = userService.getUserJwtId(userModel);
|
||||
// UserLoginDto userLoginDto = new UserLoginDto(JwtUtil.builder(userModel, jwtId), jwtId);
|
||||
userLoginDto.setBindWorkspaceModels(bindWorkspaceModels);
|
||||
//
|
||||
setSessionAttribute(LoginInterceptor.SESSION_NAME, userModel);
|
||||
return userLoginDto;
|
||||
}
|
||||
|
||||
|
@ -154,10 +154,10 @@ public class DbUserOperateLogService extends BaseWorkspaceService<UserOperateLog
|
||||
map.putAll(dataMap);
|
||||
}
|
||||
List<String> list = map.entrySet()
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() != null)
|
||||
.map(entry -> entry.getKey() + ":" + entry.getValue())
|
||||
.collect(Collectors.toList());
|
||||
.stream()
|
||||
.filter(entry -> entry.getValue() != null)
|
||||
.map(entry -> entry.getKey() + ":" + entry.getValue())
|
||||
.collect(Collectors.toList());
|
||||
//
|
||||
return CollUtil.join(list, StrUtil.LF);
|
||||
}
|
||||
@ -180,9 +180,9 @@ public class DbUserOperateLogService extends BaseWorkspaceService<UserOperateLog
|
||||
|
||||
String optTypeMsg = StrUtil.format(" 【{}】->【{}】", classFeature.getName(), methodFeature.getName());
|
||||
List<MonitorUserOptModel> monitorUserOptModels = monitorUserOptService.listByType(userOperateLogV1.getWorkspaceId(),
|
||||
classFeature,
|
||||
methodFeature,
|
||||
userOperateLogV1.getUserId());
|
||||
classFeature,
|
||||
methodFeature,
|
||||
userOperateLogV1.getUserId());
|
||||
if (CollUtil.isEmpty(monitorUserOptModels)) {
|
||||
return;
|
||||
}
|
||||
@ -267,8 +267,9 @@ public class DbUserOperateLogService extends BaseWorkspaceService<UserOperateLog
|
||||
@Override
|
||||
public String getCheckUserWorkspace(HttpServletRequest request) {
|
||||
// 忽略检查
|
||||
String header = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
return ObjectUtil.defaultIfNull(header, StrUtil.EMPTY);
|
||||
return BaseWorkspaceService.getWorkspaceId(request);
|
||||
// String header = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
// return ObjectUtil.defaultIfNull(header, StrUtil.EMPTY);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -201,6 +201,14 @@ public abstract class BaseWorkspaceService<T extends BaseWorkspaceModel> extends
|
||||
});
|
||||
}
|
||||
|
||||
public static String getWorkspaceId(HttpServletRequest request) {
|
||||
String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
if (StrUtil.isEmpty(workspaceId)) {
|
||||
workspaceId = request.getParameter(Const.WORKSPACEID_REQ_HEADER);
|
||||
}
|
||||
return StrUtil.emptyToDefault(workspaceId, Const.WORKSPACE_DEFAULT_ID);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取 工作空间ID 并判断是否有权限
|
||||
*
|
||||
@ -208,7 +216,7 @@ public abstract class BaseWorkspaceService<T extends BaseWorkspaceModel> extends
|
||||
* @return 工作空间ID
|
||||
*/
|
||||
public String getCheckUserWorkspace(HttpServletRequest request) {
|
||||
String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
|
||||
String workspaceId = getWorkspaceId(request);
|
||||
Assert.hasText(workspaceId, "请选择工作空间");
|
||||
//
|
||||
this.checkUserWorkspace(workspaceId);
|
||||
|
@ -45,6 +45,7 @@ import io.jpom.permission.ClassFeature;
|
||||
import io.jpom.permission.Feature;
|
||||
import io.jpom.permission.MethodFeature;
|
||||
import io.jpom.service.dblog.DbUserOperateLogService;
|
||||
import io.jpom.service.h2db.BaseWorkspaceService;
|
||||
import io.jpom.system.AopLogInterface;
|
||||
import io.jpom.system.WebAopLog;
|
||||
import lombok.Data;
|
||||
@ -134,7 +135,8 @@ public class OperateLogController implements AopLogInterface {
|
||||
cacheInfo.nodeModel = (NodeModel) request.getAttribute("node");
|
||||
//
|
||||
cacheInfo.userAgent = ServletUtil.getHeaderIgnoreCase(request, HttpHeaders.USER_AGENT);
|
||||
cacheInfo.workspaceId = ServletUtil.getHeaderIgnoreCase(request, Const.WORKSPACEID_REQ_HEADER);
|
||||
cacheInfo.workspaceId = BaseWorkspaceService.getWorkspaceId(request);
|
||||
//ServletUtil.getHeaderIgnoreCase(request, Const.WORKSPACEID_REQ_HEADER);
|
||||
//
|
||||
Map<String, Object> allData = this.buildRequestParam(request);
|
||||
//
|
||||
|
Loading…
Reference in New Issue
Block a user