use of org.springframework.web.bind.annotation.RequestMethod in project disconf by knightliao.
the class RoleResourceMgrImpl method getAllAsMap.
/**
* @return
*/
@Override
@Cacheable(value = "${role_res_cache_name}")
public Map<String, Map<RequestMethod, List<Integer>>> getAllAsMap() {
Map<String, Map<RequestMethod, List<Integer>>> infoMap = new HashMap<String, Map<RequestMethod, List<Integer>>>();
LOG.info("Querying role_resource table to get all...");
List<RoleResource> roleResList = roleResDao.findAll();
// 遍历列表,把数据按<url, <method, List<roleId>>>的形式加到infoMap
for (RoleResource roleRes : roleResList) {
String urlPattern = roleRes.getUrlPattern();
if (!urlPattern.endsWith(RoleResourceConstant.URL_SPLITOR)) {
urlPattern += RoleResourceConstant.URL_SPLITOR;
}
// LOG.info(urlPattern);
Map<RequestMethod, List<Integer>> value = infoMap.get(urlPattern);
if (value == null) {
value = new HashMap<RequestMethod, List<Integer>>();
infoMap.put(urlPattern, value);
}
updateMethodMap(value, roleRes.getRoleId(), roleRes.getMethodMask());
}
return infoMap;
}
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;
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMapping method initCorsConfiguration.
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
Class<?> beanType = handlerMethod.getBeanType();
CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
if (typeAnnotation == null && methodAnnotation == null) {
return null;
}
CorsConfiguration config = new CorsConfiguration();
updateCorsConfig(config, typeAnnotation);
updateCorsConfig(config, methodAnnotation);
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
return config.applyPermitDefaultValues();
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMapping method initCorsConfiguration.
@Override
protected CorsConfiguration initCorsConfiguration(Object handler, Method method, RequestMappingInfo mappingInfo) {
HandlerMethod handlerMethod = createHandlerMethod(handler, method);
Class<?> beanType = handlerMethod.getBeanType();
CrossOrigin typeAnnotation = AnnotatedElementUtils.findMergedAnnotation(beanType, CrossOrigin.class);
CrossOrigin methodAnnotation = AnnotatedElementUtils.findMergedAnnotation(method, CrossOrigin.class);
if (typeAnnotation == null && methodAnnotation == null) {
return null;
}
CorsConfiguration config = new CorsConfiguration();
updateCorsConfig(config, typeAnnotation);
updateCorsConfig(config, methodAnnotation);
if (CollectionUtils.isEmpty(config.getAllowedMethods())) {
for (RequestMethod allowedMethod : mappingInfo.getMethodsCondition().getMethods()) {
config.addAllowedMethod(allowedMethod.name());
}
}
return config.applyPermitDefaultValues();
}
use of org.springframework.web.bind.annotation.RequestMethod in project spring-framework by spring-projects.
the class RequestMappingHandlerMappingTests method assertComposedAnnotationMapping.
private RequestMappingInfo assertComposedAnnotationMapping(String methodName, String path, RequestMethod requestMethod) throws Exception {
Class<?> clazz = ComposedAnnotationController.class;
Method method = clazz.getMethod(methodName);
RequestMappingInfo info = this.handlerMapping.getMappingForMethod(method, clazz);
assertNotNull(info);
Set<String> paths = info.getPatternsCondition().getPatterns();
assertEquals(1, paths.size());
assertEquals(path, paths.iterator().next());
Set<RequestMethod> methods = info.getMethodsCondition().getMethods();
assertEquals(1, methods.size());
assertEquals(requestMethod, methods.iterator().next());
return info;
}
Aggregations