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

anton-vinogradov pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/ignite.git


The following commit(s) were added to refs/heads/master by this push:
     new de347aa5872 IGNITE-29209 Allow SSL context factories to reload their 
context (#13751)
de347aa5872 is described below

commit de347aa587248b852af64791c6a6d7362ec78428
Author: Anton Vinogradov <[email protected]>
AuthorDate: Fri Nov 6 19:47:34 2026 +0300

    IGNITE-29209 Allow SSL context factories to reload their context (#13751)
---
 .../ignite/ssl/AbstractSslContextFactory.java      | 19 ++++++--
 .../org/apache/ignite/ssl/SslContextFactory.java   |  4 --
 .../ignite/ssl/SslContextFactoryInitTest.java      | 56 ++++++++++++++++++++++
 .../ignite/testsuites/SecurityTestSuite.java       |  2 +
 4 files changed, 74 insertions(+), 7 deletions(-)

diff --git 
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
 
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
index 77dedf84eba..5139f98bc39 100644
--- 
a/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
+++ 
b/modules/commons/src/main/java/org/apache/ignite/ssl/AbstractSslContextFactory.java
@@ -30,9 +30,7 @@ import org.apache.ignite.IgniteException;
 import org.apache.ignite.internal.util.typedef.internal.A;
 
 /**
- * Represents abstract implementation of SSL Context Factory that caches the 
result of the first successful
- * attempt to create an {@link SSLContext} and always returns it as a result 
of further invocations of the
- * {@link AbstractSslContextFactory#create()}} method.
+ * Base class for SSL context factories that cache their {@link SSLContext}.
  */
 public abstract class AbstractSslContextFactory implements Factory<SSLContext> 
{
     /** */
@@ -178,6 +176,21 @@ public abstract class AbstractSslContextFactory implements 
Factory<SSLContext> {
      */
     protected abstract TrustManager[] createTrustManagers() throws 
SSLException;
 
+    /**
+     * Loads a new SSL context and caches it for the base implementation of 
{@link #create()}.
+     * If loading fails, the previously cached context is kept.
+     *
+     * @throws IgniteException If the context cannot be initialized.
+     */
+    protected final void init() {
+        try {
+            sslCtx.set(createSslContext());
+        }
+        catch (SSLException e) {
+            throw new IgniteException(e);
+        }
+    }
+
     /** {@inheritDoc} */
     @Override public SSLContext create() {
         SSLContext ctx = sslCtx.get();
diff --git 
a/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java 
b/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
index e060dcc241b..5db5c511c7b 100644
--- a/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
+++ b/modules/commons/src/main/java/org/apache/ignite/ssl/SslContextFactory.java
@@ -29,7 +29,6 @@ import java.security.cert.X509Certificate;
 import java.util.Arrays;
 import javax.net.ssl.KeyManager;
 import javax.net.ssl.KeyManagerFactory;
-import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLException;
 import javax.net.ssl.TrustManager;
 import javax.net.ssl.TrustManagerFactory;
@@ -39,9 +38,6 @@ import org.apache.ignite.internal.util.typedef.internal.A;
 
 /**
  * SSL context factory that provides SSL context configuration with specified 
key and trust stores.
- *
- * This factory caches the result of the first successful attempt to create an 
{@link SSLContext} and always returns it
- * as a result of further invocations of the {@link 
SslContextFactory#create()}} method.
  * <p>
  * In some cases it is useful to disable certificate validation of client side 
(e.g. when connecting
  * to a server with self-signed certificate). This can be achieved by setting 
a disabled trust manager
diff --git 
a/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
 
b/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
new file mode 100644
index 00000000000..5c3b9564b09
--- /dev/null
+++ 
b/modules/core/src/test/java/org/apache/ignite/ssl/SslContextFactoryInitTest.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ignite.ssl;
+
+import javax.net.ssl.SSLContext;
+import org.apache.ignite.IgniteException;
+import org.junit.Test;
+
+import static org.apache.ignite.testframework.GridTestUtils.sslTrustedFactory;
+import static org.junit.Assert.assertArrayEquals;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.assertThrows;
+
+/** */
+public class SslContextFactoryInitTest {
+    /** */
+    @Test
+    public void testInitUsesUpdatedProtocols() {
+        SslContextFactory factory = 
(SslContextFactory)sslTrustedFactory("node01", "trustone");
+
+        factory.setProtocols("TLSv1.2");
+        factory.create();
+
+        factory.setProtocols("TLSv1.3");
+        factory.init();
+
+        assertArrayEquals(new String[] {"TLSv1.3"}, 
factory.create().createSSLEngine().getEnabledProtocols());
+    }
+
+    /** */
+    @Test
+    public void testFailedInitKeepsContext() {
+        SslContextFactory factory = 
(SslContextFactory)sslTrustedFactory("node01", "trustone");
+        SSLContext original = factory.create();
+
+        factory.setKeyStorePassword("wrong-password".toCharArray());
+
+        assertThrows(IgniteException.class, factory::init);
+        assertSame(original, factory.create());
+    }
+}
diff --git 
a/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
 
b/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
index 37fa57703b5..4a2770a2064 100644
--- 
a/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
+++ 
b/modules/core/src/test/java/org/apache/ignite/testsuites/SecurityTestSuite.java
@@ -80,6 +80,7 @@ import 
org.apache.ignite.internal.thread.context.OperationContextAttributesTest;
 import 
org.apache.ignite.plugin.security.SecurityBasicPermissionSetSerializationTest;
 import org.apache.ignite.ssl.MultipleSSLContextsTest;
 import org.apache.ignite.ssl.SSLContextWrapperTest;
+import org.apache.ignite.ssl.SslContextFactoryInitTest;
 import org.apache.ignite.tools.junit.JUnitTeamcityReporter;
 import org.junit.BeforeClass;
 import org.junit.runner.RunWith;
@@ -143,6 +144,7 @@ import org.junit.runners.Suite;
     IgniteSecurityProcessorTest.class,
     MultipleSSLContextsTest.class,
     SSLContextWrapperTest.class,
+    SslContextFactoryInitTest.class,
     MaintenanceModeNodeSecurityTest.class,
     ServiceAuthorizationTest.class,
     ServiceStaticConfigTest.class,

Reply via email to