MP-JWT Injection of Principal test

93 views
Skip to first unread message

Arjan Tijms

unread,
Feb 11, 2018, 5:46:39 PM2/11/18
to Eclipse MicroProfile
Hi,

Users can inject a principal in CDI as follows:

@Inject
private Principal principal;

Since JsonWebToken inherits from Principal, implementors should be careful not to introduce a Bean<T> for this that also returns Principal as type.

WildFly Swam for instance doesn't seem to do this, causing the following error:

2018-02-11 23:29:19,270 ERROR [stderr] (main)     Caused by: org.jboss.weld.exceptions.DeploymentException: WELD-001409: Ambiguous dependencies for type Principal with qualifiers @Default
2018-02-11 23:29:19,270 ERROR [stderr] (main)   at injection point [BackedAnnotatedField] @Inject private org.eclipse.microprofile12.jwtauth.jaxrs.Resource.principal
2018-02-11 23:29:19,270 ERROR [stderr] (main)   at org.eclipse.microprofile12.jwtauth.jaxrs.Resource.principal(Resource.java:0)
2018-02-11 23:29:19,270 ERROR [stderr] (main)   Possible dependencies: 
2018-02-11 23:29:19,271 ERROR [stderr] (main)   - Producer Method [JsonWebToken] with qualifiers [@Any @Default] declared as [[UnbackedAnnotatedMethod] @Produces @RequestScoped org.wildfly.swarm.microprofile.jwtauth.deployment.auth.cdi.MPJWTProducer.currentPrincipalOrNull()],
2018-02-11 23:29:19,271 ERROR [stderr] (main)   - Built-in Bean [java.security.Principal] with qualifiers [@Default]


I've personally implemented this as follows: 


Note that the Principal type is explicitly omitted from the list of types.

It would probably be a good idea to add a TCK test for this that tests that Principal can indeed still be injected.

Kind regards,
Arjan Tijms

(p.s. where can WildFly MP bugs be reported?)

Jean-Louis Monteiro

unread,
Feb 12, 2018, 5:53:35 AM2/12/18
to MicroProfile
Good catch Arjan!

--
You received this message because you are subscribed to the Google Groups "Eclipse MicroProfile" group.
To unsubscribe from this group and stop receiving emails from it, send an email to microprofile+unsubscribe@googlegroups.com.
To post to this group, send email to microp...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/microprofile/d8dcdcee-7947-493e-9d72-d558231d6c0c%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Scott Stark

unread,
Mar 2, 2018, 8:48:07 PM3/2/18
to Eclipse MicroProfile
You can create issues https://issues.jboss.org/projects/SWARM/ if you have a jboss-developer account. Select the microprofile component to flag the issue as related to the MicroProfile implementation. I have created the following issue for this:

as well as this issue to add an additional test to the TCK:

Cristofo Vilares

unread,
Oct 3, 2018, 7:10:03 AM10/3/18
to Eclipse MicroProfile
Hi Arjan,

we are running into the same Issue... What did you do to workaraound or to solve this? Unfortunatly your Github url doesn't work...
Thank you for a reply...

Best Regards,
Cris

Scott Stark

unread,
Oct 3, 2018, 3:35:57 PM10/3/18
to Eclipse MicroProfile
We have made a new 1.1.1 release that relaxes the requirements around the Principal injection type based on feedback from implementations and the non-obvious way to override the CDI Principal bean. It is available on maven central, and github:
Reply all
Reply to author
Forward
0 new messages