1 package com.supwisdom.institute.backend.admin.bff.security.web.access.intercept;
3 import java.util.ArrayList;
4 import java.util.Collection;
5 import java.util.Iterator;
6 import java.util.LinkedHashMap;
9 import javax.servlet.http.HttpServletRequest;
11 import org.springframework.security.access.ConfigAttribute;
12 import org.springframework.security.access.SecurityConfig;
13 import org.springframework.security.web.FilterInvocation;
14 import org.springframework.security.web.access.intercept.FilterInvocationSecurityMetadataSource;
15 import org.springframework.security.web.util.matcher.AntPathRequestMatcher;
16 import org.springframework.security.web.util.matcher.RequestMatcher;
18 public class InMemeryFilterInvocationSecurityMetadataSource implements FilterInvocationSecurityMetadataSource {
20 private Map<RequestMatcher, Collection<ConfigAttribute>> requestMap = null;
22 private void loadRequestMap() {
23 if (requestMap == null) {
24 requestMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();
26 AntPathRequestMatcher requestMatcher0 = new AntPathRequestMatcher("/api/**");
27 Collection<ConfigAttribute> attributes0 = new ArrayList<ConfigAttribute>(); // FIXME: 返回当前请求的url 对应的 角色代码
28 attributes0.add(new SecurityConfig("user"));
29 requestMap.put(requestMatcher0, attributes0);
32 AntPathRequestMatcher requestMatcher = new AntPathRequestMatcher("/web/**");
33 Collection<ConfigAttribute> attributes = new ArrayList<ConfigAttribute>(); // FIXME: 返回当前请求的url 对应的 角色代码
34 attributes.add(new SecurityConfig("user"));
35 requestMap.put(requestMatcher, attributes);
40 * 获取当前请求关联的所有角色code {@link SecurityConfig}
44 public Collection<ConfigAttribute> getAttributes(Object object) throws IllegalArgumentException {
46 if (requestMap == null) {
50 HttpServletRequest request = ((FilterInvocation) object).getHttpRequest();
52 RequestMatcher requestMatcher;
53 for(Iterator<RequestMatcher> iter = requestMap.keySet().iterator(); iter.hasNext(); ) {
54 requestMatcher = iter.next();
56 if(requestMatcher.matches(request)) {
57 return requestMap.get(requestMatcher);
65 public Collection<ConfigAttribute> getAllConfigAttributes() {
71 public boolean supports(Class<?> clazz) {