Search in sources :

Example 1 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class WebResourceHTTPMethod method check.

/**
 * The http-method element contains the name of web resource collection's HTTP
 * method
 *
 * @param descriptor the Web deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.getSecurityConstraints().hasMoreElements()) {
        boolean oneFailed = false;
        boolean foundIt = false;
        int na = 0;
        int noSc = 0;
        int naWRC = 0;
        int noWRC = 0;
        // get the http method's in this .war
        for (Enumeration e = descriptor.getSecurityConstraints(); e.hasMoreElements(); ) {
            foundIt = false;
            noSc++;
            SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) e.nextElement();
            if (!securityConstraintImpl.getWebResourceCollections().isEmpty()) {
                for (WebResourceCollection webResourceCollection : securityConstraintImpl.getWebResourceCollections()) {
                    noWRC++;
                    if (!webResourceCollection.getHttpMethods().isEmpty()) {
                        for (String webRCHTTPMethod : webResourceCollection.getHttpMethods()) {
                            // valid methods are the following
                            if ((webRCHTTPMethod.equals("OPTIONS")) || (webRCHTTPMethod.equals("GET")) || (webRCHTTPMethod.equals("HEAD")) || (webRCHTTPMethod.equals("POST")) || (webRCHTTPMethod.equals("PUT")) || (webRCHTTPMethod.equals("DELETE")) || (webRCHTTPMethod.equals("TRACE")) || (webRCHTTPMethod.equals("CONNECT"))) {
                                foundIt = true;
                            } else {
                                foundIt = false;
                            }
                            if (foundIt) {
                                result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "http-method [ {0} ] is valid HTTP method name within web resource collection [ {1} ] in web application [ {2} ]", new Object[] { webRCHTTPMethod, webResourceCollection.getName(), descriptor.getName() }));
                            } else {
                                if (!oneFailed) {
                                    oneFailed = true;
                                }
                                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                                result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: http-method [ {0} ] is not valid HTTP method name within web resource collection [ {1} ] in web application [ {2} ]", new Object[] { webRCHTTPMethod, webResourceCollection.getName(), descriptor.getName() }));
                            }
                        }
                    } else {
                        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "There are no web http-methods in the web resource collection [ {0} ] within [ {1} ]", new Object[] { webResourceCollection.getName(), descriptor.getName() }));
                        naWRC++;
                    }
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "There are no web web resource collections in the web security constraint within [ {0} ]", new Object[] { descriptor.getName() }));
                na++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if ((na == noSc) || (naWRC == noWRC)) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no http-method elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebResourceCollection(com.sun.enterprise.deployment.web.WebResourceCollection) Enumeration(java.util.Enumeration) SecurityConstraintImpl(org.glassfish.web.deployment.descriptor.SecurityConstraintImpl) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 2 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class WebResourceName method check.

/**
 * The web-resource-name element contains the name of this web resource
 * collection
 *
 * @param descriptor the Web deployment descriptor
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    if (descriptor.getSecurityConstraints().hasMoreElements()) {
        boolean oneFailed = false;
        int na = 0;
        int noSc = 0;
        boolean foundIt = false;
        // get the security constraint's in this .war
        for (Enumeration e = descriptor.getSecurityConstraints(); e.hasMoreElements(); ) {
            foundIt = false;
            noSc++;
            SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) e.nextElement();
            if (!securityConstraintImpl.getWebResourceCollections().isEmpty()) {
                for (WebResourceCollection webResCollection : securityConstraintImpl.getWebResourceCollections()) {
                    String webRCName = webResCollection.getName();
                    // cannot be blank
                    if (webRCName.length() > 0) {
                        foundIt = true;
                    } else {
                        foundIt = false;
                    }
                    if (foundIt) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addGoodDetails(smh.getLocalString(getClass().getName() + ".passed", "web-resource-name [ {0} ] contains the name of this web resource collection within web application [ {1} ]", new Object[] { webRCName, descriptor.getName() }));
                    } else {
                        if (!oneFailed) {
                            oneFailed = true;
                        }
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.addErrorDetails(smh.getLocalString(getClass().getName() + ".failed", "Error: web-resource-name [ {0} ] does not contain the name of this web resource collection within web application [ {1} ]", new Object[] { webRCName, descriptor.getName() }));
                    }
                }
            } else {
                result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "There are no web web resource collections in the web security constraint within [ {0} ]", new Object[] { descriptor.getName() }));
                na++;
            }
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (na == noSc) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "There are no web-resource-name elements within the web archive [ {0} ]", new Object[] { descriptor.getName() }));
    }
    return result;
}
Also used : WebResourceCollection(com.sun.enterprise.deployment.web.WebResourceCollection) Enumeration(java.util.Enumeration) SecurityConstraintImpl(org.glassfish.web.deployment.descriptor.SecurityConstraintImpl) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 3 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class WebEjbRefTypeElement method check.

/**
 * The web archive ejb-ref-type element must be one of the following:
 *   Entity
 *   Session
 *
 * @param descriptor the Web deployment descriptor
 *
 * @return <code>Result</code> the results for this assertion
 */
public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean failed = false;
    // Session
    if (!descriptor.getEjbReferenceDescriptors().isEmpty()) {
        for (Iterator itr = descriptor.getEjbReferenceDescriptors().iterator(); itr.hasNext(); ) {
            EjbReferenceDescriptor nextEjbReference = (EjbReferenceDescriptor) itr.next();
            String ejbRefTypeStr = nextEjbReference.getType();
            if (!((ejbRefTypeStr.equals(EjbSessionDescriptor.TYPE)) || (ejbRefTypeStr.equals(EjbEntityDescriptor.TYPE)))) {
                result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                result.failed(smh.getLocalString(getClass().getName() + ".failed", "Error: ejb-ref-type [ {0} ] within \n web archive [ {1} ] is not valid.  \n Must be [ {2} ] or [ {3} ]", new Object[] { ejbRefTypeStr, descriptor.getName(), EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE }));
                failed = true;
            }
        }
    } else {
        result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        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;
    }
    if (failed) {
        result.setStatus(Result.FAILED);
    } else {
        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
        result.passed(smh.getLocalString(getClass().getName() + ".passed", "All ejb-ref-type elements are valid.  They are all [ {0} ] or [ {1} ] within this web archive [ {2} ]", new Object[] { EjbEntityDescriptor.TYPE, EjbSessionDescriptor.TYPE, descriptor.getName() }));
    }
    return result;
}
Also used : EjbReferenceDescriptor(com.sun.enterprise.deployment.EjbReferenceDescriptor) Iterator(java.util.Iterator) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Example 4 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class ASCacheHelperClass method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    boolean oneFailed = false;
    boolean notApp = false;
    boolean oneWarning = false;
    boolean presentHelper = false;
    try {
        Cache cache = ((SunWebAppImpl) descriptor.getSunDescriptor()).getCache();
        CacheHelper[] helperClasses = null;
        CacheHelper helperClass = null;
        WebProperty[] webProps;
        String name = null;
        String classname = null;
        String[] names = null;
        // to-do vkv# check for class-name attribute.
        if (cache != null)
            helperClasses = cache.getCacheHelper();
        if (cache != null && helperClasses != null && helperClasses.length > 0) {
            names = new String[helperClasses.length];
            for (int rep = 0; rep < helperClasses.length; rep++) {
                helperClass = helperClasses[rep];
                if (helperClass == null)
                    continue;
                int i = rep + 1;
                name = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@name");
                classname = getXPathValue("sun-web-app/cache/cache-helper[" + i + "]/@class-name");
                Class hClass = null;
                names[rep] = name;
                if (name != null && name.length() != 0) {
                    // check if the name already exist
                    boolean isDuplicate = false;
                    for (int rep1 = 0; rep1 < rep; rep1++) {
                        if (name.equals(names[rep1])) {
                            isDuplicate = true;
                            break;
                        }
                    }
                    if (isDuplicate) {
                        oneFailed = true;
                        addErrorDetails(result, compName);
                        result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB cache-helper] name attribute [ {0} ], must be unique in the entire list of cache-helper.", new Object[] { name }));
                    } else {
                        if (classname != null && classname.length() != 0) {
                            hClass = loadClass(result, classname);
                        }
                        if (hClass != null)
                            presentHelper = true;
                        else
                            presentHelper = false;
                        if (!presentHelper) {
                            addWarningDetails(result, compName);
                            result.warning(smh.getLocalString(getClass().getName() + ".error", "WARNING [AS-WEB cache-helper] " + "name [ {0} ], class not present in the war file.", new Object[] { name }));
                            oneWarning = true;
                        } else {
                            addGoodDetails(result, compName);
                            result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB cache-helper] name  [ {0} ], helper class is valid.", new Object[] { name }));
                        }
                    }
                } else {
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB cache-helper] name [ {0} ], either empty or null.", new Object[] { name }));
                    oneFailed = true;
                }
                webProps = helperClass.getWebProperty();
                if (ASWebProperty.checkWebProperties(webProps, result, descriptor, this)) {
                    oneFailed = true;
                    addErrorDetails(result, compName);
                    result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB cache-helper] Atleast one name/value pair is not valid in helper-class of [ {0} ].", new Object[] { descriptor.getName() }));
                }
            }
        // end of for
        } else {
            notApp = true;
            addNaDetails(result, compName);
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB cache-helper] There is no cache-helper element for the web application", new Object[] { descriptor.getName() }));
        }
        if (oneFailed) {
            result.setStatus(Result.FAILED);
        } else if (oneWarning) {
            result.setStatus(Result.WARNING);
        } else if (notApp) {
            result.setStatus(Result.NOT_APPLICABLE);
        } else {
            result.setStatus(Result.PASSED);
        }
    } catch (Exception ex) {
        oneFailed = true;
        addErrorDetails(result, compName);
        result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB cache-helper] could not create the cache object"));
    }
    return result;
}
Also used : SunWebAppImpl(org.glassfish.web.deployment.runtime.SunWebAppImpl) CacheHelper(org.glassfish.web.deployment.runtime.CacheHelper) WebProperty(org.glassfish.web.deployment.runtime.WebProperty) Result(com.sun.enterprise.tools.verifier.Result) ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Cache(org.glassfish.web.deployment.runtime.Cache)

Example 5 with ComponentNameConstructor

use of com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor in project Payara by payara.

the class ASConstraintField method check.

public Result check(WebBundleDescriptor descriptor) {
    Result result = getInitializedResult();
    ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
    String value = null;
    int count = 0;
    boolean oneFailed = false;
    try {
        count = getCountNodeSet("sun-web-app/cache/cache-mapping/constraint-field");
        if (count > 0) {
            for (int i = 1; i <= count; i++) {
                // name attribute
                value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field[" + i + "]/@name");
                if (value == null || value.length() == 0) {
                    oneFailed = true;
                    result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.failed(smh.getLocalString(getClass().getName() + ".failed", "FAILED [AS-WEB constraint-field] :  name attribute is required", new Object[] { descriptor.getName() }));
                } else {
                    result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.passed(smh.getLocalString(getClass().getName() + ".passed", "PASSED [AS-WEB constraint-field] : name attribute is {1}", new Object[] { descriptor.getName(), value }));
                }
                // scope attribute
                value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field[" + i + "]/@scope");
                if (value == null || value.length() == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable", "NOT APPLICABLE [AS-WEB constraint-field] : scope attribute not defined"));
                } else {
                    String[] scopeValue = { "context.attribute", "request.header", "request.parameter", "request.cookie", "request.attribute", "session.attribute" };
                    boolean found = false;
                    for (int j = 0; j < scopeValue.length; j++) {
                        if (scopeValue[j].compareTo(value) == 0) {
                            found = true;
                        }
                    }
                    if (found) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed1", "PASSED [AS-WEB constraint-field] : scope attribute is {1}", new Object[] { descriptor.getName(), value }));
                    } else {
                        oneFailed = true;
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed1", "FAILED [AS-WEB constraint-field] :  scope attribute must be one of context.attribute, request.header, request.parameter, request.cookie, request.attribute, session.attribute", new Object[] { descriptor.getName() }));
                    }
                }
                // cache-on-match % boolean "(yes | no | on | off | 1 | 0 | true | false)">
                value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field[" + i + "]/@cache-on-match");
                if (value == null || value.length() == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable1", "NOT APPLICABLE [AS-WEB constraint-field] : cache-on-match attribute not defined"));
                } else {
                    String[] cacheOnMatchValue = { "yes", "no", "on", "off", "1", "0", "true", "false" };
                    boolean foundCacheOnMatch = false;
                    for (int j = 0; j < cacheOnMatchValue.length; j++) {
                        if (cacheOnMatchValue[j].compareTo(value) == 0) {
                            foundCacheOnMatch = true;
                        }
                    }
                    if (foundCacheOnMatch) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed2", "PASSED [AS-WEB constraint-field] : cache-on-match attribute is {1}", new Object[] { descriptor.getName(), value }));
                    } else {
                        oneFailed = true;
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed2", "FAILED [AS-WEB constraint-field] :  cache-on-match attribute must be one of yes, no, on, off, 1, 0, true, false", new Object[] { descriptor.getName() }));
                    }
                }
                // cache-on-match-failure
                value = getXPathValue("sun-web-app/cache/cache-mapping/constraint-field[" + i + "]/@cache-on-match-failure");
                if (value == null || value.length() == 0) {
                    result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                    result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable2", "NOT APPLICABLE [AS-WEB constraint-field] : cache-on-match-failure attribute not defined"));
                } else {
                    String[] cacheOnMatchFailureValue = { "yes", "no", "on", "off", "1", "0", "true", "false" };
                    boolean found = false;
                    for (int j = 0; j < cacheOnMatchFailureValue.length; j++) {
                        if (cacheOnMatchFailureValue[j].compareTo(value) == 0) {
                            found = true;
                        }
                    }
                    if (found) {
                        result.addGoodDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.passed(smh.getLocalString(getClass().getName() + ".passed3", "PASSED [AS-WEB constraint-field] : cache-on-match-failure attribute is {1}", new Object[] { descriptor.getName(), value }));
                    } else {
                        oneFailed = true;
                        result.addErrorDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
                        result.failed(smh.getLocalString(getClass().getName() + ".failed3", "FAILED [AS-WEB constraint-field] :  cache-on-match-failure attribute must be one of yes, no, on, off, 1, 0, true, false", new Object[] { descriptor.getName() }));
                    }
                }
            }
        } else {
            result.addNaDetails(smh.getLocalString("tests.componentNameConstructor", "For [ {0} ]", new Object[] { compName.toString() }));
            result.notApplicable(smh.getLocalString(getClass().getName() + ".notApplicable3", "NOT APPLICABLE [AS-WEB sun-web-app] : constraint-field Element not defined"));
        }
        if (oneFailed)
            result.setStatus(Result.FAILED);
    } catch (Exception ex) {
        result.failed(smh.getLocalString(getClass().getName() + ".failed4", "FAILED [AS-WEB sun-web-app] could not create the constraint-field object"));
    }
    return result;
}
Also used : ComponentNameConstructor(com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor) Result(com.sun.enterprise.tools.verifier.Result)

Aggregations

ComponentNameConstructor (com.sun.enterprise.tools.verifier.tests.ComponentNameConstructor)237 Result (com.sun.enterprise.tools.verifier.Result)212 EjbEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbEntityDescriptor)87 Method (java.lang.reflect.Method)70 VerifierTestContext (com.sun.enterprise.tools.verifier.VerifierTestContext)66 Iterator (java.util.Iterator)40 EjbSessionDescriptor (org.glassfish.ejb.deployment.descriptor.EjbSessionDescriptor)28 Set (java.util.Set)19 EjbDescriptor (org.glassfish.ejb.deployment.descriptor.EjbDescriptor)16 EjbCMPEntityDescriptor (org.glassfish.ejb.deployment.descriptor.EjbCMPEntityDescriptor)15 EjbSessionDescriptor (com.sun.enterprise.deployment.EjbSessionDescriptor)14 Field (java.lang.reflect.Field)13 MethodDescriptor (com.sun.enterprise.deployment.MethodDescriptor)12 Enumeration (java.util.Enumeration)11 EjbBundleDescriptorImpl (org.glassfish.ejb.deployment.descriptor.EjbBundleDescriptorImpl)11 FieldDescriptor (org.glassfish.ejb.deployment.descriptor.FieldDescriptor)9 TagLibDescriptor (com.sun.enterprise.tools.verifier.TagLibDescriptor)7 EjbReferenceDescriptor (com.sun.enterprise.deployment.EjbReferenceDescriptor)6 ResourceReferenceDescriptor (com.sun.enterprise.deployment.ResourceReferenceDescriptor)6 Vector (java.util.Vector)6