KickJava   Java API By Example, From Geeks To Geeks.

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


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 /**
32  * If the Application assembler defines security roles in the deployment
33  * descriptor, the Application Assembler must bind security role references
34  * declared by the Bean Provider to the security roles.
35  */

36 public class SecurityRolesBind extends EjbTest implements EjbCheck {
37
38
39
40     /**
41      * If the Application assembler defines security roles in the deployment
42      * descriptor, the Application Assembler must bind security role references
43      * declared by the Bean Provider to the security roles.
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
54     EjbBundleDescriptor bundleDescriptor = descriptor.getEjbBundleDescriptor();
55     Set ejbs = bundleDescriptor.getEjbs();
56     Iterator ejbIterator = ejbs.iterator();
57     EjbDescriptor ejb = null;
58     Set roleReferences = null;
59     Iterator roleRefsIterator = null;
60     Set roles = bundleDescriptor.getRoles();
61     Iterator rolesIterator = roles.iterator();
62     RoleReference roleReference = null;
63     Role role = null;
64     boolean oneFailed = false;
65         
66     // check to see if there are any undefined roles being referenced
67
while (ejbIterator.hasNext()) {
68         ejb = (EjbDescriptor)ejbIterator.next();
69         roleReferences = ejb.getRoleReferences();
70         roleRefsIterator = roleReferences.iterator();
71         if (roleRefsIterator.hasNext()) {
72         while (roleRefsIterator.hasNext()) {
73             roleReference = (RoleReference)roleRefsIterator.next();
74             role = roleReference.getRole();
75             if (!role.getName().equals("")
76             && !bundleDescriptor.getRoles().contains(role) ) {
77             // print the undefine role
78
result.addErrorDetails(smh.getLocalString
79                            ("tests.componentNameConstructor",
80                         "For [ {0} ]",
81                         new Object JavaDoc[] {compName.toString()}));
82             result.addErrorDetails(smh.getLocalString
83                            (getClass().getName() + ".failed",
84                         "Error: The role [ {0} ] for bean [ {1} ] is undefined.",
85                         new Object JavaDoc[] {role.getName(),ejb.getName()}));
86             if (!oneFailed) {
87                 oneFailed = true;
88             }
89             } else {
90             result.addGoodDetails(smh.getLocalString
91                           ("tests.componentNameConstructor",
92                            "For [ {0} ]",
93                            new Object JavaDoc[] {compName.toString()}));
94             result.passed(smh.getLocalString
95                       (getClass().getName() + ".passed",
96                        "The role [ {0} ] for bean [ {1} ] is defined.",
97                        new Object JavaDoc[] {role.getName(),ejb.getName()}));
98             }
99         }
100         } else {
101         result.addNaDetails(smh.getLocalString
102                     ("tests.componentNameConstructor",
103                      "For [ {0} ]",
104                      new Object JavaDoc[] {compName.toString()}));
105         result.notApplicable(smh.getLocalString
106                      (getClass().getName() + ".notApplicable",
107                       "There are no role references which need to be bound to other security roles within this bean [ {0} ]",
108                       new Object JavaDoc[] {ejb.getName()}));
109         }
110     }
111
112     if (oneFailed) {
113         result.setStatus(Result.FAILED);
114     }
115         
116     return result;
117     }
118 }
119
Popular Tags