Search in sources :

Example 1 with GrantedAuthorityImpl

use of org.acegisecurity.GrantedAuthorityImpl in project ramus by Vitaliy-Yakovchuk.

the class DaoSupportImpl method loadUserByUsername.

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException, DataAccessException {
    com.ramussoft.net.common.User user = getUserFactory().getUser(username);
    if (user == null) {
        throw new UsernameNotFoundException(MessageFormat.format("User {0} not found", username));
    }
    List<Group> list = user.getGroups();
    GrantedAuthority[] arrayAuths = new GrantedAuthority[list.size() + 1];
    for (int i = 0; i < list.size(); i++) {
        arrayAuths[i] = new GrantedAuthorityImpl("ROLE_" + list.get(i).getName().toUpperCase());
    }
    arrayAuths[list.size()] = new GrantedAuthorityImpl("ROLE_USER");
    return new User(user.getLogin(), user.getPassword(), true, true, true, true, arrayAuths);
}
Also used : UsernameNotFoundException(org.acegisecurity.userdetails.UsernameNotFoundException) Group(com.ramussoft.net.common.Group) User(org.acegisecurity.userdetails.User) GrantedAuthorityImpl(org.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(org.acegisecurity.GrantedAuthority)

Example 2 with GrantedAuthorityImpl

use of org.acegisecurity.GrantedAuthorityImpl in project reverse-proxy-auth-plugin by jenkinsci.

the class DefaultReverseProxyAuthoritiesPopulator method getGroupMembershipRoles.

public Set<GrantedAuthority> getGroupMembershipRoles(String username) {
    Set<GrantedAuthority> authorities = new HashSet<GrantedAuthority>();
    @CheckForNull final GrantedAuthority[] contextAuthorities = authContext != null ? authContext.get(username) : null;
    SearchTemplate searchTemplate = new UserSearchTemplate(username);
    Set<String> userRoles = reverseProxyTemplate.searchForSingleAttributeValues(searchTemplate, contextAuthorities);
    if (logger.isDebugEnabled()) {
        logger.debug("Roles from search: " + userRoles);
    }
    Iterator<String> it = userRoles.iterator();
    while (it.hasNext()) {
        String role = it.next();
        if (convertToUpperCase) {
            role = role.toUpperCase();
        }
        authorities.add(new GrantedAuthorityImpl(rolePrefix + role));
    }
    return authorities;
}
Also used : GrantedAuthorityImpl(org.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(org.acegisecurity.GrantedAuthority) CheckForNull(javax.annotation.CheckForNull) UserSearchTemplate(org.jenkinsci.plugins.reverse_proxy_auth.data.UserSearchTemplate) UserSearchTemplate(org.jenkinsci.plugins.reverse_proxy_auth.data.UserSearchTemplate) ReverseProxySearchTemplate(org.jenkinsci.plugins.reverse_proxy_auth.ReverseProxySearchTemplate) SearchTemplate(org.jenkinsci.plugins.reverse_proxy_auth.data.SearchTemplate) HashSet(java.util.HashSet)

Example 3 with GrantedAuthorityImpl

use of org.acegisecurity.GrantedAuthorityImpl in project reverse-proxy-auth-plugin by jenkinsci.

the class DefaultReverseProxyAuthoritiesPopulator method setDefaultRole.

/**
 * The default role which will be assigned to all users.
 *
 * @param defaultRole the role name, including any desired prefix.
 */
public void setDefaultRole(String defaultRole) {
    Assert.notNull(defaultRole, "The defaultRole property cannot be set to null");
    this.defaultRole = new GrantedAuthorityImpl(defaultRole);
}
Also used : GrantedAuthorityImpl(org.acegisecurity.GrantedAuthorityImpl)

Example 4 with GrantedAuthorityImpl

use of org.acegisecurity.GrantedAuthorityImpl in project reverse-proxy-auth-plugin by jenkinsci.

the class ReverseProxyAuthoritiesPopulatorImpl method getGroupMembershipRoles.

/**
 * Retrieves the group membership in two ways.
 *
 * We'd like to retain the original name, but we historically used to do
 * "ROLE_GROUPNAME". So to remain backward compatible, we make the super
 * class pass the unmodified "groupName", then do the backward
 * compatible translation here, so that the user gets both
 * "ROLE_GROUPNAME" and "groupName".
 */
@Override
public Set<GrantedAuthority> getGroupMembershipRoles(String username) {
    Set<GrantedAuthority> names = super.getGroupMembershipRoles(username);
    Set<GrantedAuthority> groupRoles = new HashSet<GrantedAuthority>(names.size() * 2);
    groupRoles.addAll(names);
    for (GrantedAuthority ga : names) {
        String role = ga.getAuthority();
        // backward compatible name mangling
        if (convertToUpperCase) {
            role = role.toUpperCase();
        }
        groupRoles.add(new GrantedAuthorityImpl(rolePrefix + role));
    }
    return groupRoles;
}
Also used : GrantedAuthorityImpl(org.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(org.acegisecurity.GrantedAuthority) HashSet(java.util.HashSet)

Example 5 with GrantedAuthorityImpl

use of org.acegisecurity.GrantedAuthorityImpl in project reverse-proxy-auth-plugin by jenkinsci.

the class ProxyLDAPAuthoritiesPopulator method getGroupMembershipRoles.

/**
 * Retrieves the group membership in two ways.
 *
 * We'd like to retain the original name, but we historically used to do "ROLE_GROUPNAME".
 * So to remain backward compatible, we make the super class pass the unmodified "groupName",
 * then do the backward compatible translation here, so that the user gets both "ROLE_GROUPNAME" and "groupName".
 */
@Override
@SuppressWarnings("unchecked")
public Set<GrantedAuthority> getGroupMembershipRoles(String userDn, String username) {
    Set<GrantedAuthority> names = super.getGroupMembershipRoles(userDn, username);
    Set<GrantedAuthority> r = new HashSet<GrantedAuthority>(names.size() * 2);
    r.addAll(names);
    for (GrantedAuthority ga : names) {
        String role = ga.getAuthority();
        // backward compatible name mangling
        if (convertToUpperCase)
            role = role.toUpperCase();
        r.add(new GrantedAuthorityImpl(rolePrefix + role));
    }
    return r;
}
Also used : GrantedAuthorityImpl(org.acegisecurity.GrantedAuthorityImpl) GrantedAuthority(org.acegisecurity.GrantedAuthority) HashSet(java.util.HashSet)

Aggregations

GrantedAuthorityImpl (org.acegisecurity.GrantedAuthorityImpl)8 GrantedAuthority (org.acegisecurity.GrantedAuthority)7 HashSet (java.util.HashSet)4 UsernamePasswordAuthenticationToken (org.acegisecurity.providers.UsernamePasswordAuthenticationToken)2 UsernameNotFoundException (org.acegisecurity.userdetails.UsernameNotFoundException)2 SearchTemplate (org.jenkinsci.plugins.reverse_proxy_auth.data.SearchTemplate)2 UserSearchTemplate (org.jenkinsci.plugins.reverse_proxy_auth.data.UserSearchTemplate)2 Principal (com.autentia.tnt.manager.security.Principal)1 Group (com.ramussoft.net.common.Group)1 User (hudson.model.User)1 ArrayList (java.util.ArrayList)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 CheckForNull (javax.annotation.CheckForNull)1 Filter (javax.servlet.Filter)1 FilterChain (javax.servlet.FilterChain)1 FilterConfig (javax.servlet.FilterConfig)1 ServletRequest (javax.servlet.ServletRequest)1 ServletResponse (javax.servlet.ServletResponse)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1