16
16
import java .util .HashMap ;
17
17
import java .util .Map ;
18
18
19
-
20
19
@ Tag (Constants .kerberos )
21
20
@ RunWith (JUnitPlatform .class )
22
21
public class KerberosTest extends AbstractTest {
@@ -34,11 +33,16 @@ public static void setupTests() throws Exception {
34
33
* Configures JAAS for the test environment.
35
34
*/
36
35
private static void configureJaas () {
37
- AppConfigurationEntry kafkaClientConfigurationEntry = new AppConfigurationEntry (
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 (
38
42
"com.sun.security.auth.module.Krb5LoginModule" , AppConfigurationEntry .LoginModuleControlFlag .REQUIRED ,
39
- new HashMap <>() );
43
+ options );
40
44
Map <String , AppConfigurationEntry []> configurationEntries = new HashMap <>();
41
- configurationEntries .put ("SQLJDBCDriver" , new AppConfigurationEntry [] {kafkaClientConfigurationEntry });
45
+ configurationEntries .put ("SQLJDBCDriver" , new AppConfigurationEntry [] {kerberosConfigurationEntry });
42
46
Configuration .setConfiguration (new InternalConfiguration (configurationEntries ));
43
47
}
44
48
@@ -105,15 +109,42 @@ private static void createKerberosConnection(String connectionString) throws Exc
105
109
}
106
110
}
107
111
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
+
108
134
/**
109
135
* Overwrites the default JAAS config. Call before making a connection.
110
136
*/
111
137
private static void overwriteJaasConfig () {
112
- AppConfigurationEntry kafkaClientConfigurationEntry = new AppConfigurationEntry (
138
+ Map <String , String > options = new HashMap <>();
139
+ options .put ("useTicketCache" , "true" );
140
+ options .put ("renewTGT" , "true" );
141
+ options .put ("doNotPrompt" , "false" ); // Allow prompting for credentials if necessary
142
+
143
+ AppConfigurationEntry kerberosConfigurationEntry = new AppConfigurationEntry (
113
144
"com.sun.security.auth.module.Krb5LoginModule" , AppConfigurationEntry .LoginModuleControlFlag .REQUIRED ,
114
- new HashMap <>() );
145
+ options );
115
146
Map <String , AppConfigurationEntry []> configurationEntries = new HashMap <>();
116
- configurationEntries .put ("CLIENT_CONTEXT_NAME" , new AppConfigurationEntry [] {kafkaClientConfigurationEntry });
147
+ configurationEntries .put ("CLIENT_CONTEXT_NAME" , new AppConfigurationEntry [] {kerberosConfigurationEntry });
117
148
Configuration .setConfiguration (new InternalConfiguration (configurationEntries ));
118
149
}
119
150
0 commit comments