KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > tools > verifier > tests > web > TransportGuarantee


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

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 /**
35  * The transport-guarantee element specifies that the communication between
36  * client and server should be "SECURE", "NONE", or "CONFIDENTIAL".
37  */

38 public class TransportGuarantee extends WebTest implements WebCheck {
39
40     
41     /**
42      * The transport-guarantee element specifies that the communication between
43      * client and server should be "SECURE", "NONE", or "CONFIDENTIAL".
44      *
45      * @param descriptor the Web deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(WebBundleDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53
54     if (descriptor.getSecurityConstraints().hasMoreElements()) {
55         boolean oneFailed = false;
56         boolean foundIt = false;
57         int na = 0;
58         int noSc = 0;
59         // get the errorpage's in this .war
60
for (Enumeration e = descriptor.getSecurityConstraints() ; e.hasMoreElements() ;) {
61         foundIt = false;
62                 noSc++;
63         SecurityConstraintImpl securityConstraintImpl = (SecurityConstraintImpl) e.nextElement();
64         UserDataConstraintImpl userDataConstraint = (UserDataConstraintImpl) securityConstraintImpl.getUserDataConstraint();
65         if (userDataConstraint != null) {
66                     String JavaDoc transportGuarantee = userDataConstraint.getTransportGuarantee();
67             if (transportGuarantee.length() > 0) {
68                 if ((transportGuarantee.equals("NONE")) ||
69                 (transportGuarantee.equals("INTEGRAL")) ||
70                 (transportGuarantee.equals("CONFIDENTIAL"))) {
71                 foundIt = true;
72                 } else {
73                 foundIt = false;
74                 }
75             } else {
76                 foundIt = false;
77             }
78          
79             if (foundIt) {
80             result.addGoodDetails(smh.getLocalString
81                        ("tests.componentNameConstructor",
82                     "For [ {0} ]",
83                     new Object JavaDoc[] {compName.toString()}));
84                 result.addGoodDetails(smh.getLocalString
85                           (getClass().getName() + ".passed",
86                            "transport-guarantee [ {0} ] specifies that the communication between client and server should be one of \"SECURE\", \"NONE\", or \"CONFIDENTIAL\" within web application [ {1} ]",
87                            new Object JavaDoc[] {transportGuarantee, 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 JavaDoc[] {compName.toString()}));
96                 result.addErrorDetails(smh.getLocalString
97                            (getClass().getName() + ".failed",
98                             "Error: transport-guarantee [ {0} ] does not specify that the communication between client and server is one of \"SECURE\", \"NONE\", or \"CONFIDENTIAL\" within web application [ {1} ]",
99                             new Object JavaDoc[] {transportGuarantee, descriptor.getName()}));
100             }
101             } else {
102             result.addNaDetails(smh.getLocalString
103                        ("tests.componentNameConstructor",
104                     "For [ {0} ]",
105                     new Object JavaDoc[] {compName.toString()}));
106                 result.addNaDetails(smh.getLocalString
107              (getClass().getName() + ".notApplicable1",
108               "There are no transport-guarantee elements within the web application [ {0} ]",
109               new Object JavaDoc[] {descriptor.getName()}));
110                     na++;
111             }
112         }
113         if (oneFailed) {
114         result.setStatus(Result.FAILED);
115         } else if (na == noSc) {
116         result.setStatus(Result.NOT_APPLICABLE);
117         } else {
118         result.setStatus(Result.PASSED);
119         }
120     } else {result.addNaDetails(smh.getLocalString
121                        ("tests.componentNameConstructor",
122                     "For [ {0} ]",
123                     new Object JavaDoc[] {compName.toString()}));
124         result.notApplicable(smh.getLocalString
125                  (getClass().getName() + ".notApplicable",
126                   "There are no transport-guarantee elements within the web archive [ {0} ]",
127                   new Object JavaDoc[] {descriptor.getName()}));
128     }
129
130     return result;
131     }
132 }
133
Popular Tags