Search in sources :

Example 1 with SecurityIdentityMetaData

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

the class RunAsMergingProcessor method handleDeploymentDescriptor.

@Override
protected void handleDeploymentDescriptor(final DeploymentUnit deploymentUnit, final DeploymentReflectionIndex deploymentReflectionIndex, final Class<?> componentClass, final EJBComponentDescription componentConfiguration) throws DeploymentUnitProcessingException {
    if (componentConfiguration.getDescriptorData() != null) {
        final SecurityIdentityMetaData identity = componentConfiguration.getDescriptorData().getSecurityIdentity();
        if (identity != null) {
            final RunAsMetaData runAs = identity.getRunAs();
            if (runAs != null) {
                final String role = runAs.getRoleName();
                if (role != null && !role.trim().isEmpty()) {
                    componentConfiguration.setRunAs(role.trim());
                }
            }
        }
    }
    if (componentConfiguration.getRunAs() != null) {
        String principal = null;
        String globalRunAsPrincipal = null;
        EjbJarMetaData jbossMetaData = deploymentUnit.getAttachment(EjbDeploymentAttachmentKeys.EJB_JAR_METADATA);
        if (jbossMetaData != null && jbossMetaData.getAssemblyDescriptor() != null) {
            List<EJBBoundSecurityMetaData> securityMetaDatas = jbossMetaData.getAssemblyDescriptor().getAny(EJBBoundSecurityMetaData.class);
            if (securityMetaDatas != null) {
                for (EJBBoundSecurityMetaData securityMetaData : securityMetaDatas) {
                    if (securityMetaData.getEjbName().equals(componentConfiguration.getComponentName())) {
                        principal = securityMetaData.getRunAsPrincipal();
                        break;
                    }
                    // check global run-as principal
                    if (securityMetaData.getEjbName().equals("*")) {
                        globalRunAsPrincipal = securityMetaData.getRunAsPrincipal();
                        continue;
                    }
                }
            }
            if (principal != null)
                componentConfiguration.setRunAsPrincipal(principal);
            else if (globalRunAsPrincipal != null)
                componentConfiguration.setRunAsPrincipal(globalRunAsPrincipal);
            else {
                // we only set the run-as-principal to default, if it's not already set (via annotation) on the component
                if (componentConfiguration.getRunAsPrincipal() == null) {
                    componentConfiguration.setRunAsPrincipal(DEFAULT_RUN_AS_PRINCIPAL);
                }
            }
        }
    }
}
Also used : EJBBoundSecurityMetaData(org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData) RunAsMetaData(org.jboss.metadata.javaee.spec.RunAsMetaData) EjbJarMetaData(org.jboss.metadata.ejb.spec.EjbJarMetaData) SecurityIdentityMetaData(org.jboss.metadata.ejb.spec.SecurityIdentityMetaData)

Aggregations

EJBBoundSecurityMetaData (org.jboss.as.ejb3.security.metadata.EJBBoundSecurityMetaData)1 EjbJarMetaData (org.jboss.metadata.ejb.spec.EjbJarMetaData)1 SecurityIdentityMetaData (org.jboss.metadata.ejb.spec.SecurityIdentityMetaData)1 RunAsMetaData (org.jboss.metadata.javaee.spec.RunAsMetaData)1