Package org.springframework.security.web.util

Examples of org.springframework.security.web.util.RequestMatcher


     */
    public synchronized void addMapping(final String pattern, final RequestMatcher matcher, final String access, final int position) {
        _baseSource = null;
        final Collection<ConfigAttribute> attributes = createAttributes(matcher, access);

        RequestMatcher requestMatcher = findMatchingRequestMatcher(pattern);
        if(requestMatcher == null) {
            requestMatcher = matcher;
        }
        Collection<ConfigAttribute> allAttributes = _requestMap.get(requestMatcher);
        if (allAttributes == null) {
View Full Code Here


     * @param access the new access permissions
     * @throws IllegalArgumentException thrown in pattern does not find a match
     */
    public synchronized void setMapping(String pattern, final String access) throws IllegalArgumentException {
        _baseSource = null;
        RequestMatcher oldMatcher = findMatchingRequestMatcher(pattern);
        for (Map.Entry<RequestMatcher, Collection<ConfigAttribute>> entry : _requestMap.entrySet()) {
            if(entry.getKey() == oldMatcher) {
                entry.setValue(createAttributes(oldMatcher, access));
                break;
            }
View Full Code Here

        return ms.getAllConfigAttributes();
    }

    public synchronized RequestMatcher removeMapping(String pattern) {
        _baseSource = null;
        RequestMatcher toRemove = findMatchingRequestMatcher(pattern);
        if(toRemove == null) {
            throw new IllegalArgumentException(pattern+" has not been found.");
        } else {
            _requestMap.remove(toRemove);
        }
View Full Code Here

    @Override
    public void handleRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        Map<String, String> urlPatternDispatchMap = (Map<String, String>) getApplicationContext().getBean("blResourceUrlPatternRequestDispatchMap");
        for (Map.Entry<String, String> entry : urlPatternDispatchMap.entrySet()) {
            RequestMatcher matcher = new AntPathRequestMatcher(entry.getKey());
            if (matcher.matches(request)){
                request.getRequestDispatcher(entry.getValue()).forward(request, response);
                return;
            }
        }
        super.handleRequest(request, response);
View Full Code Here

        HttpServletResponse response = (HttpServletResponse) baseResponse;

        boolean excludedRequestFound = false;
        if (excludedRequestPatterns != null && excludedRequestPatterns.size() > 0) {
            for (String pattern : excludedRequestPatterns) {
                RequestMatcher matcher = new AntPathRequestMatcher(pattern);
                if (matcher.matches(request)){
                    excludedRequestFound = true;
                    break;
                }
            }
        }
View Full Code Here

            return false;
        }
       
        if (excludedOrderLockRequestPatterns != null && excludedOrderLockRequestPatterns.size() > 0) {
            for (String pattern : excludedOrderLockRequestPatterns) {
                RequestMatcher matcher = new AntPathRequestMatcher(pattern);
                if (matcher.matches(request)){
                    return false;
                }
            }
        }
View Full Code Here

            throw new IllegalStateException("An incomplete mapping was found for " + unmappedMatchers +". Try completing it with something like requestUrls().<something>.hasRole('USER')");
        }

        LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>> requestMap = new LinkedHashMap<RequestMatcher, Collection<ConfigAttribute>>();
        for (UrlMapping mapping : getUrlMappings()) {
            RequestMatcher matcher = mapping.getRequestMatcher();
            Collection<ConfigAttribute> configAttrs = mapping.getConfigAttrs();
            requestMap.put(matcher,configAttrs);
        }
        return requestMap;
    }
View Full Code Here

        Map<RequestMatcher,List<Filter>> filterChainMap =
                new LinkedHashMap<RequestMatcher,List<Filter>>();

        for (RequestFilterChain chain : filterChain.getRequestChains()) {
            RequestMatcher matcher = matcherForChain(chain);
            List<Filter> filters = new ArrayList<Filter>();
            for (String filterName : chain.getCompiledFilterNames()) {
                try {
                    Filter filter = lookupFilter(filterName);
                    if (filter == null) {
View Full Code Here

    public void testMacher() {
        GeoServerSecurityFilterChainProxy proxy = new GeoServerSecurityFilterChainProxy(getSecurityManager());
       
        // match all
        VariableFilterChain chain =  new ServiceLoginFilterChain("/**");        
        RequestMatcher matcher = proxy.matcherForChain(chain);       
        assertTrue(matcher.matches(createRequest(HTTPMethod.GET, "/wms")));
       
        // set methods, but match is inactvie
        chain =  new ServiceLoginFilterChain("/**");
        chain.getHttpMethods().add(HTTPMethod.GET);
        chain.getHttpMethods().add(HTTPMethod.POST);
        matcher = proxy.matcherForChain(chain);       
        assertTrue(matcher.matches(createRequest(HTTPMethod.GET, "/wms")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.POST, "/wms")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.PUT, "/wms")));

        // active method matching
        chain.setMatchHTTPMethod(true);
        matcher = proxy.matcherForChain(chain);       
        assertTrue(matcher.matches(createRequest(HTTPMethod.GET, "/wms")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.POST, "/wms")));
        assertFalse(matcher.matches(createRequest(HTTPMethod.PUT, "/wms")));
       
        chain =  new ServiceLoginFilterChain("/wfs/**,/web/**");        
        matcher = proxy.matcherForChain(chain);
       
        assertFalse(matcher.matches(createRequest(HTTPMethod.GET, "/wms/abc")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.GET, "/wfs/acc")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.GET, "/web/abc")));

        chain.getHttpMethods().add(HTTPMethod.GET);
        chain.getHttpMethods().add(HTTPMethod.POST);
        matcher = proxy.matcherForChain(chain);

        assertFalse(matcher.matches(createRequest(HTTPMethod.GET, "/wms/abc")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.POST, "/wfs/acc")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.PUT, "/web/abc")));

        chain.setMatchHTTPMethod(true);
        matcher = proxy.matcherForChain(chain);       
       
        assertFalse(matcher.matches(createRequest(HTTPMethod.GET, "/wms/abc")));
        assertTrue(matcher.matches(createRequest(HTTPMethod.POST, "/wfs/acc")));
        assertFalse(matcher.matches(createRequest(HTTPMethod.PUT, "/web/abc")));

    }
View Full Code Here

                Collection<ConfigAttribute> v=new ArrayList<>();
                for(String role : roles){
                    v.add(new SecurityConfig(role));
                }
                //POST
                RequestMatcher key=new AntPathRequestMatcher(url,"POST");
                requestMap.put(key, v);
                //GET
                key=new AntPathRequestMatcher(url,"GET");
                requestMap.put(key, v);
            }
            //格式2:超级管理员 或是 普通管理员都可以访问
            else{
                //POST
                RequestMatcher key=new AntPathRequestMatcher(url,"POST");
                requestMap.put(key, value);
                //GET
                key=new AntPathRequestMatcher(url,"GET");
                requestMap.put(key, value);
            }
        }

       
//2、动态指定系统中模块及命令的url访问规则
        //遍历所有的Command对象
        for(Command command : serviceFacade.query(Command.class).getModels()){
            List<String> paths=ModuleService.getCommandPath(command);
            //命令访问路径到角色名称的映射
            Map<String,String> map=ModuleService.getCommandPathToRole(command);
            for(String path : paths){
                //POST
                RequestMatcher key=new AntPathRequestMatcher(path.toString().toLowerCase()+".action*","POST");
                value=new ArrayList<>();
                //要把路径转换为角色
                //如:命令路径:/**/security/user!query 映射角色:_SECURITY_USER_QUERY
                value.add(new SecurityConfig("ROLE_MANAGER"+map.get(path)));
                value.add(superManager);
                requestMap.put(key, value);
                //GET
                key=new AntPathRequestMatcher(path.toString().toLowerCase()+".action*","GET");
                requestMap.put(key, value);
            }
        }
       
//3、超级管理员对所有的POST操作具有权限
        RequestMatcher key=new AntPathRequestMatcher("/**","POST");
        //value为超级管理员
        value=new ArrayList<>();
        value.add(superManager);
        requestMap.put(key, value);
       
View Full Code Here

TOP

Related Classes of org.springframework.security.web.util.RequestMatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.