use of org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback in project kafka by apache.
the class OAuthBearerUnsecuredLoginCallbackHandlerTest method minimalToken.
@Test
public void minimalToken() throws IOException, UnsupportedCallbackException {
Map<String, String> options = new HashMap<>();
String user = "user";
options.put("unsecuredLoginStringClaim_sub", user);
MockTime mockTime = new MockTime();
OAuthBearerUnsecuredLoginCallbackHandler callbackHandler = createCallbackHandler(options, mockTime);
OAuthBearerTokenCallback callback = new OAuthBearerTokenCallback();
callbackHandler.handle(new Callback[] { callback });
OAuthBearerUnsecuredJws jws = (OAuthBearerUnsecuredJws) callback.token();
assertNotNull(jws, "create token failed");
long startMs = mockTime.milliseconds();
confirmCorrectValues(jws, user, startMs, 1000 * 60 * 60);
assertEquals(new HashSet<>(Arrays.asList("sub", "iat", "exp")), jws.claims().keySet());
}
use of org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback in project kafka by apache.
the class OAuthBearerLoginCallbackHandlerTest method testMissingAccessToken.
@Test
public void testMissingAccessToken() {
AccessTokenRetriever accessTokenRetriever = () -> {
throw new IOException("The token endpoint response access_token value must be non-null");
};
Map<String, ?> configs = getSaslConfigs();
OAuthBearerLoginCallbackHandler handler = createHandler(accessTokenRetriever, configs);
try {
OAuthBearerTokenCallback callback = new OAuthBearerTokenCallback();
assertThrowsWithMessage(IOException.class, () -> handler.handle(new Callback[] { callback }), "token endpoint response access_token value must be non-null");
} finally {
handler.close();
}
}
Aggregations