Search in sources :

Example 11 with EjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.

the class LocalInterfaceExposed method check.

/**
 * Bean interface type test.
 * The bean provider must provide either Local or Remote or Both interfaces
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (!(descriptor instanceof EjbSessionDescriptor) && !(descriptor instanceof EjbEntityDescriptor)) {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "Test apply only to session or entity beans."));
        return result;
    }
    EjbBundleDescriptorImpl bundle = descriptor.getEjbBundleDescriptor();
    Iterator<EjbDescriptor> iterator = (bundle.getEjbs()).iterator();
    Set<String> localInterfaces = new HashSet<String>();
    while (iterator.hasNext()) {
        EjbDescriptor entity = iterator.next();
        if (entity.getLocalClassName() != null)
            localInterfaces.add(entity.getLocalClassName());
        localInterfaces.addAll(entity.getLocalBusinessClassNames());
    }
    ClassLoader jcl = getVerifierContext().getClassLoader();
    try {
        Set<String> remoteInterfaces = new HashSet<String>();
        if (descriptor.getRemoteClassName() != null)
            remoteInterfaces.add(descriptor.getRemoteClassName());
        remoteInterfaces.addAll(descriptor.getRemoteBusinessClassNames());
        for (String intf : remoteInterfaces) {
            Class c = Class.forName(intf, false, getVerifierContext().getClassLoader());
            Method[] methods = c.getDeclaredMethods();
            for (int i = 0; i < methods.length; i++) {
                // check all the local interfaces in the ejb bundle
                for (Iterator itr = localInterfaces.iterator(); itr.hasNext(); ) {
                    String localIntf = (String) itr.next();
                    Class returnType = methods[i].getReturnType();
                    if ((getBaseComponentType(returnType).getName()).equals(localIntf) || (contains(methods[i].getParameterTypes(), localIntf))) {
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error : Local Interface [ {0} ] has been " + "exposed in remote interface [ {1} ]", new Object[] { localIntf, c.getName() }));
                        return result;
                    }
                }
            }
        }
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Remote interface."));
    } catch (ClassNotFoundException e) {
        Verifier.debug(e);
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failedException", "Error: [ {0} ] class not found.", new Object[] { descriptor.getRemoteClassName() }));
    }
    return result;
}
Also used : Method(java.lang.reflect.Method) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) EjbEntityDescriptor(org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor) Iterator(java.util.Iterator) EjbSessionDescriptor(org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl) HashSet(java.util.HashSet)

Example 12 with EjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.

the class SecurityRolesBind method check.

/**
 * If the Application assembler defines security roles in the deployment
 * descriptor, the Application Assembler must bind security role references
 * declared by the Bean Provider to the security roles.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    EjbBundleDescriptorImpl bundleDescriptor = descriptor.getEjbBundleDescriptor();
    Set ejbs = bundleDescriptor.getEjbs();
    Iterator ejbIterator = ejbs.iterator();
    EjbDescriptor ejb = null;
    Set roleReferences = null;
    Iterator roleRefsIterator = null;
    Set roles = bundleDescriptor.getRoles();
    Iterator rolesIterator = roles.iterator();
    RoleReference roleReference = null;
    Role role = null;
    boolean oneFailed = false;
    // check to see if there are any undefined roles being referenced
    while (ejbIterator.hasNext()) {
        ejb = (EjbDescriptor) ejbIterator.next();
        roleReferences = ejb.getRoleReferences();
        roleRefsIterator = roleReferences.iterator();
        if (roleRefsIterator.hasNext()) {
            while (roleRefsIterator.hasNext()) {
                roleReference = (RoleReference) roleRefsIterator.next();
                role = roleReference.getRole();
                if (!role.getName().equals("") && !bundleDescriptor.getRoles().contains(role)) {
                    // print the undefine role
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: The role [ {0} ] for bean [ {1} ] is undefined.", new Object[] { role.getName(), ejb.getName() }));
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                } else {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "The role [ {0} ] for bean [ {1} ] is defined.", new Object[] { role.getName(), ejb.getName() }));
                }
            }
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no role references which need to be bound to other security roles within this bean [ {0} ]", new Object[] { ejb.getName() }));
        }
    }
    if (oneFailed) {
        result.setStatus(Result.FAILED);
    }
    return result;
}
Also used : Role(org.glassfish.security.common.Role) Set(java.util.Set) RoleReference(com.sun.enterprise.deployment.RoleReference) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 13 with EjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.

the class MDBInheritsMDB method check.

public Result check(EjbMessageBeanDescriptor descriptor) {
    try {
        ClassLoader cl = getVerifierContext().getClassLoader();
        Class ejbCls = Class.forName(descriptor.getEjbClassName(), false, cl);
        Set<EjbDescriptor> descrptors = descriptor.getEjbBundleDescriptor().getEjbs();
        for (EjbDescriptor ejbDescriptor : descrptors) {
            if (!(ejbDescriptor instanceof EjbMessageBeanDescriptor))
                continue;
            if (descriptor.getEjbClassName().equals(ejbDescriptor.getEjbClassName()))
                continue;
            Class mdbCls = null;
            try {
                mdbCls = Class.forName(ejbDescriptor.getEjbClassName(), false, cl);
            } catch (ClassNotFoundException e) {
                // ignore as this error will be caught by other tests
                continue;
            }
            if (mdbCls.isAssignableFrom(ejbCls)) {
                addErrorDetails(result, compName);
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Message bean [ {0} ] inherits other message bean [ {1} ]", new Object[] { ejbCls.getName(), mdbCls.getName() }));
            }
        }
    } catch (ClassNotFoundException e) {
        // ignore as this error will be caught by other tests
        logger.fine(descriptor.getEjbClassName() + " Not found");
    }
    if (result.getStatus() != Result.FAILED) {
        addGoodDetails(result, compName);
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "Valid Message bean [ {0} ]", new Object[] { descriptor.getEjbClassName() }));
    }
    return result;
}
Also used : EjbMessageBeanDescriptor(org.glassfish.ejb.deployment.descriptor.EjbMessageBeanDescriptor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Example 14 with EjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.

the class EjbLinkElement method check.

/**
 * The referenced bean must be an enterprise bean in the same ear file.
 *
 * @param descriptor the Enterprise Java Bean deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(EjbDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean resolved = false;
    boolean oneFailed = false;
    int na = 0;
    // bean in the same application .ear file.
    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);
                try {
                    // applicationName = application.getName();
                    // File tmpFile = new File(System.getProperty("java.io.tmpdir"));
                    // tmpFile = new File(tmpFile, Verifier.TMPFILENAME + ".tmp");
                    Set ejbBundles = descriptor.getApplication().getBundleDescriptors(EjbBundleDescriptorImpl.class);
                    Iterator ejbBundlesIterator = ejbBundles.iterator();
                    EjbBundleDescriptorImpl ejbBundle = null;
                    while (ejbBundlesIterator.hasNext()) {
                        ejbBundle = (EjbBundleDescriptorImpl) 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() });
                                addGoodDetails(result, compName);
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "Valid referenced bean [ {0} ].", new Object[] { ejb_link }));
                                break;
                            }
                        }
                    }
                } catch (Exception e) {
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failedException1", "Exception occured while opening or saving the J2EE archive.", new Object[] {}));
                    logger.log(Level.FINE, "com.sun.enterprise.tools.verifier.testsprint", new Object[] { "[" + getClass() + "] Error: " + e.getMessage() });
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                }
                // resolved the last ejb-link okay
                if (!resolved) {
                    if (!oneFailed) {
                        oneFailed = true;
                    }
                    addErrorDetails(result, compName);
                    result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: No EJB matching [ {0} ] found within [ {1} ] jar file.", new Object[] { ejb_link, descriptor.getName() }));
                } 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, The value of the ejb-link element
                // must be the ejb-name of an enterprise bean in the same
                // ejb-ear file.
                addNaDetails(result, compName);
                result.addNaDetails(smh.getLocalString(getClass().getName() + ".notApplicable1", "Warning:  Cannot verify the existence 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 {
        addNaDetails(result, compName);
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no ejb references to other beans within this bean [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : Set(java.util.Set) EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor) Result(com.sun.enterprise.tools.verifier.Result) EjbBundleDescriptorImpl(org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)

Example 15 with EjbDescriptor

use of org.glassfish.ejb.deployment.descriptor.EjbDescriptor in project Payara by payara.

the class EnterpriseBeansRuntimeNode method writeDescriptor.

/**
 * write the descriptor class to a DOM tree and return it
 *
 * @param parent node for the DOM tree
 * @param the descriptor to write
 * @return the DOM tree top node
 */
public Node writeDescriptor(Node parent, String nodeName, EjbBundleDescriptorImpl bundleDescriptor) {
    Node ejbs = super.writeDescriptor(parent, nodeName, bundleDescriptor);
    // NOTE : unique-id is no longer written out to sun-ejb-jar.xml.  It is persisted via
    // domain.xml deployment context properties instead.
    // ejb*
    EjbNode ejbNode = new EjbNode();
    for (Iterator ejbIterator = bundleDescriptor.getEjbs().iterator(); ejbIterator.hasNext(); ) {
        EjbDescriptor ejbDescriptor = (EjbDescriptor) ejbIterator.next();
        ejbNode.writeDescriptor(ejbs, RuntimeTagNames.EJB, ejbDescriptor);
    }
    // pm-descriptors?
    PMDescriptorsNode pmsNode = new PMDescriptorsNode();
    pmsNode.writeDescriptor(ejbs, RuntimeTagNames.PM_DESCRIPTORS, bundleDescriptor);
    // cmpresource?
    ResourceReferenceDescriptor rrd = bundleDescriptor.getCMPResourceReference();
    if (rrd != null) {
        CmpResourceNode crn = new CmpResourceNode();
        crn.writeDescriptor(ejbs, RuntimeTagNames.CMP_RESOURCE, rrd);
    }
    // message-destination*
    writeMessageDestinationInfo(ejbs, bundleDescriptor);
    // webservice-description*
    WebServiceRuntimeNode webServiceNode = new WebServiceRuntimeNode();
    webServiceNode.writeWebServiceRuntimeInfo(ejbs, bundleDescriptor);
    for (NameValuePairDescriptor p : bundleDescriptor.getEnterpriseBeansProperties()) {
        RuntimeNameValuePairNode nameValNode = new RuntimeNameValuePairNode();
        nameValNode.writeDescriptor(ejbs, RuntimeTagNames.PROPERTY, p);
    }
    return ejbs;
}
Also used : NameValuePairDescriptor(com.sun.enterprise.deployment.NameValuePairDescriptor) MessageDestinationRuntimeNode(com.sun.enterprise.deployment.node.runtime.MessageDestinationRuntimeNode) RuntimeNameValuePairNode(com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) Node(org.w3c.dom.Node) RuntimeDescriptorNode(com.sun.enterprise.deployment.node.runtime.RuntimeDescriptorNode) Iterator(java.util.Iterator) RuntimeNameValuePairNode(com.sun.enterprise.deployment.node.runtime.common.RuntimeNameValuePairNode) ResourceReferenceDescriptor(com.sun.enterprise.deployment.ResourceReferenceDescriptor) WebServiceRuntimeNode(com.sun.enterprise.deployment.node.runtime.WebServiceRuntimeNode) EjbDescriptor(org.glassfish.ejb.deployment.descriptor.EjbDescriptor)

Aggregations

EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)48 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)19 Iterator (java.util.Iterator)18 ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)16 Result (com.sun.enterprise.tools.verifier.Result)14 Method (java.lang.reflect.Method)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)11 EjbContext (com.sun.enterprise.deployment.annotation.context.EjbContext)10 Set (java.util.Set)8 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)7 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)6 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)5 Container (com.sun.ejb.Container)4 Field (java.lang.reflect.Field)4 ContainerTransaction (org.glassfish.ejb.deployment.descriptor.ContainerTransaction)4 DummyEjbDescriptor (org.glassfish.ejb.deployment.descriptor.DummyEjbDescriptor)4 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)3 Constructor (java.lang.reflect.Constructor)3 Descriptor (org.glassfish.deployment.common.Descriptor)3 InterceptorBindingDescriptor (org.glassfish.ejb.deployment.descriptor.InterceptorBindingDescriptor)3