From 153b3176291c21d055cc1d6c34209f90d9d760f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Wed, 7 Jan 2026 09:49:23 -0500 Subject: [PATCH 1/2] fix(jPOS-665) JCESecurityManager is ignoring the `debug` property. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Call super.setConfiguration, instead of just assigning cfg. Signed-off-by: Andrés Alcarraz --- .../jceadapter/JCESecurityModule.java | 2 +- .../jceadapter/JCESecurityModuleTest.java | 30 +++++++++++++++++++ 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/jpos/src/main/java/org/jpos/security/jceadapter/JCESecurityModule.java b/jpos/src/main/java/org/jpos/security/jceadapter/JCESecurityModule.java index 4fa8b72551..39b420f9c4 100644 --- a/jpos/src/main/java/org/jpos/security/jceadapter/JCESecurityModule.java +++ b/jpos/src/main/java/org/jpos/security/jceadapter/JCESecurityModule.java @@ -178,7 +178,7 @@ public JCESecurityModule (Configuration cfg, Logger logger, String realm) throws */ @Override public void setConfiguration (Configuration cfg) throws ConfigurationException { - this.cfg = cfg; + super.setConfiguration(cfg); try { init(cfg.get("provider"), cfg.get("lmk", null), cfg.getBoolean("rebuildlmk")); } catch (SMException e) { diff --git a/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java b/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java index 838ef35f60..6fbf233d55 100644 --- a/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java +++ b/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java @@ -45,6 +45,10 @@ import org.jpos.security.SMException; import org.jpos.security.SecureDESKey; import org.jpos.util.Logger; +import org.jpos.util.LogEvent; +import org.jpos.util.LogListener; +import java.io.File; +import static org.mockito.Mockito.*; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -1821,4 +1825,30 @@ public void testFormKeyFromClearComponent() throws Throwable { assertArrayEquals(ISOUtil.hex2byte("40D522"), sdk.getKeyCheckValue(), "3: KeyCheck was " + ISOUtil.hexString(sdk.getKeyCheckValue())); } + @Test + public void testDebugPropertyEnablesLogging() throws Exception { + JCESecurityModule module = new JCESecurityModule(); + Configuration cfg = new SimpleConfiguration(); + + File tempLmk = File.createTempFile("test-lmk", ".lmk"); + tempLmk.deleteOnExit(); + + cfg.put("lmk", tempLmk.getAbsolutePath()); + cfg.put("rebuildlmk", "true"); + cfg.put("debug", "true"); + + + module.setConfiguration(cfg); + + Logger logger = new Logger(); + LogListener listener = mock(LogListener.class); + logger.addListener(listener); + module.setLogger(logger, "test-realm"); + + // Generate a key to trigger logging + module.generateKey((short) 128, "ZPK"); + + verify(listener, times(1)).log(any(LogEvent.class)); + } + } From 2547ba289e95201b4b3ab809d633f62b699e4387 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andr=C3=A9s=20Alcarraz?= Date: Wed, 7 Jan 2026 10:43:27 -0500 Subject: [PATCH 2/2] Don't be too specific on exceptions. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Andrés Alcarraz --- .../jceadapter/JCESecurityModuleTest.java | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java b/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java index 6fbf233d55..3c8aa0c2cf 100644 --- a/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java +++ b/jpos/src/test/java/org/jpos/security/jceadapter/JCESecurityModuleTest.java @@ -327,12 +327,8 @@ public void testConstructorThrowsNullPointerException2() throws Throwable { try { new JCESecurityModule(cfg, new Logger(), "testJCESecurityModuleRealm"); fail("Expected NullPointerException to be thrown"); - } catch (NullPointerException ex) { - if (isJavaVersionAtMost(JAVA_14)) { - assertNull(ex.getMessage(), "ex.getMessage()"); - } else { - assertEquals("Cannot invoke \"org.jpos.core.Configuration.get(String)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()"); - } + } catch (NullPointerException _) { + //expected } } @@ -684,12 +680,8 @@ public void testSetConfigurationThrowsNullPointerException() throws Throwable { try { jCESecurityModule.setConfiguration(cfg); fail("Expected NullPointerException to be thrown"); - } catch (NullPointerException ex) { - if (isJavaVersionAtMost(JAVA_14)) { - assertNull(ex.getMessage(), "ex.getMessage()"); - } else { - assertEquals("Cannot invoke \"org.jpos.core.Configuration.get(String)\" because \"this.cfg\" is null", ex.getMessage(), "ex.getMessage()"); - } + } catch (NullPointerException _) { + //expected } }