KickJava   Java API By Example, From Geeks To Geeks.

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


1 package com.sun.enterprise.tools.verifier.tests.ejb.runtime;
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 com.sun.enterprise.deployment.EjbDescriptor;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30
31 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
32
33 /** ejb [0,n]
34  * ior-security-config ?
35  * transport-config?
36  * integrity [String]
37  * confidentiality [String]
38  * establish-trust-in-client [String]
39  * establish-trust-in-target [String]
40  * as-context?
41  * auth-method [String]
42  * realm [String]
43  * required [String]
44  * sas-context?
45  * caller-propagation [String]
46  *
47  * The tag describes the security configuration for the IOR
48  * @author Irfan Ahmed
49  */

50 public class ASEjbIORSecurityConfig extends EjbTest implements EjbCheck {
51     boolean oneFailed = false;
52
53     /** The function that performs the test.
54      *
55      * @param descriptor EjbDescriptor object representing the bean.
56      */

57     public Result check(EjbDescriptor descriptor)
58     {
59         Result result = getInitializedResult();
60         ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
61         int count = 0;
62         try{
63 // Set ejbIORConfDescSet = descriptor.getIORConfigurationDescriptors();
64
count = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config");
65             if (count>0){
66                 for(int i=0;i<count;i++){
67                     testTranConfig(i, descriptor, compName, result);
68                     testAsContext(i, descriptor, compName, result);
69                     testSasContext(i, descriptor, compName, result);
70                 }
71             }else{
72                 addNaDetails(result, compName);
73                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
74                     "NOT APPLICABLE [AS-EJB ior-security-config] : ior-security-config Element not defined"));
75             }
76
77             if(oneFailed)
78                 result.setStatus(Result.FAILED);
79         }catch(Exception JavaDoc ex){
80             addErrorDetails(result, compName);
81             result.addErrorDetails(smh.getLocalString
82                 (getClass().getName() + ".notRun",
83                 "NOT RUN [AS-EJB] : Could not create a descriptor object"));
84         }
85         return result;
86
87     }
88     /** This function tests the <transport-config> tag for valid values
89      *
90      * @param
91      * @param result Result - The Result object
92      */

93     protected void testTranConfig(int i, EjbDescriptor descriptor, ComponentNameConstructor compName, Result result)
94     {
95         try{
96             int counter = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config/transport-config");
97             if (counter>0){
98                 //integrity
99
String JavaDoc integrity = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/transport-config/integrity");
100                 if (integrity!=null){
101                     testMsgs(integrity,result,"transport-config","integrity", compName);
102                 }
103
104                 //confidentiality
105
String JavaDoc confdn = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/transport-config/confidentiality");
106                 if (confdn!=null){
107                     testMsgs(confdn,result,"transport-config","confidentiality", compName);
108                 }
109
110                 //establish-trust-in-target
111
String JavaDoc trustTarget = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/transport-config/establish-trust-in-target");
112                 if (trustTarget!=null){
113                     testMsgs1(trustTarget,result,"transport-config","extablish-trust-in-target", compName);
114                 }
115
116                 //establish-trust-in-client
117
String JavaDoc trustClient = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/transport-config/establish-trust-in-client");
118                 if (trustClient!=null){
119                     testMsgs(trustClient,result,"transport-config","establish-trust-in-client", compName);
120                 }
121             }else{
122                 addNaDetails(result, compName);
123                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable1",
124                     "NOT APPLICABLE [AS-EJB ior-security-config] : transport-config Element not defined"));
125             }
126         }catch(Exception JavaDoc ex){
127             oneFailed = true;
128             addErrorDetails(result, compName);
129             result.addErrorDetails(smh.getLocalString
130                 (getClass().getName() + ".notRun",
131                 "NOT RUN [AS-EJB] : Could not create a descriptor object"));
132         }
133     }
134     /** The function tests the <as-context> tag for valid values
135      *
136      * @param
137      * @param result Result object
138      */

139     protected void testAsContext(int i, EjbDescriptor descriptor, ComponentNameConstructor compName, Result result)
140     {
141         try{
142             int counter = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config/as-context");
143             if (counter>0){
144                 //auth-method
145
String JavaDoc value = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/as-context/auth-method");
146                 if(value==null || value.length()==0){
147                     oneFailed = true;
148                     addErrorDetails(result, compName);
149                     result.failed(smh.getLocalString(getClass().getName()+".failedAsContextAuthMethod",
150                         "FAILED [AS-EJB as-context] : auth-method cannot be an empty string"));
151                 }else{
152                     if(value.equals("USERNAME_PASSWORD")){
153                         addGoodDetails(result, compName);
154                         result.passed(smh.getLocalString(getClass().getName()+".passedAsContextAuthMethod",
155                             "PASSED [AS-EJB as-context] : auth-method is {0}", new Object JavaDoc[] {value}));
156                     }else{
157                         oneFailed = true;
158                         addErrorDetails(result, compName);
159                         result.failed(smh.getLocalString(getClass().getName()+".failedAsContextAuthMethod1",
160                             "FAILED [AS-EJB as-context] : auth-method cannot be {0}. It can only be USERNAME_PASSWORD"
161                             ,new Object JavaDoc[]{value}));
162                     }
163                 }
164                 //realm
165
value = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/as-context/realm");
166                 if (value != null){
167                     if(value.length()==0){
168                         oneFailed = true;
169                         addErrorDetails(result, compName);
170                         result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRealm",
171                             "FAILED [AS-EJB as-context] : realm cannot be an empty string"));
172
173                     }else{
174                         addGoodDetails(result, compName);
175                         result.passed(smh.getLocalString(getClass().getName()+".passedAsContextRealm",
176                             "PASSED [AS-EJB as-context] : realm is {0}", new Object JavaDoc[] {value}));
177                     }
178                 } else {
179                     oneFailed = true;
180                         addErrorDetails(result, compName);
181                         result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRealm1",
182                             "FAILED [AS-EJB as-context] : realm cannot be null"));
183                 }
184                 //required
185
value = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/as-context/required");
186                 if(value==null || value.length()==0){
187                     oneFailed = true;
188                     addErrorDetails(result, compName);
189                     result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRequired1",
190                         "FAILED [AS-EJB as-context] : required cannot be an empty string"));
191                 }else{
192                     if(value.equals("true") || value.equals("false")){
193                         addGoodDetails(result, compName);
194                         result.passed(smh.getLocalString(getClass().getName()+".passedAsContextRequired",
195                             "PASSED [AS-EJB as-context] : required is {0}", new Object JavaDoc[]{new Boolean JavaDoc(value)}));
196                     }else{
197                         oneFailed = true;
198                         addErrorDetails(result, compName);
199                         result.failed(smh.getLocalString(getClass().getName()+".failedAsContextRequired2",
200                             "FAILED [AS-EJB as-context] : required cannot be {0}. It can only be USERNAME_PASSWORD"
201                             ,new Object JavaDoc[]{value}));
202                     }
203                 }
204             }else{
205                 addNaDetails(result, compName);
206                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable2",
207                     "NOT APPLICABLE [AS-EJB ior-security-config] : Element not defined"));
208             }
209
210         }catch(Exception JavaDoc ex){
211             oneFailed = true;
212             addErrorDetails(result, compName);
213             result.addErrorDetails(smh.getLocalString
214                 (getClass().getName() + ".notRun",
215                 "NOT RUN [AS-EJB] : Could not create a descriptor object"));
216         }
217         
218     }
219     /**
220      * @param
221      * @param result */

222     protected void testSasContext(int i, EjbDescriptor descriptor, ComponentNameConstructor compName, Result result)
223     {
224         try{
225             int counter = getCountNodeSet("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config/sas-context");
226             if (counter>0){
227                 String JavaDoc caller = getXPathValue("sun-ejb-jar/enterprise-beans/ejb[ejb-name=\""+descriptor.getName()+"\"]/ior-security-config[\""+i+"\"]/sas-context/caller-propagation");
228                 if (caller!=null){
229                     testMsgs1(caller,result,"sas-context","caller-propagation", compName);
230                 }
231             }
232         }catch(Exception JavaDoc ex){
233             oneFailed = true;
234             addErrorDetails(result, compName);
235             result.addErrorDetails(smh.getLocalString
236                 (getClass().getName() + ".notRun",
237                 "NOT RUN [AS-EJB] : Could not create a descriptor object"));
238         }
239     }
240     
241     private void testMsgs(String JavaDoc tCase, Result result, String JavaDoc parentElement, String JavaDoc testElement, ComponentNameConstructor compName)
242     {
243         if(tCase.length()==0)
244         {
245             oneFailed = true;
246             addErrorDetails(result, compName);
247             result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg",
248                 "FAILED [AS-EJB {1}] : {2} cannot be an empty String",
249                 new Object JavaDoc[]{tCase, parentElement, testElement}));
250         }
251         else
252         {
253             if(!tCase.equals("NONE") && !tCase.equals("SUPPORTED")
254                 && !tCase.equals("REQUIRED"))
255             {
256                 oneFailed = true;
257                 addErrorDetails(result, compName);
258                 result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg1",
259                     "FAILED [AS-EJB {1}] : {2} cannot be {0}. It can be either NONE, SUPPORTED or REQUIRED",
260                     new Object JavaDoc[]{tCase, parentElement, testElement}));
261             }
262             else {
263                 addGoodDetails(result, compName);
264                 result.passed(smh.getLocalString(getClass().getName()+".passedTestMsg",
265                     "PASSED [AS-EJB "+ parentElement+"] : " + testElement +" is {0}", new Object JavaDoc[]{tCase}));
266             }
267         }
268     }
269     
270     /**
271      * This method will check for values that should be either NONE or SUPPORTED
272      */

273     private void testMsgs1(String JavaDoc tCase, Result result, String JavaDoc parentElement, String JavaDoc testElement, ComponentNameConstructor compName)
274     {
275         if(tCase.length()==0)
276         {
277             oneFailed = true;
278             addErrorDetails(result, compName);
279             result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg",
280                 "FAILED [AS-EJB {1}] : {2} cannot be an empty String",
281                 new Object JavaDoc[]{tCase, parentElement, testElement}));
282         }
283         else
284         {
285             if(!tCase.equals("NONE") && !tCase.equals("SUPPORTED"))
286             {
287                 oneFailed = true;
288                 addErrorDetails(result, compName);
289                 result.failed(smh.getLocalString(getClass().getName()+".failedTestMsg2",
290                     "FAILED [AS-EJB {1}] : {2} cannot be {0}. It can be either NONE or SUPPORTED.",
291                     new Object JavaDoc[]{tCase, parentElement, testElement}));
292             }
293             else {
294                 addGoodDetails(result, compName);
295                 result.passed(smh.getLocalString(getClass().getName()+".passedTestMsg",
296                     "PASSED [AS-EJB "+ parentElement+"] : " + testElement +" is {0}", new Object JavaDoc[]{tCase}));
297             }
298         }
299     }
300 }
301
Popular Tags