Search in sources :

Example 6 with ClassFeature

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

the class DbUserOperateLogService method buildDataMsg.

/**
 * 根据 数据ID 和 节点ID 查询相关数据名称
 *
 * @param classFeature 功能
 * @param dataId       数据ID
 * @param nodeId       节点ID
 * @return map
 */
public Map<String, Object> buildDataMsg(ClassFeature classFeature, String dataId, String nodeId) {
    if (classFeature == null) {
        return null;
    }
    Class<? extends BaseDbService<?>> dbService = classFeature.getDbService();
    if (dbService == null) {
        return null;
    }
    Map<String, Object> map = new LinkedHashMap<>();
    map.put("数据id", dataId);
    BaseDbService<?> baseDbCommonService = SpringUtil.getBean(dbService);
    Object data = baseDbCommonService.getData(nodeId, dataId);
    map.put("数据名称", this.tryGetBeanName(data));
    // 
    map.put("节点id", nodeId);
    ClassFeature parent = classFeature.getParent();
    if (parent == ClassFeature.NODE) {
        Class<? extends BaseDbService<?>> dbServiceParent = parent.getDbService();
        BaseDbService<?> baseDbCommonServiceParent = SpringUtil.getBean(dbServiceParent);
        Object dataParent = baseDbCommonServiceParent.getData(nodeId, dataId);
        map.put("节点名称", this.tryGetBeanName(dataParent));
    }
    return map;
}
Also used : ClassFeature(io.jpom.permission.ClassFeature) LinkedHashMap(java.util.LinkedHashMap)

Example 7 with ClassFeature

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

the class DbUserOperateLogService method checkMonitor.

/**
 * 判断当前操作是否需要报警
 *
 * @param userOperateLogV1 操作信息
 * @param cacheInfo        操作缓存相关
 */
private void checkMonitor(UserOperateLogV1 userOperateLogV1, OperateLogController.CacheInfo cacheInfo) {
    ClassFeature classFeature = EnumUtil.fromString(ClassFeature.class, userOperateLogV1.getClassFeature(), null);
    MethodFeature methodFeature = EnumUtil.fromString(MethodFeature.class, userOperateLogV1.getMethodFeature(), null);
    UserModel optUserItem = userService.getByKey(userOperateLogV1.getUserId());
    if (classFeature == null || methodFeature == null || optUserItem == null) {
        return;
    }
    Map<String, Object> dataMap = this.buildDataMsg(classFeature, cacheInfo, userOperateLogV1);
    WorkspaceModel workspaceModel = workspaceService.getByKey(userOperateLogV1.getWorkspaceId());
    String optTypeMsg = StrUtil.format(" 【{}】->【{}】", classFeature.getName(), methodFeature.getName());
    List<MonitorUserOptModel> monitorUserOptModels = monitorUserOptService.listByType(userOperateLogV1.getWorkspaceId(), classFeature, methodFeature, userOperateLogV1.getUserId());
    if (CollUtil.isEmpty(monitorUserOptModels)) {
        return;
    }
    String context = this.buildContent(optUserItem, dataMap, workspaceModel, optTypeMsg, userOperateLogV1);
    for (MonitorUserOptModel monitorUserOptModel : monitorUserOptModels) {
        List<String> notifyUser = monitorUserOptModel.notifyUser();
        if (CollUtil.isEmpty(notifyUser)) {
            continue;
        }
        for (String userId : notifyUser) {
            UserModel item = userService.getByKey(userId);
            if (item == null) {
                continue;
            }
            // 邮箱
            String email = item.getEmail();
            if (StrUtil.isNotEmpty(email)) {
                MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.mail, email);
                ThreadUtil.execute(() -> {
                    try {
                        NotifyUtil.send(notify1, "用户操作报警", context);
                    } catch (Exception e) {
                        DefaultSystemLog.getLog().error("发送报警信息错误", e);
                    }
                });
            }
            // dingding
            String dingDing = item.getDingDing();
            if (StrUtil.isNotEmpty(dingDing)) {
                MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.dingding, dingDing);
                ThreadUtil.execute(() -> {
                    try {
                        NotifyUtil.send(notify1, "用户操作报警", context);
                    } catch (Exception e) {
                        DefaultSystemLog.getLog().error("发送报警信息错误", e);
                    }
                });
            }
            // 企业微信
            String workWx = item.getWorkWx();
            if (StrUtil.isNotEmpty(workWx)) {
                MonitorModel.Notify notify1 = new MonitorModel.Notify(MonitorModel.NotifyType.workWx, workWx);
                ThreadUtil.execute(() -> {
                    try {
                        NotifyUtil.send(notify1, "用户操作报警", context);
                    } catch (Exception e) {
                        DefaultSystemLog.getLog().error("发送报警信息错误", e);
                    }
                });
            }
        }
    }
}
Also used : WorkspaceModel(io.jpom.model.data.WorkspaceModel) MonitorModel(io.jpom.model.data.MonitorModel) MethodFeature(io.jpom.permission.MethodFeature) UserModel(io.jpom.model.data.UserModel) ClassFeature(io.jpom.permission.ClassFeature) MonitorUserOptModel(io.jpom.model.data.MonitorUserOptModel)

Example 8 with ClassFeature

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

the class OperateLogController method createCacheInfo.

private CacheInfo createCacheInfo(Method method) {
    Feature feature = method.getAnnotation(Feature.class);
    if (feature == null) {
        return null;
    }
    Class<?> declaringClass = method.getDeclaringClass();
    MethodFeature methodFeature = feature.method();
    if (methodFeature == MethodFeature.NULL) {
        DefaultSystemLog.getLog().error("权限分发配置错误:{}  {}", declaringClass, method.getName());
        return null;
    }
    ClassFeature classFeature = feature.cls();
    if (classFeature == ClassFeature.NULL) {
        Feature feature1 = declaringClass.getAnnotation(Feature.class);
        if (feature1 == null || feature1.cls() == ClassFeature.NULL) {
            DefaultSystemLog.getLog().error("权限分发配置错误:{}  {} class not find", declaringClass, method.getName());
            return null;
        }
        classFeature = feature1.cls();
    }
    CacheInfo cacheInfo = new CacheInfo();
    cacheInfo.setClassFeature(classFeature);
    cacheInfo.setMethodFeature(methodFeature);
    cacheInfo.setOptTime(SystemClock.now());
    cacheInfo.setResultCode(feature.resultCode());
    cacheInfo.setLogResponse(feature.logResponse());
    // 
    if (dbUserOperateLogService == null) {
        dbUserOperateLogService = SpringUtil.getBean(DbUserOperateLogService.class);
    }
    return cacheInfo;
}
Also used : ClassFeature(io.jpom.permission.ClassFeature) DbUserOperateLogService(io.jpom.service.dblog.DbUserOperateLogService) MethodFeature(io.jpom.permission.MethodFeature) Feature(io.jpom.permission.Feature) MethodFeature(io.jpom.permission.MethodFeature) ClassFeature(io.jpom.permission.ClassFeature)

Aggregations

ClassFeature (io.jpom.permission.ClassFeature)8 MethodFeature (io.jpom.permission.MethodFeature)7 Feature (io.jpom.permission.Feature)5 MonitorUserOptModel (io.jpom.model.data.MonitorUserOptModel)4 StrUtil (cn.hutool.core.util.StrUtil)2 JSONArray (com.alibaba.fastjson.JSONArray)2 UserModel (io.jpom.model.data.UserModel)2 List (java.util.List)2 Collectors (java.util.stream.Collectors)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 JsonMessage (cn.jiangzeyin.common.JsonMessage)1 ValidatorItem (cn.jiangzeyin.common.validator.ValidatorItem)1 ValidatorRule (cn.jiangzeyin.common.validator.ValidatorRule)1 JSONObject (com.alibaba.fastjson.JSONObject)1 BaseServerController (io.jpom.common.BaseServerController)1 PageResultDto (io.jpom.model.PageResultDto)1 MonitorModel (io.jpom.model.data.MonitorModel)1