Examples of MockFilterChain


Examples of org.springframework.mock.web.MockFilterChain

    @Test(expected=PreAuthenticatedCredentialsNotFoundException.class)
    public void missingHeaderCausesException() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();
        RequestHeaderAuthenticationFilter filter = new RequestHeaderAuthenticationFilter();
        filter.setAuthenticationManager(createAuthenticationManager());

        filter.doFilter(request, response, chain);
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    @Test
    public void missingHeaderIsIgnoredIfExceptionIfHeaderMissingIsFalse() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        MockHttpServletResponse response = new MockHttpServletResponse();
        MockFilterChain chain = new MockFilterChain();
        RequestHeaderAuthenticationFilter filter = new RequestHeaderAuthenticationFilter();
        filter.setExceptionIfHeaderMissing(false);
        filter.setAuthenticationManager(createAuthenticationManager());
        filter.doFilter(request, response, chain);
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

        MockHttpServletRequest request = new MockHttpServletRequest("POST", "/destination");
        MockHttpServletResponse response = new MockHttpServletResponse();
        cache.saveRequest(request, response);
        assertNotNull(request.getSession().getAttribute(HttpSessionRequestCache.SAVED_REQUEST));

        filter.doFilter(request, response, new MockFilterChain());
        assertNull(request.getSession().getAttribute(HttpSessionRequestCache.SAVED_REQUEST));
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("oldUser", "pass","ROLE_USER"));
        ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
        filter.principal = null;
        filter.setCheckForPrincipalChanges(true);

        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());

        assertEquals(null, SecurityContextHolder.getContext().getAuthentication());
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

        TestingAuthenticationToken authentication = new TestingAuthenticationToken("oldUser", "pass","ROLE_USER");
        SecurityContextHolder.getContext().setAuthentication(authentication);
        ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
        filter.principal = null;

        filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), new MockFilterChain());

        assertEquals(authentication, SecurityContextHolder.getContext().getAuthentication());
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    }

    private void testDoFilter(boolean grantAccess) throws Exception {
        MockHttpServletRequest req = new MockHttpServletRequest();
        MockHttpServletResponse res = new MockHttpServletResponse();
        getFilter(grantAccess).doFilter(req,res,new MockFilterChain());
        assertEquals(grantAccess, null != SecurityContextHolder.getContext().getAuthentication());
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    }

    private void runWithStack(FilterChainProxy stack) throws Exception {
        for(int i = 0; i < N_INVOCATIONS; i++) {
            MockHttpServletRequest request = createRequest("/somefile.html");
            stack.doFilter(request, new MockHttpServletResponse(), new MockFilterChain());
            session = request.getSession();
        }
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    public void requestThatIsMatchedByDefaultInterceptorIsAllowed() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setServletPath("/somefile.html");
        request.setSession(createAuthenticatedSession("ROLE_0", "ROLE_1", "ROLE_2"));
        MockHttpServletResponse response = new MockHttpServletResponse();
        fcp.doFilter(request, response, new MockFilterChain());
        assertEquals(200, response.getStatus());
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    public void securedUrlAccessIsRejectedWithoutRequiredRole() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setServletPath("/secure/somefile.html");
        request.setSession(createAuthenticatedSession("ROLE_0"));
        MockHttpServletResponse response = new MockHttpServletResponse();
        fcp.doFilter(request, response, new MockFilterChain());
        assertEquals(403, response.getStatus());
    }
View Full Code Here

Examples of org.springframework.mock.web.MockFilterChain

    public void securedFilterChainCannotBeBypassedByAddingPathParameters() throws Exception {
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setPathInfo("/secured;x=y/admin.html");
        request.setSession(createAuthenticatedSession("ROLE_USER"));
        MockHttpServletResponse response = new MockHttpServletResponse();
        fcp.doFilter(request, response, new MockFilterChain());
        assertEquals(403, response.getStatus());
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.