Search in sources :

Example 1 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class UserBindWorkspaceService method updateUserWorkspace.

/**
 * 更新用户的工作空间信息
 *
 * @param userId    用户ID
 * @param workspace 工作空间信息
 */
public void updateUserWorkspace(String userId, List<String> workspace) {
    Assert.notEmpty(workspace, "没有任何工作空间信息");
    List<UserBindWorkspaceModel> list = new HashSet<>(workspace).stream().filter(s -> {
        s = StrUtil.removeSuffix(s, SYSTEM_USER);
        s = StrUtil.removeSuffix(s, SSH_COMMAND_NOT_LIMITED);
        MethodFeature[] values = MethodFeature.values();
        for (MethodFeature value : values) {
            s = StrUtil.removeSuffix(s, StrUtil.DASHED + value.name());
        }
        return workspaceService.exists(new WorkspaceModel(s));
    }).map(s -> {
        UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
        userBindWorkspaceModel.setWorkspaceId(s);
        userBindWorkspaceModel.setUserId(userId);
        userBindWorkspaceModel.setId(UserBindWorkspaceModel.getId(userId, s));
        return userBindWorkspaceModel;
    }).collect(Collectors.toList());
    // 删除之前的数据
    UserBindWorkspaceModel userBindWorkspaceModel = new UserBindWorkspaceModel();
    userBindWorkspaceModel.setUserId(userId);
    super.del(super.dataBeanToEntity(userBindWorkspaceModel));
    // 重新入库
    super.insert(list);
}
Also used : UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) WorkspaceService(io.jpom.service.system.WorkspaceService) Collectors(java.util.stream.Collectors) HashSet(java.util.HashSet) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) Service(org.springframework.stereotype.Service) Entity(cn.hutool.db.Entity) UserModel(io.jpom.model.data.UserModel) MethodFeature(io.jpom.permission.MethodFeature) BaseDbService(io.jpom.service.h2db.BaseDbService) Assert(org.springframework.util.Assert) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) WorkspaceModel(io.jpom.model.data.WorkspaceModel) MethodFeature(io.jpom.permission.MethodFeature) UserBindWorkspaceModel(io.jpom.model.data.UserBindWorkspaceModel) HashSet(java.util.HashSet)

Example 2 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class MonitorUserOptService method listByType.

/**
 * 查询 对应操作的监控信息
 *
 * @param workspaceId   工作空间ID
 * @param classFeature  功能
 * @param methodFeature 操作
 * @return list
 */
public List<MonitorUserOptModel> listByType(String workspaceId, ClassFeature classFeature, MethodFeature methodFeature, String userId) {
    MonitorUserOptModel where = new MonitorUserOptModel();
    if (StrUtil.isNotEmpty(workspaceId)) {
        // 没有工作空间查询全部
        where.setWorkspaceId(workspaceId);
    }
    where.setStatus(true);
    List<MonitorUserOptModel> list = super.listByBean(where);
    if (CollUtil.isEmpty(list)) {
        return null;
    }
    return list.stream().filter(monitorUserOptModel -> {
        List<ClassFeature> classFeatures = monitorUserOptModel.monitorFeature();
        List<MethodFeature> methodFeatures = monitorUserOptModel.monitorOpt();
        boolean b = CollUtil.contains(classFeatures, classFeature) && CollUtil.contains(methodFeatures, methodFeature);
        if (b) {
            List<String> monitorUser = monitorUserOptModel.monitorUser();
            return CollUtil.contains(monitorUser, userId);
        }
        return false;
    }).collect(Collectors.toList());
}
Also used : CollUtil(cn.hutool.core.collection.CollUtil) StrUtil(cn.hutool.core.util.StrUtil) List(java.util.List) BaseWorkspaceService(io.jpom.service.h2db.BaseWorkspaceService) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) Service(org.springframework.stereotype.Service) ClassFeature(io.jpom.permission.ClassFeature) MethodFeature(io.jpom.permission.MethodFeature) Collectors(java.util.stream.Collectors) List(java.util.List) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel)

Example 3 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class PermissionInterceptor method preHandle.

@Override
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, HandlerMethod handlerMethod) throws Exception {
    this.init();
    this.addNode(request);
    UserModel userModel = BaseServerController.getUserModel();
    if (userModel == null || userModel.isSuperSystemUser()) {
        // 没有登录、或者超级管理直接放过
        return true;
    }
    // 
    boolean permission = this.checkSystemPermission(userModel, request, response, handlerMethod);
    if (!permission) {
        return false;
    }
    permission = this.checkNodeDataPermission(userModel, request, response, handlerMethod);
    if (!permission) {
        return false;
    }
    Feature feature = handlerMethod.getMethodAnnotation(Feature.class);
    if (feature == null) {
        return true;
    }
    MethodFeature method = feature.method();
    if (ArrayUtil.contains(DEMO, method) && userModel.isDemoUser()) {
        this.errorMsg(response, DEMO_TIP);
        return false;
    }
    ClassFeature classFeature = feature.cls();
    if (classFeature == ClassFeature.NULL) {
        Feature feature1 = handlerMethod.getBeanType().getAnnotation(Feature.class);
        if (feature1 != null && feature1.cls() != ClassFeature.NULL) {
            classFeature = feature1.cls();
        }
    }
    // 判断功能权限
    if (method != MethodFeature.LIST) {
        String workspaceId = ServletUtil.getHeader(request, Const.WORKSPACEID_REQ_HEADER, CharsetUtil.CHARSET_UTF_8);
        boolean exists = userBindWorkspaceService.exists(userModel.getId(), workspaceId + StrUtil.DASHED + method.name());
        if (!exists) {
            this.errorMsg(response, "您没有对应功能【" + classFeature.getName() + StrUtil.DASHED + method.getName() + "】管理权限");
            return false;
        }
    }
    return true;
}
Also used : UserModel(io.jpom.model.data.UserModel) 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)

Example 4 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class MonitorUserOptListController method getOperateTypeList.

/**
 * 操作监控类型列表
 *
 * @return json
 */
@RequestMapping(value = "type_data", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.LIST)
public String getOperateTypeList() {
    JSONObject jsonObject = new JSONObject();
    // 
    List<JSONObject> classFeatureList = Arrays.stream(ClassFeature.values()).filter(classFeature -> classFeature != ClassFeature.NULL).map(classFeature -> {
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("title", classFeature.getName());
        jsonObject1.put("value", classFeature.name());
        return jsonObject1;
    }).collect(Collectors.toList());
    jsonObject.put("classFeature", classFeatureList);
    // 
    List<JSONObject> methodFeatureList = Arrays.stream(MethodFeature.values()).filter(methodFeature -> methodFeature != MethodFeature.NULL && methodFeature != MethodFeature.LIST).map(classFeature -> {
        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("title", classFeature.getName());
        jsonObject1.put("value", classFeature.name());
        return jsonObject1;
    }).collect(Collectors.toList());
    jsonObject.put("methodFeature", methodFeatureList);
    return JsonMessage.getString(200, "success", jsonObject);
}
Also used : PageResultDto(io.jpom.model.PageResultDto) Arrays(java.util.Arrays) ClassFeature(io.jpom.permission.ClassFeature) MediaType(org.springframework.http.MediaType) EnumUtil(cn.hutool.core.util.EnumUtil) RequestMapping(org.springframework.web.bind.annotation.RequestMapping) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) RestController(org.springframework.web.bind.annotation.RestController) Collectors(java.util.stream.Collectors) Feature(io.jpom.permission.Feature) Objects(java.util.Objects) JsonMessage(cn.jiangzeyin.common.JsonMessage) JSONArray(com.alibaba.fastjson.JSONArray) StrUtil(cn.hutool.core.util.StrUtil) ValidatorRule(cn.jiangzeyin.common.validator.ValidatorRule) List(java.util.List) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) MonitorUserOptService(io.jpom.service.monitor.MonitorUserOptService) ValidatorItem(cn.jiangzeyin.common.validator.ValidatorItem) Convert(cn.hutool.core.convert.Convert) JSONObject(com.alibaba.fastjson.JSONObject) MethodFeature(io.jpom.permission.MethodFeature) BaseServerController(io.jpom.common.BaseServerController) Assert(org.springframework.util.Assert) JSONObject(com.alibaba.fastjson.JSONObject) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Example 5 with MethodFeature

use of io.jpom.permission.MethodFeature in project Jpom by dromara.

the class MonitorUserOptListController method updateMonitor.

/**
 * 增加或修改监控
 *
 * @param id         id
 * @param name       name
 * @param notifyUser user
 * @return json
 */
@RequestMapping(value = "update", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
@Feature(method = MethodFeature.EDIT)
public String updateMonitor(String id, @ValidatorItem(value = ValidatorRule.NOT_BLANK, msg = "监控名称不能为空") String name, String notifyUser, String monitorUser, String monitorOpt, String monitorFeature) {
    String status = getParameter("status");
    JSONArray jsonArray = JSONArray.parseArray(notifyUser);
    List<String> notifyUsers = jsonArray.toJavaList(String.class).stream().filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(notifyUsers, "请选择报警联系人");
    JSONArray monitorUserArray = JSONArray.parseArray(monitorUser);
    List<String> monitorUserArrays = monitorUserArray.toJavaList(String.class).stream().filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorUserArrays, "请选择监控人员");
    JSONArray monitorOptArray = JSONArray.parseArray(monitorOpt);
    List<MethodFeature> monitorOptArrays = monitorOptArray.stream().map(o -> EnumUtil.fromString(MethodFeature.class, StrUtil.toString(o), null)).filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorOptArrays, "请选择监控的操作");
    JSONArray monitorFeatureArray = JSONArray.parseArray(monitorFeature);
    List<ClassFeature> monitorFeatureArrays = monitorFeatureArray.stream().map(o -> EnumUtil.fromString(ClassFeature.class, StrUtil.toString(o), null)).filter(Objects::nonNull).collect(Collectors.toList());
    Assert.notEmpty(monitorFeatureArrays, "请选择监控的功能");
    boolean start = "on".equalsIgnoreCase(status);
    MonitorUserOptModel monitorModel = monitorUserOptService.getByKey(id);
    if (monitorModel == null) {
        monitorModel = new MonitorUserOptModel();
    }
    monitorModel.monitorUser(monitorUserArrays);
    monitorModel.setStatus(start);
    monitorModel.monitorOpt(monitorOptArrays);
    monitorModel.monitorFeature(monitorFeatureArrays);
    monitorModel.notifyUser(notifyUsers);
    monitorModel.setName(name);
    if (StrUtil.isEmpty(id)) {
        // 添加监控
        monitorUserOptService.insert(monitorModel);
        return JsonMessage.getString(200, "添加成功");
    }
    monitorUserOptService.update(monitorModel);
    return JsonMessage.getString(200, "修改成功");
}
Also used : ClassFeature(io.jpom.permission.ClassFeature) MethodFeature(io.jpom.permission.MethodFeature) JSONArray(com.alibaba.fastjson.JSONArray) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel) ClassFeature(io.jpom.permission.ClassFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) RequestMapping(org.springframework.web.bind.annotation.RequestMapping)

Aggregations

MethodFeature (io.jpom.permission.MethodFeature)9 ClassFeature (io.jpom.permission.ClassFeature)7 Feature (io.jpom.permission.Feature)6 MonitorUserOptModel (io.jpom.model.data.MonitorUserOptModel)4 UserModel (io.jpom.model.data.UserModel)4 StrUtil (cn.hutool.core.util.StrUtil)3 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 JSONArray (com.alibaba.fastjson.JSONArray)2 JSONObject (com.alibaba.fastjson.JSONObject)2 WorkspaceModel (io.jpom.model.data.WorkspaceModel)2 Service (org.springframework.stereotype.Service)2 Assert (org.springframework.util.Assert)2 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)2 CollUtil (cn.hutool.core.collection.CollUtil)1 Convert (cn.hutool.core.convert.Convert)1 EnumUtil (cn.hutool.core.util.EnumUtil)1 Entity (cn.hutool.db.Entity)1 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 ValidatorItem (cn.jiangzeyin.common.validator.ValidatorItem)1