Skip to content

Commit

Permalink
Tweak @Tenant interceptor detection on classes
Browse files Browse the repository at this point in the history
  • Loading branch information
michalvavrik committed May 26, 2024
1 parent 3322be2 commit 1298caf
Showing 1 changed file with 10 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,9 @@ public void transform(TransformationContext ctx) {
@BuildStep
void produceTenantIdentityProviders(BuildProducer<SyntheticBeanBuildItem> 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()
Expand Down Expand Up @@ -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(
Expand All @@ -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);
}
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit 1298caf

Please sign in to comment.