Examples of AnonymousAuthenticationToken


Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

    protected boolean applyAnonymousForThisRequest(HttpServletRequest request) {
        return true;
    }

    protected Authentication createAuthentication(HttpServletRequest request) {
        AnonymousAuthenticationToken auth = new AnonymousAuthenticationToken(key, principal, authorities);
        auth.setDetails(authenticationDetailsSource.buildDetails(request));

        return auth;
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

    @Test
    public void principalIsEmptyForAnonymousUser() {
        AuthenticationSource source = new SpringSecurityAuthenticationSource();

        SecurityContextHolder.getContext().setAuthentication(
                new AnonymousAuthenticationToken("key", "anonUser", AuthorityUtils.createAuthorityList("ignored")));
        assertEquals("", source.getPrincipal());
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

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

    public void testCorrectOperationIsAnonymous() {
        AuthenticationTrustResolverImpl trustResolver = new AuthenticationTrustResolverImpl();
        assertTrue(trustResolver.isAnonymous(
                new AnonymousAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))));
        assertFalse(trustResolver.isAnonymous(
                new TestingAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"))));
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

* @author Ben Alex
*/
public class AuthenticatedVoterTests extends TestCase {

    private Authentication createAnonymous() {
        return new AnonymousAuthenticationToken("ignored", "ignored", AuthorityUtils.createAuthorityList("ignored"));
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

    @Test
    public void testDetectsAnInvalidKey() throws Exception {
        AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
        aap.setKey("qwerty");

        AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("WRONG_KEY", "Test",
                AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));

        try {
            aap.authenticate(token);
            fail("Should have thrown BadCredentialsException");
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

    @Test
    public void testNormalOperation() throws Exception {
        AnonymousAuthenticationProvider aap = new AnonymousAuthenticationProvider();
        aap.setKey("qwerty");

        AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("qwerty", "Test",
                AuthorityUtils.createAuthorityList("ROLE_ONE", "ROLE_TWO"));

        Authentication result = aap.authenticate(token);

        assertEquals(result, token);
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

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

    public void testConstructorRejectsNulls() {
        try {
            new AnonymousAuthenticationToken(null, "Test", ROLES_12);
            fail("Should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }

        try {
            new AnonymousAuthenticationToken("key", null, ROLES_12);
            fail("Should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }

        try {
            new AnonymousAuthenticationToken("key", "Test", (List<GrantedAuthority>)null);
            fail("Should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }

        try {
            new AnonymousAuthenticationToken("key", "Test", AuthorityUtils.NO_AUTHORITIES );
            fail("Should have thrown IllegalArgumentException");
        } catch (IllegalArgumentException expected) {
        }
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

        } catch (IllegalArgumentException expected) {
        }
    }

    public void testEqualsWhenEqual() {
        AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key", "Test", ROLES_12);
        AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key", "Test", ROLES_12);

        assertEquals(token1, token2);
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

        assertEquals(token1, token2);
    }

    public void testGetters() {
        AnonymousAuthenticationToken token = new AnonymousAuthenticationToken("key", "Test", ROLES_12);

        assertEquals("key".hashCode(), token.getKeyHash());
        assertEquals("Test", token.getPrincipal());
        assertEquals("", token.getCredentials());
        assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains("ROLE_ONE"));
        assertTrue(AuthorityUtils.authorityListToSet(token.getAuthorities()).contains("ROLE_TWO"));
        assertTrue(token.isAuthenticated());
    }
View Full Code Here

Examples of org.springframework.security.authentication.AnonymousAuthenticationToken

        } catch (NoSuchMethodException expected) {
        }
    }

    public void testNotEqualsDueToAbstractParentEqualsCheck() {
        AnonymousAuthenticationToken token1 = new AnonymousAuthenticationToken("key", "Test", ROLES_12);
        AnonymousAuthenticationToken token2 = new AnonymousAuthenticationToken("key", "DIFFERENT_PRINCIPAL", ROLES_12);

        assertFalse(token1.equals(token2));
    }
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.