Skip to content

Commit

Permalink
Merge pull request #40845 from michalvavrik/feature/tweak-tenant-ann-…
Browse files Browse the repository at this point in the history
…detection-on-classes

Detect @Tenant interceptors are required when only JAX-RS classes are annotated, but no resource methods
  • Loading branch information
sberyozkin authored May 26, 2024
2 parents 3322be2 + 509cce5 commit 69b8c41
Showing 1 changed file with 8 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -300,11 +300,10 @@ public void registerTenantResolverInterceptor(Capabilities capabilities, OidcRec
.getAnnotations(TENANT_NAME)
.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));
// ignore field injection points and injection setters
// 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(
Expand All @@ -315,6 +314,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);
}
Expand Down Expand Up @@ -356,14 +359,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;

Expand Down

0 comments on commit 69b8c41

Please sign in to comment.