diff --git a/docs/src/main/asciidoc/security-customization.adoc b/docs/src/main/asciidoc/security-customization.adoc index ff3345fa314442..89aeb1957d51b6 100644 --- a/docs/src/main/asciidoc/security-customization.adoc +++ b/docs/src/main/asciidoc/security-customization.adoc @@ -241,27 +241,48 @@ The solution is to activate the request context, the following example shows how 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; import javax.enterprise.context.ApplicationScoped; -import javax.enterprise.context.control.ActivateRequestContext; -import java.util.function.Supplier; +import javax.enterprise.inject.Instance; +import javax.inject.Inject; @ApplicationScoped public class RolesAugmentor implements SecurityIdentityAugmentor { + + @Inject + Instance identitySupplierInstance; + @Override public Uni augment(SecurityIdentity identity, AuthenticationRequestContext context) { if(identity.isAnonymous()) { return Uni.createFrom().item(identity); } - // Hibernate ORM is blocking - return context.runBlocking(build(identity)); + // Hibernate ORM is + SecurityIdentitySupplier identitySupplier = identitySupplierInstance.get(); + identitySupplier.setIdentity(identity); + return context.runBlocking(identitySupplier); } +} +---- +[source,java] +---- +import io.quarkus.security.identity.SecurityIdentity; +import io.quarkus.security.runtime.QuarkusSecurityIdentity; - @ActivateRequestContext // Will activate the request context - Supplier build(SecurityIdentity identity) { +import javax.enterprise.context.Dependent; +import javax.enterprise.context.control.ActivateRequestContext; +import java.util.function.Supplier; + +@Dependent +class SecurityIdentitySupplier implements Supplier { + + private SecurityIdentity identity; + + @Override + @ActivateRequestContext + public SecurityIdentity get() { QuarkusSecurityIdentity.Builder builder = QuarkusSecurityIdentity.builder(identity); String user = identity.getPrincipal().getName(); @@ -269,9 +290,14 @@ public class RolesAugmentor implements SecurityIdentityAugmentor { .filter(role -> user.equals(role.user)) .forEach(role -> builder.addRole(role.role)); - return builder::build; + return builder.build(); + } + + public void setIdentity(SecurityIdentity identity) { + this.identity = identity; } } + ---- [[jaxrs-security-context]]