Package org.springframework.security.authentication

Examples of org.springframework.security.authentication.AuthenticationManager


        assertEquals(grantAccess, null != SecurityContextHolder.getContext().getAuthentication());
    }

    private static ConcretePreAuthenticatedProcessingFilter getFilter(boolean grantAccess) throws Exception {
        ConcretePreAuthenticatedProcessingFilter filter = new ConcretePreAuthenticatedProcessingFilter();
        AuthenticationManager am = mock(AuthenticationManager.class);

        if (!grantAccess) {
            when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        } else {
            when(am.authenticate(any(Authentication.class))).thenAnswer(new Answer<Authentication>() {
                public Authentication answer(InvocationOnMock invocation) throws Throwable {
                    return (Authentication) invocation.getArguments()[0];
                }
            });
        }
View Full Code Here


    //~ Methods ========================================================================================================

    @Test(expected=RemoteAuthenticationException.class)
    public void testFailedAuthenticationReturnsRemoteAuthenticationException() {
        RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));
        manager.setAuthenticationManager(am);

        manager.attemptAuthentication("rod", "password");
    }
View Full Code Here

    }

    @Test
    public void testSuccessfulAuthentication() {
        RemoteAuthenticationManagerImpl manager = new RemoteAuthenticationManagerImpl();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenReturn(new TestingAuthenticationToken("u","p","A"));
        manager.setAuthenticationManager(am);

        manager.attemptAuthentication("rod", "password");
    }
View Full Code Here

    @Test
    public void changePasswordSucceedsWithIfReAuthenticationSucceeds() {
        insertJoe();
        Authentication currentAuth = authenticateJoe();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(currentAuth)).thenReturn(currentAuth);

        manager.setAuthenticationManager(am);
        manager.changePassword("password", "newPassword");
        UserDetails newJoe = manager.loadUserByUsername("joe");
View Full Code Here

    @Test
    public void changePasswordFailsIfReAuthenticationFails() {
        insertJoe();
        authenticateJoe();
        AuthenticationManager am = mock(AuthenticationManager.class);
        when(am.authenticate(any(Authentication.class))).thenThrow(new BadCredentialsException(""));

        manager.setAuthenticationManager(am);

        try {
            manager.changePassword("password", "newPassword");
View Full Code Here

    public final void setUp() throws Exception {
        SecurityContextHolder.clearContext();
        interceptor = new MethodSecurityInterceptor();
        token = new TestingAuthenticationToken("Test", "Password", "ROLE_SOMETHING");
        adm = mock(AccessDecisionManager.class);
        AuthenticationManager authman = mock(AuthenticationManager.class);
        mds = mock(MethodSecurityMetadataSource.class);
        interceptor.setAccessDecisionManager(adm);
        interceptor.setAuthenticationManager(authman);
        interceptor.setSecurityMetadataSource(mds);
    }
View Full Code Here

    @Test
    public void testSuccessfulAuthentication() {
        String[] grants = {"tester", "insight"};
        Authentication token = new TestingAuthenticationToken("testSuccessfulAuthentication", "shir", grants);
        AuthenticationManager testManager = new AuthenticationTestManager(false);
        Authentication result = testManager.authenticate(token);
        assertNotNull("No authentication result", result);
        assertSame("Mismatched authentication instances equality", token, result);
        assertOperationResult(result, Arrays.asList(grants));
    }
View Full Code Here

        ObscuredValueSetMarker marker = new ObscuredValueSetMarker();
        getAspect().setSensitiveValueMarker(marker);

        String[] grants = {"tester", "insight"};
        Authentication token = new TestingAuthenticationToken("testObscuredCredentials", "omer", grants);
        AuthenticationManager testManager = new AuthenticationTestManager(true);
        Authentication result = testManager.authenticate(token);
        assertNotSame("Authentication token not cloned", token, result);
        assertObscuredAuthValues(token, result, marker);
    }
View Full Code Here

     * @throws Exception error
     */
    @Test(expected = AuthenticationServiceException.class)
    public void testInvalidBinding() throws Exception {

        AuthenticationManager manager = createMock(AuthenticationManager.class);
        processingFiler.setAuthenticationManager(manager);

        SAMLTestHelper.setLocalContextParameters(request, "/saml", null);
        final Capture<SAMLMessageContext> context = new Capture<SAMLMessageContext>();
        expect(request.getRequestURL()).andReturn(new StringBuffer("http://localhost:8081/spring-security-saml2-webapp/saml/SSO"));
View Full Code Here

     * @throws Exception error
     */
    @Test(expected = AuthenticationServiceException.class)
    public void testInvalidEndpoint() throws Exception {

        AuthenticationManager manager = createMock(AuthenticationManager.class);
        processingFiler.setAuthenticationManager(manager);

        SAMLTestHelper.setLocalContextParameters(request, "/saml", null);
        final Capture<SAMLMessageContext> context = new Capture<SAMLMessageContext>();
        expect(request.getRequestURL()).andReturn(new StringBuffer("http://localhost:8081/spring-security-saml2-webapp/saml/SSOMissing"));
View Full Code Here

TOP

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

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.