KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.logging.Level JavaDoc;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32
33 /**
34  * The role-link element is used to link a security role reference to a
35  * defined security role. The role-link element must contain the name of
36  * one of the security roles defined in the security-role elements.
37  */

38 public class RoleLink extends WebTest implements WebCheck {
39
40     /**
41      * The role-link element is used to link a security role reference to a
42      * defined security role. The role-link element must contain the name of
43      * one of the security roles defined in the security-role elements.
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.getWebComponentDescriptors().hasMoreElements()) {
55         boolean oneFailed = false;
56             int na = 0;
57             int noWd = 0;
58         for (Enumeration e = descriptor.getWebComponentDescriptors(); e.hasMoreElements();) {
59                 noWd++;
60         WebComponentDescriptor next = (WebComponentDescriptor) e.nextElement();
61         boolean foundIt = false;
62         // get the security role-link's in this .war
63
if (next.getSecurityRoleReferences().hasMoreElements()) {
64             for (Enumeration ee = next.getSecurityRoleReferences(); ee.hasMoreElements();) {
65             RoleReference rr = (RoleReference) ee.nextElement();
66             foundIt = false;
67             String JavaDoc linkName = rr.getValue();
68                         logger.log(Level.FINE, "servlet linkName: " + linkName);
69             // now check to see if role-link exist in security role names
70
if (descriptor.getSecurityRoles().hasMoreElements()) {
71                 for (Enumeration eee = descriptor.getSecurityRoles(); eee.hasMoreElements();) {
72                 SecurityRoleDescriptor srdNext = (SecurityRoleDescriptor) eee.nextElement();
73
74                 if (linkName.equals(srdNext.getName())) {
75                     foundIt = true;
76                     break;
77                 } else {
78                     continue;
79                 }
80                 }
81             } else {
82                 // if descriptor.getSecurityRoles().hasMoreElements())
83
foundIt = false;
84             }
85
86             if (foundIt) {
87                 result.addGoodDetails(smh.getLocalString
88                        ("tests.componentNameConstructor",
89                     "For [ {0} ]",
90                     new Object JavaDoc[] {compName.toString()}));
91                 result.addGoodDetails(smh.getLocalString
92                           (getClass().getName() + ".passed",
93                            "role-link [ {0} ] links security role reference to a defined security role within web application [ {1} ]",
94                            new Object JavaDoc[] {linkName, descriptor.getName()}));
95             } else {
96                 if (!oneFailed) {
97                 oneFailed = true;
98                 }
99                 result.addErrorDetails(smh.getLocalString
100                        ("tests.componentNameConstructor",
101                     "For [ {0} ]",
102                     new Object JavaDoc[] {compName.toString()}));
103                 result.addErrorDetails(smh.getLocalString
104                            (getClass().getName() + ".failed",
105                             "Error: role-link [ {0} ] does not link security role reference to a defined security role within web application [ {1} ]",
106                             new Object JavaDoc[] {linkName, descriptor.getName()}));
107             }
108             } // for loop next.getSecurityRoleReferences() has more elements
109
} else {
110             result.addNaDetails(smh.getLocalString
111                        ("tests.componentNameConstructor",
112                     "For [ {0} ]",
113                     new Object JavaDoc[] {compName.toString()}));
114             result.addNaDetails(smh.getLocalString
115                     (getClass().getName() + ".notApplicable1",
116                      "[ {0} ] has no role-link element defined within the web archive [ {1} ]",
117                      new Object JavaDoc[] {next.getName(),descriptor.getName()}));
118                     na++;
119         }
120         } // for loop descriptor.getWebComponentDescriptors(); e.hasMoreElements()
121
if (oneFailed) {
122         result.setStatus(Result.FAILED);
123             } else if (na == noWd) {
124                 result.setStatus(Result.NOT_APPLICABLE);
125         } else {
126         result.setStatus(Result.PASSED);
127         }
128     } else {
129         result.addNaDetails(smh.getLocalString
130                        ("tests.componentNameConstructor",
131                     "For [ {0} ]",
132                     new Object JavaDoc[] {compName.toString()}));
133         result.notApplicable(smh.getLocalString
134                  (getClass().getName() + ".notApplicable",
135                   "There are no location elements within the web archive [ {0} ]",
136                   new Object JavaDoc[] {descriptor.getName()}));
137     }
138
139     return result;
140     }
141 }
142
Popular Tags