Search in sources :

Example 61 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class SecurityActions method getModuleClassLoader.

static ModuleClassLoader getModuleClassLoader(final String moduleSpec) throws ModuleLoadException {
    ModuleLoader loader = Module.getCallerModuleLoader();
    final Module module = loader.loadModule(ModuleIdentifier.fromString(moduleSpec));
    GetModuleClassLoaderAction action = new GetModuleClassLoaderAction(module);
    return WildFlySecurityManager.isChecking() ? doPrivileged(action) : action.run();
}
Also used : ModuleLoader(org.jboss.modules.ModuleLoader) GetModuleClassLoaderAction(org.wildfly.security.manager.action.GetModuleClassLoaderAction) Module(org.jboss.modules.Module)

Example 62 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class JSFAnnotationProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final Map<Class<? extends Annotation>, Set<Class<?>>> instances = new HashMap<Class<? extends Annotation>, Set<Class<?>>>();
    final CompositeIndex compositeIndex = deploymentUnit.getAttachment(Attachments.COMPOSITE_ANNOTATION_INDEX);
    if (compositeIndex == null) {
        // Can not continue without index
        return;
    }
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    if (module == null) {
        // Can not continue without module
        return;
    }
    final ClassLoader classLoader = module.getClassLoader();
    for (FacesAnnotation annotation : FacesAnnotation.values()) {
        final List<AnnotationInstance> annotationInstances = compositeIndex.getAnnotations(annotation.indexName);
        if (annotationInstances == null || annotationInstances.isEmpty()) {
            continue;
        }
        final Set<Class<?>> discoveredClasses = new HashSet<Class<?>>();
        instances.put(annotation.annotationClass, discoveredClasses);
        for (AnnotationInstance annotationInstance : annotationInstances) {
            final AnnotationTarget target = annotationInstance.target();
            if (target instanceof ClassInfo) {
                final DotName className = ClassInfo.class.cast(target).name();
                final Class<?> annotatedClass;
                try {
                    annotatedClass = classLoader.loadClass(className.toString());
                } catch (ClassNotFoundException e) {
                    throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.classLoadingFailed(className));
                }
                discoveredClasses.add(annotatedClass);
            } else {
                throw new DeploymentUnitProcessingException(JSFLogger.ROOT_LOGGER.invalidAnnotationLocation(annotation, target));
            }
        }
    }
    deploymentUnit.addToAttachmentList(ServletContextAttribute.ATTACHMENT_KEY, new ServletContextAttribute(FACES_ANNOTATIONS_SC_ATTR, instances));
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) HashSet(java.util.HashSet) Set(java.util.Set) HashMap(java.util.HashMap) CompositeIndex(org.jboss.as.server.deployment.annotation.CompositeIndex) DotName(org.jboss.jandex.DotName) Annotation(java.lang.annotation.Annotation) ServletContextAttribute(org.jboss.as.web.common.ServletContextAttribute) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet) ClassInfo(org.jboss.jandex.ClassInfo)

Example 63 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class EjbIIOPDeploymentUnitProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!IIOPDeploymentMarker.isIIOPDeployment(deploymentUnit)) {
        return;
    }
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
        return;
    }
    // a bean-name -> IIOPMetaData map, reflecting the assembly descriptor IIOP configuration.
    Map<String, IIOPMetaData> iiopMetaDataMap = new HashMap<String, IIOPMetaData>();
    final EjbJarMetaData ejbMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbMetaData != null && ejbMetaData.getAssemblyDescriptor() != null) {
        List<IIOPMetaData> iiopMetaDatas = ejbMetaData.getAssemblyDescriptor().getAny(IIOPMetaData.class);
        if (iiopMetaDatas != null && iiopMetaDatas.size() > 0) {
            for (IIOPMetaData metaData : iiopMetaDatas) {
                iiopMetaDataMap.put(metaData.getEjbName(), metaData);
            }
        }
    }
    final DeploymentReflectionIndex deploymentReflectionIndex = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.REFLECTION_INDEX);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (moduleDescription != null) {
        for (final ComponentDescription componentDescription : moduleDescription.getComponentDescriptions()) {
            if (componentDescription instanceof EJBComponentDescription) {
                final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) componentDescription;
                if (ejbComponentDescription.getEjbRemoteView() != null && ejbComponentDescription.getEjbHomeView() != null) {
                    // check if there is IIOP metadata for the bean - first using the bean name, then the wildcard "*" if needed.
                    IIOPMetaData iiopMetaData = iiopMetaDataMap.get(ejbComponentDescription.getEJBName());
                    if (iiopMetaData == null) {
                        iiopMetaData = iiopMetaDataMap.get(IIOPMetaData.WILDCARD_BEAN_NAME);
                    }
                    // has been enabled by default in the EJB3 subsystem.
                    if (iiopMetaData != null || settingsService.isEnabledByDefault()) {
                        processEjb(ejbComponentDescription, deploymentReflectionIndex, module, phaseContext.getServiceTarget(), iiopMetaData);
                    }
                }
            }
        }
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) HashMap(java.util.HashMap) IIOPMetaData(org.jboss.metadata.ejb.jboss.IIOPMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription)

Example 64 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class DeploymentRepositoryProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    if (eeModuleDescription == null) {
        return;
    }
    // Note, we do not use the EEModuleDescription.getApplicationName() because that API returns the
    // module name if the top level unit isn't a .ear, which is not what we want. We really want a
    // .ear name as application name (that's the semantic in EJB spec). So use EEModuleDescription.getEarApplicationName
    String applicationName = eeModuleDescription.getEarApplicationName();
    // if it's not a .ear deployment then set app name to empty string
    applicationName = applicationName == null ? "" : applicationName;
    final DeploymentModuleIdentifier identifier = new DeploymentModuleIdentifier(applicationName, eeModuleDescription.getModuleName(), eeModuleDescription.getDistinctName());
    final Collection<ComponentDescription> componentDescriptions = eeModuleDescription.getComponentDescriptions();
    final Map<String, EjbDeploymentInformation> deploymentInformationMap = new HashMap<String, EjbDeploymentInformation>();
    final Set<ServiceName> componentStartServices = new HashSet<ServiceName>();
    final Map<ServiceName, InjectedValue<?>> injectedValues = new HashMap<ServiceName, InjectedValue<?>>();
    for (final ComponentDescription component : componentDescriptions) {
        if (component instanceof EJBComponentDescription) {
            final EJBComponentDescription ejbComponentDescription = (EJBComponentDescription) component;
            componentStartServices.add(component.getStartServiceName());
            final InjectedValue<EJBComponent> componentInjectedValue = new InjectedValue<EJBComponent>();
            injectedValues.put(component.getCreateServiceName(), componentInjectedValue);
            final Map<String, InjectedValue<ComponentView>> remoteViews = new HashMap<String, InjectedValue<ComponentView>>();
            final Map<String, InjectedValue<ComponentView>> localViews = new HashMap<String, InjectedValue<ComponentView>>();
            for (final ViewDescription view : ejbComponentDescription.getViews()) {
                boolean remoteView = false;
                if (view instanceof EJBViewDescription) {
                    final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                    if (viewType == MethodIntf.HOME || viewType == MethodIntf.REMOTE) {
                        remoteView = true;
                    }
                }
                final InjectedValue<ComponentView> componentViewInjectedValue = new InjectedValue<ComponentView>();
                if (remoteView) {
                    remoteViews.put(view.getViewClassName(), componentViewInjectedValue);
                } else {
                    localViews.put(view.getViewClassName(), componentViewInjectedValue);
                }
                injectedValues.put(view.getServiceName(), componentViewInjectedValue);
            }
            final InjectedValue<EjbIIOPService> iorFactory = new InjectedValue<EjbIIOPService>();
            if (ejbComponentDescription.isExposedViaIiop()) {
                injectedValues.put(ejbComponentDescription.getServiceName().append(EjbIIOPService.SERVICE_NAME), iorFactory);
            }
            final EjbDeploymentInformation info = new EjbDeploymentInformation(ejbComponentDescription.getEJBName(), componentInjectedValue, remoteViews, localViews, module.getClassLoader(), iorFactory);
            deploymentInformationMap.put(ejbComponentDescription.getEJBName(), info);
        }
    }
    final StartupCountdown countdown = deploymentUnit.getAttachment(Attachments.STARTUP_COUNTDOWN);
    final ModuleDeployment deployment = new ModuleDeployment(identifier, deploymentInformationMap, countdown);
    ServiceName moduleDeploymentService = deploymentUnit.getServiceName().append(ModuleDeployment.SERVICE_NAME);
    final ServiceBuilder<ModuleDeployment> builder = phaseContext.getServiceTarget().addService(moduleDeploymentService, deployment);
    for (Map.Entry<ServiceName, InjectedValue<?>> entry : injectedValues.entrySet()) {
        builder.addDependency(entry.getKey(), (InjectedValue<Object>) entry.getValue());
    }
    builder.addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, deployment.getDeploymentRepository());
    builder.install();
    final ModuleDeployment.ModuleDeploymentStartService deploymentStart = new ModuleDeployment.ModuleDeploymentStartService(identifier, countdown);
    final ServiceBuilder<Void> startBuilder = phaseContext.getServiceTarget().addService(deploymentUnit.getServiceName().append(ModuleDeployment.START_SERVICE_NAME), deploymentStart);
    startBuilder.addDependencies(componentStartServices);
    startBuilder.addDependency(moduleDeploymentService);
    startBuilder.addDependency(DeploymentRepository.SERVICE_NAME, DeploymentRepository.class, deploymentStart.getDeploymentRepository());
    startBuilder.install();
}
Also used : InjectedValue(org.jboss.msc.value.InjectedValue) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) HashMap(java.util.HashMap) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) ModuleDeployment(org.jboss.as.ejb3.deployment.ModuleDeployment) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) StartupCountdown(org.jboss.as.ee.component.deployers.StartupCountdown) HashSet(java.util.HashSet) EjbDeploymentInformation(org.jboss.as.ejb3.deployment.EjbDeploymentInformation) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) EJBComponent(org.jboss.as.ejb3.component.EJBComponent) ComponentView(org.jboss.as.ee.component.ComponentView) ServiceName(org.jboss.msc.service.ServiceName) DeploymentModuleIdentifier(org.jboss.as.ejb3.deployment.DeploymentModuleIdentifier) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EjbIIOPService(org.jboss.as.ejb3.iiop.EjbIIOPService) HashMap(java.util.HashMap) Map(java.util.Map)

Example 65 with Module

use of org.jboss.modules.Module in project wildfly by wildfly.

the class EJBContainerInterceptorsViewConfigurator method doConfigure.

private void doConfigure(final DeploymentPhaseContext context, final EJBComponentDescription ejbComponentDescription, final ViewConfiguration viewConfiguration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final EEApplicationClasses applicationClasses = deploymentUnit.getAttachment(Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final Module module = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.MODULE);
    final Map<String, List<InterceptorFactory>> userAroundInvokesByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    final Map<String, List<InterceptorFactory>> userAroundTimeoutsByInterceptorClass;
    if (ejbComponentDescription.isTimerServiceRequired()) {
        userAroundTimeoutsByInterceptorClass = new HashMap<String, List<InterceptorFactory>>();
    } else {
        userAroundTimeoutsByInterceptorClass = null;
    }
    // info
    for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getAllContainerInterceptors()) {
        final String interceptorClassName = interceptorDescription.getInterceptorClassName();
        final Class<?> intereptorClass;
        try {
            intereptorClass = ClassLoadingUtils.loadClass(interceptorClassName, module);
        } catch (ClassNotFoundException e) {
            throw EeLogger.ROOT_LOGGER.cannotLoadInterceptor(e, interceptorClassName);
        }
        // run the interceptor class (and its super class hierarchy) through the InterceptorClassDescriptionTraversal so that it can
        // find the relevant @AroundInvoke/@AroundTimeout methods
        final InterceptorClassDescriptionTraversal interceptorClassDescriptionTraversal = new InterceptorClassDescriptionTraversal(intereptorClass, applicationClasses, deploymentUnit, ejbComponentDescription);
        interceptorClassDescriptionTraversal.run();
        // now that the InterceptorClassDescriptionTraversal has done the relevant processing, keep track of the @AroundInvoke and
        // @AroundTimeout methods applicable for this interceptor class, within a map
        final List<InterceptorFactory> aroundInvokeInterceptorFactories = interceptorClassDescriptionTraversal.getAroundInvokeInterceptorFactories();
        if (aroundInvokeInterceptorFactories != null) {
            userAroundInvokesByInterceptorClass.put(interceptorClassName, aroundInvokeInterceptorFactories);
        }
        if (ejbComponentDescription.isTimerServiceRequired()) {
            final List<InterceptorFactory> aroundTimeoutInterceptorFactories = interceptorClassDescriptionTraversal.getAroundTimeoutInterceptorFactories();
            if (aroundTimeoutInterceptorFactories != null) {
                userAroundTimeoutsByInterceptorClass.put(interceptorClassName, aroundTimeoutInterceptorFactories);
            }
        }
    }
    // At this point we have each interceptor class mapped against their corresponding @AroundInvoke/@AroundTimeout InterceptorFactory(s)
    // Let's now iterate over all the methods of the EJB view and apply the relevant InterceptorFactory(s) to that method
    final List<InterceptorDescription> classLevelContainerInterceptors = ejbComponentDescription.getClassLevelContainerInterceptors();
    final Map<MethodIdentifier, List<InterceptorDescription>> methodLevelContainerInterceptors = ejbComponentDescription.getMethodLevelContainerInterceptors();
    final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods();
    for (final Method method : viewMethods) {
        final MethodIdentifier methodIdentifier = MethodIdentifier.getIdentifier(method.getReturnType(), method.getName(), method.getParameterTypes());
        final List<InterceptorFactory> aroundInvokesApplicableForMethod = new ArrayList<InterceptorFactory>();
        final List<InterceptorFactory> aroundTimeoutsApplicableForMethod = new ArrayList<InterceptorFactory>();
        // first add the default interceptors (if not excluded) to the deque
        if (!ejbComponentDescription.isExcludeDefaultContainerInterceptors() && !ejbComponentDescription.isExcludeDefaultContainerInterceptors(methodIdentifier)) {
            for (final InterceptorDescription interceptorDescription : ejbComponentDescription.getDefaultContainerInterceptors()) {
                String interceptorClassName = interceptorDescription.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // now add class level interceptors (if not excluded) to the deque
        if (!ejbComponentDescription.isExcludeClassLevelContainerInterceptors(methodIdentifier)) {
            for (final InterceptorDescription interceptorDescription : classLevelContainerInterceptors) {
                String interceptorClassName = interceptorDescription.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // now add method level interceptors for to the deque so that they are triggered after the class interceptors
        final List<InterceptorDescription> interceptorsForMethod = methodLevelContainerInterceptors.get(methodIdentifier);
        if (interceptorsForMethod != null) {
            for (final InterceptorDescription methodLevelInterceptor : interceptorsForMethod) {
                String interceptorClassName = methodLevelInterceptor.getInterceptorClassName();
                final List<InterceptorFactory> aroundInvokesOnInterceptor = userAroundInvokesByInterceptorClass.get(interceptorClassName);
                if (aroundInvokesOnInterceptor != null) {
                    aroundInvokesApplicableForMethod.addAll(aroundInvokesOnInterceptor);
                }
                if (ejbComponentDescription.isTimerServiceRequired()) {
                    final List<InterceptorFactory> aroundTimeoutsOnInterceptor = userAroundTimeoutsByInterceptorClass.get(interceptorClassName);
                    if (aroundTimeoutsOnInterceptor != null) {
                        aroundTimeoutsApplicableForMethod.addAll(aroundTimeoutsOnInterceptor);
                    }
                }
            }
        }
        // apply the interceptors to the view's method.
        viewConfiguration.addViewInterceptor(method, new UserInterceptorFactory(weaved(aroundInvokesApplicableForMethod), weaved(aroundTimeoutsApplicableForMethod)), InterceptorOrder.View.USER_APP_SPECIFIC_CONTAINER_INTERCEPTORS);
    }
}
Also used : HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) MethodIdentifier(org.jboss.invocation.proxy.MethodIdentifier) Method(java.lang.reflect.Method) InterceptorDescription(org.jboss.as.ee.component.InterceptorDescription) InterceptorFactory(org.jboss.invocation.InterceptorFactory) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) UserInterceptorFactory(org.jboss.as.ee.component.interceptors.UserInterceptorFactory) ArrayList(java.util.ArrayList) List(java.util.List) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Aggregations

Module (org.jboss.modules.Module)100 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)58 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)28 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)27 ServiceName (org.jboss.msc.service.ServiceName)21 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)19 HashMap (java.util.HashMap)17 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)17 ServiceTarget (org.jboss.msc.service.ServiceTarget)17 HashSet (java.util.HashSet)16 ArrayList (java.util.ArrayList)13 ModuleLoadException (org.jboss.modules.ModuleLoadException)11 ModuleIdentifier (org.jboss.modules.ModuleIdentifier)10 EEApplicationClasses (org.jboss.as.ee.component.EEApplicationClasses)9 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)8 Method (java.lang.reflect.Method)7 Map (java.util.Map)7 IOException (java.io.IOException)6 InterceptorDescription (org.jboss.as.ee.component.InterceptorDescription)6 ContextNames (org.jboss.as.naming.deployment.ContextNames)6