-1

I'm setting a java application with RestEasy, and I created an authentication filter to get jwt token and extract from it user information (for example a user DTO). I'd like to inject a bean (RequestScope?) to save user information, but I don't know how to do it: I tried as the following, but the object is null:

@Inject WebContextDto webContext;
BillRobertson42
  • 12,602
  • 4
  • 40
  • 57
duns
  • 83
  • 1
  • 16

2 Answers2

0

You'll need to trigger Weld for that to work. The way I usually do that is to put a beans.xml file in the src/main/webapp/WEB-INF (I use maven you see). The content of the beans.xml could be as trivial as this:

<beans 
xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/beans_1_1.xsd" 
version="1.1" 
bean-discovery-mode="all">

keni
  • 1,730
  • 13
  • 19
  • Thank you very much for your answer. If I'm not in error, in java ee 7/8 is not necessary to declare bean.xml – duns Mar 03 '16 at 07:38
0

doesn't need to inject, just filter the request.Just use a ContainerRequestFilter and get the token from the header.

  • I can get my token in the ContainerRequestFilter, but I don't know how to pass token data to destination filter – duns Mar 09 '16 at 07:28
  • what do you mean by ** destination filter** in any method that you can access request scope you can use the @Context HttpHeaders headers - to get token – chathura rupasinghe Mar 19 '16 at 09:59