Package org.springframework.security.core.authority

Examples of org.springframework.security.core.authority.SimpleGrantedAuthority


        SwitchUserFilter filter = new SwitchUserFilter();
        filter.setUserDetailsService(new MockUserDetailsService());
        filter.setSwitchUserAuthorityChanger(new SwitchUserAuthorityChanger() {
            public Collection<GrantedAuthority> modifyGrantedAuthorities(UserDetails targetUser, Authentication currentAuthentication, Collection<? extends GrantedAuthority> authoritiesToBeGranted) {
                List <GrantedAuthority>auths = new ArrayList<GrantedAuthority>();
                auths.add(new SimpleGrantedAuthority("ROLE_NEW"));
                return auths;
            }
        });

        Authentication result = filter.attemptSwitchUser(request);
View Full Code Here


    private List<GrantedAuthority> createRoles(int howMany) {
     // This is always the worst case scenario - the required role is ROLE_1, but they are created in reverse order
        GrantedAuthority[] roles = new GrantedAuthority[howMany];

        for (int i = howMany - 1; i >=0 ; i--) {
            roles[i] = new SimpleGrantedAuthority("ROLE_" + i);
        }

        return Arrays.asList(roles);
    }
View Full Code Here

    public void testAuthoritiesAreImmutable() {
        MockAuthenticationImpl token = new MockAuthenticationImpl("Test", "Password", authorities);
        List<GrantedAuthority> gotAuthorities = (List<GrantedAuthority>) token.getAuthorities();
        assertNotSame(authorities, gotAuthorities);

        gotAuthorities.set(0, new SimpleGrantedAuthority("ROLE_SUPER_USER"));
    }
View Full Code Here

    protected GrantedAuthority createAuthority(Object role) {
        if (role instanceof String) {
            if (convertToUpperCase) {
                role = ((String) role).toUpperCase();
            }
            return new SimpleGrantedAuthority(rolePrefix + role);
        }
        return null;
    }
View Full Code Here

            if (convertToUpperCase) {
                role = role.toUpperCase();
            }

            authorities.add(new SimpleGrantedAuthority(rolePrefix + role));
        }

        return authorities;
    }
View Full Code Here

     * @deprecated Assign a default role in the {@code AuthenticationProvider} using a {@code GrantedAuthoritiesMapper}.
     */
    @Deprecated
    public void setDefaultRole(String defaultRole) {
        Assert.notNull(defaultRole, "The defaultRole property cannot be set to null");
        this.defaultRole = new SimpleGrantedAuthority(defaultRole);
    }
View Full Code Here

        }

        ArrayList<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>(groups.length);

        for (String group : groups) {
            authorities.add(new SimpleGrantedAuthority(new DistinguishedName(group).removeLast().getValue()));
        }

        return authorities;
    }
View Full Code Here

        assertEquals(AuthorityUtils.createAuthorityList("ROLE_A"), manager.findGroupAuthorities("GROUP_0"));
    }

    @Test
    public void addGroupAuthorityInsertsCorrectGroupAuthorityRow() throws Exception {
        GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_X");
        manager.addGroupAuthority("GROUP_0", auth);

        template.queryForObject("select authority from group_authorities where authority = 'ROLE_X' and group_id = 0", String.class);
    }
View Full Code Here

        template.queryForObject("select authority from group_authorities where authority = 'ROLE_X' and group_id = 0", String.class);
    }

    @Test
    public void deleteGroupAuthorityRemovesCorrectRows() throws Exception {
        GrantedAuthority auth = new SimpleGrantedAuthority("ROLE_A");
        manager.removeGroupAuthority("GROUP_0", auth);
        assertEquals(0, template.queryForList("select authority from group_authorities where group_id = 0").size());

        manager.removeGroupAuthority("GROUP_2", auth);
        assertEquals(2, template.queryForList("select authority from group_authorities where group_id = 2").size());
View Full Code Here

        catch (IllegalArgumentException expected) {
            Assert.assertTrue(true);
        }

        try {
            GrantedAuthority ga = new SimpleGrantedAuthority(null);
            new GrantedAuthoritySid(ga);
            Assert.fail("It should have thrown IllegalArgumentException");
        }
        catch (IllegalArgumentException expected) {
            Assert.assertTrue(true);
        }

        try {
            GrantedAuthority ga = new SimpleGrantedAuthority("ROLE_TEST");
            new GrantedAuthoritySid(ga);
            Assert.assertTrue(true);
        }
        catch (IllegalArgumentException notExpected) {
            Assert.fail("It shouldn't have thrown IllegalArgumentException");
View Full Code Here

TOP

Related Classes of org.springframework.security.core.authority.SimpleGrantedAuthority

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.