You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/03/07 17:28:09 UTC

svn commit: r1733940 - in /tomcat/trunk: java/org/apache/catalina/realm/JNDIRealm.java webapps/docs/changelog.xml

Author: markt
Date: Mon Mar  7 16:28:09 2016
New Revision: 1733940

URL: http://svn.apache.org/viewvc?rev=1733940&view=rev
Log:
Fix https://bz.apache.org/bugzilla/show_bug.cgi?id=59123
Close NamingEnumeration objects used by the JNDIRealm once they are no longer required.

Modified:
    tomcat/trunk/java/org/apache/catalina/realm/JNDIRealm.java
    tomcat/trunk/webapps/docs/changelog.xml

Modified: tomcat/trunk/java/org/apache/catalina/realm/JNDIRealm.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/java/org/apache/catalina/realm/JNDIRealm.java?rev=1733940&r1=1733939&r2=1733940&view=diff
==============================================================================
--- tomcat/trunk/java/org/apache/catalina/realm/JNDIRealm.java (original)
+++ tomcat/trunk/java/org/apache/catalina/realm/JNDIRealm.java Mon Mar  7 16:28:09 2016
@@ -1685,60 +1685,65 @@ public class JNDIRealm extends RealmBase
         NamingEnumeration<SearchResult> results =
             context.search(userBase, filter, constraints);
 
-
-        // Fail if no entries found
         try {
-            if (results == null || !results.hasMore()) {
-                return null;
-            }
-        } catch (PartialResultException ex) {
-            if (!adCompat)
-                throw ex;
-            else
-                return null;
-        }
-
-        // Get result for the first entry found
-        SearchResult result = results.next();
-
-        // Check no further entries were found
-        try {
-            if (results.hasMore()) {
-                if(containerLog.isInfoEnabled())
-                    containerLog.info("username " + username + " has multiple entries");
+            // Fail if no entries found
+            try {
+                if (results == null || !results.hasMore()) {
+                    return null;
+                }
+            } catch (PartialResultException ex) {
+                if (!adCompat)
+                    throw ex;
+                else
+                    return null;
+            }
+    
+            // Get result for the first entry found
+            SearchResult result = results.next();
+    
+            // Check no further entries were found
+            try {
+                if (results.hasMore()) {
+                    if(containerLog.isInfoEnabled())
+                        containerLog.info("username " + username + " has multiple entries");
+                    return null;
+                }
+            } catch (PartialResultException ex) {
+                if (!adCompat)
+                    throw ex;
+            }
+    
+            String dn = getDistinguishedName(context, userBase, result);
+    
+            if (containerLog.isTraceEnabled())
+                containerLog.trace("  entry found for " + username + " with dn " + dn);
+    
+            // Get the entry's attributes
+            Attributes attrs = result.getAttributes();
+            if (attrs == null)
                 return null;
+    
+            // Retrieve value of userPassword
+            String password = null;
+            if (userPassword != null)
+                password = getAttributeValue(userPassword, attrs);
+    
+            String userRoleAttrValue = null;
+            if (userRoleAttribute != null) {
+                userRoleAttrValue = getAttributeValue(userRoleAttribute, attrs);
+            }
+    
+            // Retrieve values of userRoleName attribute
+            ArrayList<String> roles = null;
+            if (userRoleName != null)
+                roles = addAttributeValues(userRoleName, attrs, roles);
+    
+            return new User(username, dn, password, roles, userRoleAttrValue);
+        } finally {
+            if (results != null) {
+                results.close();
             }
-        } catch (PartialResultException ex) {
-            if (!adCompat)
-                throw ex;
         }
-
-        String dn = getDistinguishedName(context, userBase, result);
-
-        if (containerLog.isTraceEnabled())
-            containerLog.trace("  entry found for " + username + " with dn " + dn);
-
-        // Get the entry's attributes
-        Attributes attrs = result.getAttributes();
-        if (attrs == null)
-            return null;
-
-        // Retrieve value of userPassword
-        String password = null;
-        if (userPassword != null)
-            password = getAttributeValue(userPassword, attrs);
-
-        String userRoleAttrValue = null;
-        if (userRoleAttribute != null) {
-            userRoleAttrValue = getAttributeValue(userRoleAttribute, attrs);
-        }
-
-        // Retrieve values of userRoleName attribute
-        ArrayList<String> roles = null;
-        if (userRoleName != null)
-            roles = addAttributeValues(userRoleName, attrs, roles);
-
-        return new User(username, dn, password, roles, userRoleAttrValue);
     }
 
 
@@ -2003,6 +2008,8 @@ public class JNDIRealm extends RealmBase
         } catch (PartialResultException ex) {
             if (!adCompat)
                 throw ex;
+        } finally {
+            results.close();
         }
 
         if (containerLog.isTraceEnabled()) {
@@ -2054,6 +2061,8 @@ public class JNDIRealm extends RealmBase
                     } catch (PartialResultException ex) {
                         if (!adCompat)
                             throw ex;
+                    } finally {
+                        results.close();
                     }
                 }
 
@@ -2131,6 +2140,8 @@ public class JNDIRealm extends RealmBase
         } catch (PartialResultException ex) {
             if (!adCompat)
                 throw ex;
+        } finally {
+            e.close();
         }
         return values;
     }

Modified: tomcat/trunk/webapps/docs/changelog.xml
URL: http://svn.apache.org/viewvc/tomcat/trunk/webapps/docs/changelog.xml?rev=1733940&r1=1733939&r2=1733940&view=diff
==============================================================================
--- tomcat/trunk/webapps/docs/changelog.xml (original)
+++ tomcat/trunk/webapps/docs/changelog.xml Mon Mar  7 16:28:09 2016
@@ -156,6 +156,11 @@
        quoted-string, unquote the string before returning it to the user.
        (markt)
       </fix>
+      <fix>
+        <bug>59123</bug>: Close <code>NamingEnumeration</code> objects used by
+        the <code>JNDIRealm</code> once they are no longer required.
+        (fschumacher/markt)
+      </fix>
     </changelog>
   </subsection>
   <subsection name="Coyote">



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org