Search in sources :

Example 1 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class EjbLinkElement method check.

/**
 * The value of the ejb-link element is the ejb-name of an enterprise
 * bean in the same J2EE Application archive.
 *
 * @param descriptor the Web Application deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean resolved = false;
    boolean oneFailed = false;
    int na = 0;
    // The value of the ejb-link element must be the ejb-name of an enterprise
    // bean in the same J2EE Application archive.
    String applicationName = null;
    if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
        for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
            EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
            if (nextEjbReference.isLinked()) {
                String ejb_link = nextEjbReference.getLinkName();
                ejb_link = ejb_link.substring(ejb_link.indexOf("#") + 1);
                // get the application descriptor and check all ejb-jars in the application
                try {
                    Application application = descriptor.getApplication();
                    applicationName = application.getName();
                    // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
                    // tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
                    // iterate through the ejb jars in this J2EE Application
                    Set ejbBundles = application.getBundleDescriptors(EjbBundleDescriptor.class);
                    Iterator ejbBundlesIterator = ejbBundles.iterator();
                    EjbBundleDescriptor ejbBundle = null;
                    while (ejbBundlesIterator.hasNext()) {
                        ejbBundle = (EjbBundleDescriptor) ejbBundlesIterator.next();
                        // }
                        for (Iterator itr2 = ejbBundle.getEjbs().iterator(); itr2.hasNext(); ) {
                            EjbDescriptor ejbDescriptor = (EjbDescriptor) itr2.next();
                            if (ejbDescriptor.getName().equals(ejb_link)) {
                                resolved = true;
                                logger.log(Level.FINE, getClass().getName() + ".passed", new Object[] { ejb_link, ejbDescriptor.getName() });
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "ejb-link [ {0} ] found same value as EJB [ {1} ]", new Object[] { ejb_link, ejbDescriptor.getName() }));
                                break;
                            }
                        }
                    }
                } catch (Exception e) {
                    logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint {0}", new Object[] { "[" + getClass() + "] Error: " + e.getMessage() });
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                }
                // resolved the last ejb-link okay
                if (!resolved) {
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No EJB matching [ {0} ] found within [ {1} ] ear file.", new Object[] { ejb_link, applicationName }));
                } else {
                    // clear the resolved flag for the next ejb-link
                    resolved = false;
                }
            } else {
                // Cannot get the link name of an ejb reference referring
                // to an external bean
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Not Applicable:  Cannot verify the existance of an ejb reference [ {0} ] to external bean within different .ear file.", new Object[] { nextEjbReference.getName() }));
                na++;
            }
        }
        if (oneFailed) {
            result.setStatus(result.FAILED);
        } else if (na == descriptor.getEjbReferenceDescriptors().size()) {
            result.setStatus(result.NOT_APPLICABLE);
        } else {
            result.setStatus(result.PASSED);
        }
        // tmpFile.delete();
        return result;
    } else {
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no ejb references to other beans within this web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) EjbBundleDescriptor(com.sun.enterprise.deployment.EjbBundleDescriptor) Application(com.sun.enterprise.deployment.Application)

Example 2 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class StatefulSessionBeanInjection method check.

public Result check(WebBundleDescriptor descriptor) {
    // initialize the result object
    Result result = getInitializedResult();
    addWarningDetails(result, getVerifierContext().getComponentNameConstructor());
    // default status is PASSED
    result.setStatus(Result.PASSED);
    Set<EjbReference> s = descriptor.getEjbReferenceDescriptors();
    if (s == null)
        return result;
    for (EjbReference ejbRefDesc : s) {
        EjbDescriptor ejbDescriptor = ejbRefDesc.getEjbDescriptor();
        if (ejbDescriptor instanceof EjbSessionDescriptor) {
            // instaceof returns false if ejbDescriptor=null.
            String stateType = ((EjbSessionDescriptor) ejbDescriptor).getSessionType();
            if (EjbSessionDescriptor.STATEFUL.equals(stateType)) {
                Set<InjectionTarget> injectionTargets = ejbRefDesc.getInjectionTargets();
                if (injectionTargets != null) {
                    for (InjectionTarget it : injectionTargets) {
                        String itClassName = it.getClassName();
                        result.warning(smh.getLocalString(className + ".warning", "Found a stateful session bean [ {0} ] injected into [ {1} ].", new Object[] { ejbDescriptor.getEjbClassName(), itClassName }));
                    }
                }
            }
        }
    }
    return result;
}
Also used : EjbReference(com.sun.enterprise.deployment.types.EjbReference) InjectionTarget(com.sun.enterprise.deployment.InjectionTarget) EjbSessionDescriptor(com.sun.enterprise.deployment.EjbSessionDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result)

Example 3 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class SecurityMechanismSelector method evaluate_client_conformance.

/**
 * Evaluates a client's conformance to the security policies configured on the target. Returns true
 * if conformant to the security policies otherwise return false.
 *
 * Conformance checking is done as follows: First, the object_id is mapped to the set of
 * EjbIORConfigurationDescriptor. Each EjbIORConfigurationDescriptor corresponds to a single
 * CompoundSecMechanism of the CSIv2 spec. A client is considered to be conformant if a
 * CompoundSecMechanism consistent with the client's actions is found i.e. transport_mech,
 * as_context_mech and sas_context_mech must all be consistent.
 */
private boolean evaluate_client_conformance(SecurityContext ctx, byte[] object_id, boolean ssl_used, X509Certificate[] certchain) {
    if (object_id == null)
        return true;
    if (protocolMgr == null)
        protocolMgr = orbHelper.getProtocolManager();
    // is on a callback object in the client VM.
    if (protocolMgr == null)
        return true;
    EjbDescriptor ejbDesc = protocolMgr.getEjbDescriptor(object_id);
    Set iorDescSet = null;
    if (ejbDesc != null) {
        iorDescSet = ejbDesc.getIORConfigurationDescriptors();
    } else {
        // Probably a non-EJB CORBA object.
        // Create a temporary EjbIORConfigurationDescriptor.
        iorDescSet = getCorbaIORDescSet();
    }
    if (_logger.isLoggable(Level.FINE)) {
        _logger.log(Level.FINE, "SecurityMechanismSelector.evaluate_client_conformance: iorDescSet: " + iorDescSet);
    }
    /*
         * if there are no IORConfigurationDescriptors configured, then no security policy is configured. So
         * consider the client to be conformant.
         */
    if (iorDescSet.isEmpty())
        return true;
    // go through each EjbIORConfigurationDescriptor trying to find
    // a find a CompoundSecMechanism that matches client's actions.
    boolean checkSkipped = false;
    for (Iterator itr = iorDescSet.iterator(); itr.hasNext(); ) {
        EjbIORConfigurationDescriptor iorDesc = (EjbIORConfigurationDescriptor) itr.next();
        if (skip_client_conformance(iorDesc)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "SecurityMechanismSelector.evaluate_client_conformance: skip_client_conformance");
            }
            checkSkipped = true;
            continue;
        }
        if (!evaluate_client_conformance_ssl(iorDesc, ssl_used, certchain)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "SecurityMechanismSelector.evaluate_client_conformance: evaluate_client_conformance_ssl");
            }
            checkSkipped = false;
            continue;
        }
        String realmName = "default";
        if (ejbDesc != null && ejbDesc.getApplication() != null) {
            realmName = ejbDesc.getApplication().getRealm();
        }
        if (realmName == null) {
            realmName = iorDesc.getRealmName();
        }
        if (realmName == null) {
            realmName = "default";
        }
        if (!evaluate_client_conformance_ascontext(ctx, iorDesc, realmName)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "SecurityMechanismSelector.evaluate_client_conformance: evaluate_client_conformance_ascontext");
            }
            checkSkipped = false;
            continue;
        }
        if (!evaluate_client_conformance_sascontext(ctx, iorDesc)) {
            if (_logger.isLoggable(Level.FINE)) {
                _logger.log(Level.FINE, "SecurityMechanismSelector.evaluate_client_conformance: evaluate_client_conformance_sascontext");
            }
            checkSkipped = false;
            continue;
        }
        // security policy matched.
        return true;
    }
    if (checkSkipped)
        return true;
    // No matching security policy found
    return false;
}
Also used : Set(java.util.Set) HashSet(java.util.HashSet) Iterator(java.util.Iterator) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) EjbIORConfigurationDescriptor(com.sun.enterprise.deployment.EjbIORConfigurationDescriptor)

Example 4 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class AbstractAuthAnnotationHandler method postProcessAnnotation.

/**
 * This method is for processing security annotation associated to ejb.
 * Dervied class call this method may like to override
 *
 * protected void processEjbMethodSecurity(Annotation authAnnotation,
 *         MethodDescriptor md, EjbDescriptor ejbDesc)
 */
@Override
public void postProcessAnnotation(AnnotationInfo ainfo, AnnotatedElementHandler aeHandler) throws AnnotationProcessorException {
    EjbContext ejbContext = (EjbContext) aeHandler;
    EjbDescriptor ejbDesc = ejbContext.getDescriptor();
    Annotation authAnnotation = ainfo.getAnnotation();
    if (!ejbContext.isInherited() && (ejbDesc.getMethodPermissionsFromDD() == null || ejbDesc.getMethodPermissionsFromDD().size() == 0)) {
        for (MethodDescriptor md : getMethodAllDescriptors(ejbDesc)) {
            processEjbMethodSecurity(authAnnotation, md, ejbDesc);
        }
    } else {
        Class classAn = (Class) ainfo.getAnnotatedElement();
        for (Object next : ejbDesc.getSecurityBusinessMethodDescriptors()) {
            MethodDescriptor md = (MethodDescriptor) next;
            // override by existing info
            if (classAn.equals(ejbContext.getDeclaringClass(md)) && !hasMethodPermissionsFromDD(md, ejbDesc)) {
                processEjbMethodSecurity(authAnnotation, md, ejbDesc);
            }
        }
    }
}
Also used : MethodDescriptor(com.sun.enterprise.deployment.MethodDescriptor) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor) Annotation(java.lang.annotation.Annotation)

Example 5 with EjbDescriptor

use of com.sun.enterprise.deployment.EjbDescriptor in project Payara by payara.

the class RunAsHandler method processAnnotation.

protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, EjbContext[] ejbContexts) throws AnnotationProcessorException {
    RunAs runAsAn = (RunAs) ainfo.getAnnotation();
    for (EjbContext ejbContext : ejbContexts) {
        EjbDescriptor ejbDesc = ejbContext.getDescriptor();
        // override by xml
        if (ejbDesc.getUsesCallerIdentity() != null) {
            continue;
        }
        String roleName = runAsAn.value();
        Role role = new Role(roleName);
        // add Role if not exists
        ejbDesc.getEjbBundleDescriptor().addRole(role);
        RunAsIdentityDescriptor runAsDesc = new RunAsIdentityDescriptor();
        runAsDesc.setRoleName(roleName);
        ejbDesc.setUsesCallerIdentity(false);
        if (ejbDesc.getRunAsIdentity() == null) {
            ejbDesc.setRunAsIdentity(runAsDesc);
        }
    }
    return getDefaultProcessedResult();
}
Also used : Role(org.glassfish.security.common.Role) RunAsIdentityDescriptor(com.sun.enterprise.deployment.RunAsIdentityDescriptor) EjbContext(com.sun.enterprise.deployment.annotation.context.EjbContext) RunAs(javax.annotation.security.RunAs) EjbDescriptor(com.sun.enterprise.deployment.EjbDescriptor)

Aggregations

EjbDescriptor (com.sun.enterprise.deployment.EjbDescriptor)55 EjbBundleDescriptor (com.sun.enterprise.deployment.EjbBundleDescriptor)17 BundleDescriptor (com.sun.enterprise.deployment.BundleDescriptor)14 WebBundleDescriptor (com.sun.enterprise.deployment.WebBundleDescriptor)13 JndiNameEnvironment (com.sun.enterprise.deployment.JndiNameEnvironment)9 Application (com.sun.enterprise.deployment.Application)8 WebServiceEndpoint (com.sun.enterprise.deployment.WebServiceEndpoint)7 NamingException (javax.naming.NamingException)5 ComponentInvocation (org.glassfish.api.invocation.ComponentInvocation)5 ComponentEnvManager (com.sun.enterprise.container.common.spi.util.ComponentEnvManager)4 ManagedBeanDescriptor (com.sun.enterprise.deployment.ManagedBeanDescriptor)4 WebComponentDescriptor (com.sun.enterprise.deployment.WebComponentDescriptor)4 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)4 Method (java.lang.reflect.Method)4 ArrayList (java.util.ArrayList)4 Descriptor (org.glassfish.deployment.common.Descriptor)4 BeanDeploymentArchive (org.jboss.weld.bootstrap.spi.BeanDeploymentArchive)4 ApplicationClientDescriptor (com.sun.enterprise.deployment.ApplicationClientDescriptor)3 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)3 RunAsIdentityDescriptor (com.sun.enterprise.deployment.RunAsIdentityDescriptor)3