Search in sources :

Example 16 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)

Example 17 with EjbJarMetaData

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

the class EjbJarParsingDeploymentUnitProcessor method parseEjbJarXml.

private static EjbJarMetaData parseEjbJarXml(final DeploymentUnit deploymentUnit) throws DeploymentUnitProcessingException {
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(Attachments.DEPLOYMENT_ROOT);
    final VirtualFile alternateDescriptor = deploymentRoot.getAttachment(org.jboss.as.ee.structure.Attachments.ALTERNATE_EJB_DEPLOYMENT_DESCRIPTOR);
    //this is a bit tri
    // Locate the descriptor
    final VirtualFile descriptor;
    if (alternateDescriptor != null) {
        descriptor = alternateDescriptor;
    } else {
        descriptor = getDescriptor(deploymentRoot.getRoot(), EJB_JAR_XML);
    }
    if (descriptor == null) {
        // no descriptor found, nothing to do!
        return null;
    }
    // get the XMLStreamReader and parse the descriptor
    MetaDataElementParser.DTDInfo dtdInfo = new MetaDataElementParser.DTDInfo();
    InputStream stream = open(descriptor);
    try {
        XMLStreamReader reader = getXMLStreamReader(stream, descriptor, dtdInfo);
        EjbJarMetaData ejbJarMetaData = EjbJarMetaDataParser.parse(reader, dtdInfo, SpecDescriptorPropertyReplacement.propertyReplacer(deploymentUnit));
        return ejbJarMetaData;
    } catch (XMLStreamException xmlse) {
        throw EjbLogger.ROOT_LOGGER.failedToParse(xmlse, "ejb-jar.xml: " + descriptor.getPathName());
    } finally {
        try {
            stream.close();
        } catch (IOException ioe) {
            EjbLogger.DEPLOYMENT_LOGGER.failToCloseFile(ioe);
        }
    }
}
Also used : VirtualFile(org.jboss.vfs.VirtualFile) ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) 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)

Example 18 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 19 with EjbJarMetaData

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

the class AbstractPoolMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, T description) throws DeploymentUnitProcessingException {
    final String ejbName = description.getEJBName();
    final EjbJarMetaData metaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (metaData == null) {
        return;
    }
    final AssemblyDescriptorMetaData assemblyDescriptor = metaData.getAssemblyDescriptor();
    if (assemblyDescriptor == null) {
        return;
    }
    // get the pool metadata
    final List<EJBBoundPoolMetaData> pools = assemblyDescriptor.getAny(EJBBoundPoolMetaData.class);
    String poolName = null;
    if (pools != null) {
        for (final EJBBoundPoolMetaData poolMetaData : pools) {
            // for the specific bean (i.e. via an ejb-name match)
            if ("*".equals(poolMetaData.getEjbName()) && poolName == null) {
                poolName = poolMetaData.getPoolName();
            } else if (ejbName.equals(poolMetaData.getEjbName())) {
                poolName = poolMetaData.getPoolName();
            }
        }
    }
    if (poolName != null) {
        this.setPoolName(description, poolName);
    }
}
Also used : EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData) EJBBoundPoolMetaData(org.jboss.as.ejb3.pool.EJBBoundPoolMetaData)

Example 20 with EjbJarMetaData

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

the class ApplicationExceptionMergingProcessor method deploy.

@Override
public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    if (!EjbDeploymentMarker.isEjbDeployment(deploymentUnit)) {
        return;
    }
    final List<DeploymentUnit> accessibleSubDeployments = deploymentUnit.getAttachment(Attachments.ACCESSIBLE_SUB_DEPLOYMENTS);
    final Module module = deploymentUnit.getAttachment(Attachments.MODULE);
    final ApplicationExceptions applicationExceptions = new ApplicationExceptions();
    for (DeploymentUnit unit : accessibleSubDeployments) {
        //we want to get the details for classes from all sub deployments we have access to
        final ApplicationExceptionDescriptions exceptionDescriptions = unit.getAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DESCRIPTIONS);
        if (exceptionDescriptions != null) {
            for (Map.Entry<String, org.jboss.as.ejb3.tx.ApplicationExceptionDetails> exception : exceptionDescriptions.getApplicationExceptions().entrySet()) {
                try {
                    final Class<?> index = ClassLoadingUtils.loadClass(exception.getKey(), module);
                    applicationExceptions.addApplicationException(index, exception.getValue());
                } catch (ClassNotFoundException e) {
                    ROOT_LOGGER.debug("Could not load application exception class", e);
                }
            }
        }
    }
    //now add the exceptions from the assembly descriptor
    EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData != null) {
        // process assembly-descriptor stuff
        AssemblyDescriptorMetaData assemblyDescriptor = ejbJarMetaData.getAssemblyDescriptor();
        if (assemblyDescriptor != null) {
            // process application-exception(s)
            ApplicationExceptionsMetaData ddAppExceptions = assemblyDescriptor.getApplicationExceptions();
            if (ddAppExceptions != null && !ddAppExceptions.isEmpty()) {
                for (ApplicationExceptionMetaData applicationException : ddAppExceptions) {
                    String exceptionClassName = applicationException.getExceptionClass();
                    try {
                        final Class<?> index = ClassLoadingUtils.loadClass(exceptionClassName, module);
                        boolean rollback = applicationException.isRollback();
                        // by default inherited is true
                        boolean inherited = applicationException.isInherited() == null ? true : applicationException.isInherited();
                        // add the application exception to the ejb jar description
                        applicationExceptions.addApplicationException(index, new ApplicationExceptionDetails(exceptionClassName, inherited, rollback));
                    } catch (ClassNotFoundException e) {
                        throw EjbLogger.ROOT_LOGGER.failToLoadAppExceptionClassInEjbJarXml(exceptionClassName, e);
                    }
                }
            }
        }
    }
    deploymentUnit.putAttachment(EjbDeploymentAttachmentKeys.APPLICATION_EXCEPTION_DETAILS, applicationExceptions);
}
Also used : ApplicationExceptions(org.jboss.as.ejb3.deployment.ApplicationExceptions) ApplicationExceptionDetails(org.jboss.as.ejb3.tx.ApplicationExceptionDetails) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) ApplicationExceptionDescriptions(org.jboss.as.ejb3.deployment.ApplicationExceptionDescriptions) ApplicationExceptionsMetaData(org.jboss.metadata.ejb.spec.ApplicationExceptionsMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData) ApplicationExceptionMetaData(org.jboss.metadata.ejb.spec.ApplicationExceptionMetaData) Module(org.jboss.modules.Module) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) Map(java.util.Map)

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