Make sure connections are closed in the event of an error.
authorwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 18 Aug 2003 22:01:42 +0000 (22:01 +0000)
committerwassa <wassa@ab3bd59b-922f-494d-bb5f-6f0a3c29deca>
Mon, 18 Aug 2003 22:01:42 +0000 (22:01 +0000)
git-svn-id: https://subversion.switch.ch/svn/shibboleth/java-idp/trunk@727 ab3bd59b-922f-494d-bb5f-6f0a3c29deca

src/edu/internet2/middleware/shibboleth/aa/attrresolv/provider/JNDIDirectoryDataConnector.java

index 9dabb70..8da9c84 100644 (file)
@@ -119,15 +119,24 @@ public class JNDIDirectoryDataConnector extends BaseResolutionPlugIn implements
                                throw new ResolutionPlugInException("Property is malformed.");
                        }
                }
+               InitialDirContext context = null;
                try {
-                       InitialDirContext context = new InitialDirContext(properties);
-                       context.close();
+                       context = new InitialDirContext(properties);
                        log.debug("JNDI Directory context activated.");
+                       
                } catch (NamingException e1) {
                        log.error("Failed to startup directory context: " + e1);
                        throw new ResolutionPlugInException("Failed to startup directory context.");
-               }
+               } finally {
+                       try {
+                               if (context != null) {
+                                       context.close();
+                               }
+                       } catch (NamingException ne) {
+                               //Squelch
+                       }
 
+               }
        }
 
        protected void defineSearchControls(Element searchNode) {
@@ -203,10 +212,12 @@ public class JNDIDirectoryDataConnector extends BaseResolutionPlugIn implements
        /**
         * @see edu.internet2.middleware.shibboleth.aa.attrresolv.DataConnectorPlugIn#resolve(java.security.Principal)
         */
-       public Attributes resolve(Principal principal, String requester, Dependencies depends) throws ResolutionPlugInException {
+       public Attributes resolve(Principal principal, String requester, Dependencies depends)
+               throws ResolutionPlugInException {
 
+               InitialDirContext context = null;
                try {
-                       InitialDirContext context = new InitialDirContext(properties);
+                       context = new InitialDirContext(properties);
                        NamingEnumeration enum = null;
 
                        try {
@@ -232,7 +243,6 @@ public class JNDIDirectoryDataConnector extends BaseResolutionPlugIn implements
                                throw new ResolutionPlugInException("Cannot disambiguate data for this principal.");
                        }
 
-                       context.close();
                        return attributes;
 
                } catch (NamingException e) {
@@ -242,6 +252,14 @@ public class JNDIDirectoryDataConnector extends BaseResolutionPlugIn implements
                                        + ") :"
                                        + e.getMessage());
                        throw new ResolutionPlugInException("Error retrieving data for principal.");
+               } finally {
+                       try {
+                               if (context != null) {
+                                       context.close();
+                               }
+                       } catch (NamingException e) {
+                               //Squelch
+                       }
                }
        }