use of org.apache.kafka.common.security.auth.SaslExtensionsCallback in project kafka by apache.
the class OAuthBearerLoginCallbackHandlerTest method testHandleSaslExtensionsCallback.
@Test
public void testHandleSaslExtensionsCallback() throws Exception {
OAuthBearerLoginCallbackHandler handler = new OAuthBearerLoginCallbackHandler();
Map<String, ?> configs = getSaslConfigs(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL, "http://www.example.com");
Map<String, Object> jaasConfig = new HashMap<>();
jaasConfig.put(CLIENT_ID_CONFIG, "an ID");
jaasConfig.put(CLIENT_SECRET_CONFIG, "a secret");
jaasConfig.put("extension_foo", "1");
jaasConfig.put("extension_bar", 2);
jaasConfig.put("EXTENSION_baz", "3");
configureHandler(handler, configs, jaasConfig);
try {
SaslExtensionsCallback callback = new SaslExtensionsCallback();
handler.handle(new Callback[] { callback });
assertNotNull(callback.extensions());
Map<String, String> extensions = callback.extensions().map();
assertEquals("1", extensions.get("foo"));
assertEquals("2", extensions.get("bar"));
assertNull(extensions.get("baz"));
assertEquals(2, extensions.size());
} finally {
handler.close();
}
}
use of org.apache.kafka.common.security.auth.SaslExtensionsCallback in project kafka by apache.
the class OAuthBearerLoginCallbackHandlerTest method testHandleSaslExtensionsCallbackWithInvalidExtension.
@Test
public void testHandleSaslExtensionsCallbackWithInvalidExtension() {
String illegalKey = "extension_" + OAuthBearerClientInitialResponse.AUTH_KEY;
OAuthBearerLoginCallbackHandler handler = new OAuthBearerLoginCallbackHandler();
Map<String, ?> configs = getSaslConfigs(SASL_OAUTHBEARER_TOKEN_ENDPOINT_URL, "http://www.example.com");
Map<String, Object> jaasConfig = new HashMap<>();
jaasConfig.put(CLIENT_ID_CONFIG, "an ID");
jaasConfig.put(CLIENT_SECRET_CONFIG, "a secret");
jaasConfig.put(illegalKey, "this key isn't allowed per OAuthBearerClientInitialResponse.validateExtensions");
configureHandler(handler, configs, jaasConfig);
try {
SaslExtensionsCallback callback = new SaslExtensionsCallback();
assertThrowsWithMessage(ConfigException.class, () -> handler.handle(new Callback[] { callback }), "Extension name " + OAuthBearerClientInitialResponse.AUTH_KEY + " is invalid");
} finally {
handler.close();
}
}
use of org.apache.kafka.common.security.auth.SaslExtensionsCallback in project kafka by apache.
the class OAuthBearerUnsecuredLoginCallbackHandlerTest method addsExtensions.
@Test
public void addsExtensions() throws IOException, UnsupportedCallbackException {
Map<String, String> options = new HashMap<>();
options.put("unsecuredLoginExtension_testId", "1");
OAuthBearerUnsecuredLoginCallbackHandler callbackHandler = createCallbackHandler(options, new MockTime());
SaslExtensionsCallback callback = new SaslExtensionsCallback();
callbackHandler.handle(new Callback[] { callback });
assertEquals("1", callback.extensions().map().get("testId"));
}
use of org.apache.kafka.common.security.auth.SaslExtensionsCallback in project kafka by apache.
the class OAuthBearerUnsecuredLoginCallbackHandlerTest method throwsErrorOnInvalidExtensionValue.
@Test
public void throwsErrorOnInvalidExtensionValue() {
Map<String, String> options = new HashMap<>();
options.put("unsecuredLoginExtension_testId", "Çalifornia");
OAuthBearerUnsecuredLoginCallbackHandler callbackHandler = createCallbackHandler(options, new MockTime());
SaslExtensionsCallback callback = new SaslExtensionsCallback();
assertThrows(IOException.class, () -> callbackHandler.handle(new Callback[] { callback }));
}
use of org.apache.kafka.common.security.auth.SaslExtensionsCallback in project kafka by apache.
the class OAuthBearerLoginModule method identifyExtensions.
/**
* Attaches SASL extensions to the Subject
*/
private void identifyExtensions() throws LoginException {
SaslExtensionsCallback extensionsCallback = new SaslExtensionsCallback();
try {
callbackHandler.handle(new Callback[] { extensionsCallback });
extensionsRequiringCommit = extensionsCallback.extensions();
} catch (IOException e) {
log.error(e.getMessage(), e);
throw new LoginException("An internal error occurred while retrieving SASL extensions from callback handler");
} catch (UnsupportedCallbackException e) {
extensionsRequiringCommit = EMPTY_EXTENSIONS;
log.debug("CallbackHandler {} does not support SASL extensions. No extensions will be added", callbackHandler.getClass().getName());
}
if (extensionsRequiringCommit == null) {
log.error("SASL Extensions cannot be null. Check whether your callback handler is explicitly setting them as null.");
throw new LoginException("Extensions cannot be null.");
}
}
Aggregations