How to inject security context into CDI @Named bean?
I have a named bean with some methods annotated with @RolesAllowed, this works fine.
But in another method I need to perform some custom validations, so I need to inject SessionContext. This is done with this:
@Resource
javax.ejb.SessionContext context;
But this injection only works in EJB beans, so I need to create an @Stateless bean just to wrap SessionContext, then I can inject this stateless bean into named bean and use it to access the security context.
I have tried with @Inject javax.security.enterprise.SecurityContext also, but this do not work either.
Obs. If there is another approach, this will be welcome too!
Environment:
- Wildfly 24
- Java SE 11
References