KickJava   Java API By Example, From Geeks To Geeks.

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


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

26
27 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
28 import java.util.*;
29 import com.sun.enterprise.deployment.EjbDescriptor;
30 import com.sun.enterprise.deployment.EjbSessionDescriptor;
31 import com.sun.enterprise.tools.verifier.*;
32 import com.sun.enterprise.tools.verifier.tests.*;
33
34 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
35
36 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar;
37 import com.sun.enterprise.tools.common.dd.ejb.EnterpriseBeans;
38 import com.sun.enterprise.tools.common.dd.ejb.Ejb;
39 import com.sun.enterprise.deployment.EjbEntityDescriptor;
40 import com.sun.enterprise.deployment.EjbSessionDescriptor;
41 import com.sun.enterprise.tools.common.dd.SecurityRoleMapping;
42 import com.sun.enterprise.security.acl.Role;
43 import java.lang.reflect.*;
44
45 /** ias-ejb-jar
46  * security-role-mapping [0,n]
47  * role-name [String]
48  * principal-name [String] | group-name [String]
49  *
50  * The element defines the security role mappings for the bean.
51  * The role-name should not be an empty string
52  * The role-name should be desclared in the assembly-descriptor in the ejb-jar.xml
53  * file.
54  * The principal-name and group-name should not be empty strings.
55  *
56  * @author Irfan Ahmed
57  */

58 public class ASSecurityRoleMapping extends EjbTest implements EjbCheck {
59
60     public Result check(EjbDescriptor descriptor)
61     {
62         Result result = getInitializedResult();
63     ComponentNameConstructor compName = new ComponentNameConstructor(descriptor);
64         boolean oneFailed = false;
65         SunEjbJar ejbJar = descriptor.getEjbBundleDescriptor().getIasEjbObject();
66         
67         if(descriptor.getEjbBundleDescriptor().getTestsDone().contains(getClass().getName()))
68         {
69             result.setStatus(Result.NOT_RUN);
70             result.addGoodDetails(smh.getLocalString("iasEjbJar.allReadyRun",
71                 "NOT RUN [AS-EJB ias-ejb-jar] security-role-mapping is a JAR Level Test. This test has already been run once"));
72             return result;
73         }
74         descriptor.getEjbBundleDescriptor().setTestsDone(getClass().getName());
75         
76         if(ejbJar!=null)
77         {
78             SecurityRoleMapping secRoleMapping[] = ejbJar.getSecurityRoleMapping();
79             if(secRoleMapping.length>0)
80             {
81                 for(int i=0;i<secRoleMapping.length;i++)
82                 {
83                     String JavaDoc roleName = secRoleMapping[i].getRoleName();
84                     if(roleName.length()==0)
85                     {
86                         oneFailed = true;
87                         result.failed(smh.getLocalString(getClass().getName()+".failed",
88                             "FAILED [AS-EJB security-role-mapping] : role-name cannot be an empty string",
89                             new Object JavaDoc[]{new Integer JavaDoc(i)}));
90                     }
91                     else
92                     {
93                         boolean roleNameFound = false;
94                         Set roles = descriptor.getEjbBundleDescriptor().getRoles();
95                         Iterator it = roles.iterator();
96                         while(it.hasNext())
97                         {
98                             Role role = (Role)it.next();
99                             if(role.getName().equals(roleName))
100                             {
101                                 roleNameFound = true;
102                                 break;
103                             }
104                         }
105                         if(roleNameFound)
106                         {
107                             result.passed(smh.getLocalString(getClass().getName()+".passed",
108                                 "PASSED [AS-EJB security-role-mapping] : role-name {1} verified with ejb-jar.xml",
109                                 new Object JavaDoc[]{new Integer JavaDoc(i), roleName}));
110                         }
111                         else
112                         {
113                             oneFailed = true;
114                             //<addition> srini@sun.com Bug: 4721914
115
//result.failed(smh.getLocalString(getClass().getName()+".failed",
116
result.failed(smh.getLocalString(getClass().getName()+".failed1",
117                                 "FAILED [AS-EJB security-role-mapping] : role-name {1} could not be located in ejb-jar.xml",
118                                 new Object JavaDoc[]{new Integer JavaDoc(i), roleName}));
119                             //<addition>
120
}
121                     }
122
123                     String JavaDoc pName[] = secRoleMapping[i].getPrincipalName();
124                     for(int j=0;j<pName.length;j++)
125                     {
126                         if(pName[j].length()==0)
127                         {
128                             oneFailed = true;
129                             //<addition> srini@sun.com Bug: 4721914
130
//result.failed(smh.getLocalString(getClass().getName()+".failed",
131
result.failed(smh.getLocalString(getClass().getName()+".failed2",
132                                 "FAILED [AS-EJB security-role-mapping] : principal-name cannot be empty string",
133                                 new Object JavaDoc[]{new Integer JavaDoc(i)}));
134                             //<addition>
135
}
136                         else
137                         {
138                             //<addition> srini@sun.com Bug: 4721914
139
//result.passed(smh.getLocalString(getClass().getName()+".passed",
140
result.passed(smh.getLocalString(getClass().getName()+".passed1",
141                                 "PASSED [AS-EJB security-role-mapping] : principal-name is {1}",
142                                 new Object JavaDoc[]{new Integer JavaDoc(i),pName[j]}));
143                             //<addition>
144
}
145                     }
146
147                     pName = secRoleMapping[i].getGroupName();
148                     for(int j=0;j<pName.length;j++)
149                     {
150                         if(pName[j].length()==0)
151                         {
152                             oneFailed = true;
153                             //<addition> srini@sun.com Bug: 4721914
154
//result.failed(smh.getLocalString(getClass().getName()+".failed",
155
result.failed(smh.getLocalString(getClass().getName()+".failed3",
156                                 "FAILED [AS-EJB security-role-mapping] : group-name cannot be empty string",
157                                 new Object JavaDoc[]{new Integer JavaDoc(i)}));
158                             //<addition>
159
}
160                         else
161                         {
162                             //<addition> srini@sun.com Bug: 4721914
163
//result.passed(smh.getLocalString(getClass().getName()+".passed",
164
result.passed(smh.getLocalString(getClass().getName()+".passed2",
165                                 "PASSED [AS-EJB security-role-mapping] : group-name is {1}",
166                                 new Object JavaDoc[]{new Integer JavaDoc(i),pName[j]}));
167                             //<addition>
168
}
169                     }
170                 }
171             }
172             else
173             {
174                 result.notApplicable(smh.getLocalString(getClass().getName()+".notApplicable",
175                     "NOT APPLICABLE [AS-EJB] : security-role-mapping element is not defined"));
176             }
177             if(oneFailed)
178                 result.setStatus(Result.FAILED);
179         }
180         else
181         {
182             result.addErrorDetails(smh.getLocalString
183                                    ("tests.componentNameConstructor",
184                                     "For [ {0} ]",
185                                     new Object JavaDoc[] {compName.toString()}));
186             result.addErrorDetails(smh.getLocalString
187                  (getClass().getName() + ".notRun",
188                   "NOT RUN [AS-EJB] : Could not create an SunEjbJar object"));
189         }
190         return result;
191     }
192 }
193         
194
Popular Tags