javax.enterprise.inject.spi.BeforeBeanDiscovery Java Examples

The following examples show how to use javax.enterprise.inject.spi.BeforeBeanDiscovery. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source Project: smallrye-jwt   Author: smallrye   File: SmallRyeJWTAuthCDIExtension.java    License: Apache License 2.0 6 votes vote down vote up
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {
    CDILogging.log.beforeBeanDiscovery(beanManager);

    // TODO: Do not add CDI beans unless @LoginConfig (or other trigger) is configured
    addAnnotatedType(event, beanManager, ClaimValueProducer.class);
    addAnnotatedType(event, beanManager, CommonJwtProducer.class);
    addAnnotatedType(event, beanManager, DefaultJWTParser.class);
    addAnnotatedType(event, beanManager, JsonValueProducer.class);
    addAnnotatedType(event, beanManager, JWTAuthContextInfoProvider.class);
    addAnnotatedType(event, beanManager, JWTAuthenticationFilter.class);
    addAnnotatedType(event, beanManager, PrincipalProducer.class);
    addAnnotatedType(event, beanManager, RawClaimTypeProducer.class);
    if (registerOptionalClaimTypeProducer()) {
        addAnnotatedType(event, beanManager, OptionalClaimTypeProducer.class);
    }

    if (isEESecurityAvailable()) {
        addAnnotatedType(event, beanManager, JWTHttpAuthenticationMechanism.class);
        CDILogging.log.jwtHttpAuthenticationMechanismRegistered();
    } else {
        // EE Security is not available, register the JAX-RS authentication filter.
        CDILogging.log.jwtHttpAuthenticationMechanismNotRegistered();
    }
}
 
Example #2
Source Project: smallrye-fault-tolerance   Author: smallrye   File: FaultToleranceExtension.java    License: Apache License 2.0 6 votes vote down vote up
void registerInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    LOGGER.info("MicroProfile: Fault Tolerance activated");
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(CircuitBreaker.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Retry.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Timeout.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Asynchronous.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Fallback.class)));
    bbd.addInterceptorBinding(new FTInterceptorBindingAnnotatedType<>(bm.createAnnotatedType(Bulkhead.class)));

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    bbd.addAnnotatedType(bm.createAnnotatedType(FaultToleranceInterceptor.class),
            FaultToleranceInterceptor.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFallbackHandlerProvider.class),
            DefaultFallbackHandlerProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(ExecutorProvider.class),
            ExecutorProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(DefaultFaultToleranceOperationProvider.class),
            DefaultFaultToleranceOperationProvider.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(MetricsCollectorFactory.class), MetricsCollectorFactory.class.getName());
    bbd.addAnnotatedType(bm.createAnnotatedType(StrategyCache.class), StrategyCache.class.getName());
}
 
Example #3
Source Project: smallrye-metrics   Author: smallrye   File: MetricCdiInjectionExtension.java    License: Apache License 2.0 6 votes vote down vote up
private void addInterceptorBindings(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
    SmallRyeMetricsLogging.log.logSmallRyeMetricsVersion(getImplementationVersion().orElse("unknown"));

    String extensionName = MetricCdiInjectionExtension.class.getName();

    // It seems that fraction deployment module cannot be picked up as a CDI bean archive - see also SWARM-1725
    for (Class clazz : new Class[] {
            MetricProducer.class,
            MetricNameFactory.class,
            GaugeRegistrationInterceptor.class,
            MetricRegistries.class,

            MeteredInterceptor.class,
            CountedInterceptor.class,
            ConcurrentGaugeInterceptor.class,
            TimedInterceptor.class,
            SimplyTimedInterceptor.class,
            MetricsRequestHandler.class
    }) {
        bbd.addAnnotatedType(manager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
    }
}
 
Example #4
Source Project: deltaspike   Author: apache   File: ViewScopedExtension.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * javax.faces.bean.ViewScoped is no CDI Scope.
 * We need to add it programmatically to CDI.
 */
public void addViewScoped(@Observes BeforeBeanDiscovery beforeBeanDiscovery)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());

    if (isActivated)
    {
        //this extension is only needed if the cdi-based view-scope handling isn't delegated to jsf 2.2+
        isActivated = !JsfUtils.isViewScopeDelegationEnabled();
    }

    if (!isActivated)
    {
        return;
    }

    beforeBeanDiscovery.addScope(ViewScoped.class, true, true);
}
 
Example #5
Source Project: deltaspike   Author: apache   File: InterDynExtension.java    License: Apache License 2.0 6 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
{
    if (!ClassDeactivationUtils.isActivated(getClass()))
    {
        return;
    }

    enabled = CoreBaseConfig.InterDynCustomization.INTERDYN_ENABLED.getValue();

    if (enabled)
    {
        logger.info("Starting with deltaspike.interdyn instrumentation");
        init();
    }
}
 
Example #6
Source Project: piranha   Author: piranhacloud   File: CdiExtension.java    License: BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public void register(@Observes BeforeBeanDiscovery beforeBean, BeanManager beanManager) {
    if (!InMemoryIdentityStore.getCALLER_TO_CREDENTIALS().isEmpty()) {
        beforeBean.addAnnotatedType(
            beanManager.createAnnotatedType(InMemoryIdentityStore.class), 
            "Piranha " + InMemoryIdentityStore.class.getName());
    }
}
 
Example #7
Source Project: thorntail   Author: thorntail   File: OpenTracingCDIExtension.java    License: Apache License 2.0 5 votes vote down vote up
public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager manager) {
  logger.info("Registering Tracer CDI producer");
  String extensionName = OpenTracingCDIExtension.class.getName();
  for (Class<?> clazz : new Class<?>[] {
          TracerProducer.class,
          OpenTracingInterceptor.class,
  }) {
    bbd.addAnnotatedType(manager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
  }
}
 
Example #8
Source Project: thorntail   Author: thorntail   File: MPJWTExtension.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Register the MPJWTProducer JsonWebToken producer bean
 *
 * @param bbd         before discovery event
 * @param beanManager cdi bean manager
 */
public void observeBeforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) {
    log.debugf("MPJWTExtension(), adding producers");
    String extensionName = MPJWTExtension.class.getName();
    for (Class<?> clazz : new Class<?>[] {
            JWTAuthContextInfoProvider.class,
            CommonJwtProducer.class,
            PrincipalProducer.class,
            RawClaimTypeProducer.class,
            ClaimValueProducer.class,
            JsonValueProducer.class,
    }) {
        bbd.addAnnotatedType(beanManager.createAnnotatedType(clazz), extensionName + "_" + clazz.getName());
    }
}
 
Example #9
Source Project: openwebbeans-meecrowave   Author: apache   File: JtaExtension.java    License: Apache License 2.0 5 votes vote down vote up
void register(@Observes final BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager beanManager) {
    Stream.of(
            MandatoryInterceptor.class, NeverInterceptor.class,
            NotSupportedInterceptor.class, RequiredInterceptor.class,
            RequiredNewInterceptor.class, SupportsInterceptor.class)
            .forEach(c -> beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(c)));
}
 
Example #10
Source Project: openwebbeans-meecrowave   Author: apache   File: MeecrowaveExtension.java    License: Apache License 2.0 5 votes vote down vote up
void addBeansFromJava(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm) {
    if (Cxfs.IS_PRESENT) {
        bbd.addInterceptorBinding(JAXRSFieldInjectionInterceptor.Binding.class);

        Stream.of(MeecrowaveBus.class, JAXRSFieldInjectionInterceptor.class)
              .forEach(type -> bbd.addAnnotatedType(bm.createAnnotatedType(type)));
    }
}
 
Example #11
Source Project: tomee   Author: apache   File: TomEESecurityExtension.java    License: Apache License 2.0 5 votes vote down vote up
void observeBeforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanDiscovery,
                                final BeanManager beanManager) {
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(DefaultAuthenticationMechanism.class));
    beforeBeanDiscovery.addAnnotatedType(
            beanManager.createAnnotatedType(TomEESecurityServletAuthenticationMechanismMapper.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEEDefaultIdentityStore.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEEIdentityStoreHandler.class));

    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(AutoApplySessionInterceptor.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(RememberMeInterceptor.class));
    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(LoginToContinueInterceptor.class));

    beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TomEESecurityContext.class));
}
 
Example #12
Source Project: tomee   Author: apache   File: TomEEOpenAPIExtension.java    License: Apache License 2.0 5 votes vote down vote up
void init(@Observes final BeforeBeanDiscovery beforeBeanDiscovery) {
    config = GeronimoOpenAPIConfig.create();
    processor = new AnnotationProcessor(config, loadNamingStrategy(config), null);
    skipScan = Boolean.parseBoolean(config.read(OASConfig.SCAN_DISABLE, "false"));
    classes = getConfigCollection(OASConfig.SCAN_CLASSES);
    packages = getConfigCollection(OASConfig.SCAN_PACKAGES);
    excludePackages = getConfigCollection(OASConfig.SCAN_EXCLUDE_PACKAGES);
    excludeClasses = getConfigCollection(OASConfig.SCAN_EXCLUDE_CLASSES);
    try {
        Yaml.getObjectMapper();
        jacksonIsPresent = true;
    } catch (final Error | RuntimeException e) {
        // no-op
    }
}
 
Example #13
Source Project: tomee   Author: apache   File: MPJWTCDIExtension.java    License: Apache License 2.0 5 votes vote down vote up
public void observeBeforeBeanDiscovery(@Observes final BeforeBeanDiscovery bbd, final BeanManager beanManager) {
    bbd.addAnnotatedType(beanManager.createAnnotatedType(JWTAuthConfigurationProperties.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(JsonbProducer.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(MPJWTFilter.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(MPJWTInitializer.class));
    bbd.addAnnotatedType(beanManager.createAnnotatedType(org.apache.tomee.microprofile.jwt.bval.BValInterceptor.class));
}
 
Example #14
Source Project: metrics-cdi   Author: astefanutti   File: CdiHelper.java    License: Apache License 2.0 5 votes vote down vote up
static <T extends Annotation> void declareAsInterceptorBinding(Class<T> annotation, BeanManager manager, BeforeBeanDiscovery bbd) {
    AnnotatedType<T> annotated = manager.createAnnotatedType(annotation);
    Set<AnnotatedMethod<? super T>> methods = new HashSet<>();
    for (AnnotatedMethod<? super T> method : annotated.getMethods())
        methods.add(new AnnotatedMethodDecorator<>(method, NON_BINDING));

    bbd.addInterceptorBinding(new AnnotatedTypeDecorator<>(annotated, INTERCEPTOR_BINDING, methods));
}
 
Example #15
Source Project: deltaspike   Author: apache   File: PersistenceUnitDescriptorInitExtension.java    License: Apache License 2.0 5 votes vote down vote up
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery before)
{
    isActivated = ClassDeactivationUtils.isActivated(getClass());

    if (!isActivated)
    {
        return;
    }

    PersistenceUnitDescriptorProvider.getInstance().init();
}
 
Example #16
Source Project: deltaspike   Author: apache   File: GlobalInterceptorExtension.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("UnusedDeclaration")
protected void init(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager)
{
    if (!ClassDeactivationUtils.isActivated(getClass()))
    {
        return;
    }

    this.beanManager = beanManager;
    int priorityValue = CoreBaseConfig.InterceptorCustomization.PRIORITY;
    priorityAnnotationInstance = AnnotationInstanceUtils.getPriorityAnnotationInstance(priorityValue);
}
 
Example #17
Source Project: smallrye-jwt   Author: smallrye   File: SmallRyeJWTAuthCDIExtension.java    License: Apache License 2.0 4 votes vote down vote up
void addAnnotatedType(BeforeBeanDiscovery event, BeanManager beanManager, Class<?> type) {
    final String id = "SmallRye" + type.getSimpleName();
    event.addAnnotatedType(beanManager.createAnnotatedType(type), id);
    CDILogging.log.addedType(type.getName());
}
 
Example #18
Source Project: datawave   Author: NationalSecurityAgency   File: RefreshableScopeExtension.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    bbd.addScope(RefreshableScope.class, true, false);
}
 
Example #19
Source Project: datawave   Author: NationalSecurityAgency   File: SpringCDIExtension.java    License: Apache License 2.0 4 votes vote down vote up
@SuppressWarnings("unused")
void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {}
 
Example #20
Source Project: smallrye-config   Author: smallrye   File: ConfigExtension.java    License: Apache License 2.0 4 votes vote down vote up
protected void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) {
    AnnotatedType<ConfigProducer> configBean = bm.createAnnotatedType(ConfigProducer.class);
    bbd.addAnnotatedType(configBean, ConfigProducer.class.getName());
}
 
Example #21
Source Project: krazo   Author: eclipse-ee4j   File: CdiUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param beforeBean The BeforeBeanDiscovery.
 * @param bm         The BeanManager.
 * @param types      annotated types to register
 */
public static void addAnnotatedTypes(BeforeBeanDiscovery beforeBean, BeanManager bm, Class<?>... types) {
    for (Class<?> type : types) {
        beforeBean.addAnnotatedType(bm.createAnnotatedType(type), type.getName());
    }
}
 
Example #22
Source Project: activiti6-boot2   Author: dingziyang   File: ActivitiExtension.java    License: Apache License 2.0 4 votes vote down vote up
public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {
  event.addScope(BusinessProcessScoped.class, true, true);
}
 
Example #23
Source Project: microprofile-jwt-auth   Author: eclipse   File: MPConfigExtension.java    License: Apache License 2.0 4 votes vote down vote up
public void addConfigPropertyProduer(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) {
    System.out.printf("MPConfigExtension, added ConfigPropertyProduer\n");
    //bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigProducer.class));
    //bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigPropertyProducer.class));
}
 
Example #24
Source Project: ozark   Author: mvc-spec   File: CdiUtils.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * @param beforeBean The BeforeBeanDiscovery.
 * @param bm         The BeanManager.
 * @param types      annotated types to register
 */
public static void addAnnotatedTypes(BeforeBeanDiscovery beforeBean, BeanManager bm, Class<?>... types) {
    for (Class<?> type : types) {
        beforeBean.addAnnotatedType(bm.createAnnotatedType(type), type.getName());
    }
}
 
Example #25
Source Project: thorntail   Author: thorntail   File: SwaggerExtension.java    License: Apache License 2.0 4 votes vote down vote up
/**
 * Associate the InterceptorBinding annotation.
 */
public void processBeforeBeanDiscovery(@Observes BeforeBeanDiscovery event, BeanManager beanManager) {
    event.addInterceptorBinding(beanManager.createAnnotatedType(AddSwaggerResources.class));
    event.addAnnotatedType(beanManager.createAnnotatedType(SwaggerRestApplicationInterceptor.class), SwaggerRestApplicationInterceptor.class.getName());
}
 
Example #26
Source Project: thorntail   Author: thorntail   File: InjectConfigViewExtension.java    License: Apache License 2.0 4 votes vote down vote up
public void addConfigView(@Observes BeforeBeanDiscovery bbd, BeanManager beanManager) {
    bbd.addAnnotatedType(beanManager.createAnnotatedType(ConfigurationValueProducer.class), ConfigurationValueProducer.class.getName());
}
 
Example #27
Source Project: weld-vertx   Author: weld   File: ServiceProxyExtension.java    License: Apache License 2.0 4 votes vote down vote up
void init(@Observes BeforeBeanDiscovery event) {
    serviceInterfaces = new HashSet<>();
}
 
Example #28
Source Project: flowable-engine   Author: flowable   File: FlowableExtension.java    License: Apache License 2.0 4 votes vote down vote up
public void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery event) {
    event.addScope(BusinessProcessScoped.class, true, true);
}
 
Example #29
Source Project: openwebbeans-meecrowave   Author: apache   File: JpaExtension.java    License: Apache License 2.0 4 votes vote down vote up
void addInternals(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm) {
    Stream.of(JpaTransactionInterceptor.class, JpaNoTransactionInterceptor.class)
            .forEach(interceptor -> bbd.addAnnotatedType(bm.createAnnotatedType(interceptor)));
}
 
Example #30
Source Project: drools-workshop   Author: salaboy   File: BusinessScopeExtension.java    License: Apache License 2.0 4 votes vote down vote up
public void addACustomScope(@Observes final BeforeBeanDiscovery event) {
    event.addScope(BusinessScoped.class, true, false);
}