Search in sources :

Example 16 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class CDISecondChanceResolver method justInTimeResolution.

/* (non-Javadoc)
     * @see org.glassfish.hk2.api.JustInTimeInjectionResolver#justInTimeResolution(org.glassfish.hk2.api.Injectee)
     */
@SuppressWarnings({ "unchecked" })
@Override
public boolean justInTimeResolution(Injectee failedInjectionPoint) {
    Type requiredType = failedInjectionPoint.getRequiredType();
    Set<Annotation> setQualifiers = failedInjectionPoint.getRequiredQualifiers();
    Annotation[] qualifiers = setQualifiers.toArray(new Annotation[setQualifiers.size()]);
    BeanManager manager = getCurrentBeanManager();
    if (manager == null)
        return false;
    Set<Bean<?>> beans = manager.getBeans(requiredType, qualifiers);
    if (beans == null || beans.isEmpty()) {
        return false;
    }
    DynamicConfiguration config = ServiceLocatorUtilities.createDynamicConfiguration(locator);
    for (Bean<?> bean : beans) {
        // Add a bean to the service locator
        CDIHK2Descriptor<Object> descriptor = new CDIHK2Descriptor<Object>(manager, (Bean<Object>) bean, requiredType);
        config.addActiveDescriptor(descriptor);
    }
    config.commit();
    return true;
}
Also used : Type(java.lang.reflect.Type) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) BeanManager(javax.enterprise.inject.spi.BeanManager) Annotation(java.lang.annotation.Annotation) Bean(javax.enterprise.inject.spi.Bean)

Example 17 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class HK2IntegrationExtension method injectionTargetObserver.

/**
 * Called by CDI, gathers up all of the injection points known to hk2.
 *
 * @param pit The injection target even from CDI
 */
@SuppressWarnings("unused")
private <T> void injectionTargetObserver(@Observes ProcessInjectionTarget<T> pit) {
    if (locator == null)
        return;
    InjectionTarget<?> injectionTarget = pit.getInjectionTarget();
    Set<InjectionPoint> injectionPoints = injectionTarget.getInjectionPoints();
    for (InjectionPoint injectionPoint : injectionPoints) {
        Injectee injectee = HK2IntegrationUtilities.convertInjectionPointToInjectee(injectionPoint);
        ActiveDescriptor<?> descriptor = locator.getInjecteeDescriptor(injectee);
        if (descriptor == null || descriptor.getServiceId() == null)
            continue;
        // using a map removes duplicates
        foundWithHK2.put(descriptor.getServiceId(), descriptor);
    }
}
Also used : Injectee(org.glassfish.hk2.api.Injectee) InjectionPoint(javax.enterprise.inject.spi.InjectionPoint)

Example 18 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class AppServerStartupTest method initialize.

// ----- test initialization ---------------------------------------------
private void initialize(ServiceLocator testLocator) {
    DynamicConfigurationService dcs = testLocator.getService(DynamicConfigurationService.class);
    DynamicConfiguration config = dcs.createDynamicConfiguration();
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new TestSystemTasks()));
    // These are services that would normally be started by hk2 core
    config.addActiveDescriptor(AppServerStartup.AppInstanceListener.class);
    AbstractActiveDescriptor<?> descriptor = BuilderHelper.createConstantDescriptor(new TestModulesRegistry());
    descriptor.addContractType(ModulesRegistry.class);
    config.addActiveDescriptor(descriptor);
    descriptor = BuilderHelper.createConstantDescriptor(new ExecutorServiceFactory().provide());
    descriptor.addContractType(ExecutorService.class);
    config.addActiveDescriptor(descriptor);
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new ServerEnvironmentImpl()));
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new EventsImpl()));
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new Version()));
    config.addActiveDescriptor(BuilderHelper.createConstantDescriptor(new StartupContext()));
    config.bind(BuilderHelper.link(RunLevelControllerImpl.class).to(RunLevelController.class).build());
    config.addUnbindFilter(BuilderHelper.createContractFilter(RunLevelContext.class.getName()));
    config.bind(BuilderHelper.link(RunLevelContext.class).to(Context.class).in(Singleton.class).build());
    config.addUnbindFilter(BuilderHelper.createContractFilter(AsyncRunLevelContext.class.getName()));
    config.bind(BuilderHelper.link(AsyncRunLevelContext.class).in(Singleton.class).build());
    config.bind(BuilderHelper.link(AppServerStartup.class).build());
    descriptor = BuilderHelper.createConstantDescriptor(testLocator);
    descriptor.addContractType(ServiceLocator.class);
    config.addActiveDescriptor(descriptor);
    bindService(config, TestInitRunLevelService.class);
    bindService(config, TestStartupService.class);
    bindService(config, TestStartupRunLevelService.class);
    bindService(config, TestPostStartupRunLevelService.class);
    bindService(config, CommonClassLoaderServiceImpl.class);
    bindService(config, APIClassLoaderServiceImpl.class);
    bindService(config, APIExporterImpl.class);
    config.commit();
}
Also used : RunLevelContext(org.glassfish.hk2.runlevel.RunLevelContext) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) AsyncRunLevelContext(org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext) Context(org.glassfish.hk2.api.Context) DynamicConfigurationService(org.glassfish.hk2.api.DynamicConfigurationService) StartupContext(com.sun.enterprise.module.bootstrap.StartupContext) ServerEnvironmentImpl(org.glassfish.server.ServerEnvironmentImpl) DynamicConfiguration(org.glassfish.hk2.api.DynamicConfiguration) Version(com.sun.appserv.server.util.Version) AsyncRunLevelContext(org.glassfish.hk2.runlevel.internal.AsyncRunLevelContext) RunLevelControllerImpl(org.glassfish.hk2.runlevel.internal.RunLevelControllerImpl) EventsImpl(org.glassfish.kernel.event.EventsImpl)

Example 19 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class SecurityAccessValidator method isSecureAnnotated.

private boolean isSecureAnnotated(ValidationInformation info) {
    Descriptor d = info.getCandidate();
    Set<String> qualifiers = d.getQualifiers();
    if (qualifiers != null && qualifiers.size() != 0) {
        for (String s : qualifiers) {
            if (Secure.class.getCanonicalName().equals(s)) {
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("The instance is annotated with \'Secure\': " + info);
                }
                return true;
            }
        }
    }
    return false;
}
Also used : ActiveDescriptor(org.glassfish.hk2.api.ActiveDescriptor) Descriptor(org.glassfish.hk2.api.Descriptor)

Example 20 with Descriptor

use of org.glassfish.hk2.api.Descriptor in project Payara by payara.

the class ConfigApiTest method prepareAdminSubject.

private Subject prepareAdminSubject() {
    final ServiceLocator locator = getBaseServiceLocator();
    if (locator != null) {
        final List<ServiceHandle<? extends Object>> adminIdentities = /*                
                    (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(
                    new Filter() {

                @Override
                public boolean matches(Descriptor d) {
                    if (d == null) {
                        return false;
                    }
                    final Set<String> contracts = d.getAdvertisedContracts();
                    return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                }
            });
*/
        AccessController.doPrivileged(new PrivilegedAction<List<ServiceHandle<? extends Object>>>() {

            public List<ServiceHandle<? extends Object>> run() {
                List<ServiceHandle<? extends Object>> identities = (List<ServiceHandle<? extends Object>>) getBaseServiceLocator().getAllServices(new Filter() {

                    @Override
                    public boolean matches(Descriptor d) {
                        if (d == null) {
                            return false;
                        }
                        final Set<String> contracts = d.getAdvertisedContracts();
                        return (contracts == null ? false : contracts.contains("org.glassfish.internal.api.InternalSystemAdmin"));
                    }
                });
                return identities;
            }
        });
        if (!adminIdentities.isEmpty()) {
            final Object adminIdentity = adminIdentities.get(0);
            try {
                final Method getSubjectMethod = adminIdentity.getClass().getDeclaredMethod("getSubject", Subject.class);
                return (Subject) getSubjectMethod.invoke(adminIdentity);
            } catch (Exception ex) {
            // ignore - fallback to creating a subject explicitly that
            // should match the GlassFish admin identity
            }
        }
    }
    final Subject s = new Subject();
    s.getPrincipals().add(new PrincipalImpl("asadmin"));
    s.getPrincipals().add(new PrincipalImpl("_InternalSystemAdministrator_"));
    return s;
}
Also used : Set(java.util.Set) Method(java.lang.reflect.Method) Subject(javax.security.auth.Subject) ServiceLocator(org.glassfish.hk2.api.ServiceLocator) Filter(org.glassfish.hk2.api.Filter) ServiceHandle(org.glassfish.hk2.api.ServiceHandle) Descriptor(org.glassfish.hk2.api.Descriptor) List(java.util.List)

Aggregations

ActiveDescriptor (org.glassfish.hk2.api.ActiveDescriptor)10 ArrayList (java.util.ArrayList)4 Descriptor (org.glassfish.hk2.api.Descriptor)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 DynamicConfiguration (org.glassfish.hk2.api.DynamicConfiguration)3 AnnotationModel (org.glassfish.hk2.classmodel.reflect.AnnotationModel)3 AnnotationType (org.glassfish.hk2.classmodel.reflect.AnnotationType)3 Type (org.glassfish.hk2.classmodel.reflect.Type)3 Types (org.glassfish.hk2.classmodel.reflect.Types)3 HashSet (java.util.HashSet)2 Filter (org.glassfish.hk2.api.Filter)2 ServiceHandle (org.glassfish.hk2.api.ServiceHandle)2 Test (org.junit.Test)2 Version (com.sun.appserv.server.util.Version)1 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)1 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)1 ConnectorDescriptor (com.sun.enterprise.deployment.ConnectorDescriptor)1 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)1 EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)1 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)1