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);
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.
Thanks
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.
来源:https://stackoverflow.com/questions/26275771/jboss-resteasy-parameter-injection-with-context