Skip to content

Commit

Permalink
Add OAuth support for Kafka client in native mode
Browse files Browse the repository at this point in the history
  • Loading branch information
dejanb committed Oct 15, 2020
1 parent 8070d9f commit 0122ea9
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@
import org.apache.kafka.common.security.authenticator.AbstractLogin;
import org.apache.kafka.common.security.authenticator.DefaultLogin;
import org.apache.kafka.common.security.authenticator.SaslClientCallbackHandler;
import org.apache.kafka.common.security.oauthbearer.OAuthBearerToken;
import org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerRefreshingLogin;
import org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerSaslClient;
import org.apache.kafka.common.serialization.ByteArrayDeserializer;
import org.apache.kafka.common.serialization.ByteArraySerializer;
import org.apache.kafka.common.serialization.ByteBufferDeserializer;
Expand Down Expand Up @@ -113,6 +116,11 @@ public void build(CombinedIndexBuildItem indexBuildItem, BuildProducer<Reflectiv
collectImplementors(toRegister, indexBuildItem, PartitionAssignor.class);
collectImplementors(toRegister, indexBuildItem, ConsumerPartitionAssignor.class);

reflectiveClass.produce(new ReflectiveClassBuildItem(false, false,
OAuthBearerSaslClient.class,
OAuthBearerToken.class,
OAuthBearerRefreshingLogin.class));

for (Class<?> i : BUILT_INS) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, i.getName()));
collectSubclasses(toRegister, indexBuildItem, i);
Expand Down Expand Up @@ -209,6 +217,28 @@ public void build(CombinedIndexBuildItem indexBuildItem, BuildProducer<Reflectiv
//ignore, Apicurio Avro is not in the classpath
}

try {
Class.forName("io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler", false,
Thread.currentThread().getContextClassLoader());

reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true,
"io.strimzi.kafka.oauth.client.JaasClientOauthLoginCallbackHandler"));

reflectiveClass.produce(new ReflectiveClassBuildItem(true, true, true,
"org.keycloak.jose.jws.JWSHeader",
"org.keycloak.representations.AccessToken",
"org.keycloak.representations.AccessToken$Access",
"org.keycloak.representations.AccessTokenResponse",
"org.keycloak.representations.IDToken",
"org.keycloak.representations.JsonWebToken",
"org.keycloak.jose.jwk.JSONWebKeySet",
"org.keycloak.jose.jwk.JWK",
"org.keycloak.json.StringOrArrayDeserializer",
"org.keycloak.json.StringListMapDeserializer"));
} catch (ClassNotFoundException e) {
//ignore, Strimzi OAuth Client is not on the classpath
}

}

@BuildStep
Expand Down

0 comments on commit 0122ea9

Please sign in to comment.