Search in sources :

Example 6 with OAuthBearerValidatorCallback

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();
    }
}
Also used : OAuthBearerToken(org.apache.kafka.common.security.oauthbearer.OAuthBearerToken) OAuthBearerValidatorCallback(org.apache.kafka.common.security.oauthbearer.OAuthBearerValidatorCallback) Test(org.junit.jupiter.api.Test)

Aggregations

OAuthBearerValidatorCallback (org.apache.kafka.common.security.oauthbearer.OAuthBearerValidatorCallback)6 UnsupportedCallbackException (javax.security.auth.callback.UnsupportedCallbackException)3 IOException (java.io.IOException)2 OAuthBearerToken (org.apache.kafka.common.security.oauthbearer.OAuthBearerToken)2 Test (org.junit.jupiter.api.Test)2 Encoder (java.util.Base64.Encoder)1 HashMap (java.util.HashMap)1 Callback (javax.security.auth.callback.Callback)1 SaslAuthenticationException (org.apache.kafka.common.errors.SaslAuthenticationException)1 SaslExtensions (org.apache.kafka.common.security.auth.SaslExtensions)1 OAuthBearerExtensionsValidatorCallback (org.apache.kafka.common.security.oauthbearer.OAuthBearerExtensionsValidatorCallback)1 OAuthBearerTokenCallback (org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenCallback)1 OAuthBearerTokenMock (org.apache.kafka.common.security.oauthbearer.OAuthBearerTokenMock)1 OAuthBearerUnsecuredValidatorCallbackHandler (org.apache.kafka.common.security.oauthbearer.internals.unsecured.OAuthBearerUnsecuredValidatorCallbackHandler)1