KickJava   Java API By Example, From Geeks To Geeks.

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


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.ejb;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import java.util.*;
27 import com.sun.enterprise.deployment.*;
28 import com.sun.enterprise.tools.verifier.*;
29 import com.sun.enterprise.tools.verifier.tests.*;
30 /**
31  * Security role references test.
32  * The Bean provider must declare all of the enterprise's bean references
33  * to security roles as specified in section 15.2.1.3 of the Moscone spec.
34  * Role names must be mapped to names within the jar.
35  */

36 public class SecurityRolesRefs extends EjbTest implements EjbCheck {
37
38
39     /**
40      * Security role references test.
41      * The Bean provider must declare all of the enterprise's bean references
42      * to security roles as specified in section 15.2.1.3 of the Moscone spec.
43      * Role names must be mapped to names within the jar.
44      *
45      * @param descriptor the Enterprise Java Bean deployment descriptor
46      *
47      * @return <code>Result</code> the results for this assertion
48      */

49     public Result check(EjbDescriptor descriptor) {
50
51     Result result = getInitializedResult();
52     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
53     if ((descriptor instanceof EjbEntityDescriptor) ||
54         (descriptor instanceof EjbSessionDescriptor)) {
55         
56         // RULE: Role names must be mapped to names within the ejb-jar
57
Set roleReferences = descriptor.getRoleReferences();
58         Iterator roleRefsIterator = roleReferences.iterator();
59         EjbBundleDescriptor bundleDescriptor = descriptor.getEjbBundleDescriptor();
60         Set roles = bundleDescriptor.getRoles();
61         Iterator roleIterator = roles.iterator();
62         Role role = null;
63         RoleReference roleReference = null;
64         boolean found = false;
65         boolean oneFailed = false;
66       
67         if (roleRefsIterator.hasNext()) {
68         while (roleRefsIterator.hasNext()) {
69             found = false;
70             roleReference = (RoleReference)roleRefsIterator.next();
71
72             while (roleIterator.hasNext()) {
73             role = (Role)roleIterator.next();
74             if (role.getName().equals(roleReference.getValue())) {
75                 found = true;
76                 //reset this so next time it drop back into here
77
roleIterator = roles.iterator();
78                 break;
79             }
80             }
81
82             if (!found) {
83             // print the roleReference with no corresponding env-prop
84
result.addErrorDetails(smh.getLocalString
85                    ("tests.componentNameConstructor",
86                     "For [ {0} ]",
87                     new Object JavaDoc[] {compName.toString()}));
88             result.addErrorDetails(smh.getLocalString
89                            (getClass().getName() + ".failed",
90                         "Erro: The security role reference [ {0} ] has no corresponding linked security role name [ {1} ]",
91                         new Object JavaDoc[] {roleReference.getName(),roleReference.getValue()}));
92             if (!oneFailed) {
93                 oneFailed = true;
94             }
95             } else {
96             result.addGoodDetails(smh.getLocalString
97                    ("tests.componentNameConstructor",
98                     "For [ {0} ]",
99                     new Object JavaDoc[] {compName.toString()}));
100             result.addGoodDetails(smh.getLocalString
101                           (getClass().getName() + ".passed",
102                            "The security role reference [ {0} ] has corresponding linked security role name [ {1} ]",
103                            new Object JavaDoc[] {roleReference.getName(),roleReference.getValue()}));
104             }
105         }
106         } else {
107         result.addNaDetails(smh.getLocalString
108                    ("tests.componentNameConstructor",
109                     "For [ {0} ]",
110                     new Object JavaDoc[] {compName.toString()}));
111         result.notApplicable(smh.getLocalString
112                      (getClass().getName() + ".notApplicable1",
113                       "There are no role references within this bean [ {0} ]",
114                       new Object JavaDoc[] {descriptor.getName()}));
115         return result;
116         }
117
118         // if one of 'em failed reset the status appropriately, in case
119
// status got stomped on within the while loop by the next env-prop
120
if (oneFailed) {
121         result.setStatus(Result.FAILED);
122         } else {
123         result.setStatus(Result.PASSED);
124         }
125
126         return result;
127     } else {
128         result.addNaDetails(smh.getLocalString
129                    ("tests.componentNameConstructor",
130                     "For [ {0} ]",
131                     new Object JavaDoc[] {compName.toString()}));
132         result.notApplicable(smh.getLocalString
133                  (getClass().getName() + ".notApplicable",
134                   "[ {0} ] not called \n with a Session or Entity bean.",
135                   new Object JavaDoc[] {getClass()}));
136         return result;
137     }
138     }
139 }
140
Popular Tags