Search in sources :

Example 6 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class SecurityRolesMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(DeploymentUnit deploymentUnit, DeploymentReflectionIndex deploymentReflectionIndex, Class<?> componentClass, EJBComponentDescription ejbComponentDescription) throws DeploymentUnitProcessingException {
    final SecurityRolesMetaData roleMappings = new SecurityRolesMetaData();
    final EjbJarMetaData ejbJarMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
    if (ejbJarMetaData != null) {
        final AssemblyDescriptorMetaData assemblyDescriptorMetaData = ejbJarMetaData.getAssemblyDescriptor();
        if (assemblyDescriptorMetaData != null) {
            // get the mapping between principal to rolename, defined in the assembly descriptor
            final List<SecurityRoleMetaData> securityRoleMetaDatas = assemblyDescriptorMetaData.getAny(SecurityRoleMetaData.class);
            if (securityRoleMetaDatas != null) {
                for (SecurityRoleMetaData securityRoleMetaData : securityRoleMetaDatas) {
                    roleMappings.add(securityRoleMetaData);
                }
            }
        }
    }
    //Let us look at the ear metadata also
    DeploymentUnit parent = deploymentUnit.getParent();
    if (parent != null) {
        final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA);
        if (earMetaData != null) {
            SecurityRolesMetaData earSecurityRolesMetaData = earMetaData.getSecurityRoles();
            SecurityRolesMetaDataMerger.merge(roleMappings, roleMappings, earSecurityRolesMetaData);
        }
    }
    // add it to the EJB component description
    ejbComponentDescription.setSecurityRoles(roleMappings);
}
Also used : SecurityRoleMetaData(org.jboss.metadata.javaee.spec.SecurityRoleMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) AssemblyDescriptorMetaData(org.jboss.metadata.ejb.spec.AssemblyDescriptorMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Example 7 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class UndertowDeploymentProcessor method getJBossAppSecurityDomain.

/**
     * Try to obtain the security domain configured in jboss-app.xml at the ear level if available
     */
private String getJBossAppSecurityDomain(final DeploymentUnit deploymentUnit) {
    String securityDomain = null;
    DeploymentUnit parent = deploymentUnit.getParent();
    if (parent != null) {
        final EarMetaData jbossAppMetaData = parent.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
        if (jbossAppMetaData instanceof JBossAppMetaData) {
            securityDomain = ((JBossAppMetaData) jbossAppMetaData).getSecurityDomain();
        }
    }
    return securityDomain;
}
Also used : JBossAppMetaData(org.jboss.metadata.ear.jboss.JBossAppMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Example 8 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class EarContextRootProcessor method deploy.

public void deploy(final DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
    final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
    final WarMetaData warMetaData = deploymentUnit.getAttachment(WarMetaData.ATTACHMENT_KEY);
    if (warMetaData == null) {
        // Nothing we can do without WarMetaData
        return;
    }
    final ResourceRoot deploymentRoot = deploymentUnit.getAttachment(org.jboss.as.server.deployment.Attachments.DEPLOYMENT_ROOT);
    if (deploymentRoot == null) {
        // We don't have a root to work with
        return;
    }
    final DeploymentUnit parent = deploymentUnit.getParent();
    if (parent == null || !DeploymentTypeMarker.isType(DeploymentType.EAR, parent)) {
        // Only care if this war is nested in an EAR
        return;
    }
    final EarMetaData earMetaData = parent.getAttachment(Attachments.EAR_METADATA);
    if (earMetaData == null) {
        // Nothing to see here
        return;
    }
    final ModulesMetaData modulesMetaData = earMetaData.getModules();
    if (modulesMetaData != null)
        for (ModuleMetaData moduleMetaData : modulesMetaData) {
            if (Web.equals(moduleMetaData.getType()) && moduleMetaData.getFileName().equals(deploymentRoot.getRootName())) {
                String contextRoot = WebModuleMetaData.class.cast(moduleMetaData.getValue()).getContextRoot();
                if (contextRoot == null && (warMetaData.getJBossWebMetaData() == null || warMetaData.getJBossWebMetaData().getContextRoot() == null)) {
                    contextRoot = "/" + parent.getName().substring(0, parent.getName().length() - 4) + "/" + deploymentUnit.getName().substring(0, deploymentUnit.getName().length() - 4);
                }
                if (contextRoot != null) {
                    JBossWebMetaData jBossWebMetaData = warMetaData.getJBossWebMetaData();
                    if (jBossWebMetaData == null) {
                        jBossWebMetaData = new JBoss70WebMetaData();
                        warMetaData.setJBossWebMetaData(jBossWebMetaData);
                    }
                    jBossWebMetaData.setContextRoot(contextRoot);
                }
                return;
            }
        }
}
Also used : ResourceRoot(org.jboss.as.server.deployment.module.ResourceRoot) JBossWebMetaData(org.jboss.metadata.web.jboss.JBossWebMetaData) ModulesMetaData(org.jboss.metadata.ear.spec.ModulesMetaData) WarMetaData(org.jboss.as.web.common.WarMetaData) JBoss70WebMetaData(org.jboss.metadata.web.jboss.JBoss70WebMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData) WebModuleMetaData(org.jboss.metadata.ear.spec.WebModuleMetaData) ModuleMetaData(org.jboss.metadata.ear.spec.ModuleMetaData)

Example 9 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class AbstractSecurityMetaDataAccessorEJB method getSecurityDomain.

/**
     * @see org.jboss.webservices.integration.tomcat.AbstractSecurityMetaDataAccessorEJB#getSecurityDomain(Deployment)
     *
     * @param dep webservice deployment
     * @return security domain associated with EJB 3 deployment
     */
public String getSecurityDomain(final Deployment dep) {
    String securityDomain = null;
    for (final EJBEndpoint ejbEndpoint : getEjbEndpoints(dep)) {
        String nextSecurityDomain = ejbEndpoint.getSecurityDomain();
        if (nextSecurityDomain == null || nextSecurityDomain.isEmpty()) {
            nextSecurityDomain = null;
        }
        securityDomain = getDomain(securityDomain, nextSecurityDomain);
    }
    if (securityDomain == null) {
        final DeploymentUnit unit = WSHelper.getRequiredAttachment(dep, DeploymentUnit.class);
        if (unit.getParent() != null) {
            final EarMetaData jbossAppMD = unit.getParent().getAttachment(Attachments.EAR_METADATA);
            return jbossAppMD instanceof JBossAppMetaData ? ((JBossAppMetaData) jbossAppMD).getSecurityDomain() : null;
        }
    }
    return securityDomain;
}
Also used : JBossAppMetaData(org.jboss.metadata.ear.jboss.JBossAppMetaData) EJBEndpoint(org.jboss.as.webservices.metadata.model.EJBEndpoint) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Example 10 with EarMetaData

use of org.jboss.metadata.ear.spec.EarMetaData in project wildfly by wildfly.

the class WebMetaDataCreator method createSecurityRoles.

/**
     * Creates security roles part of web.xml descriptor.
     * <p/>
     * <pre>
     * &lt;security-role&gt;
     *   &lt;role-name&gt;role1&lt;/role-name&gt;
     *   ...
     *   &lt;role-name&gt;roleN&lt;/role-name&gt;
     * &lt;/security-role&gt;
     * </pre>
     *
     * @param dep        webservice deployment
     * @param jbossWebMD jboss web meta data
     */
private void createSecurityRoles(final Deployment dep, final JBossWebMetaData jbossWebMD) {
    final String authMethod = getAuthMethod(dep);
    final boolean hasAuthMethod = authMethod != null;
    if (hasAuthMethod) {
        final SecurityRolesMetaData securityRolesMD = ejb3SecurityAccessor.getSecurityRoles(dep);
        final boolean hasSecurityRolesMD = securityRolesMD != null && !securityRolesMD.isEmpty();
        if (hasSecurityRolesMD) {
            WSLogger.ROOT_LOGGER.trace("Setting security roles");
            jbossWebMD.setSecurityRoles(securityRolesMD);
        }
    }
    //merge security roles from the ear
    //TODO: is there somewhere better to put this?
    final DeploymentUnit unit = dep.getAttachment(DeploymentUnit.class);
    DeploymentUnit parent = unit.getParent();
    if (parent != null) {
        final EarMetaData earMetaData = parent.getAttachment(org.jboss.as.ee.structure.Attachments.EAR_METADATA);
        if (earMetaData != null) {
            if (jbossWebMD.getSecurityRoles() == null) {
                jbossWebMD.setSecurityRoles(new SecurityRolesMetaData());
            }
            SecurityRolesMetaData earSecurityRolesMetaData = earMetaData.getSecurityRoles();
            if (earSecurityRolesMetaData != null) {
                SecurityRolesMetaDataMerger.merge(jbossWebMD.getSecurityRoles(), jbossWebMD.getSecurityRoles(), earSecurityRolesMetaData);
            }
        }
    }
}
Also used : SecurityRolesMetaData(org.jboss.metadata.javaee.spec.SecurityRolesMetaData) DeploymentUnit(org.jboss.as.server.deployment.DeploymentUnit) EarMetaData(org.jboss.metadata.ear.spec.EarMetaData)

Aggregations

DeploymentUnit (org.jboss.as.server.deployment.DeploymentUnit)12 EarMetaData (org.jboss.metadata.ear.spec.EarMetaData)12 ResourceRoot (org.jboss.as.server.deployment.module.ResourceRoot)6 JBossAppMetaData (org.jboss.metadata.ear.jboss.JBossAppMetaData)4 ArrayList (java.util.ArrayList)3 HashMap (java.util.HashMap)3 HashSet (java.util.HashSet)3 ModuleMetaData (org.jboss.metadata.ear.spec.ModuleMetaData)3 SecurityRolesMetaData (org.jboss.metadata.javaee.spec.SecurityRolesMetaData)3 VirtualFile (org.jboss.vfs.VirtualFile)3 DeploymentDescriptorEnvironment (org.jboss.as.ee.component.DeploymentDescriptorEnvironment)2 EEModuleDescription (org.jboss.as.ee.component.EEModuleDescription)2 WarMetaData (org.jboss.as.web.common.WarMetaData)2 JBossWebMetaData (org.jboss.metadata.web.jboss.JBossWebMetaData)2 Closeable (java.io.Closeable)1 IOException (java.io.IOException)1 LinkedList (java.util.LinkedList)1 Map (java.util.Map)1 ExecutorService (java.util.concurrent.ExecutorService)1 Manifest (java.util.jar.Manifest)1