use of org.apache.kafka.common.security.authenticator.TestJaasConfig in project kafka by apache.
the class SaslChannelBuilderTest method createChannelBuilder.
private SaslChannelBuilder createChannelBuilder(SecurityProtocol securityProtocol, String saslMechanism) {
Class<?> loginModule = null;
switch(saslMechanism) {
case "PLAIN":
loginModule = PlainLoginModule.class;
break;
case "SCRAM-SHA-256":
loginModule = ScramLoginModule.class;
break;
case "OAUTHBEARER":
loginModule = OAuthBearerLoginModule.class;
break;
case "GSSAPI":
loginModule = TestGssapiLoginModule.class;
break;
default:
throw new IllegalArgumentException("Unsupported SASL mechanism " + saslMechanism);
}
TestJaasConfig jaasConfig = new TestJaasConfig();
jaasConfig.addEntry("jaasContext", loginModule.getName(), new HashMap<>());
JaasContext jaasContext = new JaasContext("jaasContext", JaasContext.Type.SERVER, jaasConfig, null);
Map<String, JaasContext> jaasContexts = Collections.singletonMap(saslMechanism, jaasContext);
return new SaslChannelBuilder(Mode.CLIENT, jaasContexts, securityProtocol, new ListenerName(saslMechanism), false, saslMechanism, true, null, null, null, Time.SYSTEM, new LogContext(), defaultApiVersionsSupplier());
}
use of org.apache.kafka.common.security.authenticator.TestJaasConfig in project kafka by apache.
the class SaslChannelBuilderTest method testNativeGssapiCredentials.
@Test
public void testNativeGssapiCredentials() throws Exception {
System.setProperty(SaslChannelBuilder.GSS_NATIVE_PROP, "true");
TestJaasConfig jaasConfig = new TestJaasConfig();
jaasConfig.addEntry("jaasContext", TestGssapiLoginModule.class.getName(), new HashMap<>());
JaasContext jaasContext = new JaasContext("jaasContext", JaasContext.Type.SERVER, jaasConfig, null);
Map<String, JaasContext> jaasContexts = Collections.singletonMap("GSSAPI", jaasContext);
GSSManager gssManager = Mockito.mock(GSSManager.class);
GSSName gssName = Mockito.mock(GSSName.class);
Mockito.when(gssManager.createName(Mockito.anyString(), Mockito.any())).thenAnswer(unused -> gssName);
Oid oid = new Oid("1.2.840.113554.1.2.2");
Mockito.when(gssManager.createCredential(gssName, GSSContext.INDEFINITE_LIFETIME, oid, GSSCredential.ACCEPT_ONLY)).thenAnswer(unused -> Mockito.mock(GSSCredential.class));
SaslChannelBuilder channelBuilder1 = createGssapiChannelBuilder(jaasContexts, gssManager);
assertEquals(1, channelBuilder1.subject("GSSAPI").getPrincipals().size());
assertEquals(1, channelBuilder1.subject("GSSAPI").getPrivateCredentials().size());
SaslChannelBuilder channelBuilder2 = createGssapiChannelBuilder(jaasContexts, gssManager);
assertEquals(1, channelBuilder2.subject("GSSAPI").getPrincipals().size());
assertEquals(1, channelBuilder2.subject("GSSAPI").getPrivateCredentials().size());
assertSame(channelBuilder1.subject("GSSAPI"), channelBuilder2.subject("GSSAPI"));
Mockito.verify(gssManager, Mockito.times(1)).createCredential(gssName, GSSContext.INDEFINITE_LIFETIME, oid, GSSCredential.ACCEPT_ONLY);
}
use of org.apache.kafka.common.security.authenticator.TestJaasConfig in project kafka by apache.
the class OAuthBearerUnsecuredValidatorCallbackHandlerTest method createCallbackHandler.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static OAuthBearerUnsecuredValidatorCallbackHandler createCallbackHandler(Map<String, String> options) {
TestJaasConfig config = new TestJaasConfig();
config.createOrUpdateEntry("KafkaClient", "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule", (Map) options);
OAuthBearerUnsecuredValidatorCallbackHandler callbackHandler = new OAuthBearerUnsecuredValidatorCallbackHandler();
callbackHandler.configure(Collections.emptyMap(), OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, Arrays.asList(config.getAppConfigurationEntry("KafkaClient")[0]));
return callbackHandler;
}
use of org.apache.kafka.common.security.authenticator.TestJaasConfig in project kafka by apache.
the class OAuthBearerUnsecuredLoginCallbackHandlerTest method createCallbackHandler.
@SuppressWarnings({ "unchecked", "rawtypes" })
private static OAuthBearerUnsecuredLoginCallbackHandler createCallbackHandler(Map<String, String> options, MockTime mockTime) {
TestJaasConfig config = new TestJaasConfig();
config.createOrUpdateEntry("KafkaClient", "org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule", (Map) options);
OAuthBearerUnsecuredLoginCallbackHandler callbackHandler = new OAuthBearerUnsecuredLoginCallbackHandler();
callbackHandler.time(mockTime);
callbackHandler.configure(Collections.emptyMap(), OAuthBearerLoginModule.OAUTHBEARER_MECHANISM, Arrays.asList(config.getAppConfigurationEntry("KafkaClient")[0]));
return callbackHandler;
}
Aggregations