Java Code Examples for javax.enterprise.inject.Instance#isResolvable()

The following examples show how to use javax.enterprise.inject.Instance#isResolvable() . 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 File: SmallRyeJWTAuthCDIExtension.java    From smallrye-jwt with Apache License 2.0 6 votes vote down vote up
public static boolean isHttpAuthMechanismEnabled() {
    boolean enabled = false;

    if (isEESecurityAvailable()) {
        Instance<JWTHttpAuthenticationMechanism> instance;

        try {
            instance = CDI.current().select(JWTHttpAuthenticationMechanism.class);
            enabled = instance.isResolvable();
        } catch (@SuppressWarnings("unused") Exception e) {
            //Ignore exceptions, consider HTTP authentication mechanism to be disabled
        }
    }

    return enabled;
}
 
Example 2
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        ResteasyDeployment deployment,
        String rootPath,
        BufferAllocator allocator, Executor executor, long readTimeout) {
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    this.dispatcher = new RequestDispatcher((SynchronousDispatcher) deployment.getDispatcher(),
            deployment.getProviderFactory(), null, Thread.currentThread().getContextClassLoader());
    this.rootPath = rootPath;
    this.allocator = allocator;
    this.executor = executor;
    this.readTimeout = readTimeout;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
}
 
Example 3
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        ObjectMapper mapper,
        FunqyKnativeEventsConfig config,
        FunctionInvoker defaultInvoker,
        Map<String, FunctionInvoker> typeTriggers,
        Executor executor) {
    this.defaultInvoker = defaultInvoker;
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    this.executor = executor;
    this.mapper = mapper;
    this.typeTriggers = typeTriggers;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    Instance<IdentityProviderManager> identityProviderManager = CDI.current().select(IdentityProviderManager.class);
    this.currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();

}
 
Example 4
Source File: VertxRequestHandler.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public VertxRequestHandler(Vertx vertx,
        BeanContainer beanContainer,
        String rootPath,
        Executor executor) {
    this.vertx = vertx;
    this.beanContainer = beanContainer;
    // make sure rootPath ends with "/" for easy parsing
    if (rootPath == null) {
        this.rootPath = "/";
    } else if (!rootPath.endsWith("/")) {
        this.rootPath = rootPath + "/";
    } else {
        this.rootPath = rootPath;
    }

    this.executor = executor;
    Instance<CurrentIdentityAssociation> association = CDI.current().select(CurrentIdentityAssociation.class);
    this.association = association.isResolvable() ? association.get() : null;
    currentVertxRequest = CDI.current().select(CurrentVertxRequest.class).get();
}
 
Example 5
Source File: SmallRyeGraphQLRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public Handler<RoutingContext> executionHandler(boolean allowGet) {
    Instance<CurrentIdentityAssociation> identityAssociations = CDI.current()
            .select(CurrentIdentityAssociation.class);
    CurrentIdentityAssociation association;
    if (identityAssociations.isResolvable()) {
        association = identityAssociations.get();
    } else {
        association = null;
    }
    return new SmallRyeGraphQLExecutionHandler(allowGet, association);
}
 
Example 6
Source File: DefaultPicocliCommandLineFactory.java    From quarkus with Apache License 2.0 5 votes vote down vote up
@Override
public CommandLine create() {
    String topCommandName = picocliConfiguration.topCommand.orElse(null);
    if (topCommandName != null) {
        Instance<Object> namedTopCommand = topCommand.select(NamedLiteral.of(topCommandName));
        if (namedTopCommand.isResolvable()) {
            return new CommandLine(namedTopCommand.get(), picocliFactory);
        }
        return new CommandLine(classForName(topCommandName), picocliFactory);
    }
    return new CommandLine(topCommand.get(), picocliFactory);
}
 
Example 7
Source File: WeldSecurityService.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@Override
public Principal getPrincipal() {
    Instance<SecurityContext> securityServiceInstance =  CDI.current().select(SecurityContext.class);
    if (securityServiceInstance.isResolvable()) {
        return securityServiceInstance.get().getCallerPrincipal();
    }
    
    return null;
}
 
Example 8
Source File: QuarkusJpaConnectionProviderFactory.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private void lazyInit() {
    Instance<EntityManagerFactory> instance = CDI.current().select(EntityManagerFactory.class);

    if (!instance.isResolvable()) {
        throw new RuntimeException("Failed to resolve " + EntityManagerFactory.class + " from Quarkus runtime");
    }

    emf = instance.get();

    try (Connection connection = getConnection()) {
        if (jtaEnabled) {
            KeycloakModelUtils.suspendJtaTransaction(factory, () -> {
                KeycloakSession session = factory.create();
                try {
                    migration(getSchema(), connection, session);
                } finally {
                    session.close();
                }
            });
        } else {
            KeycloakModelUtils.runJobInTransaction(factory, session -> {
                migration(getSchema(), connection, session);
            });
        }
        prepareOperationalInfo(connection);
    } catch (SQLException cause) {
        throw new RuntimeException("Failed to migrate model", cause);
    }
}
 
Example 9
Source File: VertxClientCertificateLookup.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public X509Certificate[] getCertificateChain(HttpRequest httpRequest) {
    Instance<RoutingContext> instances = CDI.current().select(RoutingContext.class);

    if (instances.isResolvable()) {
        RoutingContext context = instances.get();

        try {
            SSLSession sslSession = context.request().sslSession();
            
            if (sslSession == null) {
                return null;
            }
            
            X509Certificate[] certificates = (X509Certificate[]) sslSession.getPeerCertificates();

            if (logger.isTraceEnabled() && certificates != null) {
                for (X509Certificate cert : certificates) {
                    logger.tracef("Certificate's SubjectDN => \"%s\"", cert.getSubjectDN().getName());
                }
            }

            return certificates;
        } catch (SSLPeerUnverifiedException ignore) {
            // client not authenticated
        }
    }

    return null;
}
 
Example 10
Source File: MetricDecorator.java    From smallrye-reactive-messaging with Apache License 2.0 4 votes vote down vote up
@Inject
private void setMetricRegistry(Instance<MetricRegistry> registryInstance) {
    if (registryInstance.isResolvable()) {
        registry = registryInstance.get();
    }
}