This is an automated email from the ASF dual-hosted git repository.
markt-asf pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/tomcat.git
The following commit(s) were added to refs/heads/main by this push:
new a3ba3c1390 Follow-up to "Track StartTlsResponse per connection in
JNDIRealm"
a3ba3c1390 is described below
commit a3ba3c1390291242e9f067fafb085494a7bd6663
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 b8396dc5df..bdb4a2ffb3 100644
--- a/java/org/apache/catalina/realm/JNDIRealm.java
+++ b/java/org/apache/catalina/realm/JNDIRealm.java
@@ -65,6 +65,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;
@@ -2794,30 +2795,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]