Package org.springframework.security.core.authority

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


        if (prefix.length() > 0 && !name.startsWith(prefix)) {
            name = prefix + name;
        }

        return new SimpleGrantedAuthority(name);
    }
View Full Code Here


     *
     * @param authority the name of the authority to be assigned to all users.
     */
    public void setDefaultAuthority(String authority) {
        Assert.hasText(authority, "The authority name cannot be set to an empty value");
        this.defaultAuthority = new SimpleGrantedAuthority(authority);
    }
View Full Code Here

            attribute = attribute.toLowerCase(Locale.getDefault());
        } else if (isConvertAttributeToUpperCase()) {
            attribute = attribute.toUpperCase(Locale.getDefault());
        }
        if (isAddPrefixIfAlreadyExisting() || !attribute.startsWith(getAttributePrefix())) {
            return new SimpleGrantedAuthority(getAttributePrefix() + attribute);
        } else {
            return new SimpleGrantedAuthority(attribute);
        }
    }
View Full Code Here

    protected List<GrantedAuthority> loadUserAuthorities(String username) {
        return getJdbcTemplate().query(authoritiesByUsernameQuery, new String[] {username}, new RowMapper<GrantedAuthority>() {
            public GrantedAuthority mapRow(ResultSet rs, int rowNum) throws SQLException {
                String roleName = rolePrefix + rs.getString(2);

                return new SimpleGrantedAuthority(roleName);
            }
        });
    }
View Full Code Here

    protected List<GrantedAuthority> loadGroupAuthorities(String username) {
        return getJdbcTemplate().query(groupAuthoritiesByUsernameQuery, new String[] {username}, new RowMapper<GrantedAuthority>() {
            public GrantedAuthority mapRow(ResultSet rs, int rowNum) throws SQLException {
                 String roleName = getRolePrefix() + rs.getString(3);

                return new SimpleGrantedAuthority(roleName);
            }
        });
    }
View Full Code Here

    private void addGrantedAuthorityCollection(Collection<GrantedAuthority> result, String value) {
        StringTokenizer st = new StringTokenizer(value,stringSeparator,false);
        while ( st.hasMoreTokens() ) {
            String nextToken = st.nextToken();
            if ( StringUtils.hasText(nextToken) ) {
                result.add(new SimpleGrantedAuthority(nextToken));
            }
        }
    }
View Full Code Here

    @Test(expected=IllegalArgumentException.class)
    public void testDetectsMissingKey() throws Exception {
        UserAttribute user = new UserAttribute();
        user.setPassword("anonymousUsername");
        user.addAuthority(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));

        AnonymousAuthenticationFilter filter = new AnonymousAuthenticationFilter();
        filter.setUserAttribute(user);
        filter.afterPropertiesSet();
    }
View Full Code Here

    @Test
    public void testOperationWhenNoAuthenticationInSecurityContextHolder() throws Exception {
        UserAttribute user = new UserAttribute();
        user.setPassword("anonymousUsername");
        user.addAuthority(new SimpleGrantedAuthority("ROLE_ANONYMOUS"));

        AnonymousAuthenticationFilter filter = new AnonymousAuthenticationFilter();
        filter.setKey("qwerty");
        filter.setUserAttribute(user);
        filter.afterPropertiesSet();
View Full Code Here

        List<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
        for(String role : withUser.roles()) {
            if(role.startsWith("ROLE_")) {
                throw new IllegalArgumentException("roles cannot start with ROLE_ Got " + role);
            }
            authorities.add(new SimpleGrantedAuthority("ROLE_"+role));
        }
        User principal = new User(username, withUser.password(), true, true, true, true, authorities);
        Authentication authentication = new UsernamePasswordAuthenticationToken(principal, principal.getPassword(), principal.getAuthorities());
        SecurityContext context = SecurityContextHolder.createEmptyContext();
        context.setAuthentication(authentication);
View Full Code Here

         * @return the {@link AuthenticatedMatcher} for further customization
         */
        public AuthenticatedMatcher withRoles(String... roles) {
            Collection<GrantedAuthority> authorities = new ArrayList<GrantedAuthority>();
            for(String role : roles) {
                authorities.add(new SimpleGrantedAuthority("ROLE_"+role));
            }
            return withAuthorities(authorities);
        }
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.