use of fish.payara.microprofile.jwtauth.jwt.JWTInjectableType in project Payara by payara.
the class CdiInitEventHandler method computeTypes.
private static Set<JWTInjectableType> computeTypes() {
Set<JWTInjectableType> baseTypes = new HashSet<>(asList(new JWTInjectableType(String.class), new JWTInjectableType(new ParameterizedTypeImpl(Set.class, String.class), Set.class), new JWTInjectableType(Long.class), new JWTInjectableType(Boolean.class), new JWTInjectableType(JsonString.class), new JWTInjectableType(JsonNumber.class), new JWTInjectableType(JsonStructure.class), new JWTInjectableType(JsonArray.class), new JWTInjectableType(JsonObject.class)));
Set<JWTInjectableType> optionalTypes = new HashSet<>(baseTypes);
optionalTypes.addAll(baseTypes.stream().map(t -> new JWTInjectableType(new ParameterizedTypeImpl(Optional.class, t.getFullType()), t)).collect(toSet()));
Set<JWTInjectableType> claimValueTypes = new HashSet<>(optionalTypes);
claimValueTypes.addAll(optionalTypes.stream().map(t -> new JWTInjectableType(new ParameterizedTypeImpl(ClaimValue.class, t.getFullType()), t)).collect(toSet()));
return claimValueTypes;
}
use of fish.payara.microprofile.jwtauth.jwt.JWTInjectableType 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