Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.TestingAuthenticationToken


        SessionManagementFilter filter = new SessionManagementFilter(repo);
        filter.setTrustResolver(null);
    }

    private void authenticateUser() {
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("user", "pass"));
    }
View Full Code Here


    private static class CustomUserPrincipal {}

    private void setAuthenticationPrincipal(Object principal) {
        this.expectedPrincipal = principal;
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken(expectedPrincipal, "password", "ROLE_USER"));
    }
View Full Code Here

        response = new MockHttpServletResponse();

        handler = new SecurityContextLogoutHandler();

        SecurityContext context = SecurityContextHolder.createEmptyContext();
        context.setAuthentication(new TestingAuthenticationToken("user", "password", AuthorityUtils.createAuthorityList("ROLE_USER")));
        SecurityContextHolder.setContext(context);
    }
View Full Code Here

        verify(request, times(0)).authenticate(any(HttpServletResponse.class));
    }

    @Test
    public void authenticateTrue() throws Exception {
        SecurityContextHolder.getContext().setAuthentication(new TestingAuthenticationToken("test","password","ROLE_USER"));

        assertThat(wrappedRequest().authenticate(response)).isTrue();
        verifyZeroInteractions(authenticationEntryPoint, authenticationManager, logoutHandler);
        verify(request, times(0)).authenticate(any(HttpServletResponse.class));
    }
View Full Code Here

        verifyZeroInteractions(authenticationEntryPoint, authenticationManager, logoutHandler);
    }

    @Test
    public void login() throws Exception {
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))).thenReturn(expectedAuth);

        wrappedRequest().login(expectedAuth.getName(),String.valueOf(expectedAuth.getCredentials()));

        assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(expectedAuth);
        verifyZeroInteractions(authenticationEntryPoint, logoutHandler);
        verify(request, times(0)).login(anyString(),anyString());
    }
View Full Code Here

    }

    // SEC-2296
    @Test
    public void loginWithExstingUser() throws Exception {
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        when(authenticationManager.authenticate(any(UsernamePasswordAuthenticationToken.class))).thenReturn(new TestingAuthenticationToken("newuser","not be found","ROLE_USER"));
        SecurityContextHolder.getContext().setAuthentication(expectedAuth);

        try {
            wrappedRequest().login(expectedAuth.getName(),String.valueOf(expectedAuth.getCredentials()));
            fail("Expected Exception");
        } catch(ServletException success) {
            assertThat(SecurityContextHolder.getContext().getAuthentication()).isSameAs(expectedAuth);
            verifyZeroInteractions(authenticationEntryPoint, logoutHandler);
            verify(request, times(0)).login(anyString(),anyString());
View Full Code Here

        verifyZeroInteractions(authenticationEntryPoint, authenticationManager, logoutHandler);
    }

    @Test
    public void logout() throws Exception {
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        SecurityContextHolder.getContext().setAuthentication(expectedAuth);

        HttpServletRequest wrappedRequest = wrappedRequest();
        wrappedRequest.logout();
View Full Code Here

    @Test
    public void getAsyncContextStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.getAsyncContext()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
View Full Code Here

    @Test
    public void startAsyncStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync()).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
View Full Code Here

    @Test
    public void startAsyncWithRequestResponseStart() throws Exception {
        ArgumentCaptor<Runnable> runnableCaptor = ArgumentCaptor.forClass(Runnable.class);
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        TestingAuthenticationToken expectedAuth = new TestingAuthenticationToken("user", "password","ROLE_USER");
        context.setAuthentication(expectedAuth);
        SecurityContextHolder.setContext(context);
        AsyncContext asyncContext = mock(AsyncContext.class);
        when(request.startAsync(request,response)).thenReturn(asyncContext);
        Runnable runnable = new Runnable() {
View Full Code Here

TOP

Related Classes of org.springframework.security.authentication.TestingAuthenticationToken

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.