use of fish.payara.microprofile.jwtauth.jwt.ClaimAnnotationLiteral in project Payara by payara.
the class CdiInitEventHandler method installAuthenticationMechanism.
public static void installAuthenticationMechanism(AfterBeanDiscovery afterBeanDiscovery) {
afterBeanDiscovery.addBean(new CdiProducer<IdentityStore>().scope(ApplicationScoped.class).beanClass(IdentityStore.class).types(Object.class, IdentityStore.class, SignedJWTIdentityStore.class).addToId("store " + LoginConfig.class).create(e -> new SignedJWTIdentityStore()));
afterBeanDiscovery.addBean(new CdiProducer<HttpAuthenticationMechanism>().scope(ApplicationScoped.class).beanClass(HttpAuthenticationMechanism.class).types(Object.class, HttpAuthenticationMechanism.class, JWTAuthenticationMechanism.class).addToId("mechanism " + LoginConfig.class).create(e -> new JWTAuthenticationMechanism()));
// MP-JWT 1.0 7.1.1. Injection of JsonWebToken
afterBeanDiscovery.addBean(new CdiProducer<JsonWebToken>().scope(RequestScoped.class).beanClass(JsonWebToken.class).types(Object.class, JsonWebToken.class).addToId("token " + LoginConfig.class).create(e -> getJsonWebToken()));
// MP-JWT 1.0 7.1.2
for (JWTInjectableType injectableType : computeTypes()) {
// Add a new Bean<T>/Dynamic producer for each type that 7.1.2 asks
// us to support.
afterBeanDiscovery.addBean(new CdiProducer<Object>().scope(Dependent.class).beanClass(CdiInitEventHandler.class).types(injectableType.getFullType()).qualifiers(new ClaimAnnotationLiteral()).addToId("claim for " + injectableType.getFullType()).create(creationalContext -> {
// Get the qualifier from the injection point
Claim claim = getQualifier(getCurrentInjectionPoint(CdiUtils.getBeanManager(), creationalContext), Claim.class);
String claimName = getClaimName(claim);
// Obtain the raw named value from the request scoped JsonWebToken's embedded claims and convert
// it according to the target type for which this Bean<T> was created.
Object claimObj = injectableType.convert(getJsonWebToken().getClaims().get(claimName));
// into an Optional. I.e. Optional<Long> or ClaimValue<Optional<Long>>
if (injectableType.isOptional()) {
claimObj = Optional.ofNullable(claimObj);
}
// into a ClaimValue, e.g. ClaimValue<Long> or ClaimValue<Optional<Long>>
if (injectableType.isClaimValue()) {
claimObj = new ClaimValueImpl<Object>(claimName, claimObj);
}
return claimObj;
}));
}
}
Aggregations