This is an automated email from the ASF dual-hosted git repository.

markt-asf pushed a commit to branch 9.0.x
in repository https://gitbox.apache.org/repos/asf/tomcat.git


The following commit(s) were added to refs/heads/9.0.x by this push:
     new 880b615268 Follow-up to "Track StartTlsResponse per connection in 
JNDIRealm"
880b615268 is described below

commit 880b615268eb00d6a40c06251f5433c87e0da77b
Author: Mark Thomas <[email protected]>
AuthorDate: Sun Oct 11 10:44:25 2026 +0100

    Follow-up to "Track StartTlsResponse per connection in JNDIRealm"
    
    Improve clean-up in error handling
---
 java/org/apache/catalina/realm/JNDIRealm.java | 54 ++++++++++++++++++---------
 1 file changed, 37 insertions(+), 17 deletions(-)

diff --git a/java/org/apache/catalina/realm/JNDIRealm.java 
b/java/org/apache/catalina/realm/JNDIRealm.java
index 561ed09a69..2d3a219691 100644
--- a/java/org/apache/catalina/realm/JNDIRealm.java
+++ b/java/org/apache/catalina/realm/JNDIRealm.java
@@ -63,6 +63,7 @@ import javax.net.ssl.SSLSession;
 import javax.net.ssl.SSLSocketFactory;
 
 import org.apache.catalina.LifecycleException;
+import org.apache.tomcat.util.ExceptionUtils;
 import org.apache.tomcat.util.buf.StringUtils;
 import org.apache.tomcat.util.collections.SynchronizedStack;
 import org.ietf.jgss.GSSContext;
@@ -2813,30 +2814,49 @@ public class JNDIRealm extends RealmBase {
             }
         }
         LdapContext result = null;
+        StartTlsResponse tls = null;
         try {
             result = new InitialLdapContext(env, null);
-            StartTlsResponse tls = (StartTlsResponse) 
result.extendedOperation(new StartTlsRequest());
+            tls = (StartTlsResponse) result.extendedOperation(new 
StartTlsRequest());
+            if (getHostnameVerifier() != null) {
+                tls.setHostnameVerifier(getHostnameVerifier());
+            }
+            if (getCipherSuitesArray() != null) {
+                tls.setEnabledCipherSuites(getCipherSuitesArray());
+            }
+            SSLSession negotiate = tls.negotiate(getSSLSocketFactory());
+            containerLog.debug(sm.getString("jndiRealm.negotiatedTls", 
negotiate.getProtocol()));
+            for (Map.Entry<String,Object> savedEntry : savedEnv.entrySet()) {
+                result.addToEnvironment(savedEntry.getKey(), 
savedEntry.getValue());
+            }
+            connection.tls = tls;
+        } catch (Throwable t) {
+            ExceptionUtils.handleThrowable(t);
+            NamingException ne;
+            if (t instanceof NamingException) {
+                ne = (NamingException) t;
+            } else {
+                ne = new NamingException(t.getMessage());
+                ne.initCause(t);
+            }
             try {
-                if (getHostnameVerifier() != null) {
-                    tls.setHostnameVerifier(getHostnameVerifier());
-                }
-                if (getCipherSuitesArray() != null) {
-                    tls.setEnabledCipherSuites(getCipherSuitesArray());
+                if (tls != null) {
+                    tls.close();
                 }
-                SSLSession negotiate = tls.negotiate(getSSLSocketFactory());
-                containerLog.debug(sm.getString("jndiRealm.negotiatedTls", 
negotiate.getProtocol()));
-                connection.tls = tls;
-            } catch (IOException ioe) {
-                NamingException ne = new NamingException(ioe.getMessage());
-                ne.initCause(ioe);
-                throw ne;
+            } catch (Throwable t1) {
+                ExceptionUtils.handleThrowable(t1);
+                ne.addSuppressed(t1);
             }
-        } finally {
-            if (result != null) {
-                for (Map.Entry<String,Object> savedEntry : 
savedEnv.entrySet()) {
-                    result.addToEnvironment(savedEntry.getKey(), 
savedEntry.getValue());
+            try {
+                if (result != null) {
+                    result.close();
                 }
+            } catch (Throwable t2) {
+                ExceptionUtils.handleThrowable(t2);
+                ne.addSuppressed(t2);
             }
+            result = null;
+            throw ne;
         }
         return result;
     }


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to