use of javax.enterprise.inject.spi.AfterBeanDiscovery in project tomee by apache.
the class MPJWTCDIExtension method registerClaimProducer.
public void registerClaimProducer(@Observes final AfterBeanDiscovery abd, final BeanManager bm) {
final Set<Type> types = injectionPoints.stream().filter(NOT_PROVIDERS).filter(NOT_INSTANCES).map(ip -> REPLACED_TYPES.getOrDefault(ip.getType(), ip.getType())).collect(Collectors.<Type>toSet());
final Set<Type> providerTypes = injectionPoints.stream().filter(NOT_PROVIDERS.negate()).map(ip -> ((ParameterizedType) ip.getType()).getActualTypeArguments()[0]).collect(Collectors.<Type>toSet());
final Set<Type> instanceTypes = injectionPoints.stream().filter(NOT_INSTANCES.negate()).map(ip -> ((ParameterizedType) ip.getType()).getActualTypeArguments()[0]).collect(Collectors.<Type>toSet());
types.addAll(providerTypes);
types.addAll(instanceTypes);
types.stream().map(type -> new ClaimBean<>(bm, type)).forEach((Consumer<ClaimBean>) abd::addBean);
abd.addBean().id(MPJWTCDIExtension.class.getName() + "#" + JsonWebToken.class.getName()).beanClass(JsonWebToken.class).types(JsonWebToken.class, Object.class).qualifiers(Default.Literal.INSTANCE, Any.Literal.INSTANCE).scope(Dependent.class).createWith(ctx -> {
final Principal principal = getContextualReference(Principal.class, bm);
if (JsonWebToken.class.isInstance(principal)) {
return JsonWebToken.class.cast(principal);
}
return null;
});
}
use of javax.enterprise.inject.spi.AfterBeanDiscovery 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);
Function<String, Object> claimValueSupplier = (String claimNameParam) -> {
return loadClaimObject(injectableType, claimNameParam);
};
Object claimObj;
if (injectableType.isClaimValue()) {
// If the target type has a ClaimValue in it, wrap the converted value
// into a ClaimValue, e.g. ClaimValue<Long> or ClaimValue<Optional<Long>>
claimObj = new ClaimValueImpl<>(claimName, claimValueSupplier);
} else {
// otherwise simply return the value
claimObj = claimValueSupplier.apply(claimName);
}
return claimObj;
}));
}
}
use of javax.enterprise.inject.spi.AfterBeanDiscovery in project Payara by payara.
the class JwtAuthCdiExtension method installMechanismIfNeeded.
public void installMechanismIfNeeded(@Observes AfterBeanDiscovery eventIn, BeanManager beanManager) {
// JDK8 u60 workaround
AfterBeanDiscovery afterBeanDiscovery = eventIn;
if (addJWTAuthenticationMechanism) {
validateConfigValue();
CdiInitEventHandler.installAuthenticationMechanism(afterBeanDiscovery);
}
}
use of javax.enterprise.inject.spi.AfterBeanDiscovery in project wildfly-swarm by wildfly-swarm.
the class SocketBindingGroupExtension method afterBeanDiscovery.
@SuppressWarnings("unused")
void afterBeanDiscovery(@Observes AfterBeanDiscovery abd, BeanManager beanManager) throws Exception {
List<SimpleKey> configuredGroups = this.configView.simpleSubkeys(ROOT);
for (SimpleKey groupName : configuredGroups) {
Set<Bean<?>> groups = beanManager.getBeans(SocketBindingGroup.class, AnyLiteral.INSTANCE);
AtomicBoolean producerRequired = new AtomicBoolean(false);
if (groups.stream().noneMatch(e -> e.getQualifiers().stream().anyMatch(anno -> anno instanceof Named && ((Named) anno).value().equals(groupName)))) {
SocketBindingGroup group = new SocketBindingGroup(groupName.name(), null, "0");
applyConfiguration(group);
if (producerRequired.get()) {
CommonBean<SocketBindingGroup> interfaceBean = CommonBeanBuilder.newBuilder(SocketBindingGroup.class).beanClass(SocketBindingGroupExtension.class).scope(ApplicationScoped.class).addQualifier(AnyLiteral.INSTANCE).addQualifier(new NamedLiteral(group.name())).createSupplier(() -> group).addType(SocketBindingGroup.class).addType(Object.class).build();
abd.addBean(interfaceBean);
}
}
}
}
Aggregations