Skip to content

Commit a466021

Browse files
committed
Updated Jaas config for test
1 parent c92be4a commit a466021

File tree

1 file changed

+21
-38
lines changed

1 file changed

+21
-38
lines changed

src/test/java/com/microsoft/sqlserver/jdbc/KerberosTest.java

+21-38
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,30 @@ public class KerberosTest extends AbstractTest {
2525

2626
@BeforeAll
2727
public static void setupTests() throws Exception {
28-
configureJaas();
28+
setJaasConfiguration();
2929
setConnection();
3030
}
3131

32-
/**
33-
* Configures JAAS for the test environment.
34-
*/
35-
private static void configureJaas() {
36-
Map<String, String> options = new HashMap<>();
37-
options.put("useTicketCache", "true");
38-
options.put("renewTGT", "true");
39-
options.put("doNotPrompt", "false"); // Allow prompting for credentials if necessary
40-
41-
AppConfigurationEntry kerberosConfigurationEntry = new AppConfigurationEntry(
42-
"com.sun.security.auth.module.Krb5LoginModule", AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
43-
options);
44-
Map<String, AppConfigurationEntry[]> configurationEntries = new HashMap<>();
45-
configurationEntries.put("SQLJDBCDriver", new AppConfigurationEntry[] {kerberosConfigurationEntry});
46-
Configuration.setConfiguration(new InternalConfiguration(configurationEntries));
32+
private static void setJaasConfiguration() {
33+
AppConfigurationEntry[] entries = new AppConfigurationEntry[]{
34+
new AppConfigurationEntry(
35+
"com.sun.security.auth.module.Krb5LoginModule",
36+
AppConfigurationEntry.LoginModuleControlFlag.REQUIRED,
37+
new HashMap<String, Object>() {{
38+
put("useTicketCache", "true");
39+
put("renewTGT", "true");
40+
}}
41+
)
42+
};
43+
Configuration.setConfiguration(new Configuration() {
44+
@Override
45+
public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
46+
if ("SQLJDBCDriver".equals(name)) {
47+
return entries;
48+
}
49+
return null;
50+
}
51+
});
4752
}
4853

4954
@Test
@@ -109,28 +114,6 @@ private static void createKerberosConnection(String connectionString) throws Exc
109114
}
110115
}
111116

112-
/**
113-
* Test to verify the Kerberos module used
114-
*/
115-
@Test
116-
public void testKerberosConnectionWithDefaultJaasConfig() {
117-
try {
118-
// Set a mock JAAS configuration using the existing method
119-
overwriteJaasConfig();
120-
121-
String connectionString = connectionStringKerberos + ";useDefaultJaasConfig=true;";
122-
createKerberosConnection(connectionString);
123-
124-
Configuration config = Configuration.getConfiguration();
125-
AppConfigurationEntry[] entries = config.getAppConfigurationEntry("CLIENT_CONTEXT_NAME");
126-
Assertions.assertNotNull(entries);
127-
Assertions.assertTrue(entries.length > 0);
128-
Assertions.assertEquals("com.sun.security.auth.module.Krb5LoginModule", entries[0].getLoginModuleName());
129-
} catch (Exception e) {
130-
Assertions.fail("Exception was thrown: " + e.getMessage());
131-
}
132-
}
133-
134117
/**
135118
* Overwrites the default JAAS config. Call before making a connection.
136119
*/

0 commit comments

Comments
 (0)