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?)