@@ -25,25 +25,30 @@ public class KerberosTest extends AbstractTest {
25
25
26
26
@ BeforeAll
27
27
public static void setupTests () throws Exception {
28
- configureJaas ();
28
+ setJaasConfiguration ();
29
29
setConnection ();
30
30
}
31
31
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
+ });
47
52
}
48
53
49
54
@ Test
@@ -109,28 +114,6 @@ private static void createKerberosConnection(String connectionString) throws Exc
109
114
}
110
115
}
111
116
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
-
134
117
/**
135
118
* Overwrites the default JAAS config. Call before making a connection.
136
119
*/
0 commit comments