From 4ef9879dacc770b715fec3436c31a89378d87716 Mon Sep 17 00:00:00 2001 From: Pierre Adam Date: Thu, 7 Mar 2024 15:15:53 +0100 Subject: [PATCH] Simply and clean Signed-off-by: Pierre Adam --- .../openapi/deployment/SmallRyeOpenApiProcessor.java | 10 ++++++---- .../test/jaxrs/AutoSecurityRolesAllowedTestCase.java | 5 +++-- .../jaxrs/OpenApiResourceSecuredAtClassLevel2.java | 8 +++----- .../jaxrs/OpenApiResourceSecuredAtMethodLevel.java | 3 ++- .../jaxrs/OpenApiResourceSecuredAtMethodLevel2.java | 1 - 5 files changed, 14 insertions(+), 13 deletions(-) diff --git a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java index 595e1713f6457..fab22abc2fc80 100644 --- a/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java +++ b/extensions/smallrye-openapi/deployment/src/main/java/io/quarkus/smallrye/openapi/deployment/SmallRyeOpenApiProcessor.java @@ -89,6 +89,7 @@ import io.quarkus.runtime.LaunchMode; import io.quarkus.runtime.util.ClassPathUtils; import io.quarkus.security.Authenticated; +import io.quarkus.security.PermissionsAllowed; import io.quarkus.smallrye.openapi.OpenApiFilter; import io.quarkus.smallrye.openapi.common.deployment.SmallRyeOpenApiConfig; import io.quarkus.smallrye.openapi.deployment.filter.AutoRolesAllowedFilter; @@ -635,12 +636,13 @@ private Map> getRolesAllowedMethodReferences(OpenApiFiltere private List getPermissionsAllowedMethodReferences( OpenApiFilteredIndexViewBuildItem indexViewBuildItem) { - return Stream.of(DotName.createSimple("io.quarkus.security.PermissionsAllowed")) - .map(e -> indexViewBuildItem.getIndex().getAnnotations(e)) - .flatMap(Collection::stream) + return indexViewBuildItem.getIndex() + .getAnnotations(DotName.createSimple(PermissionsAllowed.class)) + .stream() .flatMap(SmallRyeOpenApiProcessor::getMethods) .map(e -> JandexUtil.createUniqueMethodReference(e.getKey().declaringClass(), e.getKey())) - .collect(Collectors.toList()); + .distinct() + .toList(); } private List getAuthenticatedMethodReferences(OpenApiFilteredIndexViewBuildItem indexViewBuildItem) { diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedTestCase.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedTestCase.java index e18f8073bff07..7a95fe1aaf5f3 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedTestCase.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/AutoSecurityRolesAllowedTestCase.java @@ -25,8 +25,9 @@ class AutoSecurityRolesAllowedTestCase { @RegisterExtension static QuarkusUnitTest runner = new QuarkusUnitTest() .withApplicationRoot((jar) -> jar - .addClasses(ResourceBean.class, OpenApiResourceSecuredAtClassLevel.class, OpenApiResourceSecuredAtClassLevel2.class, - OpenApiResourceSecuredAtMethodLevel.class, OpenApiResourceSecuredAtMethodLevel2.class) + .addClasses(ResourceBean.class, OpenApiResourceSecuredAtClassLevel.class, + OpenApiResourceSecuredAtClassLevel2.class, OpenApiResourceSecuredAtMethodLevel.class, + OpenApiResourceSecuredAtMethodLevel2.class) .addAsResource( new StringAsset("quarkus.smallrye-openapi.security-scheme=jwt\n" + "quarkus.smallrye-openapi.security-scheme-name=JWTCompanyAuthentication\n" diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtClassLevel2.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtClassLevel2.java index 06a4c8ae3e34b..5267e418b7558 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtClassLevel2.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtClassLevel2.java @@ -1,15 +1,13 @@ package io.quarkus.smallrye.openapi.test.jaxrs; -import io.quarkus.security.PermissionsAllowed; -import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponse; -import org.eclipse.microprofile.openapi.annotations.responses.APIResponses; -import org.eclipse.microprofile.openapi.annotations.security.SecurityRequirement; + import org.eclipse.microprofile.openapi.annotations.servers.Server; import org.eclipse.microprofile.openapi.annotations.tags.Tag; +import io.quarkus.security.PermissionsAllowed; + @Path("/resource3") @Tag(name = "test") @Server(url = "serverUrl") diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel.java index a29cb4004100c..24bb8695b83d9 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel.java @@ -1,6 +1,5 @@ package io.quarkus.smallrye.openapi.test.jaxrs; -import io.quarkus.security.PermissionsAllowed; import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path; @@ -11,6 +10,8 @@ import org.eclipse.microprofile.openapi.annotations.servers.Server; import org.eclipse.microprofile.openapi.annotations.tags.Tag; +import io.quarkus.security.PermissionsAllowed; + @Path("/resource2") @Tag(name = "test") @Server(url = "serverUrl") diff --git a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel2.java b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel2.java index 81951e8aafb74..8ff41d5efbc13 100644 --- a/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel2.java +++ b/extensions/smallrye-openapi/deployment/src/test/java/io/quarkus/smallrye/openapi/test/jaxrs/OpenApiResourceSecuredAtMethodLevel2.java @@ -1,6 +1,5 @@ package io.quarkus.smallrye.openapi.test.jaxrs; -import io.quarkus.security.PermissionsAllowed; import jakarta.annotation.security.RolesAllowed; import jakarta.ws.rs.GET; import jakarta.ws.rs.Path;