Search in sources :

Example 11 with Observes

use of jakarta.enterprise.event.Observes 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);
}
Also used : Dependent(jakarta.enterprise.context.Dependent) Arrays(java.util.Arrays) JsonValue(jakarta.json.JsonValue) JaxRsCdiExtension(io.helidon.microprofile.server.JaxRsCdiExtension) AnnotationLiteral(jakarta.enterprise.util.AnnotationLiteral) ApplicationScoped(jakarta.enterprise.context.ApplicationScoped) AfterDeploymentValidation(jakarta.enterprise.inject.spi.AfterDeploymentValidation) RuntimeStart(io.helidon.microprofile.cdi.RuntimeStart) AnnotatedParameter(jakarta.enterprise.inject.spi.AnnotatedParameter) BeforeBeanDiscovery(jakarta.enterprise.inject.spi.BeforeBeanDiscovery) Map(java.util.Map) DeploymentException(jakarta.enterprise.inject.spi.DeploymentException) JsonObject(jakarta.json.JsonObject) Method(java.lang.reflect.Method) Initialized(jakarta.enterprise.context.Initialized) Claims(org.eclipse.microprofile.jwt.Claims) PLATFORM_BEFORE(jakarta.interceptor.Interceptor.Priority.PLATFORM_BEFORE) BeanManager(jakarta.enterprise.inject.spi.BeanManager) TYPE(java.lang.annotation.ElementType.TYPE) FIELD(java.lang.annotation.ElementType.FIELD) Member(java.lang.reflect.Member) Set(java.util.Set) Objects(java.util.Objects) List(java.util.List) JaxRsApplication(io.helidon.microprofile.server.JaxRsApplication) Type(java.lang.reflect.Type) Optional(java.util.Optional) JsonNumber(jakarta.json.JsonNumber) JsonArray(jakarta.json.JsonArray) SecurityCdiExtension(io.helidon.microprofile.security.SecurityCdiExtension) Observes(jakarta.enterprise.event.Observes) ClaimValue(org.eclipse.microprofile.jwt.ClaimValue) PARAMETER(java.lang.annotation.ElementType.PARAMETER) ProcessInjectionPoint(jakarta.enterprise.inject.spi.ProcessInjectionPoint) Constructor(java.lang.reflect.Constructor) Instance(jakarta.enterprise.inject.Instance) Retention(java.lang.annotation.Retention) LoginConfig(org.eclipse.microprofile.auth.LoginConfig) AnnotatedField(jakarta.enterprise.inject.spi.AnnotatedField) Extension(jakarta.enterprise.inject.spi.Extension) Priority(jakarta.annotation.Priority) LinkedList(java.util.LinkedList) Config(io.helidon.config.Config) InjectionPoint(jakarta.enterprise.inject.spi.InjectionPoint) Claim(org.eclipse.microprofile.jwt.Claim) Target(java.lang.annotation.Target) Nonbinding(jakarta.enterprise.util.Nonbinding) RUNTIME(java.lang.annotation.RetentionPolicy.RUNTIME) METHOD(java.lang.annotation.ElementType.METHOD) ParameterizedType(java.lang.reflect.ParameterizedType) AfterBeanDiscovery(jakarta.enterprise.inject.spi.AfterBeanDiscovery) Annotated(jakarta.enterprise.inject.spi.Annotated) Provider(jakarta.inject.Provider) Qualifier(jakarta.inject.Qualifier) RequestScoped(jakarta.enterprise.context.RequestScoped) JsonString(jakarta.json.JsonString) Optional(java.util.Optional) SecurityCdiExtension(io.helidon.microprofile.security.SecurityCdiExtension) Objects(java.util.Objects) JaxRsCdiExtension(io.helidon.microprofile.server.JaxRsCdiExtension)

Aggregations

Observes (jakarta.enterprise.event.Observes)11 ApplicationScoped (jakarta.enterprise.context.ApplicationScoped)8 Extension (jakarta.enterprise.inject.spi.Extension)8 Set (java.util.Set)8 Priority (jakarta.annotation.Priority)7 AfterBeanDiscovery (jakarta.enterprise.inject.spi.AfterBeanDiscovery)7 Method (java.lang.reflect.Method)7 BeanManager (jakarta.enterprise.inject.spi.BeanManager)6 Annotation (java.lang.annotation.Annotation)6 HashSet (java.util.HashSet)6 Map (java.util.Map)6 Dependent (jakarta.enterprise.context.Dependent)5 Initialized (jakarta.enterprise.context.Initialized)5 LinkedList (java.util.LinkedList)5 Objects (java.util.Objects)5 Logger (java.util.logging.Logger)5 AnnotatedMethod (jakarta.enterprise.inject.spi.AnnotatedMethod)4 AnnotatedParameter (jakarta.enterprise.inject.spi.AnnotatedParameter)4 HashMap (java.util.HashMap)4 BeforeDestroyed (jakarta.enterprise.context.BeforeDestroyed)3