[Jboss-cvs] JBossAS SVN: r56783 - branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Sep 12 16:23:01 EDT 2006


Author: scott.stark at jboss.org
Date: 2006-09-12 16:23:00 -0400 (Tue, 12 Sep 2006)
New Revision: 56783

Modified:
   branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
   branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapLoginModule.java
Log:
JBAS-3645, close all NamingEnumeration results as these delay the close of the context connection.

Modified: branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java
===================================================================
--- branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2006-09-12 20:19:14 UTC (rev 56782)
+++ branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapExtLoginModule.java	2006-09-12 20:23:00 UTC (rev 56783)
@@ -375,6 +375,7 @@
       results = ctx.search(baseDN, filter, filterArgs, constraints);
       if (results.hasMore() == false)
       {
+    	 results.close();
          throw new NamingException("Search of baseDN(" + baseDN + ") found no matches");
       }
 
@@ -386,6 +387,7 @@
       else
          throw new NamingException("Can't follow referal for authentication: " + name);
 
+      results.close();
       results = null;
       // Bind as the user dn to authenticate the user
       InitialLdapContext userCtx = constructInitialLdapContext(userDN, credential);
@@ -409,57 +411,65 @@
    {
       Object[] filterArgs = {user, userDN};
       NamingEnumeration results = ctx.search(rolesCtxDN, roleFilter, filterArgs, constraints);
-      while (results.hasMore())
+      try
       {
-         SearchResult sr = (SearchResult) results.next();
-         String dn = canonicalize(sr.getName());
-         String[] attrNames = {roleAttributeID};
-         Attributes result = ctx.getAttributes(dn, attrNames);
-         if( result != null && result.size() > 0 )
-         {
-            Attribute roles = result.get(roleAttributeID);
-            for (int n = 0; n < roles.size(); n ++)
-            {
-               String roleName = (String) roles.get(n);
-               try
-               {
-                  if (roleAttributeIsDN)
-                  {
-                     // Query the roleDN location for the value of roleNameAttributeID
-                     String roleDN = roleName;
-                     String[] returnAttribute = {roleNameAttributeID};
-                     log.trace("Using roleDN: " + roleDN);
-                     try
-                     {
-                        result = ctx.getAttributes(roleDN, returnAttribute);
-                        if (result.get(roleNameAttributeID) != null)
-                        {
-                           roleName = result.get(roleNameAttributeID).get().toString();
-                        }
-                     }
-                     catch (NamingException e)
-                     {
-                        log.trace("Failed to query roleNameAttrName", e);
-                     }
-                  }
-
-                  Principal p = super.createIdentity(roleName);
-                  log.trace("Assign user to role " + roleName);
-                  userRoles.addMember(p);
-               }
-               catch (Exception e)
-               {
-                  log.debug("Failed to create principal: " + roleName, e);
-               }
-            }
-         }
-
-         if (nesting < recursionMax)
-         {
-            rolesSearch(ctx, constraints, user, dn,
-               recursionMax, nesting + 1);
-         }
+	      while (results.hasMore())
+	      {
+	         SearchResult sr = (SearchResult) results.next();
+	         String dn = canonicalize(sr.getName());
+	         String[] attrNames = {roleAttributeID};
+	         Attributes result = ctx.getAttributes(dn, attrNames);
+	         if( result != null && result.size() > 0 )
+	         {
+	            Attribute roles = result.get(roleAttributeID);
+	            for (int n = 0; n < roles.size(); n ++)
+	            {
+	               String roleName = (String) roles.get(n);
+	               try
+	               {
+	                  if (roleAttributeIsDN)
+	                  {
+	                     // Query the roleDN location for the value of roleNameAttributeID
+	                     String roleDN = roleName;
+	                     String[] returnAttribute = {roleNameAttributeID};
+	                     log.trace("Using roleDN: " + roleDN);
+	                     try
+	                     {
+	                        result = ctx.getAttributes(roleDN, returnAttribute);
+	                        if (result.get(roleNameAttributeID) != null)
+	                        {
+	                           roleName = result.get(roleNameAttributeID).get().toString();
+	                        }
+	                     }
+	                     catch (NamingException e)
+	                     {
+	                        log.trace("Failed to query roleNameAttrName", e);
+	                     }
+	                  }
+	
+	                  Principal p = super.createIdentity(roleName);
+	                  log.trace("Assign user to role " + roleName);
+	                  userRoles.addMember(p);
+	               }
+	               catch (Exception e)
+	               {
+	                  log.debug("Failed to create principal: " + roleName, e);
+	               }
+	            }
+	         }
+	
+	         if (nesting < recursionMax)
+	         {
+	            rolesSearch(ctx, constraints, user, dn,
+	               recursionMax, nesting + 1);
+	         }
+	      }
       }
+      finally
+      {
+    	  if( results != null )
+    		  results.close();
+      }
 
    }
 

Modified: branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapLoginModule.java
===================================================================
--- branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapLoginModule.java	2006-09-12 20:19:14 UTC (rev 56782)
+++ branches/Branch_4_0/security/src/main/org/jboss/security/auth/spi/LdapLoginModule.java	2006-09-12 20:23:00 UTC (rev 56783)
@@ -463,6 +463,7 @@
                   }
                }
             }
+            answer.close();
          }
          catch (NamingException e)
          {




More information about the jboss-cvs-commits mailing list