Skip to content

Commit

Permalink
Properly register Kafka LoginModule implementations for reflection
Browse files Browse the repository at this point in the history
I think this code is misinterpreting what ReflectiveHierarchyBuildItem
is about. It is registering the *parents* and method return types and
parameters.
I think the initial idea was to register the implementors for reflection
thus this change.
  • Loading branch information
gsmet committed Jan 31, 2022
1 parent 92f6ef8 commit 19f030b
Showing 1 changed file with 13 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import org.apache.kafka.clients.producer.Partitioner;
import org.apache.kafka.clients.producer.ProducerInterceptor;
import org.apache.kafka.clients.producer.internals.DefaultPartitioner;
import org.apache.kafka.common.security.auth.AuthenticateCallbackHandler;
import org.apache.kafka.common.security.auth.SecurityProtocol;
import org.apache.kafka.common.security.authenticator.AbstractLogin;
import org.apache.kafka.common.security.authenticator.DefaultLogin;
Expand Down Expand Up @@ -51,8 +52,6 @@
import org.eclipse.microprofile.config.ConfigProvider;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.DotName;
import org.jboss.jandex.Type;
import org.jboss.jandex.Type.Kind;
import org.xerial.snappy.OSInfo;

import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
Expand All @@ -78,7 +77,6 @@
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageSecurityProviderBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveHierarchyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.logging.LogCleanupFilterBuildItem;
Expand Down Expand Up @@ -125,6 +123,10 @@ public class KafkaProcessor {
"org.apache.kafka.common.security.oauthbearer.internals.OAuthBearerSaslClientProvider"
}).collect(Collectors.toSet());

private static final DotName LOGIN_MODULE = DotName.createSimple(LoginModule.class.getName());
private static final DotName AUTHENTICATE_CALLBACK_HANDLER = DotName
.createSimple(AuthenticateCallbackHandler.class.getName());

static final DotName PARTITION_ASSIGNER = DotName
.createSimple("org.apache.kafka.clients.consumer.internals.PartitionAssignor");

Expand Down Expand Up @@ -167,14 +169,6 @@ void addSaslProvidersToNativeImage(BuildProducer<NativeImageSecurityProviderBuil
@BuildStep
void contributeClassesToIndex(BuildProducer<AdditionalIndexedClassesBuildItem> additionalIndexedClasses,
BuildProducer<IndexDependencyBuildItem> indexDependency) {
// This is needed for SASL authentication

additionalIndexedClasses.produce(new AdditionalIndexedClassesBuildItem(
LoginModule.class.getName(),
javax.security.auth.Subject.class.getName(),
javax.security.auth.login.AppConfigurationEntry.class.getName(),
javax.security.auth.login.AppConfigurationEntry.LoginModuleControlFlag.class.getName()));

indexDependency.produce(new IndexDependencyBuildItem("org.apache.kafka", "kafka-clients"));
}

Expand Down Expand Up @@ -457,8 +451,8 @@ public AdditionalBeanBuildItem runtimeConfig() {
}

@BuildStep
public void withSasl(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ReflectiveHierarchyBuildItem> reflectiveHierarchy,
public void withSasl(CombinedIndexBuildItem index,
BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
BuildProducer<ExtensionSslNativeSupportBuildItem> sslNativeSupport) {

reflectiveClass
Expand All @@ -474,13 +468,12 @@ public void withSasl(BuildProducer<ReflectiveClassBuildItem> reflectiveClass,
sslNativeSupport.produce(new ExtensionSslNativeSupportBuildItem(Feature.KAFKA_CLIENT));
}

final Type loginModuleType = Type
.create(DotName.createSimple(LoginModule.class.getName()), Kind.CLASS);

reflectiveHierarchy.produce(new ReflectiveHierarchyBuildItem.Builder()
.type(loginModuleType)
.source(getClass().getSimpleName() + " > " + loginModuleType.name().toString())
.build());
for (ClassInfo loginModule : index.getIndex().getAllKnownImplementors(LOGIN_MODULE)) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, loginModule.name().toString()));
}
for (ClassInfo authenticateCallbackHandler : index.getIndex().getAllKnownImplementors(AUTHENTICATE_CALLBACK_HANDLER)) {
reflectiveClass.produce(new ReflectiveClassBuildItem(false, false, authenticateCallbackHandler.name().toString()));
}
}

private static void collectImplementors(Set<DotName> set, CombinedIndexBuildItem indexBuildItem, Class<?> cls) {
Expand Down

0 comments on commit 19f030b

Please sign in to comment.