use of jakarta.interceptor.Interceptor.Priority.PLATFORM_BEFORE in project helidon by oracle.
the class MicronautCdiExtension method afterBeanDiscovery.
/**
* Add all (not yet added) Micronaut beans for injection as long as they are singletons.
*
* @param event CDI event
*/
@SuppressWarnings({ "rawtypes", "unchecked" })
void afterBeanDiscovery(@Priority(PLATFORM_BEFORE) @Observes AfterBeanDiscovery event) {
event.addBean().addType(ApplicationContext.class).id(MICRONAUT_BEAN_PREFIX + "context").scope(ApplicationScoped.class).produceWith(instance -> micronautContext.get());
// add the remaining Micronaut beans
for (var entry : unprocessedBeans.entrySet()) {
Class<?> beanType = entry.getKey();
List<MicronautBean> beans = entry.getValue();
List<? extends BeanDefinitionReference<?>> refs = List.of();
if (beans.size() > 1) {
// first make sure these are singletons; if not, ignore
refs = beans.stream().map(MicronautBean::definitionRef).filter(it -> !it.getBeanType().getName().endsWith("$Intercepted")).filter(BeanDefinitionReference::isSingleton).collect(Collectors.toList());
}
// primary
event.addBean().addType(beanType).id(MICRONAUT_BEAN_PREFIX + beanType.getName()).scope(Dependent.class).produceWith(instance -> micronautContext.get().getBean(beanType));
if (refs.size() > 1) {
// we must care about qualifiers
for (var ref : refs) {
AnnotationMetadata annotationMetadata = ref.getAnnotationMetadata();
List<Class<? extends Annotation>> qualifiers = annotationMetadata.getAnnotationTypesByStereotype(Qualifier.class);
Annotation[] synthesized = new Annotation[qualifiers.size()];
io.micronaut.context.Qualifier[] mq = new io.micronaut.context.Qualifier[qualifiers.size()];
for (int i = 0; i < qualifiers.size(); i++) {
Annotation annotation = annotationMetadata.synthesize(qualifiers.get(i));
synthesized[i] = annotation;
if (annotation != null) {
mq[i] = Qualifiers.byAnnotation(annotation);
}
}
io.micronaut.context.Qualifier composite = Qualifiers.byQualifiers(mq);
BeanConfigurator<Object> newBean = event.addBean().addType(beanType).id(MICRONAUT_BEAN_PREFIX + ref.getBeanDefinitionName()).scope(Dependent.class).produceWith(instance -> micronautContext.get().getBean(beanType, composite));
for (Annotation annotation : synthesized) {
newBean.addQualifier(annotation);
}
}
}
}
unprocessedBeans.clear();
}
use of jakarta.interceptor.Interceptor.Priority.PLATFORM_BEFORE in project helidon by oracle.
the class JwtAuthCdiExtension method registerProvider.
void registerProvider(@Observes @Initialized(ApplicationScoped.class) @Priority(PLATFORM_BEFORE + 5) Object event, BeanManager bm) {
// Security extension to update and check builder
SecurityCdiExtension security = bm.getExtension(SecurityCdiExtension.class);
if (security.securityBuilder().hasProvider(JwtAuthProviderService.PROVIDER_NAME)) {
return;
}
// JAX-RS extension to get to applications to see if we are needed
JaxRsCdiExtension jaxrs = bm.getExtension(JaxRsCdiExtension.class);
boolean notNeeded = jaxrs.applicationsToRun().stream().map(JaxRsApplication::applicationClass).flatMap(Optional::stream).map(clazz -> clazz.getAnnotation(LoginConfig.class)).filter(Objects::nonNull).map(LoginConfig::authMethod).noneMatch("MP-JWT"::equals);
if (notNeeded) {
return;
}
security.securityBuilder().addProvider(JwtAuthProvider.create(config), JwtAuthProviderService.PROVIDER_NAME);
}
Aggregations