KickJava   Java API By Example, From Geeks To Geeks.

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


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
24
25 package com.sun.enterprise.tools.verifier.tests.web.ias;
26
27
28 import com.sun.enterprise.tools.verifier.tests.web.elements.*;
29 import com.sun.enterprise.tools.verifier.tests.web.WebTest;
30 import com.sun.enterprise.tools.verifier.tests.web.WebCheck;
31 import java.util.*;
32 import com.sun.enterprise.deployment.*;
33 import com.sun.enterprise.tools.verifier.*;
34 import com.sun.enterprise.tools.verifier.tests.*;
35 import com.sun.enterprise.tools.common.dd.webapp.*;
36 import com.sun.enterprise.tools.common.dd.*;
37
38 //<addition author="irfan@sun.com" [bug/rfe]-id="4711198" >
39
/* Changed the result messages to reflect consistency between the result messages generated
40  * for the EJB test cases for SunONE specific deployment descriptors*/

41 //</addition>
42

43 public class ASSecurityRoleMapping extends WebTest implements WebCheck {
44
45
46
47     public Result check(WebBundleDescriptor descriptor) {
48
49     Result result = getInitializedResult();
50     WebComponentNameConstructor compName = new WebComponentNameConstructor(descriptor);
51         SecurityRoleMapping[] secRoleMapp = descriptor.getIasWebApp().getSecurityRoleMapping();
52         String JavaDoc roleName;
53         String JavaDoc prinNames[];
54         String JavaDoc grpNames[];
55     boolean oneFailed = false;
56
57         //System.out.println(">>>>>>>>>>>>> count of refs are "+ejbRefs.length);
58
if (secRoleMapp !=null && secRoleMapp.length > 0) {
59         for (int rep=0; rep<secRoleMapp.length; rep++ ) {
60
61                 roleName=secRoleMapp[rep].getRoleName();
62                 prinNames=secRoleMapp[rep].getPrincipalName();
63                 grpNames=secRoleMapp[rep].getGroupName();
64
65                 if(validRoleName(roleName,descriptor)){
66
67                   result.passed(smh.getLocalString
68                       (getClass().getName() + ".passed",
69                        "PASSED [AS-WEB security-role-mapping] role-name [ {0} ] properly defined in the war file.",
70                        new Object JavaDoc[] {roleName}));
71
72                   }else{
73
74                   result.failed(smh.getLocalString
75                        (getClass().getName() + ".failed",
76                         "FAILED [AS-WEB security-role-mapping] role-name [ {0} ] is not valid, either empty or not defined in web.xml.",
77                         new Object JavaDoc[] {roleName}));
78                   oneFailed = true;
79
80                   }
81
82                 if (prinNames !=null && prinNames.length > 0) {
83                   String JavaDoc prinName;
84                   for (int rep1=0; rep1<prinNames.length; rep1++ ) {
85                       // <addition> srini@sun.com Bug : 4699658
86
//prinName = prinNames[rep1];
87
prinName = prinNames[rep1].trim();
88                       // </addition>
89
if(prinName !=null && ! "".equals(prinName)){
90
91                       result.passed(smh.getLocalString
92                       (getClass().getName() + ".passed1",
93                        "PASSED [AS-WEB security-role-mapping] principal-name [ {0} ] properly defined in the war file.",
94                        new Object JavaDoc[] {prinName}));
95                       }else{
96
97                       result.failed(smh.getLocalString
98                        (getClass().getName() + ".failed1",
99                         "FAILED [AS-WEB security-role-mapping] principal-name [ {0} ] cannot be empty string.",
100                         new Object JavaDoc[] {prinName}));
101                       oneFailed = true;
102
103                       }
104                     }
105                 }
106
107                 if (grpNames !=null && grpNames.length > 0) {
108                   String JavaDoc grpName;
109                   for (int rep1=0; rep1<grpNames.length; rep1++ ) {
110                       // <addition> srini@sun.com Bug : 4699658
111
//grpName =grpNames[rep1];
112
grpName =grpNames[rep1].trim();
113                       // </addition>
114
if(grpName !=null && ! "".equals(grpName)){
115                       result.passed(smh.getLocalString
116                       (getClass().getName() + ".passed2",
117                        "PASSED [AS-WEB security-role-mapping] group-name [ {0} ] properly defined in the war file.",
118                        new Object JavaDoc[] {grpName}));
119
120                       }else{
121
122                       result.failed(smh.getLocalString
123                        (getClass().getName() + ".failed2",
124                         "FAILED [AS-WEB security-role-mapping] group-name [ {0} ] cannot be an empty string.",
125                         new Object JavaDoc[] {grpName}));
126                       oneFailed = true;
127
128                       }
129                     }
130                 }
131
132           }
133          } else {
134         result.notApplicable(smh.getLocalString
135                  (getClass().getName() + ".notApplicable",
136                   "NOT APPLICABLE [AS-WEB sun-web-app] security-role-mapping element not defined in the web archive [ {0} ].",
137                   new Object JavaDoc[] {descriptor.getName()}));
138         return result;
139     }
140
141     if (oneFailed){
142         result.setStatus(Result.FAILED);
143         } else {
144                 result.setStatus(Result.PASSED);
145         result.passed
146             (smh.getLocalString
147              (getClass().getName() + ".passed3",
148               "PASSED [AS-WEB sun-web-app] security-role-mapping element(s) are valid within the web archive [ {0} ].",
149                             new Object JavaDoc[] {descriptor.getName()} ));
150         }
151     return result;
152     }
153
154     boolean validRoleName(String JavaDoc roleName, WebBundleDescriptor descriptor){
155           boolean valid=false;
156           if (roleName != null && roleName.length() != 0) {
157               Enumeration roles = descriptor.getSecurityRoles();
158                     // test the sec roles in this .war
159
while (roles!=null && roles.hasMoreElements()) {
160                         SecurityRoleDescriptor roleDesc = (SecurityRoleDescriptor) roles.nextElement();
161                         String JavaDoc thisRoleName = roleDesc.getName();
162             if (roleName.equals(thisRoleName)) {
163                             valid = true;
164                             break;
165                         }
166                     }
167                     // to-do vkv#
168
//## roles related to application also needs to be checked, although present application
169
//##descriptor dont have seperate sec roles data-structure, so leaving it for time
170

171           }
172           return valid;
173     }
174 }
175
176
Popular Tags