Search in sources :

Example 11 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kms by mahonelau.

the class PermissionDataAspect method arround.

@Around("pointCut()")
public Object arround(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
    MethodSignature signature = (MethodSignature) point.getSignature();
    Method method = signature.getMethod();
    PermissionData pd = method.getAnnotation(PermissionData.class);
    String component = pd.pageComponent();
    String requestMethod = request.getMethod();
    String requestPath = request.getRequestURI().substring(request.getContextPath().length());
    requestPath = filterUrl(requestPath);
    log.debug("拦截请求 >> " + requestPath + ";请求类型 >> " + requestMethod);
    String username = JwtUtil.getUserNameByToken(request);
    // 查询数据权限信息
    // TODO 微服务情况下也得支持缓存机制
    List<SysPermissionDataRuleModel> dataRules = commonAPI.queryPermissionDataRule(component, requestPath, username);
    if (dataRules != null && dataRules.size() > 0) {
        // 临时存储
        JeecgDataAutorUtils.installDataSearchConditon(request, dataRules);
        // TODO 微服务情况下也得支持缓存机制
        SysUserCacheInfo userinfo = commonAPI.getCacheUser(username);
        JeecgDataAutorUtils.installUserInfo(request, userinfo);
    }
    return point.proceed();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) MethodSignature(org.aspectj.lang.reflect.MethodSignature) SysUserCacheInfo(org.jeecg.common.system.vo.SysUserCacheInfo) Method(java.lang.reflect.Method) PermissionData(org.jeecg.common.aspect.annotation.PermissionData) Around(org.aspectj.lang.annotation.Around)

Example 12 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project jeecg-boot by jeecgboot.

the class PermissionDataAspect method arround.

@Around("pointCut()")
public Object arround(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
    MethodSignature signature = (MethodSignature) point.getSignature();
    Method method = signature.getMethod();
    PermissionData pd = method.getAnnotation(PermissionData.class);
    String component = pd.pageComponent();
    String requestMethod = request.getMethod();
    String requestPath = request.getRequestURI().substring(request.getContextPath().length());
    requestPath = filterUrl(requestPath);
    // TODO 参数顺序调整有隐患
    if (requestPath.indexOf(UrlMatchEnum.CGREPORT_DATA.getMatch_url()) >= 0) {
        // 获取地址栏参数
        String urlParamString = request.getParameter(CommonConstant.ONL_REP_URL_PARAM_STR);
        if (oConvertUtils.isNotEmpty(urlParamString)) {
            requestPath += "?" + urlParamString;
        }
    }
    // update-end-author:taoyan date:20211027 for:JTC-132【online报表权限】online报表带参数的菜单配置数据权限无效
    log.info("拦截请求 >> {} ; 请求类型 >> {} . ", requestPath, requestMethod);
    String username = JwtUtil.getUserNameByToken(request);
    // 查询数据权限信息
    // TODO 微服务情况下也得支持缓存机制
    List<SysPermissionDataRuleModel> dataRules = commonAPI.queryPermissionDataRule(component, requestPath, username);
    if (dataRules != null && dataRules.size() > 0) {
        // 临时存储
        JeecgDataAutorUtils.installDataSearchConditon(request, dataRules);
        // TODO 微服务情况下也得支持缓存机制
        SysUserCacheInfo userinfo = commonAPI.getCacheUser(username);
        JeecgDataAutorUtils.installUserInfo(request, userinfo);
    }
    return point.proceed();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) MethodSignature(org.aspectj.lang.reflect.MethodSignature) SysUserCacheInfo(org.jeecg.common.system.vo.SysUserCacheInfo) Method(java.lang.reflect.Method) PermissionData(org.jeecg.common.aspect.annotation.PermissionData) Around(org.aspectj.lang.annotation.Around)

Example 13 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project jeecg-boot by jeecgboot.

the class QueryGenerator method installAuthJdbc.

/**
 *   根据权限相关配置生成相关的SQL 语句
 * @param clazz
 * @return
 */
@SuppressWarnings({ "unchecked", "rawtypes" })
public static String installAuthJdbc(Class<?> clazz) {
    StringBuffer sb = new StringBuffer();
    // 权限查询
    Map<String, SysPermissionDataRuleModel> ruleMap = getRuleMap();
    PropertyDescriptor[] origDescriptors = PropertyUtils.getPropertyDescriptors(clazz);
    String sql_and = " and ";
    for (String c : ruleMap.keySet()) {
        if (oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)) {
            sb.append(sql_and + getSqlRuleValue(ruleMap.get(c).getRuleValue()));
        }
    }
    String name, column;
    for (int i = 0; i < origDescriptors.length; i++) {
        name = origDescriptors[i].getName();
        if (judgedIsUselessField(name)) {
            continue;
        }
        if (ruleMap.containsKey(name)) {
            column = getTableFieldName(clazz, name);
            if (column == null) {
                continue;
            }
            SysPermissionDataRuleModel dataRule = ruleMap.get(name);
            QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
            Class propType = origDescriptors[i].getPropertyType();
            boolean isString = propType.equals(String.class);
            Object value;
            if (isString) {
                value = converRuleValue(dataRule.getRuleValue());
            } else {
                value = NumberUtils.parseNumber(dataRule.getRuleValue(), propType);
            }
            String filedSql = getSingleSqlByRule(rule, oConvertUtils.camelToUnderline(column), value, isString);
            sb.append(sql_and + filedSql);
        }
    }
    log.info("query auth sql is:" + sb.toString());
    return sb.toString();
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) PropertyDescriptor(java.beans.PropertyDescriptor)

Example 14 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project jeecg-boot by jeecgboot.

the class QueryGenerator method getAllConfigAuth.

/**
 * 获取所有配置的权限 返回sql字符串 不受字段限制 配置什么就拿到什么
 * @return
 */
public static String getAllConfigAuth() {
    StringBuffer sb = new StringBuffer();
    // 权限查询
    Map<String, SysPermissionDataRuleModel> ruleMap = getRuleMap();
    String sql_and = " and ";
    for (String c : ruleMap.keySet()) {
        SysPermissionDataRuleModel dataRule = ruleMap.get(c);
        String ruleValue = dataRule.getRuleValue();
        if (oConvertUtils.isEmpty(ruleValue)) {
            continue;
        }
        if (oConvertUtils.isNotEmpty(c) && c.startsWith(SQL_RULES_COLUMN)) {
            sb.append(sql_and + getSqlRuleValue(ruleValue));
        } else {
            boolean isString = false;
            ruleValue = ruleValue.trim();
            if (ruleValue.startsWith("'") && ruleValue.endsWith("'")) {
                isString = true;
                ruleValue = ruleValue.substring(1, ruleValue.length() - 1);
            }
            QueryRuleEnum rule = QueryRuleEnum.getByValue(dataRule.getRuleConditions());
            String value = converRuleValue(ruleValue);
            String filedSql = getSingleSqlByRule(rule, c, value, isString);
            sb.append(sql_and + filedSql);
        }
    }
    log.info("query auth sql is = " + sb.toString());
    return sb.toString();
}
Also used : SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel)

Example 15 with SysPermissionDataRuleModel

use of org.jeecg.common.system.vo.SysPermissionDataRuleModel in project kykms by mahonelau.

the class PermissionDataAspect method arround.

@Around("pointCut()")
public Object arround(ProceedingJoinPoint point) throws Throwable {
    HttpServletRequest request = SpringContextUtils.getHttpServletRequest();
    MethodSignature signature = (MethodSignature) point.getSignature();
    Method method = signature.getMethod();
    PermissionData pd = method.getAnnotation(PermissionData.class);
    String component = pd.pageComponent();
    String requestMethod = request.getMethod();
    String requestPath = request.getRequestURI().substring(request.getContextPath().length());
    requestPath = filterUrl(requestPath);
    log.debug("拦截请求 >> " + requestPath + ";请求类型 >> " + requestMethod);
    String username = JwtUtil.getUserNameByToken(request);
    // 查询数据权限信息
    // TODO 微服务情况下也得支持缓存机制
    List<SysPermissionDataRuleModel> dataRules = commonAPI.queryPermissionDataRule(component, requestPath, username);
    if (dataRules != null && dataRules.size() > 0) {
        // 临时存储
        JeecgDataAutorUtils.installDataSearchConditon(request, dataRules);
        // TODO 微服务情况下也得支持缓存机制
        SysUserCacheInfo userinfo = commonAPI.getCacheUser(username);
        JeecgDataAutorUtils.installUserInfo(request, userinfo);
    }
    return point.proceed();
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SysPermissionDataRuleModel(org.jeecg.common.system.vo.SysPermissionDataRuleModel) MethodSignature(org.aspectj.lang.reflect.MethodSignature) SysUserCacheInfo(org.jeecg.common.system.vo.SysUserCacheInfo) Method(java.lang.reflect.Method) PermissionData(org.jeecg.common.aspect.annotation.PermissionData) Around(org.aspectj.lang.annotation.Around)

Aggregations

SysPermissionDataRuleModel (org.jeecg.common.system.vo.SysPermissionDataRuleModel)17 PropertyDescriptor (java.beans.PropertyDescriptor)3 Method (java.lang.reflect.Method)3 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)3 Around (org.aspectj.lang.annotation.Around)3 MethodSignature (org.aspectj.lang.reflect.MethodSignature)3 PermissionData (org.jeecg.common.aspect.annotation.PermissionData)3 SysUserCacheInfo (org.jeecg.common.system.vo.SysUserCacheInfo)3