[jboss-cvs] JBossAS SVN: r110724 - projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/auth/spi.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Mon Feb 21 08:47:01 EST 2011
Author: mmoyses
Date: 2011-02-21 08:47:01 -0500 (Mon, 21 Feb 2011)
New Revision: 110724
Modified:
projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java
Log:
SECURITY-570: adding parseRoleNameFromDN
Modified: projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java
===================================================================
--- projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java 2011-02-21 06:40:46 UTC (rev 110723)
+++ projects/security/security-jboss-sx/branches/Branch_2_0/jbosssx/src/main/java/org/jboss/security/auth/spi/LdapExtLoginModule.java 2011-02-21 13:47:01 UTC (rev 110724)
@@ -26,6 +26,7 @@
import java.util.Iterator;
import java.util.Map;
import java.util.Properties;
+import java.util.StringTokenizer;
import java.util.Map.Entry;
import javax.management.ObjectName;
@@ -148,6 +149,8 @@
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";
@@ -194,6 +197,8 @@
protected String roleNameAttributeID;
protected boolean roleAttributeIsDN;
+
+ protected boolean parseRoleNameFromDN;
protected int recursion = 0;
@@ -369,6 +374,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
@@ -517,16 +527,23 @@
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);
+ }
}
}
}
@@ -540,6 +557,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
@@ -671,6 +693,21 @@
}
}
}
+
+ 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());
+ }
+ }
+ }
protected String getUsername()
{
More information about the jboss-cvs-commits
mailing list