]> source.dussan.org Git - archiva.git/commitdiff
make start user dn configurable
authorOlivier Lamy <olamy@apache.org>
Mon, 21 Jan 2013 22:42:42 +0000 (22:42 +0000)
committerOlivier Lamy <olamy@apache.org>
Mon, 21 Jan 2013 22:42:42 +0000 (22:42 +0000)
some use cn= or uid= or sn= etc..
so it's now configurable with default uid=

git-svn-id: https://svn.apache.org/repos/asf/archiva/redback/redback-core/trunk@1436669 13f79535-47bb-0310-9956-ffa450edef68

redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/DefaultLdapRoleMapper.java
redback-common/redback-common-ldap/src/main/java/org/apache/archiva/redback/common/ldap/role/LdapRoleMapper.java
redback-configuration/src/main/java/org/apache/archiva/redback/configuration/UserConfigurationKeys.java
redback-rbac/redback-rbac-providers/redback-rbac-ldap/src/test/java/org/apache/archiva/redback/rbac/ldap/LdapRbacManagerTest.java

index 16b7ed9035933f2e926f3d1c837c3d649d29a54d..eb22ec2e446d130a777dd18038273a8bce486634 100644 (file)
@@ -57,7 +57,7 @@ import java.util.Set;
  * @author Olivier Lamy
  * @since 2.1
  */
-@Service("ldapRoleMapper#default")
+@Service( "ldapRoleMapper#default" )
 public class DefaultLdapRoleMapper
     implements LdapRoleMapper
 {
@@ -68,7 +68,7 @@ public class DefaultLdapRoleMapper
     private LdapConnectionFactory ldapConnectionFactory;
 
     @Inject
-    @Named(value = "userConfiguration#default")
+    @Named( value = "userConfiguration#default" )
     private UserConfiguration userConf;
 
     //---------------------------
@@ -83,6 +83,12 @@ public class DefaultLdapRoleMapper
 
     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()
     {
@@ -99,6 +105,8 @@ public class DefaultLdapRoleMapper
 
         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 )
@@ -330,8 +338,8 @@ public class DefaultLdapRoleMapper
 
             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 );
 
@@ -516,7 +524,7 @@ public class DefaultLdapRoleMapper
         // 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
@@ -576,13 +584,13 @@ public class DefaultLdapRoleMapper
                 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 ) } );
                 }
@@ -647,7 +655,7 @@ public class DefaultLdapRoleMapper
                 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 ) } );
                 }
@@ -790,4 +798,16 @@ public class DefaultLdapRoleMapper
         }
         return null;
     }
+
+
+
+    public String getUserIdAttribute()
+    {
+        return userIdAttribute;
+    }
+
+    public void setUserIdAttribute( String userIdAttribute )
+    {
+        this.userIdAttribute = userIdAttribute;
+    }
 }
index a801b7d9acd55ca1b0b7b1b770c08ca79af9a350..1ed1377adaa2f88f8b1003ae944fed5515910b92 100644 (file)
@@ -146,4 +146,6 @@ public interface LdapRoleMapper
     void removeRole( String roleName, DirContext context )
         throws MappingException;
 
+    String getUserIdAttribute();
+
 }
index 2bf1dbee7389f8dbd2b895f9c8f977fa91593b13..30aea21cbe7fc45a272cc9e4505adbe1ffc172e9 100644 (file)
@@ -82,10 +82,12 @@ public interface UserConfigurationKeys
 
     String LDAP_GROUPS_ROLE_START_KEY = "ldap.config.groups.role.";
 
-    String LDAP_GROUPS_USE_ROLENAME  = "ldap.config.groups.use.rolename";
+    String LDAP_GROUPS_USE_ROLENAME = "ldap.config.groups.use.rolename";
 
     String LDAP_WRITABLE = "ldap.config.writable";
 
+    String LDAP_USER_ID_ATTRIBUTE = "ldap.config.user.attribute";
+
     String APPLICATION_URL = "application.url";
 
     String EMAIL_URL_PATH = "email.url.path";
index dd8c1c5cefa72923b11a67dc8a53b54beb07f46d..6685037706a380d7cfb625054124816d84f099aa 100644 (file)
@@ -52,17 +52,17 @@ import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
 
-@DirtiesContext( classMode = DirtiesContext.ClassMode.AFTER_CLASS )
+@DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS)
 public class LdapRbacManagerTest
     extends AbstractRbacManagerTestCase
 {
 
     @Inject
-    @Named( value = "rbacManager#ldap" )
+    @Named(value = "rbacManager#ldap")
     LdapRbacManager rbacManager;
 
     @Inject
-    @Named( value = "apacheDS#test" )
+    @Named(value = "apacheDS#test")
     private ApacheDs apacheDs;
 
     private String suffix, groupSuffix;