use of org.jboss.weld.security.spi.SecurityServices in project wildfly by wildfly.
the class WeldDeploymentProcessor method deploy.
@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
final DeploymentUnit parent = Utils.getRootDeploymentUnit(deploymentUnit);
final ServiceTarget serviceTarget = phaseContext.getServiceTarget();
final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
if (!WeldDeploymentMarker.isPartOfWeldDeployment(deploymentUnit)) {
// if there are CDI annotation present and this is the top level deployment we log a warning
if (deploymentUnit.getParent() == null && CdiAnnotationMarker.cdiAnnotationsPresent(deploymentUnit)) {
WeldLogger.DEPLOYMENT_LOGGER.cdiAnnotationsButNotBeanArchive(deploymentUnit.getName());
}
return;
}
// add a dependency on the weld service to web deployments
final ServiceName weldBootstrapServiceName = parent.getServiceName().append(WeldBootstrapService.SERVICE_NAME);
final ServiceName weldBootstrapServiceInternalName = parent.getServiceName().append(WeldBootstrapService.INTERNAL_SERVICE_NAME);
ServiceName weldStartServiceName = parent.getServiceName().append(WeldStartService.SERVICE_NAME);
deploymentUnit.addToAttachmentList(Attachments.WEB_DEPENDENCIES, weldStartServiceName);
final Set<ServiceName> dependencies = new HashSet<ServiceName>();
// we only start weld on top level deployments
if (deploymentUnit.getParent() != null) {
return;
}
WeldLogger.DEPLOYMENT_LOGGER.startingServicesForCDIDeployment(phaseContext.getDeploymentUnit().getName());
final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
final ModuleSpecification moduleSpecification = deploymentUnit.getAttachment(Attachments.MODULE_SPECIFICATION);
final Set<BeanDeploymentArchiveImpl> beanDeploymentArchives = new HashSet<BeanDeploymentArchiveImpl>();
final Map<ModuleIdentifier, BeanDeploymentModule> bdmsByIdentifier = new HashMap<ModuleIdentifier, BeanDeploymentModule>();
final Map<ModuleIdentifier, ModuleSpecification> moduleSpecByIdentifier = new HashMap<ModuleIdentifier, ModuleSpecification>();
final Map<ModuleIdentifier, EEModuleDescriptor> eeModuleDescriptors = new HashMap<>();
// the root module only has access to itself. For most deployments this will be the only module
// for ear deployments this represents the ear/lib directory.
// war and jar deployment visibility will depend on the dependencies that
// exist in the application, and mirror inter module dependencies
final BeanDeploymentModule rootBeanDeploymentModule = deploymentUnit.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
putIfValueNotNull(eeModuleDescriptors, module.getIdentifier(), rootBeanDeploymentModule.getModuleDescriptor());
bdmsByIdentifier.put(module.getIdentifier(), rootBeanDeploymentModule);
moduleSpecByIdentifier.put(module.getIdentifier(), moduleSpecification);
beanDeploymentArchives.addAll(rootBeanDeploymentModule.getBeanDeploymentArchives());
final List<DeploymentUnit> subDeployments = deploymentUnit.getAttachmentList(Attachments.SUB_DEPLOYMENTS);
final Set<ClassLoader> subDeploymentLoaders = new HashSet<ClassLoader>();
final ServiceLoader<DeploymentUnitDependenciesProvider> dependenciesProviders = ServiceLoader.load(DeploymentUnitDependenciesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
final ServiceLoader<ModuleServicesProvider> moduleServicesProviders = ServiceLoader.load(ModuleServicesProvider.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
getDependencies(deploymentUnit, dependencies, dependenciesProviders);
for (DeploymentUnit subDeployment : subDeployments) {
getDependencies(subDeployment, dependencies, dependenciesProviders);
final Module subDeploymentModule = subDeployment.getAttachment(Attachments.MODULE);
if (subDeploymentModule == null) {
continue;
}
subDeploymentLoaders.add(subDeploymentModule.getClassLoader());
final ModuleSpecification subDeploymentModuleSpec = subDeployment.getAttachment(Attachments.MODULE_SPECIFICATION);
final BeanDeploymentModule bdm = subDeployment.getAttachment(WeldAttachments.BEAN_DEPLOYMENT_MODULE);
if (bdm == null) {
continue;
}
// add the modules bdas to the global set of bdas
beanDeploymentArchives.addAll(bdm.getBeanDeploymentArchives());
bdmsByIdentifier.put(subDeploymentModule.getIdentifier(), bdm);
moduleSpecByIdentifier.put(subDeploymentModule.getIdentifier(), subDeploymentModuleSpec);
putIfValueNotNull(eeModuleDescriptors, subDeploymentModule.getIdentifier(), bdm.getModuleDescriptor());
// we have to do this here as the aggregate components are not available in earlier phases
final ResourceRoot subDeploymentRoot = subDeployment.getAttachment(Attachments.DEPLOYMENT_ROOT);
// Add module services to bean deployment module
for (Entry<Class<? extends Service>, Service> entry : ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, subDeployment, subDeploymentModule, subDeploymentRoot).entrySet()) {
bdm.addService(entry.getKey(), Reflections.cast(entry.getValue()));
}
}
for (Map.Entry<ModuleIdentifier, BeanDeploymentModule> entry : bdmsByIdentifier.entrySet()) {
final ModuleSpecification bdmSpec = moduleSpecByIdentifier.get(entry.getKey());
final BeanDeploymentModule bdm = entry.getValue();
if (bdm == rootBeanDeploymentModule) {
// the root module only has access to itself
continue;
}
for (ModuleDependency dependency : bdmSpec.getSystemDependencies()) {
BeanDeploymentModule other = bdmsByIdentifier.get(dependency.getIdentifier());
if (other != null && other != bdm) {
bdm.addBeanDeploymentModule(other);
}
}
}
Map<Class<? extends Service>, Service> rootModuleServices = ServiceLoaders.loadModuleServices(moduleServicesProviders, deploymentUnit, deploymentUnit, module, deploymentRoot);
// Add root module services to root bean deployment module
for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
rootBeanDeploymentModule.addService(entry.getKey(), Reflections.cast(entry.getValue()));
}
// Add root module services to additional bean deployment archives
for (final BeanDeploymentArchiveImpl additional : deploymentUnit.getAttachmentList(WeldAttachments.ADDITIONAL_BEAN_DEPLOYMENT_MODULES)) {
beanDeploymentArchives.add(additional);
for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
additional.getServices().add(entry.getKey(), Reflections.cast(entry.getValue()));
}
}
final Collection<Metadata<Extension>> extensions = WeldPortableExtensions.getPortableExtensions(deploymentUnit).getExtensions();
final WeldDeployment deployment = new WeldDeployment(beanDeploymentArchives, extensions, module, subDeploymentLoaders, deploymentUnit, rootBeanDeploymentModule, eeModuleDescriptors);
installBootstrapConfigurationService(deployment, parent);
// add the weld service
final ServiceBuilder<?> weldBootstrapServiceBuilder = serviceTarget.addService(weldBootstrapServiceInternalName);
final Consumer<WeldBootstrapService> weldBootstrapServiceConsumer = weldBootstrapServiceBuilder.provides(weldBootstrapServiceInternalName);
weldBootstrapServiceBuilder.requires(TCCLSingletonService.SERVICE_NAME);
final Supplier<ExecutorServices> executorServicesSupplier = weldBootstrapServiceBuilder.requires(WeldExecutorServices.SERVICE_NAME);
final Supplier<ExecutorService> serverExecutorSupplier = weldBootstrapServiceBuilder.requires(Services.JBOSS_SERVER_EXECUTOR);
Supplier<SecurityServices> securityServicesSupplier = null;
Supplier<TransactionServices> weldTransactionServicesSupplier = null;
// Install additional services
final ServiceLoader<BootstrapDependencyInstaller> installers = ServiceLoader.load(BootstrapDependencyInstaller.class, WildFlySecurityManager.getClassLoaderPrivileged(WeldDeploymentProcessor.class));
for (BootstrapDependencyInstaller installer : installers) {
ServiceName serviceName = installer.install(serviceTarget, deploymentUnit, jtsEnabled);
// Add dependency for recognized services
if (ServiceNames.WELD_SECURITY_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
securityServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
} else if (ServiceNames.WELD_TRANSACTION_SERVICES_SERVICE_NAME.getSimpleName().equals(serviceName.getSimpleName())) {
weldTransactionServicesSupplier = weldBootstrapServiceBuilder.requires(serviceName);
}
}
ServiceName deploymentServiceName = Utils.getRootDeploymentUnit(deploymentUnit).getServiceName();
final WeldBootstrapService weldBootstrapService = new WeldBootstrapService(deployment, WildFlyWeldEnvironment.INSTANCE, deploymentUnit.getName(), weldBootstrapServiceConsumer, executorServicesSupplier, serverExecutorSupplier, securityServicesSupplier, weldTransactionServicesSupplier, deploymentServiceName, weldBootstrapServiceName);
// Add root module services to WeldDeployment
for (Entry<Class<? extends Service>, Service> entry : rootModuleServices.entrySet()) {
weldBootstrapService.addWeldService(entry.getKey(), Reflections.cast(entry.getValue()));
}
weldBootstrapServiceBuilder.setInstance(weldBootstrapService);
weldBootstrapServiceBuilder.install();
final List<SetupAction> setupActions = getSetupActions(deploymentUnit);
ServiceBuilder<?> startService = serviceTarget.addService(weldStartServiceName);
for (final ServiceName dependency : dependencies) {
startService.requires(dependency);
}
// make sure JNDI bindings are up
startService.requires(JndiNamingDependencyProcessor.serviceName(deploymentUnit));
final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
boolean tx = capabilities.hasCapability("org.wildfly.transactions");
// [WFLY-5232]
for (final ServiceName jndiSubsystemDependency : getJNDISubsytemDependencies(tx)) {
startService.requires(jndiSubsystemDependency);
}
final EarMetaData earConfig = deploymentUnit.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
if (earConfig == null || !earConfig.getInitializeInOrder()) {
// in-order install of sub-deployments may result in service dependencies deadlocks if the jndi dependency services of subdeployments are added as dependencies
for (DeploymentUnit sub : subDeployments) {
startService.requires(JndiNamingDependencyProcessor.serviceName(sub));
}
}
final Supplier<WeldBootstrapService> bootstrapSupplier = startService.requires(weldBootstrapServiceName);
startService.setInstance(new WeldStartService(bootstrapSupplier, setupActions, module.getClassLoader(), deploymentServiceName));
startService.install();
}
use of org.jboss.weld.security.spi.SecurityServices in project wildfly by wildfly.
the class SecurityBootstrapDependencyInstaller method install.
@Override
public ServiceName install(ServiceTarget serviceTarget, DeploymentUnit deploymentUnit, boolean jtsEnabled) {
final ServiceName serviceName = deploymentUnit.getServiceName().append(WeldSecurityServices.SERVICE_NAME);
final CapabilityServiceSupport capabilities = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT);
final ServiceBuilder<?> sb = serviceTarget.addService(serviceName);
final Consumer<SecurityServices> securityServicesConsumer = sb.provides(serviceName);
sb.setInstance(new WeldSecurityServices(securityServicesConsumer));
sb.install();
return serviceName;
}
use of org.jboss.weld.security.spi.SecurityServices in project Payara by payara.
the class WeldDeployer method load.
/**
* Processing in this method is performed for each module that is in the process of being loaded by
* the container.
*
* <p>
* This method will collect information from each archive (module) and produce
* <code>BeanDeploymentArchive</code> information for each module.
* </p>
*
* <p>
* The
* <code>BeanDeploymentArchive</code>s are stored in the <code>Deployment</code> (that will
* eventually be handed off to <code>Weld</code>. Once this method is called for all modules (and
* <code>BeanDeploymentArchive</code> information has been collected for all <code>Weld</code>
* modules), a relationship structure is produced defining the accessiblity rules for the
* <code>BeanDeploymentArchive</code>s.
* </p>
*
* @param container
* @param context
* @return
*/
@Override
public WeldApplicationContainer load(WeldContainer container, DeploymentContext context) {
DeployCommandParameters deployParams = context.getCommandParameters(DeployCommandParameters.class);
ApplicationInfo applicationInfo = applicationRegistry.get(deployParams.name);
ReadableArchive archive = context.getSource();
boolean[] setTransientAppMetaData = { false };
// See if a WeldBootsrap has already been created - only want one per app.
WeldBootstrap bootstrap = getWeldBootstrap(context, applicationInfo, setTransientAppMetaData);
EjbBundleDescriptor ejbBundle = getEjbBundleFromContext(context);
EjbServices ejbServices = null;
Set<EjbDescriptor> ejbs = new HashSet<>();
if (ejbBundle != null) {
ejbs.addAll(ejbBundle.getEjbs());
ejbServices = new EjbServicesImpl(services);
}
// Create a deployment collecting information from the ReadableArchive (archive)
// If the archive is a composite, or has version numbers per maven conventions, strip them out
String archiveName = getArchiveName(context, applicationInfo, archive);
DeploymentImpl deploymentImpl = context.getTransientAppMetaData(WELD_DEPLOYMENT, DeploymentImpl.class);
if (deploymentImpl == null) {
deploymentImpl = new DeploymentImpl(archive, ejbs, context, archiveFactory, archiveName, services.getService(InjectionManager.class));
// Add services
TransactionServices transactionServices = new TransactionServicesImpl(services);
deploymentImpl.getServices().add(TransactionServices.class, transactionServices);
SecurityServices securityServices = new SecurityServicesImpl();
deploymentImpl.getServices().add(SecurityServices.class, securityServices);
ProxyServices proxyServices = new ProxyServicesImpl(services);
deploymentImpl.getServices().add(ProxyServices.class, proxyServices);
try {
ExecutorServices executorServices = new ExecutorServicesImpl();
deploymentImpl.getServices().add(ExecutorServices.class, executorServices);
} catch (NamingException ex) {
throw new RuntimeException(ex);
}
addWeldListenerToAllWars(context);
} else {
deploymentImpl.scanArchive(archive, ejbs, context, archiveName);
}
deploymentImpl.addDeployedEjbs(ejbs);
if (ejbBundle != null && (!deploymentImpl.getServices().contains(EjbServices.class))) {
// EJB Services is registered as a top-level service
deploymentImpl.getServices().add(EjbServices.class, ejbServices);
}
ExternalConfigurationImpl externalConfiguration = new ExternalConfigurationImpl();
externalConfiguration.setRollingUpgradesDelimiter(System.getProperty("fish.payara.rollingUpgradesDelimiter", ":"));
externalConfiguration.setBeanIndexOptimization(!deployParams.isAvailabilityEnabled());
externalConfiguration.setNonPortableMode(false);
configureConcurrentDeployment(context, externalConfiguration);
deploymentImpl.getServices().add(ExternalConfiguration.class, externalConfiguration);
BeanDeploymentArchive beanDeploymentArchive = deploymentImpl.getBeanDeploymentArchiveForArchive(archiveName);
if (beanDeploymentArchive != null && !beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
if (setTransientAppMetaData[0]) {
// Do this only if we have a root BDA
appToBootstrap.put(context.getModuleMetaData(Application.class), bootstrap);
applicationInfo.addTransientAppMetaData(WELD_BOOTSTRAP, bootstrap);
}
WebBundleDescriptor webBundleDescriptor = context.getModuleMetaData(WebBundleDescriptor.class);
boolean developmentMode = isDevelopmentMode(context);
if (webBundleDescriptor != null) {
webBundleDescriptor.setExtensionProperty(WELD_EXTENSION, "true");
// Add the Weld Listener. We have to do it here too in case addWeldListenerToAllWars wasn't
// able to do it.
webBundleDescriptor.addAppListenerDescriptorToFirst(new AppListenerDescriptorImpl(WELD_LISTENER));
// Add Weld Context Listener - this listener will ensure the WeldELContextListener is used
// for JSP's..
webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WELD_CONTEXT_LISTENER));
// Weld 2.2.1.Final. There is a tck test for this:
// org.jboss.cdi.tck.tests.context.session.listener.SessionContextHttpSessionListenerTest
// This WeldTerminationListener must come after all application-defined listeners
webBundleDescriptor.addAppListenerDescriptor(new AppListenerDescriptorImpl(WeldTerminationListenerProxy.class.getName()));
// Adding Weld ConverstationFilter if there is a filterMapping for it and it doesn't exist already.
// However, it will be applied only if web.xml has a mapping for it.
// Doing this here to make sure that its done only for CDI enabled web applications
registerWeldConversationFilter(webBundleDescriptor);
// every deployment
if (developmentMode) {
registerProbeFilter(webBundleDescriptor);
}
}
if (developmentMode) {
registerProbeExtension(externalConfiguration, deploymentImpl);
}
BundleDescriptor bundle = (webBundleDescriptor != null) ? webBundleDescriptor : ejbBundle;
if (bundle != null) {
if (!beanDeploymentArchive.getBeansXml().getBeanDiscoveryMode().equals(NONE)) {
// Register EE injection manager at the bean deployment archive level.
// We use the generic InjectionService service to handle all EE-style
// injection instead of the per-dependency-type InjectionPoint approach.
// Each InjectionServicesImpl instance knows its associated GlassFish bundle.
InjectionServices injectionServices = new InjectionServicesImpl(deploymentImpl.injectionManager, bundle, deploymentImpl);
ResourceInjectionServicesImpl resourceInjectionServices = new ResourceInjectionServicesImpl();
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, beanDeploymentArchive.getId() });
}
beanDeploymentArchive.getServices().add(InjectionServices.class, injectionServices);
beanDeploymentArchive.getServices().add(ResourceInjectionServices.class, resourceInjectionServices);
EEModuleDescriptor eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
// Relevant in WAR BDA - WEB-INF/lib BDA scenarios
for (BeanDeploymentArchive subBda : beanDeploymentArchive.getBeanDeploymentArchives()) {
if (logger.isLoggable(FINE)) {
logger.log(FINE, ADDING_INJECTION_SERVICES, new Object[] { injectionServices, subBda.getId() });
}
subBda.getServices().add(InjectionServices.class, injectionServices);
// Should not be subBda?
eeModuleDescriptor = getEEModuleDescriptor(beanDeploymentArchive);
if (eeModuleDescriptor != null) {
beanDeploymentArchive.getServices().add(EEModuleDescriptor.class, eeModuleDescriptor);
}
}
}
bundleToBeanDeploymentArchive.put(bundle, beanDeploymentArchive);
}
}
context.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
applicationInfo.addTransientAppMetaData(WELD_DEPLOYMENT, deploymentImpl);
return new WeldApplicationContainer();
}
Aggregations