Search code examples
javaresteasyquarkus

Providing the SecurityIdentity directly to a Quarkus/RESTEasy web service method


I am using Quarkus with RESTEasy to make a web service and I need access to the SecurityIdentity in some of my methods.

It is possible to get it injected by making the service RequestScoped:

@RequestScoped
@Path("/foo")
public class FooResource {
    @Inject
    public SecurityIdentity securityIdentity;

    @GET
    public Foos getFoos() {
        // use securityIdentity
    }
}

But I would prefer to have the class ApplicationScoped and have the SecurityIdentity provided to the method instead. Something like this:

@ApplicationScoped
@Path("/foo")
public class FooResource {
    @GET
    // This does not work, Quarkus tries to convert the request body to a SecurityIdentity.
    public Foos getFoos(SecurityIdentity securityIdentity) { 
        // use securityIdentity
    }
}

Is this possible? Is there a magic annotation I can put on to make Quarkus inject the SecurityIdentity?


Solution

  • Keeping it injected into a field will still work for ApplicationScoped beans and be thread safe