* @author Olivier Lamy
* @since 2.1
*/
-@Service("ldapRoleMapper#default")
+@Service( "ldapRoleMapper#default" )
public class DefaultLdapRoleMapper
implements LdapRoleMapper
{
private LdapConnectionFactory ldapConnectionFactory;
@Inject
- @Named(value = "userConfiguration#default")
+ @Named( value = "userConfiguration#default" )
private UserConfiguration userConf;
//---------------------------
private boolean useDefaultRoleName = false;
+ /**
+ * possible to user cn=beer or uid=beer or sn=beer etc
+ * so make it configurable
+ */
+ private String userIdAttribute = "uid";
+
@PostConstruct
public void initialize()
{
this.useDefaultRoleName =
userConf.getBoolean( UserConfigurationKeys.LDAP_GROUPS_USE_ROLENAME, this.useDefaultRoleName );
+
+ this.userIdAttribute = userConf.getString( UserConfigurationKeys.LDAP_USER_ID_ATTRIBUTE, this.userIdAttribute );
}
public String getLdapGroup( String role )
String filter =
new StringBuilder().append( "(&" ).append( "(objectClass=" + getLdapGroupClass() + ")" ).append(
- "(uniquemember=" ).append( "uid=" + username + "," + this.getBaseDn() ).append( ")" ).append(
- ")" ).toString();
+ "(uniquemember=" ).append( this.userIdAttribute + "=" + username + "," + this.getBaseDn() ).append(
+ ")" ).append( ")" ).toString();
log.debug( "filter: {}", filter );
// attribute mandatory when created a group so add admin as default member
// TODO make this default configurable
BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
- basicAttribute.add( "uid=admin," + getBaseDn() );
+ basicAttribute.add( this.userIdAttribute + "=admin," + getBaseDn() );
attributes.put( basicAttribute );
try
if ( attribute == null )
{
BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
- basicAttribute.add( "uid=" + username + "," + getGroupsDn() );
+ basicAttribute.add( this.userIdAttribute + "=" + username + "," + getGroupsDn() );
context.modifyAttributes( "cn=" + groupName + "," + getGroupsDn(), new ModificationItem[]{
new ModificationItem( DirContext.ADD_ATTRIBUTE, basicAttribute ) } );
}
else
{
- attribute.add( "uid=" + username + "," + getGroupsDn() );
+ attribute.add( this.userIdAttribute + "=" + username + "," + getGroupsDn() );
context.modifyAttributes( "cn=" + groupName + "," + getGroupsDn(), new ModificationItem[]{
new ModificationItem( DirContext.REPLACE_ATTRIBUTE, attribute ) } );
}
if ( attribute != null )
{
BasicAttribute basicAttribute = new BasicAttribute( "uniquemember" );
- basicAttribute.add( "uid=" + username + "," + getGroupsDn() );
+ basicAttribute.add( this.userIdAttribute + "=" + username + "," + getGroupsDn() );
context.modifyAttributes( "cn=" + groupName + "," + getGroupsDn(), new ModificationItem[]{
new ModificationItem( DirContext.REMOVE_ATTRIBUTE, basicAttribute ) } );
}
}
return null;
}
+
+
+
+ public String getUserIdAttribute()
+ {
+ return userIdAttribute;
+ }
+
+ public void setUserIdAttribute( String userIdAttribute )
+ {
+ this.userIdAttribute = userIdAttribute;
+ }
}