Package org.springframework.security.providers

Examples of org.springframework.security.providers.TestingAuthenticationToken


    /**
     * Creates an Acegi SecureContext and stores it on the ContextHolder
     */
    private void createSecureContext() {

        TestingAuthenticationToken auth = new TestingAuthenticationToken(
                username,
                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });
View Full Code Here


    /**
     * Creates an Acegi SecureContext and stores it on the ContextHolder
     */
    private void createSecureContext() {

        TestingAuthenticationToken auth = new TestingAuthenticationToken(
                username,
                username,
                new GrantedAuthority[] {
                        new GrantedAuthorityImpl("ROLE_TELLER"),
                        new GrantedAuthorityImpl("ROLE_PERMISSION_LIST") });
View Full Code Here

    /**
     * Construct a token with the given id, password, and role
     */
    public static Authentication makeAuthentication( String user, String password, String role ) {
        return new TestingAuthenticationToken( user, password,
            new GrantedAuthority[] { new GrantedAuthorityImpl( role ) } );
    }
View Full Code Here

        // Set the decision manager to authorize
        accessDecisionManager.setDecisionValue( true );

        // Now install a token, a should be updated
        controller.setAuthenticationToken( new TestingAuthenticationToken( "USER2", "FOO") );
        assertTrue( "Object should be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 1 );
        assertTrue( "Object should be authorized", a2.isAuthorized() );
        assertEquals( "Object should be updated", a2.getAuthCount(), 1 );

        controller.setAuthenticationToken( null );
        assertFalse( "Object should not be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 2 );
        assertFalse( "Object should not be authorized", a2.isAuthorized() );
        assertEquals( "Object should be updated", a2.getAuthCount(), 2 );

        // Set the decision manager to NOT authorize
        accessDecisionManager.setDecisionValue( false );

        // Now install a token, a should be updated
        controller.setAuthenticationToken( new TestingAuthenticationToken( "USER2", "FOO") );
        assertFalse( "Object should not be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 3 );
        assertFalse( "Object should not be authorized", a2.isAuthorized() );
        assertEquals( "Object should be updated", a2.getAuthCount(), 3 );
    }
View Full Code Here

     * Test that added objects are initially configured.
     */
    public void testAddControlledObject() {

        // Install an authentication token
        controller.setAuthenticationToken( new TestingAuthenticationToken( "USER2", "FOO") );

        // Set the decision manager to authorize
        accessDecisionManager.setDecisionValue( true );

        TestAuthorizable a1 = new TestAuthorizable( false );
View Full Code Here

        controller.removeControlledObject( a );
        a.resetAuthCount();

        // Set the decision manager to authorize
        accessDecisionManager.setDecisionValue( true );
        controller.setAuthenticationToken( new TestingAuthenticationToken( "USER2", "FOO" ) );

        assertFalse( "Object should not be authorized", a.isAuthorized() );
        assertTrue( "Object should not be updated", a.getAuthCount() == 0 );
    }
View Full Code Here

        controller.addControlledObject( a1 );
        assertFalse( "Object should not be authorized", a1.isAuthorized() );

        // Now set the authentication token so that it contains one of these roles
        Authentication auth = new TestingAuthenticationToken( "USER1", "FOO",
            new GrantedAuthority[] { new GrantedAuthorityImpl( "ROLE_1" ) } );
        controller.setAuthenticationToken( auth );

        assertTrue( "Object should be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 2 );

        // Now to a token that does not contain one of the roles
        auth = new TestingAuthenticationToken( "USER1", "FOO", new GrantedAuthority[] { new GrantedAuthorityImpl(
            "ROLE_NOTFOUND" ) } );
        controller.setAuthenticationToken( auth );

        assertFalse( "Object should not be authorized", a1.isAuthorized() );
        assertEquals( "Object should be updated", a1.getAuthCount(), 3 );
View Full Code Here

    @Override
    protected void setUp() throws Exception {
        super.setUp();

        rwUser = new TestingAuthenticationToken("rw", "supersecret", new XACMLRole[] {
                new XACMLRole("READER"), new XACMLRole("WRITER") });
        roUser = new TestingAuthenticationToken("ro", "supersecret",
                new XACMLRole[] { new XACMLRole("READER") });
        anonymous = new TestingAuthenticationToken("anonymous", "",
                new XACMLRole[] { new XACMLRole(XACMLConstants.AnonymousRole) });
        milUser = new TestingAuthenticationToken("military", "supersecret",
                new XACMLRole[] { new XACMLRole("MILITARY") });
        root = new TestingAuthenticationToken("admin", "geoserver",
                new XACMLRole[] { new XACMLRole(XACMLConstants.AdminRole) });

    }
View Full Code Here

        catalog = createNiceMock(Catalog.class);
        expect(catalog.getWorkspace((String) anyObject())).andReturn(
                createNiceMock(WorkspaceInfo.class)).anyTimes();
        replay(catalog);

        rwUser = new TestingAuthenticationToken("rw", "supersecret", new GrantedAuthority[] {
                new GrantedAuthorityImpl("READER"), new GrantedAuthorityImpl("WRITER") });
        roUser = new TestingAuthenticationToken("ro", "supersecret",
                new GrantedAuthority[] { new GrantedAuthorityImpl("READER") });
        anonymous = new TestingAuthenticationToken("anonymous", null);
        milUser = new TestingAuthenticationToken("military", "supersecret", new GrantedAuthority[] {
                new GrantedAuthorityImpl("MILITARY") });

    }
View Full Code Here

    private TestingAuthenticationToken anonymous;

    @Override
    protected void setUp() throws Exception {
        anonymous = new TestingAuthenticationToken("anonymous", null);
    }
View Full Code Here

TOP

Related Classes of org.springframework.security.providers.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.