直接向Quarkus / RESTEasy Web服务方法提供SecurityIdentity

问题描述 投票:0回答:1

我正在使用带有RESTEasy的Quarkus来提供Web服务,并且需要使用某些方法访问SecurityIdentity

可以通过使服务RequestScoped来注入它:

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

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

但是我更希望使用类ApplicationScoped并将SecurityIdentity提供给该方法。像这样的东西:

@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
    }
}

这可能吗?我可以戴上魔术贴使Quarkus注入SecurityIdentity吗?

java resteasy quarkus
1个回答
0
投票

将其注入字段仍然适用于ApplicationScoped bean,并且是线程安全的

© www.soinside.com 2019 - 2024. All rights reserved.