From 5691df0e334247de60cef7d7fdc4857e8f46d8af Mon Sep 17 00:00:00 2001 From: Muskan Gupta Date: Fri, 24 Jan 2025 14:59:17 +0530 Subject: [PATCH] Test change --- .../sqlserver/jdbc/KerbAuthentication.java | 6 +++- .../sqlserver/jdbc/KerberosTest.java | 32 +++++++------------ 2 files changed, 16 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java index 78af53c0f..120f78999 100644 --- a/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java +++ b/src/main/java/com/microsoft/sqlserver/jdbc/KerbAuthentication.java @@ -107,7 +107,11 @@ private void initAuthInit() throws SQLServerException { } if (null == currentSubject) { - lc = new LoginContext(configName, null, callback, new JaasConfiguration(Configuration.getConfiguration())); + if (useDefaultJaas) { + lc = new LoginContext(configName, null, callback, new JaasConfiguration(null)); + } else { + lc = new LoginContext(configName, callback); + } lc.login(); // per documentation LoginContext will instantiate a new subject. currentSubject = lc.getSubject(); diff --git a/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java b/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java index 0c5a781a1..1f38f9a63 100644 --- a/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java +++ b/src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java @@ -26,30 +26,20 @@ public class KerberosTest extends AbstractTest { @BeforeAll public static void setupTests() throws Exception { - setJaasConfiguration(); + configureJaas(); setConnection(); } - private static void setJaasConfiguration() { - AppConfigurationEntry[] entries = new AppConfigurationEntry[]{ - new AppConfigurationEntry( - "com.sun.security.auth.module.Krb5LoginModule", - AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, - new HashMap() {{ - put("useTicketCache", "true"); - put("renewTGT", "true"); - }} - ) - }; - Configuration.setConfiguration(new Configuration() { - @Override - public AppConfigurationEntry[] getAppConfigurationEntry(String name) { - if ("SQLJDBCDriver".equals(name)) { - return entries; - } - return null; - } - }); + /** + * Configures JAAS for the test environment. + */ + private static void configureJaas() { + AppConfigurationEntry kafkaClientConfigurationEntry = new AppConfigurationEntry( + "com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED, + new HashMap<>()); + Map configurationEntries = new HashMap<>(); + configurationEntries.put("SQLJDBCDriver", new AppConfigurationEntry[] {kafkaClientConfigurationEntry}); + Configuration.setConfiguration(new InternalConfiguration(configurationEntries)); } @Test