From e628853f9e40b54ce294019792f9e99d3a828426 Mon Sep 17 00:00:00 2001 From: rjung Date: Fri, 7 Nov 2008 00:48:13 +0000 Subject: [PATCH] Move curUserPattern from a global variable to a method variable. Not necessary at the moment, because the realm is mostly synchronized, but being global doesn't help and will hurt once we implement connection pooling and concurrent usage for the realm. git-svn-id: https://svn.apache.org/repos/asf/tomcat/trunk@712024 13f79535-47bb-0310-9956-ffa450edef68 --- java/org/apache/catalina/realm/JNDIRealm.java | 42 ++++++++++++++++++--------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/java/org/apache/catalina/realm/JNDIRealm.java b/java/org/apache/catalina/realm/JNDIRealm.java index f93a1b39c..347ffa597 100644 --- a/java/org/apache/catalina/realm/JNDIRealm.java +++ b/java/org/apache/catalina/realm/JNDIRealm.java @@ -375,11 +375,6 @@ public class JNDIRealm extends RealmBase { protected int connectionAttempt = 0; /** - * The current user pattern to be used for lookup and binding of a user. - */ - protected int curUserPattern = 0; - - /** * Add this role to every authenticated user */ protected String commonRole = null; @@ -1008,16 +1003,16 @@ public class JNDIRealm extends RealmBase { if (username == null || username.equals("") || credentials == null || credentials.equals("")) { if (containerLog.isDebugEnabled()) - containerLog.debug("uername null or empty: returning null principal."); + containerLog.debug("username null or empty: returning null principal."); return (null); } if (userPatternArray != null) { - for (curUserPattern = 0; + for (int curUserPattern = 0; curUserPattern < userPatternFormatArray.length; curUserPattern++) { // Retrieve user information - User user = getUser(context, username); + User user = getUser(context, username, curUserPattern); if (user != null) { try { // Check the user's credentials @@ -1076,6 +1071,25 @@ public class JNDIRealm extends RealmBase { * with the specified username, if found in the directory; * otherwise return null. * + * @param context The directory context + * @param username Username to be looked up + * + * @exception NamingException if a directory server error occurs + * + * @see #getUser(DirContext, String, int) + */ + protected User getUser(DirContext context, String username) + throws NamingException { + + return getUser(context, username, -1); + } + + + /** + * Return a User object containing information about the user + * with the specified username, if found in the directory; + * otherwise return null. + * * If the userPassword configuration attribute is * specified, the value of that attribute is retrieved from the * user's directory entry. If the userRoleName @@ -1084,10 +1098,11 @@ public class JNDIRealm extends RealmBase { * * @param context The directory context * @param username Username to be looked up + * @param curUserPattern Index into userPatternFormatArray * * @exception NamingException if a directory server error occurs */ - protected User getUser(DirContext context, String username) + protected User getUser(DirContext context, String username, int curUserPattern) throws NamingException { User user = null; @@ -1102,8 +1117,8 @@ public class JNDIRealm extends RealmBase { list.toArray(attrIds); // Use pattern or search for user entry - if (userPatternFormatArray != null) { - user = getUserByPattern(context, username, attrIds); + if (userPatternFormatArray != null && curUserPattern >= 0) { + user = getUserByPattern(context, username, attrIds, curUserPattern); } else { user = getUserBySearch(context, username, attrIds); } @@ -1126,8 +1141,9 @@ public class JNDIRealm extends RealmBase { * @exception NamingException if a directory server error occurs */ protected User getUserByPattern(DirContext context, - String username, - String[] attrIds) + String username, + String[] attrIds, + int curUserPattern) throws NamingException { if (username == null || userPatternFormatArray[curUserPattern] == null) -- 2.11.0