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);
}
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;
}
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);
}
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;
}
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;
}
Aggregations