I am currently developing an application with JAX-RS Jersey as the backend and AngularJS as the interface; I need authentication, and so with every request I send a token, which should be checked using the backend. To do this, I decided to create a Jersey filter that will look for this token, and then call my AuthenticateService to check if the user can be authenticated. Authorization is then controlled by the @RolesAllowed annotation.
Here is my problem: I cannot inject EJB inside the Jersey filter, it is strange because it works great with resources. But with the filter, the service always remains null
Any idea how to trick him? Thanks
Filter Code:
@Provider @Priority( Priorities.AUTHORIZATION ) public class AuthenticationFilter implements ContainerRequestFilter { @EJB( name=AuthenticationService.LOOKUP_NAME) private AuthenticationService authService; @Override public void filter( ContainerRequestContext requestContext ) throws IOException { String userIdStr = requestContext.getHeaderString( SecurityConsts.HEADER_ID_PARAMETER ); int userId = 0; if( userIdStr != null && !userIdStr.isEmpty() ) { userId = Integer.parseInt( userIdStr ); } String securityToken = requestContext.getHeaderString( SecurityConsts.HEADER_TOKEN ); User user = null; if( securityToken != null && !securityToken.isEmpty() ) {
dependency-injection jersey ejb
Jérémy dutheil
source share