KickJava   Java API By Example, From Geeks To Geeks.

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


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.elements;
24
25 import com.sun.enterprise.tools.verifier.tests.ejb.EjbTest;
26 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
27 import java.util.*;
28 import com.sun.enterprise.deployment.*;
29 import com.sun.enterprise.tools.verifier.*;
30 import com.sun.enterprise.tools.verifier.tests.*;
31
32 /**
33  * Security role used in method permission element must be defined in the roles
34  * element of the deployment descriptor.
35  */

36 public class MethodPermissionSecurityRoleExists extends EjbTest implements EjbCheck {
37
38
39
40     /**
41      * Security role used in method permission element must be defined in the
42      * roles element of the deployment descriptor.
43      *
44      * @param descriptor the Enterprise Java Bean deployment descriptor
45      *
46      * @return <code>Result</code> the results for this assertion
47      */

48     public Result check(EjbDescriptor descriptor) {
49
50     Result result = getInitializedResult();
51     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
52
53         Map permissionedMethods = descriptor.getPermissionedMethodsByPermission();
54         boolean oneFailed = false;
55         if (permissionedMethods.size() >0) {
56         for (Iterator e = permissionedMethods.keySet().iterator(); e.hasNext();) {
57                 MethodPermission nextPermission = (MethodPermission) e.next();
58                 if (nextPermission.isRoleBased()) {
59                     if (!descriptor.getEjbBundleDescriptor().getRoles().contains(nextPermission.getRole())) {
60                 oneFailed =true;
61             result.addErrorDetails(smh.getLocalString
62                            ("tests.componentNameConstructor",
63                         "For [ {0} ]",
64                         new Object JavaDoc[] {compName.toString()}));
65                 result.addErrorDetails
66                 (smh.getLocalString
67                 (getClass().getName() + ".failed",
68                 "Error: Method permissions role [ {0} ] must be one of the roles defined in bean [ {1} ]",
69                 new Object JavaDoc[] {nextPermission.getRole().getName(), descriptor.getName()}));
70             } else {
71             result.addGoodDetails(smh.getLocalString
72                           ("tests.componentNameConstructor",
73                            "For [ {0} ]",
74                            new Object JavaDoc[] {compName.toString()}));
75                 result.addGoodDetails
76                 (smh.getLocalString
77                 (getClass().getName() + ".passed",
78                 "Valid: Method permissions role [ {0} ] is defined as one of the roles defined in bean [ {1} ]",
79                 new Object JavaDoc[] {nextPermission.getRole().getName(), descriptor.getName()}));
80             }
81                 } else {
82                     addNaDetails(result, compName);
83                     result.notApplicable(smh.getLocalString
84                              (getClass().getName() + ".notApplicable1",
85                               "There are no role based method-permissions within this bean [ {0} ]",
86                               new Object JavaDoc[] {descriptor.getName()}));
87                 }
88         }
89         if (oneFailed) {
90                 result.setStatus(Result.FAILED);
91             } else {
92             if(result.getStatus() != Result.NOT_APPLICABLE)
93                 result.setStatus(Result.PASSED);
94             }
95     } else {
96         result.addNaDetails(smh.getLocalString
97                 ("tests.componentNameConstructor",
98                  "For [ {0} ]",
99                  new Object JavaDoc[] {compName.toString()}));
100         result.notApplicable(smh.getLocalString
101                  (getClass().getName() + ".notApplicable",
102                   "There are no <method-permission> elements within this bean [ {0} ]",
103                   new Object JavaDoc[] {descriptor.getName()}));
104     }
105     return result;
106     }
107 }
108
109
Popular Tags