From e69be6c85dcd31112dd594089056c0063d398dbd Mon Sep 17 00:00:00 2001 From: Jose Date: Fri, 14 Oct 2022 11:08:24 +0200 Subject: [PATCH] Support setting the RolesAllowed in the Panache REST Data extension With these changes, we can specify the roles using the annotations `@ResourceProperties` at resource level, and `@MethodProperties` for method level. Fix https://github.com/quarkusio/quarkus/issues/28507 (cherry picked from commit dda7d784350e9a0badaebdb647f85f4ca3e71b9f) --- docs/src/main/asciidoc/rest-data-panache.adoc | 2 ++ .../openapi/OpenApiIntegrationTest.java | 7 +++- .../repository/CollectionsResource.java | 5 ++- .../openapi/OpenApiIntegrationTest.java | 7 +++- .../repository/CollectionsResource.java | 5 ++- .../deployment/JaxRsResourceImplementor.java | 16 ++++----- .../panache/deployment/RestDataProcessor.java | 7 +--- .../methods/AddMethodImplementor.java | 11 +++--- .../methods/CountMethodImplementor.java | 6 ++-- .../methods/DeleteMethodImplementor.java | 6 ++-- .../methods/GetMethodImplementor.java | 6 ++-- .../methods/ListMethodImplementor.java | 7 ++-- .../methods/StandardMethodImplementor.java | 34 ++++++++++++++----- .../methods/UpdateMethodImplementor.java | 11 +++--- .../methods/hal/HalMethodImplementor.java | 5 +-- .../methods/hal/ListHalMethodImplementor.java | 7 ++-- .../properties/MethodProperties.java | 9 ++++- .../properties/ResourceProperties.java | 13 ++++++- .../ResourcePropertiesProvider.java | 11 +++++- .../deployment/utils/ResponseImplementor.java | 14 +++++--- .../rest/data/panache/MethodProperties.java | 7 ++++ .../rest/data/panache/ResourceProperties.java | 7 ++++ .../ResourcePropertiesProvider.java | 4 +-- 23 files changed, 147 insertions(+), 60 deletions(-) diff --git a/docs/src/main/asciidoc/rest-data-panache.adoc b/docs/src/main/asciidoc/rest-data-panache.adoc index 2f10580f48693..3d66a770412c1 100644 --- a/docs/src/main/asciidoc/rest-data-panache.adoc +++ b/docs/src/main/asciidoc/rest-data-panache.adoc @@ -307,6 +307,7 @@ public interface PeopleResource extends PanacheEntityResource { * `exposed` - whether resource could be exposed. A global resource property that can be overridden for each method. Default is `true`. * `path` - resource base path. Default path is a hyphenated lowercase resource name without a suffix of `resource` or `controller`. +* `rolesAllowed` - List of the security roles permitted to access the resources. It needs a Quarkus security extension to be present, otherwise it will be ignored. Default is empty. * `paged` - whether collection responses should be paged or not. First, last, previous and next page URIs are included in the response headers if they exist. Request page index and size are taken from the `page` and `size` query parameters that default to `0` and `20` respectively. @@ -319,6 +320,7 @@ Default is `false`. * `exposed` - does not expose a particular HTTP verb when set to `false`. Default is `true`. * `path` - operation path (this is appended to the resource base path). Default is an empty string. +* `rolesAllowed` - List of the security roles permitted to access this operation. It needs a Quarkus security extension to be present, otherwise it will be ignored. Default is empty. == Query parameters diff --git a/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java b/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java index f948620249797..93d05cd00d4cf 100644 --- a/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java +++ b/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java @@ -38,7 +38,8 @@ class OpenApiIntegrationTest { .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-smallrye-openapi", Version.getVersion()), Dependency.of("io.quarkus", "quarkus-jdbc-h2-deployment", Version.getVersion()), - Dependency.of("io.quarkus", "quarkus-resteasy-jsonb-deployment", Version.getVersion()))) + Dependency.of("io.quarkus", "quarkus-resteasy-jsonb-deployment", Version.getVersion()), + Dependency.of("io.quarkus", "quarkus-security-deployment", Version.getVersion()))) .setRun(true); @Test @@ -52,9 +53,13 @@ public void testOpenApiForGeneratedResources() { .body("paths.'/collections'.get.tags", Matchers.hasItem("CollectionsResource")) .body("paths.'/collections'", Matchers.hasKey("post")) .body("paths.'/collections'.post.tags", Matchers.hasItem("CollectionsResource")) + .body("paths.'/collections'.post.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("get")) + .body("paths.'/collections/{id}'.get.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("put")) + .body("paths.'/collections/{id}'.put.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("delete")) + .body("paths.'/collections/{id}'.delete.security[0].SecurityScheme", Matchers.hasItem("admin")) .body("paths.'/empty-list-items'", Matchers.hasKey("get")) .body("paths.'/empty-list-items'.get.tags", Matchers.hasItem("EmptyListItemsResource")) .body("paths.'/empty-list-items'", Matchers.hasKey("post")) diff --git a/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/CollectionsResource.java b/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/CollectionsResource.java index 428e6a5be54fb..55379c59b2f56 100644 --- a/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/CollectionsResource.java +++ b/extensions/panache/hibernate-orm-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/CollectionsResource.java @@ -1,8 +1,11 @@ package io.quarkus.hibernate.orm.rest.data.panache.deployment.repository; import io.quarkus.hibernate.orm.rest.data.panache.PanacheRepositoryResource; +import io.quarkus.rest.data.panache.MethodProperties; import io.quarkus.rest.data.panache.ResourceProperties; -@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections") +@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections", rolesAllowed = "user") public interface CollectionsResource extends PanacheRepositoryResource { + @MethodProperties(rolesAllowed = "admin") + boolean delete(String name); } diff --git a/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java b/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java index 5592a1f0bc105..af41470e90998 100644 --- a/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java +++ b/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/openapi/OpenApiIntegrationTest.java @@ -38,7 +38,8 @@ class OpenApiIntegrationTest { .setForcedDependencies(List.of( Dependency.of("io.quarkus", "quarkus-smallrye-openapi", Version.getVersion()), Dependency.of("io.quarkus", "quarkus-reactive-pg-client-deployment", Version.getVersion()), - Dependency.of("io.quarkus", "quarkus-resteasy-reactive-jsonb-deployment", Version.getVersion()))) + Dependency.of("io.quarkus", "quarkus-resteasy-reactive-jsonb-deployment", Version.getVersion()), + Dependency.of("io.quarkus", "quarkus-security-deployment", Version.getVersion()))) .setRun(true); @Test @@ -52,9 +53,13 @@ public void testOpenApiForGeneratedResources() { .body("paths.'/collections'.get.tags", Matchers.hasItem("CollectionsResource")) .body("paths.'/collections'", Matchers.hasKey("post")) .body("paths.'/collections'.post.tags", Matchers.hasItem("CollectionsResource")) + .body("paths.'/collections'.post.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("get")) + .body("paths.'/collections/{id}'.get.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("put")) + .body("paths.'/collections/{id}'.put.security[0].SecurityScheme", Matchers.hasItem("user")) .body("paths.'/collections/{id}'", Matchers.hasKey("delete")) + .body("paths.'/collections/{id}'.delete.security[0].SecurityScheme", Matchers.hasItem("admin")) .body("paths.'/empty-list-items'", Matchers.hasKey("get")) .body("paths.'/empty-list-items'.get.tags", Matchers.hasItem("EmptyListItemsResource")) .body("paths.'/empty-list-items'", Matchers.hasKey("post")) diff --git a/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/repository/CollectionsResource.java b/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/repository/CollectionsResource.java index 5f9bb1fbcacf9..853e593fb6faa 100644 --- a/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/repository/CollectionsResource.java +++ b/extensions/panache/hibernate-reactive-rest-data-panache/deployment/src/test/java/io/quarkus/hibernate/reactive/rest/data/panache/deployment/repository/CollectionsResource.java @@ -1,8 +1,11 @@ package io.quarkus.hibernate.reactive.rest.data.panache.deployment.repository; import io.quarkus.hibernate.reactive.rest.data.panache.PanacheRepositoryResource; +import io.quarkus.rest.data.panache.MethodProperties; import io.quarkus.rest.data.panache.ResourceProperties; -@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections") +@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections", rolesAllowed = "user") public interface CollectionsResource extends PanacheRepositoryResource { + @MethodProperties(rolesAllowed = "admin") + boolean delete(String name); } diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/JaxRsResourceImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/JaxRsResourceImplementor.java index 28995d77a5c4b..8a52d03eae3f0 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/JaxRsResourceImplementor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/JaxRsResourceImplementor.java @@ -37,16 +37,16 @@ class JaxRsResourceImplementor { private final List methodImplementors; - JaxRsResourceImplementor(boolean withValidation, boolean isResteasyClassic, boolean isReactivePanache) { - this.methodImplementors = Arrays.asList(new GetMethodImplementor(isResteasyClassic, isReactivePanache), - new ListMethodImplementor(isResteasyClassic, isReactivePanache), - new CountMethodImplementor(isResteasyClassic, isReactivePanache), - new AddMethodImplementor(withValidation, isResteasyClassic, isReactivePanache), - new UpdateMethodImplementor(withValidation, isResteasyClassic, isReactivePanache), - new DeleteMethodImplementor(isResteasyClassic, isReactivePanache), + JaxRsResourceImplementor(Capabilities capabilities) { + this.methodImplementors = Arrays.asList(new GetMethodImplementor(capabilities), + new ListMethodImplementor(capabilities), + new CountMethodImplementor(capabilities), + new AddMethodImplementor(capabilities), + new UpdateMethodImplementor(capabilities), + new DeleteMethodImplementor(capabilities), // The list hal endpoint needs to be added for both resteasy classic and resteasy reactive // because the pagination links are programmatically added. - new ListHalMethodImplementor(isResteasyClassic, isReactivePanache)); + new ListHalMethodImplementor(capabilities)); } /** diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/RestDataProcessor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/RestDataProcessor.java index 2dc465386c1a6..ccd7a5c667596 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/RestDataProcessor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/RestDataProcessor.java @@ -65,8 +65,7 @@ void implementResources(CombinedIndexBuildItem index, List 0 && hasSecurityCapability()) { + element.addAnnotation(ROLES_ALLOWED_ANNOTATION).add("value", rolesAllowed); + } + } + protected String appendToPath(String path, String suffix) { if (path.endsWith("/")) { path = path.substring(0, path.lastIndexOf("/")); @@ -158,11 +166,19 @@ protected String appendToPath(String path, String suffix) { return String.join("/", path, suffix); } + protected boolean hasSecurityCapability() { + return capabilities.isPresent(Capability.SECURITY); + } + + protected boolean hasValidatorCapability() { + return capabilities.isPresent(Capability.HIBERNATE_VALIDATOR); + } + protected boolean isResteasyClassic() { - return isResteasyClassic; + return capabilities.isPresent(Capability.RESTEASY); } protected boolean isNotReactivePanache() { - return !isReactivePanache; + return !capabilities.isPresent(Capability.HIBERNATE_REACTIVE); } } diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java index b2847251ac2c0..558066874ae5a 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/UpdateMethodImplementor.java @@ -12,6 +12,7 @@ import io.quarkus.arc.Arc; import io.quarkus.arc.ArcContainer; import io.quarkus.arc.InstanceHandle; +import io.quarkus.deployment.Capabilities; import io.quarkus.gizmo.AssignableResultHandle; import io.quarkus.gizmo.BranchResult; import io.quarkus.gizmo.BytecodeCreator; @@ -41,11 +42,8 @@ public final class UpdateMethodImplementor extends StandardMethodImplementor { private static final String EXCEPTION_MESSAGE = "Failed to update an entity"; - private final boolean withValidation; - - public UpdateMethodImplementor(boolean withValidation, boolean isResteasyClassic, boolean isReactivePanache) { - super(isResteasyClassic, isReactivePanache); - this.withValidation = withValidation; + public UpdateMethodImplementor(Capabilities capabilities) { + super(capabilities); } /** @@ -145,8 +143,9 @@ protected void implementInternal(ClassCreator classCreator, ResourceMetadata res addConsumesAnnotation(methodCreator, APPLICATION_JSON); addProducesJsonAnnotation(methodCreator, resourceProperties); addLinksAnnotation(methodCreator, resourceMetadata.getEntityType(), REL); + addSecurityAnnotations(methodCreator, resourceProperties); // Add parameter annotations - if (withValidation) { + if (hasValidatorCapability()) { methodCreator.getParameterAnnotations(1).addAnnotation(Valid.class); } diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java index 4a880938bd89e..27b78f76f84ba 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/HalMethodImplementor.java @@ -8,6 +8,7 @@ import io.quarkus.arc.Arc; import io.quarkus.arc.ArcContainer; import io.quarkus.arc.InstanceHandle; +import io.quarkus.deployment.Capabilities; import io.quarkus.gizmo.BytecodeCreator; import io.quarkus.gizmo.ClassCreator; import io.quarkus.gizmo.FieldDescriptor; @@ -26,8 +27,8 @@ */ abstract class HalMethodImplementor extends StandardMethodImplementor { - HalMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache) { - super(isResteasyClassic, isReactivePanache); + HalMethodImplementor(Capabilities capabilities) { + super(capabilities); } /** diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java index 6c888edd013db..09da8fbfe7e73 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/methods/hal/ListHalMethodImplementor.java @@ -11,6 +11,7 @@ import javax.ws.rs.core.Response; import javax.ws.rs.core.UriInfo; +import io.quarkus.deployment.Capabilities; import io.quarkus.gizmo.BytecodeCreator; import io.quarkus.gizmo.ClassCreator; import io.quarkus.gizmo.FieldDescriptor; @@ -42,8 +43,8 @@ public final class ListHalMethodImplementor extends HalMethodImplementor { private final SortImplementor sortImplementor = new SortImplementor(); - public ListHalMethodImplementor(boolean isResteasyClassic, boolean isReactivePanache) { - super(isResteasyClassic, isReactivePanache); + public ListHalMethodImplementor(Capabilities capabilities) { + super(capabilities); this.paginationImplementor = new PaginationImplementor(); } @@ -133,6 +134,7 @@ private void implementPaged(ClassCreator classCreator, ResourceMetadata resource addPathAnnotation(methodCreator, resourceProperties.getPath(RESOURCE_METHOD_NAME)); addGetAnnotation(methodCreator); addProducesAnnotation(methodCreator, APPLICATION_HAL_JSON); + addSecurityAnnotations(methodCreator, resourceProperties); addSortQueryParamValidatorAnnotation(methodCreator); addQueryParamAnnotation(methodCreator.getParameterAnnotations(0), "sort"); addQueryParamAnnotation(methodCreator.getParameterAnnotations(1), "page"); @@ -207,6 +209,7 @@ private void implementNotPaged(ClassCreator classCreator, ResourceMetadata resou addPathAnnotation(methodCreator, resourceProperties.getPath(RESOURCE_METHOD_NAME)); addGetAnnotation(methodCreator); addProducesAnnotation(methodCreator, APPLICATION_HAL_JSON); + addSecurityAnnotations(methodCreator, resourceProperties); addQueryParamAnnotation(methodCreator.getParameterAnnotations(0), "sort"); ResultHandle sortQuery = methodCreator.getMethodParam(0); diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/MethodProperties.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/MethodProperties.java index d47615d9b2523..e9f6b48e05928 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/MethodProperties.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/MethodProperties.java @@ -6,9 +6,12 @@ public class MethodProperties { private final String path; - public MethodProperties(boolean exposed, String path) { + private final String[] rolesAllowed; + + public MethodProperties(boolean exposed, String path, String[] rolesAllowed) { this.exposed = exposed; this.path = path; + this.rolesAllowed = rolesAllowed; } public boolean isExposed() { @@ -18,4 +21,8 @@ public boolean isExposed() { public String getPath() { return path; } + + public String[] getRolesAllowed() { + return rolesAllowed; + } } diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourceProperties.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourceProperties.java index 4318e021166a9..9208b8ef049c0 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourceProperties.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourceProperties.java @@ -14,15 +14,18 @@ public class ResourceProperties { private final String halCollectionName; + private final String[] rolesAllowed; + private final Map methodProperties; public ResourceProperties(boolean exposed, String path, boolean paged, boolean hal, String halCollectionName, - Map methodProperties) { + String[] rolesAllowed, Map methodProperties) { this.exposed = exposed; this.path = path; this.paged = paged; this.hal = hal; this.halCollectionName = halCollectionName; + this.rolesAllowed = rolesAllowed; this.methodProperties = methodProperties; } @@ -68,4 +71,12 @@ public boolean isHal() { public String getHalCollectionName() { return halCollectionName; } + + public String[] getRolesAllowed(String methodName) { + if (methodProperties.containsKey(methodName)) { + return methodProperties.get(methodName).getRolesAllowed(); + } + + return rolesAllowed; + } } diff --git a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourcePropertiesProvider.java b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourcePropertiesProvider.java index 13fc2fd1bcc80..c2c3e72f025b2 100644 --- a/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourcePropertiesProvider.java +++ b/extensions/panache/rest-data-panache/deployment/src/main/java/io/quarkus/rest/data/panache/deployment/properties/ResourcePropertiesProvider.java @@ -41,6 +41,7 @@ public ResourceProperties getForInterface(String resourceInterface) { isPaged(annotation), isHal(annotation), getHalCollectionName(annotation, resourceInterface), + getRolesAllowed(annotation), methodProperties); } @@ -74,7 +75,7 @@ private void collectMethodProperties(DotName className, Map + * Default: "" + */ + String[] rolesAllowed() default {}; } diff --git a/extensions/panache/rest-data-panache/runtime/src/main/java/io/quarkus/rest/data/panache/ResourceProperties.java b/extensions/panache/rest-data-panache/runtime/src/main/java/io/quarkus/rest/data/panache/ResourceProperties.java index e1865e8b7ef95..5b15b905b7846 100644 --- a/extensions/panache/rest-data-panache/runtime/src/main/java/io/quarkus/rest/data/panache/ResourceProperties.java +++ b/extensions/panache/rest-data-panache/runtime/src/main/java/io/quarkus/rest/data/panache/ResourceProperties.java @@ -57,4 +57,11 @@ * Default: hyphenated resource name without a suffix. Ignored suffixes are `Controller` and `Resource`. */ String halCollectionName() default ""; + + /** + * List of the security roles permitted to access the resources. + *

+ * Default: "" + */ + String[] rolesAllowed() default {}; } diff --git a/extensions/spring-data-rest/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/ResourcePropertiesProvider.java b/extensions/spring-data-rest/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/ResourcePropertiesProvider.java index 16bf0966e5a4a..4613e4e22150e 100644 --- a/extensions/spring-data-rest/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/ResourcePropertiesProvider.java +++ b/extensions/spring-data-rest/deployment/src/main/java/io/quarkus/spring/data/rest/deployment/ResourcePropertiesProvider.java @@ -41,7 +41,7 @@ public ResourceProperties getResourceProperties(String interfaceName) { String halCollectionName = getHalCollectionName(annotation, ResourceName.fromClass(interfaceName)); return new ResourceProperties(isExposed(annotation), resourcePath, paged, true, halCollectionName, - getMethodProperties(repositoryInterfaceName)); + new String[0], getMethodProperties(repositoryInterfaceName)); } private Map getMethodProperties(DotName interfaceName) { @@ -56,7 +56,7 @@ private Map getMethodProperties(DotName interfaceName) } private MethodProperties getMethodProperties(AnnotationInstance annotation) { - return new MethodProperties(isExposed(annotation), getPath(annotation, "")); + return new MethodProperties(isExposed(annotation), getPath(annotation, ""), new String[0]); } private AnnotationInstance findClassAnnotation(DotName interfaceName) {