use of org.apache.kafka.common.security.oauthbearer.OAuthBearerValidatorCallback in project kafka by apache.
the class OAuthBearerValidatorCallbackHandlerTest method testBasic.
@Test
public void testBasic() throws Exception {
String expectedAudience = "a";
List<String> allAudiences = Arrays.asList(expectedAudience, "b", "c");
AccessTokenBuilder builder = new AccessTokenBuilder().audience(expectedAudience).jwk(createRsaJwk()).alg(AlgorithmIdentifiers.RSA_USING_SHA256);
String accessToken = builder.build();
Map<String, ?> configs = getSaslConfigs(SASL_OAUTHBEARER_EXPECTED_AUDIENCE, allAudiences);
OAuthBearerValidatorCallbackHandler handler = createHandler(configs, builder);
try {
OAuthBearerValidatorCallback callback = new OAuthBearerValidatorCallback(accessToken);
handler.handle(new Callback[] { callback });
assertNotNull(callback.token());
OAuthBearerToken token = callback.token();
assertEquals(accessToken, token.value());
assertEquals(builder.subject(), token.principalName());
assertEquals(builder.expirationSeconds() * 1000, token.lifetimeMs());
assertEquals(builder.issuedAtSeconds() * 1000, token.startTimeMs());
} finally {
handler.close();
}
}
Aggregations