KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > ejb > ias > ASEjbIORSecurityConfig


1 package com.sun.enterprise.tools.verifier.tests.ejb.ias;
2
3 /*
4  * The contents of this file are subject to the terms
5  * of the Common Development and Distribution License
6  * (the License). You may not use this file except in
7  * compliance with the License.
8  *
9  * You can obtain a copy of the license at
10  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
11  * glassfish/bootstrap/legal/CDDLv1.0.txt.
12  * See the License for the specific language governing
13  * permissions and limitations under the License.
14  *
15  * When distributing Covered Code, include this CDDL
16  * Header Notice in each file and include the License file
17  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
18  * If applicable, add the following below the CDDL Header,
19  * with the fields enclosed by brackets [] replaced by
20  * you own identifying information:
21  * "Portions Copyrighted [year] [name of copyright owner]"
22  *
23  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
24  */

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 /** ejb [0,n]
43  * ior-security-config ?
44  * transport-config?
45  * integrity [String]
46  * confidentiality [String]
47  * establish-trust-in-client [String]
48  * establish-trust-in-target [String]
49  * as-context?
50  * auth-method [String]
51  * realm [String]
52  * required [String]
53  * sas-context?
54  * caller-propagation [String]
55  *
56  * The tag describes the security configuration for the IOR
57  * @author Irfan Ahmed
58  */

59 public class ASEjbIORSecurityConfig extends EjbTest implements EjbCheck {
60     boolean oneFailed = false;
61
62     /** The function that performs the test.
63      *
64      * @param descriptor EjbDescriptor object representing the bean.
65      */

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     /** This function tests the <transport-config> tag for valid values
135      *
136      * @param tConfig TransportConfig - The object representing the <transport-config> tag
137      * @param result Result - The Result object
138      */

139     protected void testTranConfig(TransportConfig tConfig , Result result)
140     {
141         //integrity
142
String JavaDoc integrity = tConfig.getIntegrity();
143         testMsgs(integrity,result,"transport-config","integrity");
144         
145         //confidentiality
146
String JavaDoc confdn = tConfig.getConfidentiality();
147         testMsgs(confdn,result,"transport-config","confidentiality");
148         
149         //establish-trust-in-target
150
String JavaDoc trustTarget = tConfig.getEstablishTrustInTarget();
151         testMsgs(trustTarget,result,"transport-config","extablish-trust-in-target");
152         
153         //establish-trust-in-client
154
String JavaDoc trustClient = tConfig.getEstablishTrustInClient();
155         testMsgs(trustClient,result,"transport-config","establish-trust-in-client");
156     }
157     
158     /** The function tests the <as-context> tag in <transport-config> for
159      * valid values
160      * @param aContext AsContext object representing the <as-context> tag
161      * @param result Result object
162      */

163     protected void testAsContext(AsContext aContext, Result result)
164     {
165         //auth-method
166
String JavaDoc 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 JavaDoc[] {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 JavaDoc[]{value}));
186             }
187         }
188         
189         //realm
190
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 JavaDoc[] {value}));
201         }
202         
203         //required
204
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 JavaDoc[] {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 JavaDoc[]{value}));
224             }
225         }
226         
227     }
228     
229     /**
230      * @param sContext
231      * @param result */

232     protected void testSasContext(SasContext sContext, Result result)
233     {
234         String JavaDoc caller = sContext.getCallerPropagation();
235         testMsgs(caller,result,"sas-context","caller-propagation");
236     }
237     
238     private void testMsgs(String JavaDoc tCase, Result result, String JavaDoc parentElement, String JavaDoc 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 JavaDoc[]{tCase}));
255             }
256             else
257                 result.passed(smh.getLocalString(getClass().getName()+".passedTestMsg",
258                     "PASSED [AS-EJB "+ parentElement+"] : " + testElement +" is {0}", new Object JavaDoc[]{tCase}));
259         }
260     }
261     
262 }
263
Popular Tags