Class DefaultLdapRoleMapper
- java.lang.Object
-
- org.apache.archiva.redback.common.ldap.role.DefaultLdapRoleMapper
-
- All Implemented Interfaces:
LdapRoleMapper
@Service("ldapRoleMapper#default") public class DefaultLdapRoleMapper extends Object implements LdapRoleMapper
- Since:
- 2.1
- Author:
- Olivier Lamy
-
-
Field Summary
Fields Modifier and Type Field Description static String
DEFAULT_DESCRIPTION_ATTRIBUTE
static String
DEFAULT_GROUP_NAME_ATTRIBUTE
static String
DEFAULT_USER_ID_ATTRIBUTE
possible to user cn=beer or uid=beer or sn=beer etc so make it configurable
-
Constructor Summary
Constructors Constructor Description DefaultLdapRoleMapper()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected void
closeNamingEnumeration(NamingEnumeration namingEnumeration)
protected String
findGroupName(String role)
List<LdapGroup>
getAllGroupObjects(DirContext context)
Read all groups from LDAP and return the list of group objects.List<String>
getAllGroups(DirContext context)
read all groups from ldapList<String>
getAllRoles(DirContext context)
read all ldap groups then map to corresponding role (if no mapping found group is ignored)String
getBaseDn()
LdapGroup
getGroupForName(DirContext context, String groupName)
List<LdapGroup>
getGroupObjects(String username, DirContext context)
List<String>
getGroups(String username, DirContext context)
String
getGroupsDn()
List<String>
getGroupsMember(String group, DirContext context)
String
getLdapDnAttribute()
String
getLdapGroupClass()
String
getLdapGroupMemberAttribute()
List<String>
getRoles(String username, DirContext context, Collection<String> realRoles)
String
getUserIdAttribute()
boolean
hasRole(DirContext context, String roleName)
void
initialize()
boolean
isUseDefaultRoleName()
void
removeAllRoles(DirContext context)
void
removeRole(String roleName, DirContext context)
boolean
removeUserRole(String roleName, String username, DirContext context)
boolean
saveRole(String roleName, DirContext context)
will save a ldap group corresponding to the mapping.boolean
saveUserRole(String roleName, String username, DirContext context)
associate role to user in ldapvoid
setBaseDn(String baseDn)
void
setGroupsDn(String groupsDn)
void
setLdapConnectionFactory(LdapConnectionFactory ldapConnectionFactory)
void
setLdapGroupClass(String ldapGroupClass)
void
setLdapGroupMemberAttribute(String ldapGroupMemberAttribute)
void
setUseDefaultRoleName(boolean useDefaultRoleName)
void
setUserConf(UserConfiguration userConf)
void
setUserIdAttribute(String userIdAttribute)
-
-
-
Field Detail
-
DEFAULT_USER_ID_ATTRIBUTE
public static String DEFAULT_USER_ID_ATTRIBUTE
possible to user cn=beer or uid=beer or sn=beer etc so make it configurable
-
DEFAULT_GROUP_NAME_ATTRIBUTE
public static String DEFAULT_GROUP_NAME_ATTRIBUTE
-
DEFAULT_DESCRIPTION_ATTRIBUTE
public static String DEFAULT_DESCRIPTION_ATTRIBUTE
-
-
Constructor Detail
-
DefaultLdapRoleMapper
public DefaultLdapRoleMapper()
-
-
Method Detail
-
initialize
@PostConstruct public void initialize()
-
getAllGroups
public List<String> getAllGroups(DirContext context) throws MappingException
Description copied from interface:LdapRoleMapper
read all groups from ldap- Specified by:
getAllGroups
in interfaceLdapRoleMapper
- Returns:
- all LDAP groups
- Throws:
MappingException
-
getAllGroupObjects
public List<LdapGroup> getAllGroupObjects(DirContext context) throws MappingException
Description copied from interface:LdapRoleMapper
Read all groups from LDAP and return the list of group objects.- Specified by:
getAllGroupObjects
in interfaceLdapRoleMapper
- Returns:
- all LDAP groups found in the LDAP directory
- Throws:
MappingException
-
getGroupForName
public LdapGroup getGroupForName(DirContext context, String groupName) throws MappingException
- Specified by:
getGroupForName
in interfaceLdapRoleMapper
- Throws:
MappingException
-
closeNamingEnumeration
protected void closeNamingEnumeration(NamingEnumeration namingEnumeration)
-
hasRole
public boolean hasRole(DirContext context, String roleName) throws MappingException
- Specified by:
hasRole
in interfaceLdapRoleMapper
- Throws:
MappingException
-
getAllRoles
public List<String> getAllRoles(DirContext context) throws MappingException
Description copied from interface:LdapRoleMapper
read all ldap groups then map to corresponding role (if no mapping found group is ignored)- Specified by:
getAllRoles
in interfaceLdapRoleMapper
- Returns:
- all roles
- Throws:
MappingException
-
getGroupsMember
public List<String> getGroupsMember(String group, DirContext context) throws MappingException
- Specified by:
getGroupsMember
in interfaceLdapRoleMapper
- Parameters:
group
- ldap group- Returns:
- uids of group members
- Throws:
MappingException
-
getGroups
public List<String> getGroups(String username, DirContext context) throws MappingException
- Specified by:
getGroups
in interfaceLdapRoleMapper
- Throws:
MappingException
-
getGroupObjects
public List<LdapGroup> getGroupObjects(String username, DirContext context) throws MappingException
- Specified by:
getGroupObjects
in interfaceLdapRoleMapper
- Throws:
MappingException
-
getRoles
public List<String> getRoles(String username, DirContext context, Collection<String> realRoles) throws MappingException
- Specified by:
getRoles
in interfaceLdapRoleMapper
- Throws:
MappingException
-
getGroupsDn
public String getGroupsDn()
- Specified by:
getGroupsDn
in interfaceLdapRoleMapper
- Returns:
- the base dn which contains all ldap groups
-
getLdapGroupClass
public String getLdapGroupClass()
- Specified by:
getLdapGroupClass
in interfaceLdapRoleMapper
- Returns:
- the class used for group usually groupOfUniqueNames
-
getLdapDnAttribute
public String getLdapDnAttribute()
-
saveRole
public boolean saveRole(String roleName, DirContext context) throws MappingException
Description copied from interface:LdapRoleMapper
will save a ldap group corresponding to the mapping. will do nothing in group already exists.- Specified by:
saveRole
in interfaceLdapRoleMapper
- Returns:
true
if role was added,false
if role already exists- Throws:
MappingException
-
saveUserRole
public boolean saveUserRole(String roleName, String username, DirContext context) throws MappingException
Description copied from interface:LdapRoleMapper
associate role to user in ldap- Specified by:
saveUserRole
in interfaceLdapRoleMapper
- Returns:
true
if role was added to user,false
if role already exists for the user- Throws:
MappingException
-
removeUserRole
public boolean removeUserRole(String roleName, String username, DirContext context) throws MappingException
- Specified by:
removeUserRole
in interfaceLdapRoleMapper
- Throws:
MappingException
-
removeAllRoles
public void removeAllRoles(DirContext context) throws MappingException
- Specified by:
removeAllRoles
in interfaceLdapRoleMapper
- Throws:
MappingException
-
removeRole
public void removeRole(String roleName, DirContext context) throws MappingException
- Specified by:
removeRole
in interfaceLdapRoleMapper
- Throws:
MappingException
-
setGroupsDn
public void setGroupsDn(String groupsDn)
-
setLdapGroupClass
public void setLdapGroupClass(String ldapGroupClass)
-
setUserConf
public void setUserConf(UserConfiguration userConf)
-
setLdapConnectionFactory
public void setLdapConnectionFactory(LdapConnectionFactory ldapConnectionFactory)
-
getLdapGroupMemberAttribute
public String getLdapGroupMemberAttribute()
-
setLdapGroupMemberAttribute
public void setLdapGroupMemberAttribute(String ldapGroupMemberAttribute)
-
findGroupName
protected String findGroupName(String role) throws MappingException
- Throws:
MappingException
-
getUserIdAttribute
public String getUserIdAttribute()
- Specified by:
getUserIdAttribute
in interfaceLdapRoleMapper
-
setUserIdAttribute
public void setUserIdAttribute(String userIdAttribute)
-
isUseDefaultRoleName
public boolean isUseDefaultRoleName()
- Specified by:
isUseDefaultRoleName
in interfaceLdapRoleMapper
-
setUseDefaultRoleName
public void setUseDefaultRoleName(boolean useDefaultRoleName)
-
-