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 37 public class WebSecurityRoleName extends WebTest implements WebCheck { 38 39 40 47 public Result check(WebBundleDescriptor descriptor) { 48 49 Result result = getInitializedResult(); 50 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 51 52 if (descriptor.getSecurityConstraints().hasMoreElements()) { 53 boolean oneFailed = false; 54 boolean foundIt = false; 55 int naSr = 0; 56 int naAci = 0; 57 int noAci = 0; 58 int noSc = 0; 59 for (Enumeration e = descriptor.getSecurityConstraints() ; e.hasMoreElements() ;) { 61 foundIt = false; 62 noSc++; 63 SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) 64 e.nextElement(); 65 AuthorizationConstraintImpl aci = (AuthorizationConstraintImpl) securityConstraintImpl.getAuthorizationConstraint(); 66 if (aci != null) { 67 noAci++; 68 if (aci.getSecurityRoles().hasMoreElements()) { 69 for (Enumeration ee = aci.getSecurityRoles(); ee.hasMoreElements();) { 70 SecurityRoleDescriptor srd = (SecurityRoleDescriptor) ee.nextElement(); 71 String roleName = srd.getName(); 72 if (roleName.length() > 0) { 74 foundIt = true; 75 } else { 76 foundIt = false; 77 } 78 79 if (foundIt) { 80 result.addGoodDetails(smh.getLocalString 81 ("tests.componentNameConstructor", 82 "For [ {0} ]", 83 new Object [] {compName.toString()})); 84 result.addGoodDetails(smh.getLocalString 85 (getClass().getName() + ".passed", 86 "The security role name [ {0} ] found within web application [ {1} ]", 87 new Object [] {roleName, descriptor.getName()})); 88 } else { 89 if (!oneFailed) { 90 oneFailed = true; 91 } 92 result.addErrorDetails(smh.getLocalString 93 ("tests.componentNameConstructor", 94 "For [ {0} ]", 95 new Object [] {compName.toString()})); 96 result.addErrorDetails(smh.getLocalString 97 (getClass().getName() + ".failed", 98 "Error: The security role name [ {0} ] not found within web application [ {1} ]", 99 new Object [] {roleName, descriptor.getName()})); 100 } 101 } 102 } else { 103 result.addNaDetails(smh.getLocalString 104 ("tests.componentNameConstructor", 105 "For [ {0} ]", 106 new Object [] {compName.toString()})); 107 result.notApplicable(smh.getLocalString 108 (getClass().getName() + ".notApplicable1", 109 "Not Applicable: There are no security roles in this security constraint within [ {0} ]", 110 new Object [] {descriptor.getName()})); naSr++; 111 } 112 } else { 113 result.addNaDetails(smh.getLocalString 114 ("tests.componentNameConstructor", 115 "For [ {0} ]", 116 new Object [] {compName.toString()})); 117 result.notApplicable(smh.getLocalString 118 (getClass().getName() + ".notApplicable2", 119 "Not Applicable: There is no authorization constraint in this security constraint within [ {0} ]", 120 new Object [] {descriptor.getName()})); 121 naAci++; 122 } 123 } 124 if (oneFailed) { 125 result.setStatus(Result.FAILED); 126 } else if ((noSc == naAci) || (noAci == naSr)) { 127 result.setStatus(Result.NOT_APPLICABLE); 128 } else { 129 result.setStatus(Result.PASSED); 130 } 131 } else { 132 result.addNaDetails(smh.getLocalString 133 ("tests.componentNameConstructor", 134 "For [ {0} ]", 135 new Object [] {compName.toString()})); 136 result.notApplicable(smh.getLocalString 137 (getClass().getName() + ".notApplicable", 138 "There are no role-name elements within the web archive [ {0} ]", 139 new Object [] {descriptor.getName()})); 140 } 141 142 return result; 143 } 144 } 145 | Popular Tags |