1 23 package com.sun.enterprise.tools.verifier.tests.web; 24 25 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 26 import java.util.*; 27 import java.io.*; 28 import com.sun.enterprise.deployment.*; 29 import com.sun.enterprise.tools.verifier.*; 30 import com.sun.enterprise.tools.verifier.tests.*; 31 import com.sun.enterprise.util.FileClassLoader; 32 33 34 38 public class WebResourceHTTPMethod extends WebTest implements WebCheck { 39 40 41 49 public Result check(WebBundleDescriptor descriptor) { 50 51 Result result = getInitializedResult(); 52 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 53 54 if (descriptor.getSecurityConstraints().hasMoreElements()) { 55 boolean oneFailed = false; 56 boolean foundIt = false; 57 int na = 0; 58 int noSc = 0; 59 int naWRC = 0; 60 int noWRC = 0; 61 for (Enumeration e = descriptor.getSecurityConstraints() ; e.hasMoreElements() ;) { 63 foundIt = false; 64 noSc++; 65 SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) e.nextElement(); 66 if (securityConstraintImpl.getWebResourceCollections().hasMoreElements()) { 67 for (Enumeration ee = securityConstraintImpl.getWebResourceCollections(); ee.hasMoreElements();) { 68 noWRC++; 69 WebResourceCollectionImpl webResourceCollection = (WebResourceCollectionImpl) ee.nextElement(); 70 if (webResourceCollection.getHttpMethods().hasMoreElements()) { 71 for (Enumeration eee = webResourceCollection.getHttpMethods(); eee.hasMoreElements();) { 72 String webRCHTTPMethod = (String ) eee.nextElement(); 73 if ((webRCHTTPMethod.equals("OPTIONS")) || 75 (webRCHTTPMethod.equals("GET")) || 76 (webRCHTTPMethod.equals("HEAD")) || 77 (webRCHTTPMethod.equals("POST")) || 78 (webRCHTTPMethod.equals("PUT")) || 79 (webRCHTTPMethod.equals("DELETE")) || 80 (webRCHTTPMethod.equals("TRACE")) || 81 (webRCHTTPMethod.equals("CONNECT"))) { 82 foundIt = true; 83 } else { 84 foundIt = false; 85 } 86 87 if (foundIt) { 88 result.addGoodDetails(smh.getLocalString 89 ("tests.componentNameConstructor", 90 "For [ {0} ]", 91 new Object [] {compName.toString()})); 92 result.addGoodDetails(smh.getLocalString 93 (getClass().getName() + ".passed", 94 "http-method [ {0} ] is valid HTTP method name within web resource collection [ {1} ] in web application [ {2} ]", 95 new Object [] {webRCHTTPMethod, webResourceCollection.getName(), descriptor.getName()})); 96 } else { 97 if (!oneFailed) { 98 oneFailed = true; 99 } 100 result.addErrorDetails(smh.getLocalString 101 ("tests.componentNameConstructor", 102 "For [ {0} ]", 103 new Object [] {compName.toString()})); 104 result.addErrorDetails(smh.getLocalString 105 (getClass().getName() + ".failed", 106 "Error: http-method [ {0} ] is not valid HTTP method name within web resource collection [ {1} ] in web application [ {2} ]", 107 new Object [] {webRCHTTPMethod, webResourceCollection.getName(), descriptor.getName()})); 108 } 109 } 110 } else { 111 result.addNaDetails(smh.getLocalString 112 ("tests.componentNameConstructor", 113 "For [ {0} ]", 114 new Object [] {compName.toString()})); 115 result.notApplicable(smh.getLocalString 116 (getClass().getName() + ".notApplicable1", 117 "There are no web http-methods in the web resource collection [ {0} ] within [ {1} ]", 118 new Object [] {webResourceCollection.getName(), descriptor.getName()})); 119 naWRC++; 120 } 121 } 122 } else { 123 result.addNaDetails(smh.getLocalString 124 ("tests.componentNameConstructor", 125 "For [ {0} ]", 126 new Object [] {compName.toString()})); 127 result.notApplicable(smh.getLocalString 128 (getClass().getName() + ".notApplicable2", 129 "There are no web web resource collections in the web security constraint within [ {0} ]", 130 new Object [] {descriptor.getName()})); na++; 131 } 132 } 133 if (oneFailed) { 134 result.setStatus(Result.FAILED); 135 } else if ((na == noSc) || (naWRC == noWRC)) { 136 result.setStatus(Result.NOT_APPLICABLE); 137 } else { 138 result.setStatus(Result.PASSED); 139 } 140 } else { 141 result.addNaDetails(smh.getLocalString 142 ("tests.componentNameConstructor", 143 "For [ {0} ]", 144 new Object [] {compName.toString()})); 145 result.notApplicable(smh.getLocalString 146 (getClass().getName() + ".notApplicable", 147 "There are no http-method elements within the web archive [ {0} ]", 148 new Object [] {descriptor.getName()})); 149 } 150 151 return result; 152 } 153 } 154 | Popular Tags |