Package org.springframework.security.web.authentication.preauth

Examples of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken


        Assert.notNull(authenticationManager);
        Assert.notNull(authenticationDetailsSource);

        String userName = wasHelper.getCurrentUserName();
        if (logger.isDebugEnabled()) { logger.debug("Creating authentication request for user "+userName); }
        PreAuthenticatedAuthenticationToken authRequest = new PreAuthenticatedAuthenticationToken(userName, "N/A");
        authRequest.setDetails(authenticationDetailsSource.buildDetails(null));
        if (logger.isDebugEnabled()) { logger.debug("Authentication request for user "+userName+": "+authRequest); }
        Authentication authResponse = authenticationManager.authenticate(authRequest);
        if (logger.isDebugEnabled()) { logger.debug("Authentication response for user "+userName+": "+authResponse); }
        SecurityContextHolder.getContext().setAuthentication(authResponse);
    }
View Full Code Here


    public void testPreAuthenticatedAuthenticationTokenRequestWithDetails() {
        Object principal = "dummyUser";
        Object credentials = "dummyCredentials";
        Object details = "dummyDetails";
        PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal, credentials);
        token.setDetails(details);
        assertEquals(principal, token.getPrincipal());
        assertEquals(credentials, token.getCredentials());
        assertEquals(details, token.getDetails());
        assertTrue(token.getAuthorities().isEmpty());
    }
View Full Code Here

    }

    public void testPreAuthenticatedAuthenticationTokenRequestWithoutDetails() {
        Object principal = "dummyUser";
        Object credentials = "dummyCredentials";
        PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(principal, credentials);
        assertEquals(principal, token.getPrincipal());
        assertEquals(credentials, token.getCredentials());
        assertNull(token.getDetails());
        assertTrue(token.getAuthorities().isEmpty());
    }
View Full Code Here

    public void testPreAuthenticatedAuthenticationTokenResponse() {
        Object principal = "dummyUser";
        Object credentials = "dummyCredentials";
        List<GrantedAuthority> gas = AuthorityUtils.createAuthorityList("Role1");
        PreAuthenticatedAuthenticationToken token =
            new PreAuthenticatedAuthenticationToken(principal, credentials, gas);
        assertEquals(principal, token.getPrincipal());
        assertEquals(credentials, token.getCredentials());
        assertNull(token.getDetails());
        assertNotNull(token.getAuthorities());
        Collection<GrantedAuthority> resultColl = token.getAuthorities();
        assertTrue("GrantedAuthority collections do not match; result: " + resultColl + ", expected: " + gas,
                gas.containsAll(resultColl) && resultColl.containsAll(gas));

    }
View Full Code Here

        if (authentication == null) {
            if (googleUser != null) {
                logger.debug("Currently logged on to GAE as user " + googleUser);
                logger.debug("Authenticating to Spring Security");
                // User has returned after authenticating via GAE. Need to authenticate through Spring Security.
                PreAuthenticatedAuthenticationToken token = new PreAuthenticatedAuthenticationToken(googleUser, null);
                token.setDetails(ads.buildDetails((HttpServletRequest) request));

                try {
                    authentication = authenticationManager.authenticate(token);
                    SecurityContextHolder.getContext().setAuthentication(authentication);
View Full Code Here

    }

    @Test
    public final void nullPrincipalReturnsNullAuthentication() throws Exception {
        PreAuthenticatedAuthenticationProvider provider = new PreAuthenticatedAuthenticationProvider();
        Authentication request = new PreAuthenticatedAuthenticationToken(null, "dummyPwd");
        Authentication result = provider.authenticate(request);
        assertNull(result);
    }
View Full Code Here

    @Test
    public final void authenticateKnownUser() throws Exception {
        UserDetails ud = new User("dummyUser", "dummyPwd", true, true, true, true, AuthorityUtils.NO_AUTHORITIES );
        PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
        Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser", "dummyPwd");
        Authentication result = provider.authenticate(request);
        assertNotNull(result);
        assertEquals(result.getPrincipal(), ud);
        // @TODO: Add more asserts?
    }
View Full Code Here

    @Test
    public final void authenticateIgnoreCredentials() throws Exception {
        UserDetails ud = new User("dummyUser1", "dummyPwd1", true, true, true, true, AuthorityUtils.NO_AUTHORITIES );
        PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
        Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser1", "dummyPwd2");
        Authentication result = provider.authenticate(request);
        assertNotNull(result);
        assertEquals(result.getPrincipal(), ud);
        // @TODO: Add more asserts?
    }
View Full Code Here

    @Test(expected=UsernameNotFoundException.class)
    public final void authenticateUnknownUserThrowsException() throws Exception {
        UserDetails ud = new User("dummyUser1", "dummyPwd", true, true, true, true, AuthorityUtils.NO_AUTHORITIES );
        PreAuthenticatedAuthenticationProvider provider = getProvider(ud);
        Authentication request = new PreAuthenticatedAuthenticationToken("dummyUser2", "dummyPwd");
        provider.authenticate(request);
    }
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public Authentication getAuthentication(org.mule.api.security.Authentication authentication)
    {
        return new PreAuthenticatedAuthenticationToken(authentication.getPrincipal(),
            authentication.getCredentials());
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.web.authentication.preauth.PreAuthenticatedAuthenticationToken

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.