1 23 24 25 package com.sun.enterprise.tools.verifier.tests.web.runtime; 26 27 28 import com.sun.enterprise.tools.verifier.tests.web.WebTest; 29 import com.sun.enterprise.tools.verifier.tests.web.WebCheck; 30 import java.util.*; 31 import com.sun.enterprise.deployment.*; 32 import com.sun.enterprise.tools.verifier.*; 33 import com.sun.enterprise.tools.verifier.tests.*; 34 import com.sun.enterprise.deployment.runtime.common.*; 35 36 39 41 public class ASSecurityRoleMapping extends WebTest implements WebCheck { 42 43 44 45 public Result check(WebBundleDescriptor descriptor) { 46 47 Result result = getInitializedResult(); 48 ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor(); 49 50 String roleName; 51 List<PrincipalNameDescriptor> prinNames; 52 List<String > grpNames; 53 boolean oneFailed = false; 54 55 try{ 56 SecurityRoleMapping[] secRoleMapp = (descriptor.getSunDescriptor()).getSecurityRoleMapping(); 57 if (secRoleMapp !=null && secRoleMapp.length > 0) { 58 for (int rep=0; rep<secRoleMapp.length; rep++ ) { 59 roleName=secRoleMapp[rep].getRoleName(); 60 prinNames=secRoleMapp[rep].getPrincipalNames(); 61 grpNames=secRoleMapp[rep].getGroupNames(); 62 63 if(validRoleName(roleName,descriptor)){ 64 addGoodDetails(result, compName); 65 result.passed(smh.getLocalString 66 (getClass().getName() + ".passed", 67 "PASSED [AS-WEB security-role-mapping] role-name [ {0} ] properly defined in the war file.", 68 new Object [] {roleName})); 69 70 }else{ 71 addErrorDetails(result, compName); 72 result.failed(smh.getLocalString 73 (getClass().getName() + ".failed", 74 "FAILED [AS-WEB security-role-mapping] role-name [ {0} ] is not valid, either empty or not defined in web.xml.", 75 new Object [] {roleName})); 76 oneFailed = true; 77 78 } 79 if (prinNames !=null && prinNames.size() > 0){ 80 String prinName; 81 for (int rep1=0; rep1<prinNames.size(); rep1++ ) { 82 prinName = prinNames.get(rep1).getName().trim(); 84 if(prinName !=null && ! "".equals(prinName)){ 86 addGoodDetails(result, compName); 87 result.passed(smh.getLocalString 88 (getClass().getName() + ".passed1", 89 "PASSED [AS-WEB security-role-mapping] principal-name [ {0} ] properly defined in the war file.", 90 new Object [] {prinName})); 91 }else{ 92 addErrorDetails(result, compName); 93 result.failed(smh.getLocalString 94 (getClass().getName() + ".failed1", 95 "FAILED [AS-WEB security-role-mapping] principal-name [ {0} ] cannot be empty string.", 96 new Object [] {prinName})); 97 oneFailed = true; 98 99 } 100 } 101 } 102 if (grpNames !=null && grpNames.size() > 0) { 103 String grpName; 104 for (int rep1=0; rep1<grpNames.size(); rep1++ ) { 105 grpName =grpNames.get(rep1).trim(); 107 if(grpName !=null && ! "".equals(grpName)){ 109 addGoodDetails(result, compName); 110 result.passed(smh.getLocalString 111 (getClass().getName() + ".passed2", 112 "PASSED [AS-WEB security-role-mapping] group-name [ {0} ] properly defined in the war file.", 113 new Object [] {grpName})); 114 115 }else{ 116 117 addErrorDetails(result, compName); 118 result.failed(smh.getLocalString 119 (getClass().getName() + ".failed2", 120 "FAILED [AS-WEB security-role-mapping] group-name [ {0} ] cannot be an empty string.", 121 new Object [] {grpName})); 122 oneFailed = true; 123 124 } 125 } 126 } 127 128 } 129 } else { 130 addNaDetails(result, compName); 131 result.notApplicable(smh.getLocalString 132 (getClass().getName() + ".notApplicable", 133 "NOT APPLICABLE [AS-WEB sun-web-app] security-role-mapping element not defined in the web archive [ {0} ].", 134 new Object [] {descriptor.getName()})); 135 return result; 136 } 137 138 if (oneFailed){ 139 result.setStatus(Result.FAILED); 140 } else { 141 result.setStatus(Result.PASSED); 142 addGoodDetails(result, compName); 143 result.passed 144 (smh.getLocalString 145 (getClass().getName() + ".passed3", 146 "PASSED [AS-WEB sun-web-app] security-role-mapping element(s) are valid within the web archive [ {0} ].", 147 new Object [] {descriptor.getName()} )); 148 } 149 }catch(Exception ex){ 150 oneFailed = true; 151 addErrorDetails(result, compName); 152 result.failed(smh.getLocalString 153 (getClass().getName() + ".failed3", 154 "FAILED [AS-WEB security-role-mapping] could not create the security-role-mapping object")); 155 156 } 157 return result; 158 } 159 boolean validRoleName(String roleName, WebBundleDescriptor descriptor){ 160 boolean valid=false; 161 if (roleName != null && roleName.length() != 0) { 162 Enumeration roles = descriptor.getSecurityRoles(); 163 while (roles!=null && roles.hasMoreElements()) { 165 SecurityRoleDescriptor roleDesc = (SecurityRoleDescriptor) roles.nextElement(); 166 String thisRoleName = roleDesc.getName(); 167 if (roleName.equals(thisRoleName)) { 168 valid = true; 169 break; 170 } 171 } 172 176 } 177 return valid; 178 } 179 } 180 181 | Popular Tags |