1 package com.sun.enterprise.tools.verifier.tests.ejb.ias; 2 3 25 26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest; 27 import java.util.*; 28 import com.sun.enterprise.deployment.EjbDescriptor; 29 import com.sun.enterprise.deployment.EjbSessionDescriptor; 30 import com.sun.enterprise.tools.verifier.*; 31 import com.sun.enterprise.tools.verifier.tests.*; 32 33 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck; 34 35 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 36 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 37 import com.sun.enterprise.tools.common.dd.ejb.TransportConfig; 38 import com.sun.enterprise.tools.common.dd.ejb.AsContext; 39 import com.sun.enterprise.tools.common.dd.ejb.SasContext; 40 import com.sun.enterprise.tools.common.dd.ejb.IorSecurityConfig; 41 42 59 public class ASEjbIORSecurityConfig extends EjbTest implements EjbCheck { 60 boolean oneFailed = false; 61 62 66 public Result check(EjbDescriptor descriptor) 67 { 68 Result result = getInitializedResult(); 69 ComponentNameConstructor compName = new ComponentNameConstructor(descriptor); 70 71 SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject(); 72 73 if(ejbJar!=null) 74 { 75 Ejb ejbs[] = ejbJar.getEnterpriseBeans().getEjb(); 76 Ejb testCase = null; 77 for(int i=0;i<ejbs.length;i++) 78 { 79 if(ejbs[i].getEjbName().equals(descriptor.getName())) 80 { 81 testCase = ejbs[i]; 82 break; 83 } 84 } 85 86 IorSecurityConfig iorSec = testCase.getIorSecurityConfig(); 87 if(iorSec == null) 88 { 89 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 90 "NOT APPLICABLE [AS-EJB ior-security-config] : ior-security-config Element not defined")); 91 } 92 else 93 { 94 TransportConfig tranConfig = iorSec.getTransportConfig(); 95 if(tranConfig != null) 96 testTranConfig(tranConfig,result); 97 else 98 { 99 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 100 "NOT APPLICABLE [AS-EJB ior-security-config] : transport-config Element not defined")); 101 } 102 103 AsContext asContext = iorSec.getAsContext(); 104 if(asContext != null) 105 testAsContext(asContext,result); 106 else 107 { 108 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 109 "NOT APPLICABLE [AS-EJB ior-security-config] : as-context Element not defined")); 110 } 111 112 SasContext sasContext = iorSec.getSasContext(); 113 if(sasContext != null) 114 testSasContext(sasContext,result); 115 else 116 { 117 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable", 118 "NOT APPLICABLE [AS-EJB ior-security-config] : sas-context Element not defined")); 119 } 120 121 } 122 if(oneFailed) 123 result.setStatus(Result.FAILED); 124 } 125 else 126 { 127 result.addErrorDetails(smh.getLocalString 128 (getClass().getName() + ".notRun", 129 "NOT RUN [AS-EJB] : Could not create an SunEjbJar object")); 130 } 131 return result; 132 } 133 134 139 protected void testTranConfig(TransportConfig tConfig , Result result) 140 { 141 String integrity = tConfig.getIntegrity(); 143 testMsgs(integrity,result,"transport-config","integrity"); 144 145 String confdn = tConfig.getConfidentiality(); 147 testMsgs(confdn,result,"transport-config","confidentiality"); 148 149 String trustTarget = tConfig.getEstablishTrustInTarget(); 151 testMsgs(trustTarget,result,"transport-config","extablish-trust-in-target"); 152 153 String trustClient = tConfig.getEstablishTrustInClient(); 155 testMsgs(trustClient,result,"transport-config","establish-trust-in-client"); 156 } 157 158 163 protected void testAsContext(AsContext aContext, Result result) 164 { 165 String value = aContext.getAuthMethod(); 167 if(value.length()==0) 168 { 169 oneFailed = true; 170 result.failed(smh.getLocalString(getClass().getName()+".failedAsContextAuthMethod", 171 "FAILED [AS-EJB as-context] : auth-method cannotb be an empty string")); 172 } 173 else 174 { 175 if(value.equals("USERNAME_PASSWORD")) 176 { 177 result.passed(smh.getLocalString(getClass().getName()+".passedAsContextAuthMethod", 178 "PASSED [AS-EJB as-context] : auth-method is {0}", new Object [] {value})); 179 } 180 else 181 { 182 oneFailed = true; 183 result.failed(smh.getLocalString(getClass().getName()+".failedAsContextAuthMethod1", 184 "FAILED [AS-EJB as-context] : auth-method cannot be {0}. It can only be USERNAME_PASSWORD" 185 ,new Object []{value})); 186 } 187 } 188 189 value = aContext.getRealm(); 191 if(value.length()==0) 192 { 193 oneFailed = true; 194 result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRealm", 195 "FAILED [AS-EJB as-context] : realm cannot be an empty string")); 196 } 197 else 198 { 199 result.passed(smh.getLocalString(getClass().getName()+".passedAsContextRealm", 200 "PASSED [AS-EJB as-context] : realm is {0}", new Object [] {value})); 201 } 202 203 value = aContext.getRequired(); 205 if(value.length()==0) 206 { 207 oneFailed = true; 208 result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRequired", 209 "FAILED [AS-EJB as-context] : required cannot be an empty string")); 210 } 211 else 212 { 213 if(value.equals("true") || value.equals("false")) 214 { 215 result.passed(smh.getLocalString(getClass().getName()+".passedAsContextRequired", 216 "PASSED [AS-EJB as-context] : required is {0}", new Object [] {value})); 217 } 218 else 219 { 220 oneFailed = true; 221 result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRequired1", 222 "FAILED [AS-EJB as-context] : required cannot be {0}. It can only be true or false" 223 ,new Object []{value})); 224 } 225 } 226 227 } 228 229 232 protected void testSasContext(SasContext sContext, Result result) 233 { 234 String caller = sContext.getCallerPropagation(); 235 testMsgs(caller,result,"sas-context","caller-propagation"); 236 } 237 238 private void testMsgs(String tCase, Result result, String parentElement, String testElement) 239 { 240 if(tCase.length()==0) 241 { 242 oneFailed = true; 243 result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg", 244 "FAILED [AS-EJB " + parentElement + "] : " + testElement + " cannot be an empty String")); 245 } 246 else 247 { 248 if(!tCase.equals("NONE") && !tCase.equals("SUPPORTED") 249 && !tCase.equals("REQUIRED")) 250 { 251 oneFailed = true; 252 result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg", 253 "FAILED [AS-EJB " + parentElement+"] : "+testElement+" cannot be {0}. It can be either NONE, SUPPORTED or REQUIRED", 254 new Object []{tCase})); 255 } 256 else 257 result.passed(smh.getLocalString(getClass().getName()+".passedTestMsg", 258 "PASSED [AS-EJB "+ parentElement+"] : " + testElement +" is {0}", new Object []{tCase})); 259 } 260 } 261 262 } 263 | Popular Tags |