-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support @PermissionsAllowed with @BeanParam parameters
- Loading branch information
1 parent
6c99b6c
commit 03afb70
Showing
4 changed files
with
101 additions
and
29 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
34 changes: 34 additions & 0 deletions
34
.../quarkus/resteasy/reactive/server/test/security/BeanParamPermissionIdentityAugmentor.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,34 @@ | ||
package io.quarkus.resteasy.reactive.server.test.security; | ||
|
||
import java.security.Permission; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
|
||
import io.quarkus.security.StringPermission; | ||
import io.quarkus.security.identity.AuthenticationRequestContext; | ||
import io.quarkus.security.identity.SecurityIdentity; | ||
import io.quarkus.security.identity.SecurityIdentityAugmentor; | ||
import io.quarkus.security.runtime.QuarkusSecurityIdentity; | ||
import io.smallrye.mutiny.Uni; | ||
|
||
@ApplicationScoped | ||
public class BeanParamPermissionIdentityAugmentor implements SecurityIdentityAugmentor { | ||
|
||
@Override | ||
public Uni<SecurityIdentity> augment(SecurityIdentity securityIdentity, | ||
AuthenticationRequestContext authenticationRequestContext) { | ||
var possessedPermission = createPossessedPermission(securityIdentity); | ||
var augmentedIdentity = QuarkusSecurityIdentity | ||
.builder(securityIdentity) | ||
.addPermissionChecker(requiredPermission -> Uni | ||
.createFrom() | ||
.item(requiredPermission.implies(possessedPermission))) | ||
.build(); | ||
return Uni.createFrom().item(augmentedIdentity); | ||
} | ||
|
||
private Permission createPossessedPermission(SecurityIdentity securityIdentity) { | ||
// here comes your business logic | ||
return securityIdentity.isAnonymous() ? new StringPermission("list") : new StringPermission("read"); | ||
} | ||
} |
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