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;
}
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);
}
}
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();
}
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;
}
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;
}
Aggregations