diff --git a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityAnnotationsRegistrar.java b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityAnnotationsRegistrar.java index 50fed7beee59ea..cec64a54bb41d4 100644 --- a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityAnnotationsRegistrar.java +++ b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityAnnotationsRegistrar.java @@ -1,16 +1,12 @@ package io.quarkus.security.deployment; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.List; import javax.annotation.security.DenyAll; import javax.annotation.security.PermitAll; import javax.annotation.security.RolesAllowed; -import org.jboss.jandex.DotName; - import io.quarkus.arc.processor.InterceptorBindingRegistrar; import io.quarkus.security.Authenticated; @@ -19,18 +15,15 @@ */ public class SecurityAnnotationsRegistrar implements InterceptorBindingRegistrar { - public static final Map> SECURITY_BINDINGS = new HashMap<>(); - - static { - // keep the contents the same as in io.quarkus.resteasy.deployment.SecurityTransformerUtils - SECURITY_BINDINGS.put(DotName.createSimple(RolesAllowed.class.getName()), Collections.singleton("value")); - SECURITY_BINDINGS.put(DotName.createSimple(Authenticated.class.getName()), Collections.emptySet()); - SECURITY_BINDINGS.put(DotName.createSimple(DenyAll.class.getName()), Collections.emptySet()); - SECURITY_BINDINGS.put(DotName.createSimple(PermitAll.class.getName()), Collections.emptySet()); - } + static final List SECURITY_BINDINGS = List.of( + // keep the contents the same as in io.quarkus.resteasy.deployment.SecurityTransformerUtils + InterceptorBinding.of(RolesAllowed.class, Collections.singleton("value")), + InterceptorBinding.of(Authenticated.class), + InterceptorBinding.of(DenyAll.class), + InterceptorBinding.of(PermitAll.class)); @Override - public Map> registerAdditionalBindings() { + public List getAdditionalBindings() { return SECURITY_BINDINGS; } } diff --git a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityTransformerUtils.java b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityTransformerUtils.java index 9633ae5cb62d0b..4ca0dfa8b25175 100644 --- a/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityTransformerUtils.java +++ b/extensions/security/deployment/src/main/java/io/quarkus/security/deployment/SecurityTransformerUtils.java @@ -3,6 +3,7 @@ import java.util.Collection; import java.util.Optional; import java.util.Set; +import java.util.stream.Collectors; import javax.annotation.security.DenyAll; import javax.annotation.security.RolesAllowed; @@ -12,13 +13,16 @@ import org.jboss.jandex.DotName; import org.jboss.jandex.MethodInfo; +import io.quarkus.arc.processor.InterceptorBindingRegistrar; + /** * @author Michal Szynkiewicz, michal.l.szynkiewicz@gmail.com */ public class SecurityTransformerUtils { public static final DotName DENY_ALL = DotName.createSimple(DenyAll.class.getName()); public static final DotName ROLES_ALLOWED = DotName.createSimple(RolesAllowed.class.getName()); - private static final Set SECURITY_ANNOTATIONS = SecurityAnnotationsRegistrar.SECURITY_BINDINGS.keySet(); + private static final Set SECURITY_ANNOTATIONS = SecurityAnnotationsRegistrar.SECURITY_BINDINGS.stream() + .map(InterceptorBindingRegistrar.InterceptorBinding::getName).collect(Collectors.toSet()); public static boolean hasStandardSecurityAnnotation(MethodInfo methodInfo) { return hasStandardSecurityAnnotation(methodInfo.annotations()); diff --git a/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityAnnotationsRegistrar.java b/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityAnnotationsRegistrar.java index 243dbe439be46c..c9a3fd548202cb 100644 --- a/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityAnnotationsRegistrar.java +++ b/extensions/spring-security/deployment/src/main/java/io/quarkus/spring/security/deployment/SpringSecurityAnnotationsRegistrar.java @@ -1,11 +1,8 @@ package io.quarkus.spring.security.deployment; import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Set; +import java.util.List; -import org.jboss.jandex.DotName; import org.springframework.security.access.annotation.Secured; import org.springframework.security.access.prepost.PreAuthorize; @@ -13,15 +10,12 @@ public class SpringSecurityAnnotationsRegistrar implements InterceptorBindingRegistrar { - public static final Map> SECURITY_BINDINGS = new HashMap<>(); - - static { - SECURITY_BINDINGS.put(DotName.createSimple(Secured.class.getName()), Collections.singleton("value")); - SECURITY_BINDINGS.put(DotName.createSimple(PreAuthorize.class.getName()), Collections.singleton("value")); - } + private static final List SECURITY_BINDINGS = List.of( + InterceptorBinding.of(Secured.class, Collections.singleton("value")), + InterceptorBinding.of(PreAuthorize.class, Collections.singleton("value"))); @Override - public Map> registerAdditionalBindings() { + public List getAdditionalBindings() { return SECURITY_BINDINGS; } } diff --git a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/interceptor/bindings/AdditionalInterceptorBindingsTest.java b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/interceptor/bindings/AdditionalInterceptorBindingsTest.java index a27552416bcb7e..b19710b4c036d0 100644 --- a/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/interceptor/bindings/AdditionalInterceptorBindingsTest.java +++ b/independent-projects/arc/tests/src/test/java/io/quarkus/arc/test/buildextension/interceptor/bindings/AdditionalInterceptorBindingsTest.java @@ -13,17 +13,13 @@ import java.lang.annotation.Retention; import java.lang.annotation.Target; import java.util.Collections; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; +import java.util.List; import java.util.function.Supplier; import javax.annotation.Priority; import javax.enterprise.context.ApplicationScoped; import javax.interceptor.AroundInvoke; import javax.interceptor.Interceptor; import javax.interceptor.InvocationContext; -import org.jboss.jandex.DotName; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.RegisterExtension; @@ -94,14 +90,11 @@ private void assertAfterCall(Class beanClass, Supplier> registerAdditionalBindings() { - Map> newBindings = new HashMap<>(); - newBindings.put(DotName.createSimple(ToBeBinding.class.getName()), Collections.emptySet()); - HashSet value = new HashSet<>(); - value.add("value"); - newBindings.put(DotName.createSimple(ToBeBindingWithNonBindingField.class.getName()), value); - newBindings.put(DotName.createSimple(ToBeBindingWithBindingField.class.getName()), Collections.emptySet()); - return newBindings; + public List getAdditionalBindings() { + return List.of( + InterceptorBinding.of(ToBeBinding.class), + InterceptorBinding.of(ToBeBindingWithBindingField.class, Collections.singleton("value")), + InterceptorBinding.of(ToBeBindingWithBindingField.class)); } }