Search in sources :

Example 16 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class JPAInterceptorProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component instanceof SessionBeanComponentDescription) {
            ROOT_LOGGER.tracef("registering session bean interceptors for component '%s' in '%s'", component.getComponentName(), deploymentUnit.getName());
            registerSessionBeanInterceptors((SessionBeanComponentDescription) component, deploymentUnit);
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Example 17 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class SessionBeanObjectViewConfigurator method configure.

@Override
public void configure(final DeploymentPhaseContext context, final ComponentConfiguration componentConfiguration, final ViewDescription description, final ViewConfiguration configuration) throws DeploymentUnitProcessingException {
    //note that we don't have to handle all methods on the EJBObject, as some are handled client side
    final DeploymentReflectionIndex index = context.getDeploymentUnit().getAttachment(Attachments.REFLECTION_INDEX);
    for (final Method method : configuration.getProxyFactory().getCachedMethods()) {
        if (method.getName().equals("getPrimaryKey") && method.getParameterTypes().length == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            configuration.addViewInterceptor(method, PRIMARY_KEY_INTERCEPTOR, InterceptorOrder.View.COMPONENT_DISPATCHER);
        } else if (method.getName().equals("remove") && method.getParameterTypes().length == 0) {
            handleRemoveMethod(componentConfiguration, configuration, index, method);
        } else if (method.getName().equals("getEJBLocalHome") && method.getParameterTypes().length == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            final GetHomeInterceptorFactory factory = new GetHomeInterceptorFactory();
            configuration.addViewInterceptor(method, factory, InterceptorOrder.View.COMPONENT_DISPATCHER);
            final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
            componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                    EjbHomeViewDescription ejbLocalHomeView = componentDescription.getEjbLocalHomeView();
                    if (ejbLocalHomeView == null) {
                        throw EjbLogger.ROOT_LOGGER.beanLocalHomeInterfaceIsNull(componentDescription.getComponentName());
                    }
                    serviceBuilder.addDependency(ejbLocalHomeView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                }
            });
        } else if (method.getName().equals("getEJBHome") && method.getParameterTypes().length == 0) {
            configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            final GetHomeInterceptorFactory factory = new GetHomeInterceptorFactory();
            configuration.addViewInterceptor(method, factory, InterceptorOrder.View.COMPONENT_DISPATCHER);
            final SessionBeanComponentDescription componentDescription = (SessionBeanComponentDescription) componentConfiguration.getComponentDescription();
            componentConfiguration.getStartDependencies().add(new DependencyConfigurator<ComponentStartService>() {

                @Override
                public void configureDependency(final ServiceBuilder<?> serviceBuilder, final ComponentStartService service) throws DeploymentUnitProcessingException {
                    EjbHomeViewDescription ejbHomeView = componentDescription.getEjbHomeView();
                    if (ejbHomeView == null) {
                        throw EjbLogger.ROOT_LOGGER.beanHomeInterfaceIsNull(componentDescription.getComponentName());
                    }
                    serviceBuilder.addDependency(ejbHomeView.getServiceName(), ComponentView.class, factory.getViewToCreate());
                }
            });
        } else if (method.getName().equals("getHandle") && method.getParameterTypes().length == 0) {
        //ignore, handled client side
        } else if (method.getName().equals("isIdentical") && method.getParameterTypes().length == 1 && (method.getParameterTypes()[0].equals(EJBObject.class) || method.getParameterTypes()[0].equals(EJBLocalObject.class))) {
            handleIsIdenticalMethod(componentConfiguration, configuration, index, method);
        } else {
            final Method componentMethod = ClassReflectionIndexUtil.findMethod(index, componentConfiguration.getComponentClass(), MethodIdentifier.getIdentifierForMethod(method));
            if (componentMethod != null) {
                if (!Modifier.isPublic(componentMethod.getModifiers())) {
                    throw EjbLogger.ROOT_LOGGER.ejbBusinessMethodMustBePublic(componentMethod);
                }
                configuration.addViewInterceptor(method, new ImmediateInterceptorFactory(new ComponentDispatcherInterceptor(componentMethod)), InterceptorOrder.View.COMPONENT_DISPATCHER);
                configuration.addClientInterceptor(method, ViewDescription.CLIENT_DISPATCHER_INTERCEPTOR_FACTORY, InterceptorOrder.Client.CLIENT_DISPATCHER);
            } else if (method.getDeclaringClass() != Object.class && method.getDeclaringClass() != WriteReplaceInterface.class) {
                throw EjbLogger.ROOT_LOGGER.couldNotFindViewMethodOnEjb(method, description.getViewClassName(), componentConfiguration.getComponentName());
            }
        }
    }
    configuration.addClientPostConstructInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPostConstruct.TERMINAL_INTERCEPTOR);
    configuration.addClientPreDestroyInterceptor(Interceptors.getTerminalInterceptorFactory(), InterceptorOrder.ClientPreDestroy.TERMINAL_INTERCEPTOR);
}
Also used : DeploymentUnitProcessingException(org.jboss.as.server.deployment.DeploymentUnitProcessingException) GetHomeInterceptorFactory(org.jboss.as.ejb3.component.interceptors.GetHomeInterceptorFactory) EjbHomeViewDescription(org.jboss.as.ejb3.component.EjbHomeViewDescription) DependencyConfigurator(org.jboss.as.ee.component.DependencyConfigurator) Method(java.lang.reflect.Method) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) ServiceBuilder(org.jboss.msc.service.ServiceBuilder) ComponentView(org.jboss.as.ee.component.ComponentView) ImmediateInterceptorFactory(org.jboss.invocation.ImmediateInterceptorFactory) EJBObject(javax.ejb.EJBObject) EJBLocalObject(javax.ejb.EJBLocalObject) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) ComponentDispatcherInterceptor(org.jboss.as.ee.component.interceptors.ComponentDispatcherInterceptor) ComponentStartService(org.jboss.as.ee.component.ComponentStartService)

Example 18 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class WSIntegrationProcessorJAXWS_EJB method processAnnotation.

@SuppressWarnings("rawtypes")
private static void processAnnotation(final DeploymentUnit unit, final Class annotationType) {
    final EEModuleDescription moduleDescription = getRequiredAttachment(unit, EE_MODULE_DESCRIPTION);
    final JAXWSDeployment jaxwsDeployment = getJaxwsDeployment(unit);
    for (EEModuleClassDescription description : moduleDescription.getClassDescriptions()) {
        @SuppressWarnings("unchecked") ClassAnnotationInformation classAnnotationInfo = description.getAnnotationInformation(annotationType);
        if (classAnnotationInfo != null && !classAnnotationInfo.getClassLevelAnnotations().isEmpty()) {
            Object obj = classAnnotationInfo.getClassLevelAnnotations().get(0);
            AnnotationTarget target = null;
            if (obj instanceof WebServiceAnnotationInfo) {
                target = ((WebServiceAnnotationInfo) obj).getTarget();
            } else if (obj instanceof WebServiceProviderAnnotationInfo) {
                target = ((WebServiceProviderAnnotationInfo) obj).getTarget();
            } else {
                return;
            }
            final ClassInfo webServiceClassInfo = (ClassInfo) target;
            final String webServiceClassName = webServiceClassInfo.name().toString();
            final List<ComponentDescription> componentDescriptions = moduleDescription.getComponentsByClassName(webServiceClassName);
            final List<SessionBeanComponentDescription> sessionBeans = getSessionBeans(componentDescriptions);
            // TODO: assembly processed for each endpoint!
            final Set<String> securityRoles = getDeclaredSecurityRoles(unit, webServiceClassInfo);
            final WebContextAnnotationWrapper webCtx = getWebContextWrapper(webServiceClassInfo);
            final String authMethod = webCtx.getAuthMethod();
            final boolean isSecureWsdlAccess = webCtx.isSecureWsdlAccess();
            final String transportGuarantee = webCtx.getTransportGuarantee();
            final String realmName = webCtx.getRealmName();
            for (final SessionBeanComponentDescription sessionBean : sessionBeans) {
                if (sessionBean.isStateless() || sessionBean.isSingleton()) {
                    final EJBViewDescription ejbViewDescription = sessionBean.addWebserviceEndpointView();
                    final ServiceName ejbViewName = ejbViewDescription.getServiceName();
                    jaxwsDeployment.addEndpoint(new EJBEndpoint(sessionBean, ejbViewName, securityRoles, authMethod, realmName, isSecureWsdlAccess, transportGuarantee));
                }
            }
        }
    }
}
Also used : AnnotationTarget(org.jboss.jandex.AnnotationTarget) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ComponentDescription(org.jboss.as.ee.component.ComponentDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ClassAnnotationInformation(org.jboss.as.ee.metadata.ClassAnnotationInformation) ServiceName(org.jboss.msc.service.ServiceName) EJBEndpoint(org.jboss.as.webservices.metadata.model.EJBEndpoint) JAXWSDeployment(org.jboss.as.webservices.metadata.model.JAXWSDeployment) EEModuleClassDescription(org.jboss.as.ee.component.EEModuleClassDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) ClassInfo(org.jboss.jandex.ClassInfo)

Example 19 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class XTSInterceptorDeploymentProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit unit = phaseContext.getDeploymentUnit();
    final EEModuleDescription moduleDescription = unit.getAttachment(Attachments.EE_MODULE_DESCRIPTION);
    for (ComponentDescription component : moduleDescription.getComponentDescriptions()) {
        if (component instanceof SessionBeanComponentDescription) {
            registerSessionBeanInterceptors((SessionBeanComponentDescription) component);
        }
        if (component instanceof WSComponentDescription) {
            registerWSPOJOInterceptors((WSComponentDescription) component);
        }
    }
}
Also used : ComponentDescription(org.jboss.as.ee.component.ComponentDescription) WSComponentDescription(org.jboss.as.webservices.injection.WSComponentDescription) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription) WSComponentDescription(org.jboss.as.webservices.injection.WSComponentDescription)

Example 20 with SessionBeanComponentDescription

use of org.jboss.as.ejb3.component.session.SessionBeanComponentDescription in project wildfly by wildfly.

the class EjbJaccConfigurator method configure.

@Override
public void configure(final DeploymentPhaseContext context, final ComponentDescription description, final ComponentConfiguration configuration) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = context.getDeploymentUnit();
    final DeploymentReflectionIndex reflectionIndex = deploymentUnit.getAttachment(Attachments.REFLECTION_INDEX);
    final EJBComponentDescription ejbComponentDescription = EJBComponentDescription.class.cast(description);
    final EjbJaccConfig ejbJaccConfig = new EjbJaccConfig();
    context.getDeploymentUnit().addToAttachmentList(EjbDeploymentAttachmentKeys.JACC_PERMISSIONS, ejbJaccConfig);
    // process the method permissions.
    for (final ViewConfiguration viewConfiguration : configuration.getViews()) {
        final List<Method> viewMethods = viewConfiguration.getProxyFactory().getCachedMethods();
        for (final Method viewMethod : viewMethods) {
            if (!Modifier.isPublic(viewMethod.getModifiers()) || viewMethod.getDeclaringClass() == WriteReplaceInterface.class) {
                continue;
            }
            final EJBViewConfiguration ejbViewConfiguration = EJBViewConfiguration.class.cast(viewConfiguration);
            // try to create permissions using the descriptor metadata first.
            ApplicableMethodInformation<EJBMethodSecurityAttribute> permissions = ejbComponentDescription.getDescriptorMethodPermissions();
            boolean createdPerms = this.createPermissions(ejbJaccConfig, ejbComponentDescription, ejbViewConfiguration, viewMethod, reflectionIndex, permissions);
            // no permissions created using the descriptor metadata - try to use annotation metadata.
            if (!createdPerms) {
                permissions = ejbComponentDescription.getAnnotationMethodPermissions();
                createPermissions(ejbJaccConfig, ejbComponentDescription, ejbViewConfiguration, viewMethod, reflectionIndex, permissions);
            }
        }
    }
    Set<String> securityRoles = new HashSet<String>();
    // get all roles from the deployments descriptor (assembly descriptor roles)
    SecurityRolesMetaData secRolesMetaData = ejbComponentDescription.getSecurityRoles();
    if (secRolesMetaData != null) {
        for (SecurityRoleMetaData secRoleMetaData : secRolesMetaData) {
            securityRoles.add(secRoleMetaData.getRoleName());
        }
    }
    // at this point any roles specified via RolesAllowed annotation have been mapped to EJBMethodPermissions, so
    // going through the permissions allows us to retrieve these roles.
    // TODO there might be a better way to retrieve just annotated roles without going through all processed permissions
    List<Map.Entry<String, Permission>> processedRoles = ejbJaccConfig.getRoles();
    for (Map.Entry<String, Permission> entry : processedRoles) {
        securityRoles.add(entry.getKey());
    }
    securityRoles.add(ANY_AUTHENTICATED_USER_ROLE);
    // process the security-role-ref from the deployment descriptor.
    Map<String, Collection<String>> securityRoleRefs = ejbComponentDescription.getSecurityRoleLinks();
    for (Map.Entry<String, Collection<String>> entry : securityRoleRefs.entrySet()) {
        String roleName = entry.getKey();
        for (String roleLink : entry.getValue()) {
            EJBRoleRefPermission p = new EJBRoleRefPermission(ejbComponentDescription.getEJBName(), roleName);
            ejbJaccConfig.addRole(roleLink, p);
        }
        securityRoles.remove(roleName);
    }
    // process remaining annotated declared roles that were not overridden in the descriptor.
    Set<String> declaredRoles = ejbComponentDescription.getDeclaredRoles();
    for (String role : declaredRoles) {
        if (!securityRoleRefs.containsKey(role)) {
            EJBRoleRefPermission p = new EJBRoleRefPermission(ejbComponentDescription.getEJBName(), role);
            ejbJaccConfig.addRole(role, p);
        }
        securityRoles.remove(role);
    }
    // an EJBRoleRefPermission must be created for each declared role that does not appear in the security-role-ref.
    for (String role : securityRoles) {
        EJBRoleRefPermission p = new EJBRoleRefPermission(ejbComponentDescription.getEJBName(), role);
        ejbJaccConfig.addRole(role, p);
    }
    // proxy by sending an invocation to the ejb container.
    if (ejbComponentDescription instanceof SessionBeanComponentDescription) {
        SessionBeanComponentDescription session = SessionBeanComponentDescription.class.cast(ejbComponentDescription);
        if (session.isStateful()) {
            EJBMethodPermission p = new EJBMethodPermission(ejbComponentDescription.getEJBName(), "getEJBObject", "Home", null);
            ejbJaccConfig.addPermit(p);
        }
    }
}
Also used : SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) WriteReplaceInterface(org.jboss.as.ee.component.serialization.WriteReplaceInterface) EJBMethodPermission(javax.security.jacc.EJBMethodPermission) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) ViewConfiguration(org.jboss.as.ee.component.ViewConfiguration) EJBViewConfiguration(org.jboss.as.ejb3.component.EJBViewConfiguration) EJBMethodPermission(javax.security.jacc.EJBMethodPermission) EJBRoleRefPermission(javax.security.jacc.EJBRoleRefPermission) Permission(java.security.Permission) HashSet(java.util.HashSet) Method(java.lang.reflect.Method) EJBRoleRefPermission(javax.security.jacc.EJBRoleRefPermission) Collection(java.util.Collection) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) DeploymentReflectionIndex(org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex) Map(java.util.Map) SessionBeanComponentDescription(org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)

Aggregations

SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)17 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)11 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)9 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)9 Method (java.lang.reflect.Method)7 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)7 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)5 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)5 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)3 DependencyConfigurator (org.jboss.as.ee.component.DependencyConfigurator)3 ViewConfiguration (org.jboss.as.ee.component.ViewConfiguration)3 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)3 StatelessComponentDescription (org.jboss.as.ejb3.component.stateless.StatelessComponentDescription)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 SessionBean31MetaData (org.jboss.metadata.ejb.spec.SessionBean31MetaData)3 SessionBeanMetaData (org.jboss.metadata.ejb.spec.SessionBeanMetaData)3 Module (org.jboss.modules.Module)3 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)2 ComponentStartService (org.jboss.as.ee.component.ComponentStartService)2 ComponentView (org.jboss.as.ee.component.ComponentView)2