我正在使用 jboss 7.1 和 resteasy 进行基于 token 的身份验证。
我正在使用 PreProcessInterceptor 来拦截请求、获取 token 、从 token 中检索用户,然后根据放置在方法上的自定义注释检查用户角色。我现在要做的是将 User 注入(inject)到如下方法中。
@Path("/doStuffWithUser")
@GET
@Requires("ADMIN") // custom annotation
public Response doStuffWithUser(@Context User user);
我知道这与 this 非常接近问题,我已尝试添加 linked github example 上提出的不同解决方案但我找不到从我的 PreProcessInterceptor 中注入(inject)用户的方法。
谢谢
最佳答案
这是我最终找到的解决方案:
PreProcessInterceptor.preProcess(..){
...
retrieve User from token
check roles
...
//add the user to the context data
ResteasyProviderFactory.pushContext(User.class, user);
}
然后,您可以使用我在问题中使用的符号检索用户。希望它会帮助某人。
关于java - jboss Resteasy参数注入(inject)@Context,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26275771/