Package javax.servlet

Examples of javax.servlet.FilterChain


        SessionManagementFilter filter = new SessionManagementFilter(repo);
        filter.setAuthenticationFailureHandler(failureHandler);
        filter.setSessionAuthenticationStrategy(strategy);
        HttpServletRequest request = new MockHttpServletRequest();
        HttpServletResponse response = new MockHttpServletResponse();
        FilterChain fc = mock(FilterChain.class);
        authenticateUser();
        SessionAuthenticationException exception = new SessionAuthenticationException("Failure");
        doThrow(exception).when(strategy).onAuthentication(
                SecurityContextHolder.getContext().getAuthentication(), request, response);
View Full Code Here


        request.setRequestedSessionId("xxx");
        request.setRequestedSessionIdValid(false);
        SimpleRedirectInvalidSessionStrategy iss = new SimpleRedirectInvalidSessionStrategy("/timedOut");
        iss.setCreateNewSession(true);
        filter.setInvalidSessionStrategy(iss);
        FilterChain fc = mock(FilterChain.class);
        filter.doFilter(request, response, fc);
        verifyZeroInteractions(fc);

        assertEquals("/timedOut", response.getRedirectedUrl());
    }
View Full Code Here

        request.setServerName("www.example.com");
        request.setContextPath("/mycontext");
        request.setRequestURI("/mycontext/secure/page.html");

        // Setup the FilterChain to thrown an access denied exception
        FilterChain fc = mock(FilterChain.class);
        doThrow(new AccessDeniedException("")).when(fc).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));

        // Setup SecurityContextHolder, as filter needs to check if user is
        // anonymous
        SecurityContextHolder.getContext().setAuthentication(
View Full Code Here

        // Setup our HTTP request
        MockHttpServletRequest request = new MockHttpServletRequest();
        request.setServletPath("/secure/page.html");

        // Setup the FilterChain to thrown an access denied exception
        FilterChain fc = mock(FilterChain.class);
        doThrow(new AccessDeniedException("")).when(fc).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));

        // Setup SecurityContextHolder, as filter needs to check if user is
        // anonymous
        SecurityContextHolder.clearContext();
View Full Code Here

        request.setServerName("www.example.com");
        request.setContextPath("/mycontext");
        request.setRequestURI("/mycontext/secure/page.html");

        // Setup the FilterChain to thrown an authentication failure exception
        FilterChain fc = mock(FilterChain.class);
        doThrow(new BadCredentialsException("")).when(fc).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));

        // Test
        ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
        filter.setAuthenticationEntryPoint(mockEntryPoint);
View Full Code Here

        request.setServerName("www.example.com");
        request.setContextPath("/mycontext");
        request.setRequestURI("/mycontext/secure/page.html");

        // Setup the FilterChain to thrown an authentication failure exception
        FilterChain fc = mock(FilterChain.class);
        doThrow(new BadCredentialsException("")).when(fc).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));

        // Test
        ExceptionTranslationFilter filter = new ExceptionTranslationFilter();
        filter.setAuthenticationEntryPoint(mockEntryPoint);
View Full Code Here

        filter.setAuthenticationEntryPoint(mockEntryPoint);
        filter.afterPropertiesSet();
        Exception[] exceptions = {new IOException(), new ServletException(), new RuntimeException()};
        for (Exception e : exceptions) {
            FilterChain fc = mock(FilterChain.class);

            doThrow(e).when(fc).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
            try {
                filter.doFilter(new MockHttpServletRequest(), new MockHttpServletResponse(), fc);
                fail("Should have thrown Exception");
View Full Code Here

    private MockHttpServletResponse executeFilterInContainerSimulator(Filter filter, final ServletRequest request,
                                                                      final boolean expectChainToProceed) throws ServletException, IOException {
        final MockHttpServletResponse response = new MockHttpServletResponse();

        final FilterChain chain = mock(FilterChain.class);

        filter.doFilter(request, response, chain);

        verify(chain, times(expectChainToProceed ? 1 : 0)).doFilter(request, response);
        return response;
View Full Code Here

        matcher = mock(RequestMatcher.class);
        filter = mock(Filter.class);
        doAnswer(new Answer<Object>() {
                    public Object answer(InvocationOnMock inv) throws Throwable {
                        Object[] args = inv.getArguments();
                        FilterChain fc = (FilterChain) args[2];
                        HttpServletRequestWrapper extraWrapper =
                                new HttpServletRequestWrapper((HttpServletRequest) args[0]);
                        fc.doFilter(extraWrapper, (HttpServletResponse) args[1]);
                        return null;
                    }
                }).when(filter).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class), any(FilterChain.class));
        fcp = new FilterChainProxy(new DefaultSecurityFilterChain(matcher, Arrays.asList(filter)));
        fcp.setFilterChainValidator(mock(FilterChainProxy.FilterChainValidator.class));
View Full Code Here

    }

    // SEC-2027
    @Test
    public void doFilterClearsSecurityContextHolderOnceOnForwards() throws Exception {
        final FilterChain innerChain = mock(FilterChain.class);
        when(matcher.matches(any(HttpServletRequest.class))).thenReturn(true);
        doAnswer(new Answer<Object>() {
            public Object answer(InvocationOnMock inv) throws Throwable {
                TestingAuthenticationToken expected = new TestingAuthenticationToken("username", "password");
                SecurityContextHolder.getContext().setAuthentication(expected);
                doAnswer(new Answer<Object>() {
                    public Object answer(InvocationOnMock inv) throws Throwable {
                        innerChain.doFilter(request, response);
                        return null;
                    }
                }).when(filter).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class), any(FilterChain.class));;
                fcp.doFilter(request, response, innerChain);
                assertSame(expected, SecurityContextHolder.getContext().getAuthentication());
View Full Code Here

TOP

Related Classes of javax.servlet.FilterChain

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.