[jboss-cvs] JBossAS SVN: r64926 - branches/JBoss_4_0_5_GA_CP/security/src/main/org/jboss/security/auth/spi.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Aug 28 15:37:40 EDT 2007


Author: anil.saldhana at jboss.com
Date: 2007-08-28 15:37:40 -0400 (Tue, 28 Aug 2007)
New Revision: 64926

Modified:
   branches/JBoss_4_0_5_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
Log:
JBAS-4619: additional option parseRoleNameFromDN

Modified: branches/JBoss_4_0_5_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
===================================================================
--- branches/JBoss_4_0_5_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2007-08-28 19:33:11 UTC (rev 64925)
+++ branches/JBoss_4_0_5_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2007-08-28 19:37:40 UTC (rev 64926)
@@ -24,6 +24,7 @@
 import java.security.Principal;
 import java.security.acl.Group;
 import java.util.Iterator;
+import java.util.StringTokenizer;
 import java.util.Map.Entry;
 import java.util.Properties;
 import javax.naming.Context;
@@ -140,6 +141,7 @@
    private static final String ROLE_ATTRIBUTE_ID_OPT = "roleAttributeID";
    private static final String ROLE_ATTRIBUTE_IS_DN_OPT = "roleAttributeIsDN";
    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";
@@ -161,6 +163,7 @@
    protected String roleAttributeID;
    protected String roleNameAttributeID;
    protected boolean roleAttributeIsDN;
+   protected boolean parseRoleNameFromDN;
    protected int recursion = 0;
    protected int searchTimeLimit = 10000;
    protected int searchScope = SearchControls.SUBTREE_SCOPE;
@@ -293,6 +296,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
@@ -419,17 +427,24 @@
 	         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 ++)
+                  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 )
                   {
-                     String roleName = (String) roles2.get(m);
-                     addRole(roleName);
-                  }
+                     for(int m = 0; m < roles2.size(); m ++)
+                     {
+                        String roleName = (String) roles2.get(m);
+                        addRole(roleName);
+                     }
+                  }  
                }
             }
 
@@ -442,6 +457,11 @@
 	            for (int n = 0; n < roles.size(); n ++)
 	            {
 	               String roleName = (String) roles.get(n);
+	               if(roleAttributeIsDN && parseRoleNameFromDN)
+	               { 
+	            	   parseRole(roleName); 
+	               }
+	               else
                   if (roleAttributeIsDN)
                   {
                      // Query the roleDN location for the value of roleNameAttributeID
@@ -569,4 +589,19 @@
          }
       }
    }
+   
+   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