forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Propagate the javax.annotation.security annotations in REST Data
With these changes, the REST Data with Panache extension will propagate the Security annotations within the package `javax.annotation.security` that are defined on your resource interfaces: ```java import javax.annotation.security.DenyAll; import javax.annotation.security.RolesAllowed; @Denyall @ResourceProperties public interface PeopleResource extends PanacheEntityResource<Person, Long> { @RolesAllowed("superuser") boolean delete(Long id); } ``` Additionally, if you are only interested in specifying the roles that are allowed to use the resources, the `@ResourceProperties` and `@MethodProperties` annotations have the field `rolesAllowed` to list the security roles permitted to access the resource or operation. Fix quarkusio#28995 (cherry picked from commit e1ae1d8)
- Loading branch information
Showing
28 changed files
with
355 additions
and
38 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...st/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/AbstractEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.persistence.GeneratedValue; | ||
import javax.persistence.Id; | ||
import javax.persistence.MappedSuperclass; | ||
|
||
@MappedSuperclass | ||
public abstract class AbstractEntity<IdType extends Number> { | ||
|
||
@Id | ||
@GeneratedValue | ||
private IdType id; | ||
|
||
public IdType getId() { | ||
return id; | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
...test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/AbstractItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.persistence.ManyToOne; | ||
import javax.persistence.MappedSuperclass; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import com.fasterxml.jackson.annotation.JsonProperty.Access; | ||
|
||
@MappedSuperclass | ||
public abstract class AbstractItem<IdType extends Number> extends AbstractEntity<IdType> { | ||
|
||
private String name; | ||
|
||
@ManyToOne(optional = false) | ||
@JsonProperty(access = Access.WRITE_ONLY) | ||
private Collection collection; | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
} |
45 changes: 45 additions & 0 deletions
45
...c/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/Collection.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import javax.persistence.Entity; | ||
import javax.persistence.FetchType; | ||
import javax.persistence.Id; | ||
import javax.persistence.OneToMany; | ||
|
||
@Entity | ||
public class Collection { | ||
|
||
@Id | ||
private String id; | ||
|
||
private String name; | ||
|
||
@OneToMany(fetch = FetchType.EAGER, mappedBy = "collection") | ||
private List<Item> items = new LinkedList<>(); | ||
|
||
public String getId() { | ||
return id; | ||
} | ||
|
||
public void setId(String id) { | ||
this.id = id; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public List<Item> getItems() { | ||
return items; | ||
} | ||
|
||
public void setItems(List<Item> items) { | ||
this.items = items; | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
.../io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/CollectionsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepositoryBase; | ||
|
||
@ApplicationScoped | ||
public class CollectionsRepository implements PanacheRepositoryBase<Collection, String> { | ||
} |
16 changes: 16 additions & 0 deletions
16
...va/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/CollectionsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.annotation.security.RolesAllowed; | ||
|
||
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", rolesAllowed = "user") | ||
public interface CollectionsResource extends PanacheRepositoryResource<CollectionsRepository, Collection, String> { | ||
@RolesAllowed("superuser") | ||
Collection update(String id, Collection entity); | ||
|
||
@MethodProperties(rolesAllowed = "admin") | ||
boolean delete(String name); | ||
} |
8 changes: 8 additions & 0 deletions
8
...est/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/EmptyListItem.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
public class EmptyListItem extends AbstractItem<Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
.../quarkus/hibernate/orm/rest/data/panache/deployment/openapi/EmptyListItemsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
|
||
@ApplicationScoped | ||
public class EmptyListItemsRepository implements PanacheRepository<EmptyListItem> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/EmptyListItemsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import io.quarkus.hibernate.orm.rest.data.panache.PanacheRepositoryResource; | ||
import io.quarkus.rest.data.panache.ResourceProperties; | ||
|
||
@ResourceProperties(hal = true) | ||
public interface EmptyListItemsResource extends PanacheRepositoryResource<EmptyListItemsRepository, EmptyListItem, Long> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...ent/src/test/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/Item.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.persistence.Entity; | ||
|
||
@Entity | ||
public class Item extends AbstractItem<Long> { | ||
|
||
} |
9 changes: 9 additions & 0 deletions
9
...t/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/ItemsRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import javax.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.hibernate.orm.panache.PanacheRepository; | ||
|
||
@ApplicationScoped | ||
public class ItemsRepository implements PanacheRepository<Item> { | ||
} |
8 changes: 8 additions & 0 deletions
8
...est/java/io/quarkus/hibernate/orm/rest/data/panache/deployment/openapi/ItemsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.quarkus.hibernate.orm.rest.data.panache.deployment.openapi; | ||
|
||
import io.quarkus.hibernate.orm.rest.data.panache.PanacheRepositoryResource; | ||
import io.quarkus.rest.data.panache.ResourceProperties; | ||
|
||
@ResourceProperties(hal = true) | ||
public interface ItemsResource extends PanacheRepositoryResource<ItemsRepository, Item, Long> { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 1 addition & 4 deletions
5
...io/quarkus/hibernate/orm/rest/data/panache/deployment/repository/CollectionsResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,8 @@ | ||
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", rolesAllowed = "user") | ||
@ResourceProperties(hal = true, paged = false, halCollectionName = "item-collections") | ||
public interface CollectionsResource extends PanacheRepositoryResource<CollectionsRepository, Collection, String> { | ||
@MethodProperties(rolesAllowed = "admin") | ||
boolean delete(String name); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.