[jboss-cvs] JBossAS SVN: r110679 - projects/security/security-jboss-sx/branches/2.0.4.SP4_JBPAPP-5942/jbosssx/src/main/java/org/jboss/security/auth/spi.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Feb 15 13:10:17 EST 2011


Author: dehort
Date: 2011-02-15 13:10:17 -0500 (Tue, 15 Feb 2011)
New Revision: 110679

Modified:
   projects/security/security-jboss-sx/branches/2.0.4.SP4_JBPAPP-5942/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java
Log:
JBPAPP-5942 - Single fix patch to add parseRoleNameFromDN functionality to EAP 5.1.0


Modified: projects/security/security-jboss-sx/branches/2.0.4.SP4_JBPAPP-5942/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java
===================================================================
--- projects/security/security-jboss-sx/branches/2.0.4.SP4_JBPAPP-5942/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java	2011-02-15 17:46:17 UTC (rev 110678)
+++ projects/security/security-jboss-sx/branches/2.0.4.SP4_JBPAPP-5942/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java	2011-02-15 18:10:17 UTC (rev 110679)
@@ -23,6 +23,7 @@
 
 import java.security.Principal;
 import java.security.acl.Group;
+import java.util.StringTokenizer;
 import java.util.Iterator;
 import java.util.Map;
 import java.util.Properties;
@@ -149,6 +150,8 @@
 
    private static final String ROLE_NAME_ATTRIBUTE_ID_OPT = "roleNameAttributeID";
 
+   private static final String PARSE_ROLE_NAME_FROM_DN_OPT = "parseRoleNameFromDN";
+
    private static final String BIND_DN = "bindDN";
 
    private static final String BIND_CREDENTIAL = "bindCredential";
@@ -189,6 +192,8 @@
 
    protected boolean roleAttributeIsDN;
 
+   protected boolean parseRoleNameFromDN;
+
    protected int recursion = 0;
 
    protected int searchTimeLimit = 10000;
@@ -355,6 +360,11 @@
       roleNameAttributeID = (String) options.get(ROLE_NAME_ATTRIBUTE_ID_OPT);
       if (roleNameAttributeID == null)
          roleNameAttributeID = "name";
+      
+      //JBAS-4619:Parse Role Name from DN
+      String parseRoleNameFromDNOption = (String) options.get(PARSE_ROLE_NAME_FROM_DN_OPT);
+      parseRoleNameFromDN = Boolean.valueOf(parseRoleNameFromDNOption).booleanValue();
+      
       rolesCtxDN = (String) options.get(ROLES_CTX_DN_OPT);
       String strRecursion = (String) options.get(ROLE_RECURSION);
       try
@@ -503,18 +513,25 @@
             String dn = canonicalize(sr.getName());
             if (nesting == 0 && roleAttributeIsDN && roleNameAttributeID != null)
             {
-               // Check the top context for role names
-               String[] attrNames = {roleNameAttributeID};
-               Attributes result2 = ctx.getAttributes(dn, attrNames);
-               Attribute roles2 = result2.get(roleNameAttributeID);
-               if (roles2 != null)
+               if(parseRoleNameFromDN)
                {
-                  for (int m = 0; m < roles2.size(); m++)
-                  {
-                     String roleName = (String) roles2.get(m);
-                     addRole(roleName);
-                  }
+                  parseRole(dn);
                }
+               else
+               { 
+                 // Check the top context for role names
+                 String[] attrNames = {roleNameAttributeID};
+                 Attributes result2 = ctx.getAttributes(dn, attrNames);
+                 Attribute roles2 = result2.get(roleNameAttributeID);
+                 if (roles2 != null)
+                 {
+                    for (int m = 0; m < roles2.size(); m++)
+                    {
+                       String roleName = (String) roles2.get(m);
+                       addRole(roleName);
+                    }
+                 }
+               }
             }
 
             // Query the context for the roleDN values
@@ -526,7 +543,11 @@
                for (int n = 0; n < roles.size(); n++)
                {
                   String roleName = (String) roles.get(n);
-                  if (roleAttributeIsDN)
+                  if(roleAttributeIsDN && parseRoleNameFromDN)
+                  { 
+                    parseRole(roleName); 
+                  }
+                  else if (roleAttributeIsDN)
                   {
                      // Query the roleDN location for the value of roleNameAttributeID
                      String roleDN = roleName;
@@ -657,4 +678,19 @@
          }
       }
    }
-}
\ No newline at end of file
+   
+   private void parseRole(String dn)
+   {
+      StringTokenizer st = new StringTokenizer(dn, ",");
+      while(st != null && st.hasMoreTokens())
+      {
+         String keyVal = st.nextToken();
+         if(keyVal.indexOf(roleNameAttributeID) > -1)
+         { 
+            StringTokenizer kst = new StringTokenizer(keyVal,"=");
+            kst.nextToken();
+            addRole(kst.nextToken());
+         } 
+      }
+   }
+}



More information about the jboss-cvs-commits mailing list