Search in sources :

Example 1 with UserBindWorkspaceService

use of io.jpom.service.user.UserBindWorkspaceService in project Jpom by dromara.

the class ServerWebSocketInterceptor method checkPermission.

/**
 * 检查权限
 *
 * @param userInfo    用户
 * @param attributes  属性
 * @param handlerType 功能类型
 * @return 错误消息
 */
private String checkPermission(UserModel userInfo, Map<String, Object> attributes, HandlerType handlerType) {
    if (userInfo.isSuperSystemUser()) {
        return StrUtil.EMPTY;
    }
    if (userInfo.isDemoUser()) {
        return PermissionInterceptor.DEMO_TIP;
    }
    if (handlerType == HandlerType.nodeUpdate) {
        return "您没有对应功能【" + ClassFeature.NODE_UPGRADE.getName() + "】管理权限";
    }
    Object dataItem = attributes.get("dataItem");
    Object nodeInfo = attributes.get("nodeInfo");
    String workspaceId = BeanUtil.getProperty(dataItem == null ? nodeInfo : dataItem, "workspaceId");
    // ?  : BeanUtil.getProperty(dataItem, "workspaceId");
    // 
    attributes.put("workspaceId", workspaceId);
    Class<?> handlerClass = handlerType.getHandlerClass();
    SystemPermission systemPermission = handlerClass.getAnnotation(SystemPermission.class);
    if (systemPermission != null) {
        if (!userInfo.isSuperSystemUser()) {
            return "您没有对应功能【" + ClassFeature.NODE_UPGRADE.getName() + "】管理权限";
        }
    }
    Feature feature = handlerClass.getAnnotation(Feature.class);
    MethodFeature method = feature.method();
    ClassFeature cls = feature.cls();
    UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class);
    boolean exists = userBindWorkspaceService.exists(userInfo.getId(), workspaceId + StrUtil.DASHED + method.name());
    if (exists) {
        return StrUtil.EMPTY;
    }
    return "您没有对应功能【" + cls.getName() + "-" + method.getName() + "】管理权限";
}
Also used : SystemPermission(io.jpom.permission.SystemPermission) ClassFeature(io.jpom.permission.ClassFeature) MethodFeature(io.jpom.permission.MethodFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature) UserBindWorkspaceService(io.jpom.service.user.UserBindWorkspaceService)

Example 2 with UserBindWorkspaceService

use of io.jpom.service.user.UserBindWorkspaceService in project Jpom by dromara.

the class BaseWorkspaceService method checkUserWorkspace.

/**
 * 判断用户是否有对应工作空间权限
 *
 * @param workspaceId 工作空间ID
 */
protected void checkUserWorkspace(String workspaceId, UserModel userModel) {
    Assert.notNull(userModel, "没有对应的用户");
    if (StrUtil.equals(userModel.getId(), UserModel.SYSTEM_ADMIN)) {
        // 系统执行,发行检查
        return;
    }
    if (userModel.isSuperSystemUser()) {
        // 超级管理员
        return;
    }
    // 查询绑定的权限
    UserBindWorkspaceService userBindWorkspaceService = SpringUtil.getBean(UserBindWorkspaceService.class);
    boolean exists = userBindWorkspaceService.exists(userModel.getId(), workspaceId);
    Assert.state(exists, "没有对应的工作空间权限");
}
Also used : UserBindWorkspaceService(io.jpom.service.user.UserBindWorkspaceService)

Aggregations

UserBindWorkspaceService (io.jpom.service.user.UserBindWorkspaceService)2 ClassFeature (io.jpom.permission.ClassFeature)1 Feature (io.jpom.permission.Feature)1 MethodFeature (io.jpom.permission.MethodFeature)1 SystemPermission (io.jpom.permission.SystemPermission)1