jboss使用@Context注入Resteasy参数

我正在使用jboss 7.1和resteasy进行基于令牌的身份validation。 我正在使用PreProcessInterceptor来拦截请求,获取令牌,从令牌中检索用户,然后根据放置在方法上的自定义注释检查用户角色。 我现在要做的是将User注入方法,如下所示。

@Path("/doStuffWithUser") @GET @Requires("ADMIN") // custom annotation public Response doStuffWithUser(@Context User user); 

我知道这与这个问题非常接近,我尝试在链接的github示例中添加了不同的解决方案,但是我找不到从PreProcessInterceptor中注入用户的方法。

谢谢

这是我最终找到的解决方案:

 PreProcessInterceptor.preProcess(..){ ... retrieve User from token check roles ... //add the user to the context data ResteasyProviderFactory.pushContext(User.class, user); } 

然后,您可以使用我在问题中使用的符号来检索用户。

希望它会帮助某人。