使用@Context的jboss Resteasy参数注入 [英] jboss Resteasy parameter injection with @Context

查看:244
本文介绍了使用@Context的jboss Resteasy参数注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用jboss 7.1和resteasy进行基于令牌的身份验证. 我正在使用PreProcessInterceptor来拦截请求,获取令牌,从令牌中检索用户,然后对照放置在方法上的自定义注释检查用户角色.我现在要做的是将用户注入到以下方法中.

I'm doing a token based authentication using jboss 7.1 and resteasy. I'm using a PreProcessInterceptor to intercept request, get token, retrieve user from token and then check user roles against custom annotations placed on the method. What I want to do now is to inject User into the method like folowing.

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

我知道这与此问题,我已经尝试对链接的github示例上提出的差异解决方案进行修改,但是我找不到从我的PreProcessInterceptor内部注入用户的方法.

I know this is very close from this question and I have tried addapting the differents solutions proposed on the linked github example but I can't find a way to inject the user from within my PreProcessInterceptor.

谢谢

推荐答案

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

This is the solution I finnaly found:

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

}

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

You can then retrieve the User with the notation I used in my question.

希望它将对某人有所帮助.

Hope it will help someone.

这篇关于使用@Context的jboss Resteasy参数注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆