Package org.springframework.security.web.access.expression

Examples of org.springframework.security.web.access.expression.WebSecurityExpressionRoot


    public void ipAddressMatchesForEqualIpAddresses() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/test");
        // IPv4
        request.setRemoteAddr("192.168.1.1");
        WebSecurityExpressionRoot root = new WebSecurityExpressionRoot(mock(Authentication.class),
                new FilterInvocation(request, mock(HttpServletResponse.class), mock(FilterChain.class)));

        assertTrue(root.hasIpAddress("192.168.1.1"));

        // IPv6 Address
        request.setRemoteAddr("fa:db8:85a3::8a2e:370:7334");
        assertTrue(root.hasIpAddress("fa:db8:85a3::8a2e:370:7334"));
    }
View Full Code Here


    @Test
    public void addressesInIpRangeMatch() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setRequestURI("/test");
        WebSecurityExpressionRoot root = new WebSecurityExpressionRoot(mock(Authentication.class),
                new FilterInvocation(request, mock(HttpServletResponse.class), mock(FilterChain.class)));
        for (int i=0; i < 255; i++) {
            request.setRemoteAddr("192.168.1." + i);
            assertTrue(root.hasIpAddress("192.168.1.0/24"));
        }

        request.setRemoteAddr("192.168.1.127");
        // 25 = FF FF FF 80
        assertTrue(root.hasIpAddress("192.168.1.0/25"));
        // encroach on the mask
        request.setRemoteAddr("192.168.1.128");
        assertFalse(root.hasIpAddress("192.168.1.0/25"));
        request.setRemoteAddr("192.168.1.255");
        assertTrue(root.hasIpAddress("192.168.1.128/25"));
        assertTrue(root.hasIpAddress("192.168.1.192/26"));
        assertTrue(root.hasIpAddress("192.168.1.224/27"));
        assertTrue(root.hasIpAddress("192.168.1.240/27"));
        assertTrue(root.hasIpAddress("192.168.1.255/32"));

        request.setRemoteAddr("202.24.199.127");
        assertTrue(root.hasIpAddress("202.24.0.0/14"));
        request.setRemoteAddr("202.25.179.135");
        assertTrue(root.hasIpAddress("202.24.0.0/14"));
        request.setRemoteAddr("202.26.179.135");
        assertTrue(root.hasIpAddress("202.24.0.0/14"));
    }
View Full Code Here

        static class CustomExpressionHandler extends DefaultWebSecurityExpressionHandler {

            @Override
            protected SecurityExpressionOperations createSecurityExpressionRoot(
                    Authentication authentication, FilterInvocation fi) {
                WebSecurityExpressionRoot root = new CustomExpressionRoot(authentication, fi);
                root.setPermissionEvaluator(getPermissionEvaluator());
                root.setTrustResolver(new AuthenticationTrustResolverImpl());
                root.setRoleHierarchy(getRoleHierarchy());
                return root;
            }
View Full Code Here

public abstract class LogigearWebSecurityExpressionHandler<ER extends WebSecurityExpressionRoot> extends AbstractSecurityExpressionHandler<FilterInvocation> {

    @Override
    protected SecurityExpressionOperations createSecurityExpressionRoot(Authentication authentication, FilterInvocation invocation) {
        WebSecurityExpressionRoot root = getExpressionRootInstance(authentication, invocation);
        root.setPermissionEvaluator(getPermissionEvaluator());
        root.setTrustResolver(new AuthenticationTrustResolverImpl());
        return root;
    }
View Full Code Here

      });

      Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
      if (authentication != null)
      {
        WebSecurityExpressionRoot sec = new WebSecurityExpressionRoot(authentication, filterInvocation);
        sec.setTrustResolver(new AuthenticationTrustResolverImpl());
        modelAndView.getModel().put("sec", sec);
      }
    }
  }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.access.expression.WebSecurityExpressionRoot

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.