Search in sources :

Example 31 with EJBComponentDescription

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

the class EjbComponentIntegrator method integrate.

@Override
public boolean integrate(ServiceName beanManagerServiceName, ComponentConfiguration configuration, ComponentDescription description, ServiceBuilder<?> weldComponentServiceBuilder, Supplier<ServiceName> bindingServiceNameSupplier, DefaultInterceptorIntegrationAction integrationAction, ComponentInterceptorSupport interceptorSupport) {
    if (description instanceof EJBComponentDescription) {
        ServiceName bindingServiceName = bindingServiceNameSupplier.get();
        integrationAction.perform(bindingServiceName);
        if (description.isPassivationApplicable()) {
            configuration.addPrePassivateInterceptor(factory(InterceptionType.PRE_PASSIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
            configuration.addPostActivateInterceptor(factory(InterceptionType.POST_ACTIVATE, weldComponentServiceBuilder, bindingServiceName, interceptorSupport), InterceptorOrder.ComponentPassivation.CDI_INTERCEPTORS);
        }
        if (description instanceof StatefulComponentDescription) {
            // add a context key for weld interceptor replication
            configuration.getInterceptorContextKeys().add(SerializedCdiInterceptorsKey.class);
        }
        return true;
    } else if (description instanceof ManagedBeanComponentDescription) {
        integrationAction.perform(bindingServiceNameSupplier.get());
        return true;
    }
    return false;
}
Also used : ManagedBeanComponentDescription(org.jboss.as.ee.managedbean.component.ManagedBeanComponentDescription) ServiceName(org.jboss.msc.service.ServiceName) StatefulComponentDescription(org.jboss.as.ejb3.component.stateful.StatefulComponentDescription) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription)

Example 32 with EJBComponentDescription

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

the class EjbComponentDescriptionProcessor method registerComponents.

@Override
public void registerComponents(ResourceRoot resourceRoot, WildFlyBeanDeploymentArchive beanDeploymentArchive, DeploymentReflectionIndex reflectionIndex) {
    for (EJBComponentDescription ejb : ejbComponentDescriptions.get(resourceRoot)) {
        beanDeploymentArchive.addEjbDescriptor(new EjbDescriptorImpl<Object>(ejb, beanDeploymentArchive, reflectionIndex));
        beanDeploymentArchive.addBeanClass(ejb.getComponentClassName());
    }
}
Also used : EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription)

Example 33 with EJBComponentDescription

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

the class EjbInjectionSource method resolve.

/**
     * Checks if this ejb injection has been resolved yet, and if not resolves it.
     */
private void resolve() {
    if (!resolved) {
        synchronized (this) {
            if (!resolved) {
                final Set<ViewDescription> views = getViews();
                final Set<EJBViewDescription> ejbsForViewName = new HashSet<EJBViewDescription>();
                for (final ViewDescription view : views) {
                    if (view instanceof EJBViewDescription) {
                        final MethodIntf viewType = ((EJBViewDescription) view).getMethodIntf();
                        // @EJB injection *shouldn't* consider the @WebService endpoint view or MDBs
                        if (viewType == MethodIntf.SERVICE_ENDPOINT || viewType == MethodIntf.MESSAGE_ENDPOINT) {
                            continue;
                        }
                        ejbsForViewName.add((EJBViewDescription) view);
                    }
                }
                if (ejbsForViewName.isEmpty()) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, bindingName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.ejbNotFound(typeName, beanName, bindingName);
                    }
                } else if (ejbsForViewName.size() > 1) {
                    if (beanName == null) {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, bindingName, ejbsForViewName);
                    } else {
                        error = EjbLogger.ROOT_LOGGER.moreThanOneEjbFound(typeName, beanName, bindingName, ejbsForViewName);
                    }
                } else {
                    final EJBViewDescription description = ejbsForViewName.iterator().next();
                    final EJBViewDescription ejbViewDescription = (EJBViewDescription) description;
                    if (ejbViewDescription.getMethodIntf() == MethodIntf.REMOTE || ejbViewDescription.getMethodIntf() == MethodIntf.HOME) {
                        final EJBComponentDescription componentDescription = (EJBComponentDescription) description.getComponentDescription();
                        final EEModuleDescription moduleDescription = componentDescription.getModuleDescription();
                        final String earApplicationName = moduleDescription.getEarApplicationName();
                        final Value<ClassLoader> viewClassLoader = new Value<ClassLoader>() {

                            @Override
                            public ClassLoader getValue() throws IllegalStateException, IllegalArgumentException {
                                final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
                                return module != null ? module.getClassLoader() : null;
                            }
                        };
                        remoteFactory = new RemoteViewManagedReferenceFactory(earApplicationName, moduleDescription.getModuleName(), moduleDescription.getDistinctName(), componentDescription.getComponentName(), description.getViewClassName(), componentDescription.isStateful(), viewClassLoader, appclient);
                    }
                    final ServiceName serviceName = description.getServiceName();
                    resolvedViewName = serviceName;
                }
                resolved = true;
            }
        }
    }
}
Also used : EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) EJBViewDescription(org.jboss.as.ejb3.component.EJBViewDescription) ViewDescription(org.jboss.as.ee.component.ViewDescription) RemoteViewManagedReferenceFactory(org.jboss.as.ejb3.remote.RemoteViewManagedReferenceFactory) MethodIntf(org.jboss.as.ejb3.component.MethodIntf) EJBComponentDescription(org.jboss.as.ejb3.component.EJBComponentDescription) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) ServiceName(org.jboss.msc.service.ServiceName) Value(org.jboss.msc.value.Value) Module(org.jboss.modules.Module) HashSet(java.util.HashSet)

Example 34 with EJBComponentDescription

use of org.jboss.as.ejb3.component.EJBComponentDescription 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)

Example 35 with EJBComponentDescription

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

the class MethodPermissionsMergingProcessor method handleExcludeMethods.

private void handleExcludeMethods(final EJBComponentDescription componentDescription, final ExcludeListMetaData excludeList) {
    for (final MethodMetaData method : excludeList.getMethods()) {
        final String methodName = method.getMethodName();
        final MethodIntf defaultMethodIntf = (componentDescription instanceof MessageDrivenComponentDescription) ? MethodIntf.MESSAGE_ENDPOINT : MethodIntf.BEAN;
        final MethodIntf methodIntf = this.getMethodIntf(method.getMethodIntf(), defaultMethodIntf);
        if (methodName.equals("*")) {
            componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, null, EJBMethodSecurityAttribute.denyAll());
        } else {
            final MethodParametersMetaData methodParams = method.getMethodParams();
            // update the session bean description with the tx attribute info
            if (methodParams == null) {
                componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), methodName);
            } else {
                componentDescription.getDescriptorMethodPermissions().setAttribute(methodIntf, EJBMethodSecurityAttribute.denyAll(), null, methodName, this.getMethodParams(methodParams));
            }
        }
    }
}
Also used : MessageDrivenComponentDescription(org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription) MethodMetaData(org.jboss.metadata.ejb.spec.MethodMetaData) MethodParametersMetaData(org.jboss.metadata.ejb.spec.MethodParametersMetaData) MethodIntf(org.jboss.as.ejb3.component.MethodIntf)

Aggregations

EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)23 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)16 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)15 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)14 EJBViewDescription (org.jboss.as.ejb3.component.EJBViewDescription)9 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)9 Method (java.lang.reflect.Method)8 DeploymentPhaseContext (org.jboss.as.server.deployment.DeploymentPhaseContext)8 Module (org.jboss.modules.Module)8 ServiceName (org.jboss.msc.service.ServiceName)8 HashMap (java.util.HashMap)7 ComponentConfiguration (org.jboss.as.ee.component.ComponentConfiguration)7 SessionBeanComponentDescription (org.jboss.as.ejb3.component.session.SessionBeanComponentDescription)7 DeploymentReflectionIndex (org.jboss.as.server.deployment.reflect.DeploymentReflectionIndex)7 ViewDescription (org.jboss.as.ee.component.ViewDescription)6 DeploymentUnitProcessingException (org.jboss.as.server.deployment.DeploymentUnitProcessingException)6 Map (java.util.Map)5 ComponentConfigurator (org.jboss.as.ee.component.ComponentConfigurator)5 MethodIntf (org.jboss.as.ejb3.component.MethodIntf)5 MessageDrivenComponentDescription (org.jboss.as.ejb3.component.messagedriven.MessageDrivenComponentDescription)5