KickJava   Java API By Example, From Geeks To Geeks.

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

39 //</addition>
40

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

176           }
177           return valid;
178     }
179 }
180
181
Popular Tags