-
1. Re: Inject custom security principal (via login module)
mkouba Oct 31, 2016 5:31 AM (in response to mimra)Hi Michael,
the built-in Principal bean is
@Dependent
in Weld, that's whyctx.get(bean)
from your sample returns null. Also note that the injected reference is not a "normal" client proxy, but an "EE component proxy". So even if you get the context object for@Dependent
and callget()
you'll get the proxy. AFAIK there is no way to obtain the instance behind an "EE component proxy". The only thing you could probably do is to register a custom bean for your principal, i.e. with some special qualifier. This bean'screate()
method could delegate to the Weld specificorg.jboss.weld.security.spi.SecurityServices.getPrincipal()
or directly to some WildFly internals. -
2. Re: Inject custom security principal (via login module)
mimra Nov 1, 2016 3:50 AM (in response to mkouba)Hi Martin
First of all - thank you for your time.
I had a feeling this could be a problem :-)
The only way we have found, is to access the service registry from the bean manager, then get the SecurityService and then call getPrincipal() - just like you describe.
This does however become very JBoss / Weld specific. I don't know what the SecurityService does.
Would the same approach work inside an EJB, for example?
Thank.
Michael
-
3. Re: Inject custom security principal (via login module)
mkouba Nov 1, 2016 4:00 AM (in response to mimra)SecurityServices is a Weld SPI that allows integrators (WildFly in this case) to provide the Principal representing the current caller identity. FYI there is already a spec issue for this problem: CDI-597. Feel free to add comments.