Search in sources :

Example 21 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class EjbJarParsingDeploymentUnitProcessor method parseJBossEjb3Xml.

private static EjbJarMetaData parseJBossEjb3Xml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final VirtualFile deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT).getRoot();
    // Locate the descriptor
    final VirtualFile descriptor = getDescriptor(deploymentRoot, JBOSS_EJB3_XML);
    if (descriptor == null) {
        //but there may have been an ejb-jar element in jboss-all.xml
        return deploymentUnit.getAttachment(EjbJarJBossAllParser.ATTACHMENT_KEY);
    }
    // get the XMLStreamReader and parse the descriptor
    MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
    InputStream stream = open(descriptor);
    try {
        XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
        final JBossEjb3MetaDataParser parser = new JBossEjb3MetaDataParser(createJbossEjbJarParsers());
        final EjbJarMetaData ejbJarMetaData = parser.parse(reader, dtdInfo, JBossDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
        return ejbJarMetaData;
    } catch (XMLStreamException xmlse) {
        throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, JBOSS_EJB3_XML + ": " + descriptor.getPathName());
    } finally {
        try {
            stream.close();
        } catch (IOException ioe) {
            EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) XMLStreamReader(javax.xml.stream.XMLStreamReader) XMLStreamException(javax.xml.stream.XMLStreamException) InputStream(java.io.InputStream) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) MetaDataElementParser(org.jboss.metadata.parser.util.MetaDataElementParser) IOException(java.io.IOException) JBossEjb3MetaDataParser(org.jboss.metadata.ejb.parser.jboss.ejb3.JBossEjb3MetaDataParser)

Example 22 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class EjbJarParsingDeploymentUnitProcessor method deploy.

/**
     * Finds an ejb-jar.xml (at WEB-INF of a .war or META-INF of a .jar) parses the file and creates
     * metadata out of it. The metadata is then attached to the deployment unit.
     *
     * @param deploymentPhase
     * @throws DeploymentUnitProcessingException
     *
     */
@Override
public void deploy(DeploymentPhaseContext deploymentPhase) throws DeploymentUnitProcessingException {
    // get hold of the deployment unit.
    final DeploymentUnit deploymentUnit = deploymentPhase.getDeploymentUnit();
    // get the root of the deployment unit
    final EEModuleDescription eeModuleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
    final EEApplicationClasses applicationClassesDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_APPLICATION_CLASSES_DESCRIPTION);
    final EjbJarMetaData ejbJarMetaData;
    final EjbJarMetaData specMetaData = parseEjbJarXml(deploymentUnit);
    final EjbJarMetaData jbossMetaData = parseJBossEjb3Xml(deploymentUnit);
    if (specMetaData == null) {
        if (jbossMetaData == null)
            return;
        ejbJarMetaData = jbossMetaData;
    } else if (jbossMetaData == null) {
        ejbJarMetaData = specMetaData;
    } else {
        ejbJarMetaData = jbossMetaData.createMerged(specMetaData);
    }
    // Mark it as an EJB deployment
    EjbDeploymentMarker.mark(deploymentUnit);
    if (!deploymentUnit.hasAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION)) {
        final EEModuleDescription moduleDescription = deploymentUnit.getAttachment(org.jboss.as.ee.component.Attachments.EE_MODULE_DESCRIPTION);
        final EjbJarDescription ejbModuleDescription = new EjbJarDescription(moduleDescription, applicationClassesDescription, deploymentUnit.getName().endsWith(".war"));
        deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_DESCRIPTION, ejbModuleDescription);
    }
    // attach the EjbJarMetaData to the deployment unit
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA, ejbJarMetaData);
    // if the jboss-ejb3.xml has a distinct-name configured then attach it to the deployment unit
    if (jbossMetaData != null && jbossMetaData.getDistinctName() != null) {
        deploymentUnit.putAttachment(org.jboss.as.ee.structure.Attachments.DISTINCT_NAME, jbossMetaData.getDistinctName());
    }
    if (ejbJarMetaData.getModuleName() != null) {
        eeModuleDescription.setModuleName(ejbJarMetaData.getModuleName());
    }
    if (ejbJarMetaData.isMetadataComplete()) {
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    if (!ejbJarMetaData.isEJB3x()) {
        //EJB spec 20.5.1, we do not process annotations for older deployments
        MetadataCompleteMarker.setMetadataComplete(deploymentUnit, true);
    }
    if (ejbJarMetaData.getEnterpriseBeans() != null) {
        //check for entity beans
        StringBuilder beans = new StringBuilder();
        boolean error = false;
        for (AbstractEnterpriseBeanMetaData bean : ejbJarMetaData.getEnterpriseBeans()) {
            if (bean.getEjbType() == EjbType.ENTITY) {
                if (!error) {
                    error = true;
                } else {
                    beans.append(", ");
                }
                beans.append(bean.getEjbName());
            }
        }
        if (error) {
            throw EjbLogger.ROOT_LOGGER.entityBeansAreNotSupported(beans.toString());
        }
    }
}
Also used : AbstractEnterpriseBeanMetaData(org.jboss.metadata.ejb.spec.AbstractEnterpriseBeanMetaData) EEModuleDescription(org.jboss.as.ee.component.EEModuleDescription) EEApplicationClasses(org.jboss.as.ee.component.EEApplicationClasses) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) EjbJarDescription(org.jboss.as.ejb3.deployment.EjbJarDescription) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit)

Example 23 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData 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 24 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class AbstractDeploymentModelBuilder method propagateAttachments.

private void propagateAttachments(final DeploymentUnit unit, final ArchiveDeployment dep) {
    dep.addAttachment(DeploymentUnit.class, unit);
    unit.putAttachment(DEPLOYMENT_KEY, dep);
    final JBossWebMetaData webMD = getJBossWebMetaData(unit);
    dep.addAttachment(JBossWebMetaData.class, webMD);
    final WebservicesMetaData webservicesMD = getOptionalAttachment(unit, WEBSERVICES_METADATA_KEY);
    dep.addAttachment(WebservicesMetaData.class, webservicesMD);
    JBossWebservicesMetaData jbossWebservicesMD = getOptionalAttachment(unit, JBOSS_WEBSERVICES_METADATA_KEY);
    if (unit.getParent() != null) {
        jbossWebservicesMD = JBossWebservicesMetaData.merge(getOptionalAttachment(unit.getParent(), JBOSS_WEBSERVICES_METADATA_KEY), jbossWebservicesMD);
    }
    dep.addAttachment(JBossWebservicesMetaData.class, jbossWebservicesMD);
    final JAXWSDeployment jaxwsDeployment = getOptionalAttachment(unit, JAXWS_ENDPOINTS_KEY);
    dep.addAttachment(JAXWSDeployment.class, jaxwsDeployment);
    final EjbJarMetaData ejbJarMD = getOptionalAttachment(unit, EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    dep.addAttachment(EjbJarMetaData.class, ejbJarMD);
    final RejectionRule rr = getOptionalAttachment(unit, REJECTION_RULE_KEY);
    if (rr != null) {
        dep.addAttachment(RejectionRule.class, rr);
    }
}
Also used : JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ASHelper.getJBossWebMetaData(org.jboss.as.webservices.util.ASHelper.getJBossWebMetaData) RejectionRule(org.jboss.wsf.spi.invocation.RejectionRule) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) JBossWebservicesMetaData(org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData) JBossWebservicesMetaData(org.jboss.wsf.spi.metadata.webservices.JBossWebservicesMetaData) WebservicesMetaData(org.jboss.wsf.spi.metadata.webservices.WebservicesMetaData) JAXWSDeployment(org.jboss.as.webservices.metadata.model.JAXWSDeployment)

Example 25 with EjbJarMetaData

use of org.jboss.metadata.ejb.spec.EjbJarMetaData in project wildfly by wildfly.

the class WSIntegrationProcessorJAXWS_EJB method getDeclaredSecurityRoles.

private static Set<String> getDeclaredSecurityRoles(final DeploymentUnit unit, final ClassInfo webServiceClassInfo) {
    final Set<String> securityRoles = new HashSet<String>();
    // process assembly-descriptor DD section
    final EjbJarMetaData ejbJarMD = unit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMD != null && ejbJarMD.getAssemblyDescriptor() != null) {
        final List<SecurityRoleMetaData> securityRoleMetaDatas = ejbJarMD.getAssemblyDescriptor().getAny(SecurityRoleMetaData.class);
        if (securityRoleMetaDatas != null) {
            for (final SecurityRoleMetaData securityRoleMetaData : securityRoleMetaDatas) {
                securityRoles.add(securityRoleMetaData.getRoleName());
            }
        }
        final SecurityRolesMetaData securityRolesMD = ejbJarMD.getAssemblyDescriptor().getSecurityRoles();
        if (securityRolesMD != null && securityRolesMD.size() > 0) {
            for (final SecurityRoleMetaData securityRoleMD : securityRolesMD) {
                securityRoles.add(securityRoleMD.getRoleName());
            }
        }
    }
    // process @RolesAllowed annotation
    if (webServiceClassInfo.annotations().containsKey(ROLES_ALLOWED_ANNOTATION)) {
        final List<AnnotationInstance> allowedRoles = webServiceClassInfo.annotations().get(ROLES_ALLOWED_ANNOTATION);
        for (final AnnotationInstance allowedRole : allowedRoles) {
            if (allowedRole.target().equals(webServiceClassInfo)) {
                for (final String roleName : allowedRole.value().asStringArray()) {
                    securityRoles.add(roleName);
                }
            }
        }
    }
    // process @DeclareRoles annotation
    if (webServiceClassInfo.annotations().containsKey(DECLARE_ROLES_ANNOTATION)) {
        final List<AnnotationInstance> declareRoles = webServiceClassInfo.annotations().get(DECLARE_ROLES_ANNOTATION);
        for (final AnnotationInstance declareRole : declareRoles) {
            if (declareRole.target().equals(webServiceClassInfo)) {
                for (final String roleName : declareRole.value().asStringArray()) {
                    securityRoles.add(roleName);
                }
            }
        }
    }
    // process @PermitAll annotation
    if (webServiceClassInfo.annotations().containsKey(PERMIT_ALL_ANNOTATION)) {
        for (AnnotationInstance permitAll : webServiceClassInfo.annotations().get(PERMIT_ALL_ANNOTATION)) {
            if (permitAll.target().equals(webServiceClassInfo)) {
                securityRoles.add("*");
                break;
            }
        }
    }
    //if there is no class level security annotation, it will delegate to ejb's security check
    if (securityRoles.isEmpty()) {
        securityRoles.add("*");
    }
    return Collections.unmodifiableSet(securityRoles);
}
Also used : SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) AnnotationInstance(org.jboss.jandex.AnnotationInstance) HashSet(java.util.HashSet)

Aggregations

EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)25 AssemblyDescriptorMetaData (org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData)12 DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)10 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)7 ComponentDescription (org.jboss.as.ee.component.ComponentDescription)5 Module (org.jboss.modules.Module)5 HashMap (java.util.HashMap)4 EJBComponentDescription (org.jboss.as.ejb3.component.EJBComponentDescription)4 Map (java.util.Map)3 EjbJarDescription (org.jboss.as.ejb3.deployment.EjbJarDescription)3 EJBBoundSecurityMetaData (org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData)3 MethodIdentifier (org.jboss.invocation.proxy.MethodIdentifier)3 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 Method (java.lang.reflect.Method)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 List (java.util.List)2 XMLStreamException (javax.xml.stream.XMLStreamException)2 XMLStreamReader (javax.xml.stream.XMLStreamReader)2