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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Jan 13 19:35:55 EST 2011


Author: mmoyses
Date: 2011-01-13 19:35:55 -0500 (Thu, 13 Jan 2011)
New Revision: 110362

Modified:
   branches/JBPAPP_4_2_0_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
Log:
JBPAPP-5771: adding option to parse username

Modified: branches/JBPAPP_4_2_0_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
===================================================================
--- branches/JBPAPP_4_2_0_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2011-01-14 00:31:51 UTC (rev 110361)
+++ branches/JBPAPP_4_2_0_GA_CP/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2011-01-14 00:35:55 UTC (rev 110362)
@@ -159,6 +159,9 @@
    private static final String SEARCH_SCOPE_OPT = "searchScope";
    private static final String SECURITY_DOMAIN_OPT = "jaasSecurityDomain";
    private static final String DISTINGUISHED_NAME_ATTRIBUTE_OPT = "distinguishedNameAttribute";
+   private static final String PARSE_USERNAME = "parseUsername";
+   private static final String USERNAME_BEGIN_STRING = "usernameBeginString";
+   private static final String USERNAME_END_STRING = "usernameEndString";
 
    protected String bindDN;
    protected String bindCredential;
@@ -176,6 +179,9 @@
    protected boolean trace;
    protected boolean isPasswordValidated = false;
    protected String distinguishedNameAttribute;
+   protected boolean parseUsername;
+   protected String usernameBeginString;
+   protected String usernameEndString;
 
    public LdapExtLoginModule()
    {
@@ -662,4 +668,28 @@
          } 
       }
    }
+
+   protected String getUsername()
+   {
+      String username = super.getUsername();
+      parseUsername = Boolean.valueOf((String) options.get(PARSE_USERNAME));
+      if (parseUsername)
+      {
+         usernameBeginString = (String) options.get(USERNAME_BEGIN_STRING);
+         usernameEndString = (String) options.get(USERNAME_END_STRING);
+         int beginIndex = 0;
+         if (usernameBeginString != null && !usernameBeginString.equals(""))
+            beginIndex = username.indexOf(usernameBeginString) + usernameBeginString.length();
+         if (beginIndex == -1) // not allowed. reset
+            beginIndex = 0;
+         int endIndex = username.length();
+         if (usernameEndString != null && !usernameEndString.equals(""))
+            endIndex = username.substring(beginIndex).indexOf(usernameEndString);
+         if (endIndex == -1) // not allowed. reset
+            endIndex = username.length();
+         username = username.substring(beginIndex, endIndex);
+      }
+      return username;
+   }
+  
 }



More information about the jboss-cvs-commits mailing list