Search in sources :

Example 26 with RequestMethod

use of org.springframework.web.bind.annotation.RequestMethod in project disconf by knightliao.

the class RoleResourceMgrImpl method checkUserPermission.

/**
 * @param pattern
 * @param method
 *
 * @return
 */
@Override
public boolean checkUserPermission(String pattern, RequestMethod method) {
    // 获取用户角色
    Visitor visitor = ThreadContext.getSessionVisitor();
    if (visitor == null) {
        return false;
    }
    String urlPattarn = pattern;
    if (!urlPattarn.endsWith(RoleResourceConstant.URL_SPLITOR)) {
        urlPattarn += RoleResourceConstant.URL_SPLITOR;
    }
    Integer roleId = visitor.getRoleId();
    Map<String, Map<RequestMethod, List<Integer>>> roleResMap = getAllAsMap();
    Map<RequestMethod, List<Integer>> methodMap = roleResMap.get(urlPattarn);
    if (methodMap == null) {
        return false;
    }
    List<Integer> roleIdList = methodMap.get(method);
    if (roleIdList == null) {
        return false;
    }
    if (!roleIdList.contains(roleId)) {
        return false;
    }
    return true;
}
Also used : Visitor(com.baidu.disconf.web.service.user.dto.Visitor) RequestMethod(org.springframework.web.bind.annotation.RequestMethod) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map)

Aggregations

RequestMethod (org.springframework.web.bind.annotation.RequestMethod)26 HandlerMethod (org.springframework.web.method.HandlerMethod)6 RequestMappingInfo (org.springframework.web.servlet.mvc.method.RequestMappingInfo)6 Method (java.lang.reflect.Method)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 ArrayList (java.util.ArrayList)4 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 Visitor (com.baidu.disconf.web.service.user.dto.Visitor)2 ApiParamObject (com.terran4j.commons.api2doc.domain.ApiParamObject)2 ValueSource (com.terran4j.commons.util.value.ValueSource)2 LinkedHashMap (java.util.LinkedHashMap)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 CrossOrigin (org.springframework.web.bind.annotation.CrossOrigin)2 CorsConfiguration (org.springframework.web.cors.CorsConfiguration)2 Application (cn.edu.zjnu.acm.judge.Application)1 MatcherWrapper (cn.edu.zjnu.acm.judge.util.MatcherWrapper)1 RoleResource (com.baidu.disconf.web.service.roleres.bo.RoleResource)1