diff --git a/devtools/gradle/gradle/libs.versions.toml b/devtools/gradle/gradle/libs.versions.toml index 61cab662a4b13..d3e73f925201b 100644 --- a/devtools/gradle/gradle/libs.versions.toml +++ b/devtools/gradle/gradle/libs.versions.toml @@ -5,7 +5,7 @@ plugin-publish = "1.2.1" kotlin = "2.0.0" smallrye-config = "3.8.2" -junit5 = "5.10.2" +junit5 = "5.10.3" assertj = "3.25.3" [plugins] diff --git a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/OidcBuildStep.java b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/OidcBuildStep.java index 08dd65840379e..ca35e50989496 100644 --- a/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/OidcBuildStep.java +++ b/extensions/oidc/deployment/src/main/java/io/quarkus/oidc/deployment/OidcBuildStep.java @@ -222,7 +222,9 @@ public void transform(TransformationContext ctx) { @BuildStep void produceTenantIdentityProviders(BuildProducer syntheticBeanProducer, OidcRecorder recorder, BeanDiscoveryFinishedBuildItem beans, CombinedIndexBuildItem combinedIndex) { - if (!combinedIndex.getIndex().getAnnotations(TENANT_NAME).isEmpty()) { + var tenantAnnotations = combinedIndex.getIndex().getAnnotations(TENANT_NAME); + if (!tenantAnnotations.isEmpty()) { + // create TenantIdentityProviders for tenants selected with @Tenant like: @Tenant("my-tenant") beans .getInjectionPoints() @@ -301,10 +303,9 @@ public void registerTenantResolverInterceptor(Capabilities capabilities, OidcRec .stream() .map(AnnotationInstance::target) // ignored field injection points and injection setters - // as we don't want to count in the TenantIdentityProvider injection point - .filter(t -> t.kind() == METHOD) - .map(AnnotationTarget::asMethod) - .anyMatch(m -> !m.isConstructor() && !m.hasAnnotation(DotNames.INJECT)); + // as we don't want to count in the TenantIdentityProvider injection point; + // if class is the target, we know it cannot be a TenantIdentityProvider as we produce it ourselves + .anyMatch(t -> isMethodWithTenantAnnButNotInjPoint(t) || t.kind() == CLASS); if (foundTenantResolver) { // register method interceptor that will be run before security checks bindingProducer.produce( @@ -315,6 +316,10 @@ public void registerTenantResolverInterceptor(Capabilities capabilities, OidcRec } } + private static boolean isMethodWithTenantAnnButNotInjPoint(AnnotationTarget t) { + return t.kind() == METHOD && !t.asMethod().isConstructor() && !t.hasAnnotation(DotNames.INJECT); + } + private static boolean detectUserInfoRequired(BeanRegistrationPhaseBuildItem beanRegistrationPhaseBuildItem) { return isInjected(beanRegistrationPhaseBuildItem, USER_INFO_NAME, null); } @@ -356,14 +361,6 @@ private static boolean isApplicationPackage(String injectionPointTargetInfo) { && !injectionPointTargetInfo.startsWith(SMALLRYE_JWT_PACKAGE); } - private static String toTargetName(AnnotationTarget target) { - if (target.kind() == CLASS) { - return target.asClass().name().toString(); - } else { - return target.asMethod().declaringClass().name().toString() + "#" + target.asMethod().name(); - } - } - public static class IsEnabled implements BooleanSupplier { OidcBuildTimeConfig config;