KickJava   Java API By Example, From Geeks To Geeks.

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


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  * Security role references test.
33  * The Bean provider must declare all of the enterprise's bean references
34  * to security roles as specified in section 15.2.1.3 of the Moscone spec.
35  * Role names must be mapped to names within the jar.
36  */

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

50   public Result check(EjbDescriptor descriptor) {
51
52     Result result = getInitializedResult();
53     ComponentNameConstructor compName = getVerifierContext().getComponentNameConstructor();
54 if (descriptor.getUsesCallerIdentity()){
55         result.addNaDetails(smh.getLocalString
56             ("tests.componentNameConstructor",
57              "For [ {0} ]",
58              new Object JavaDoc[] {compName.toString()}));
59         result.notApplicable(smh.getLocalString(
60               "com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.notApplicable3",
61               "Bean [ {0} ] does not specify a run-as identity",
62               new Object JavaDoc[] {descriptor.getName()}));
63         return result;
64     }
65     RunAsIdentityDescriptor identity = descriptor.getRunAsIdentity();
66     if (identity == null) {
67       result.addNaDetails(smh.getLocalString
68           ("tests.componentNameConstructor",
69            "For [ {0} ]",
70            new Object JavaDoc[] {compName.toString()}));
71       result.notApplicable(smh.getLocalString(
72             "com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.notApplicable2",
73             "Bean [ {0} ] does not specify a security identity",
74             new Object JavaDoc[] {descriptor.getName()}));
75       return result;
76     }
77
78     EjbBundleDescriptor bundleDescriptor = descriptor.getEjbBundleDescriptor();
79     Set roles = bundleDescriptor.getRoles();
80     Iterator roleIterator = roles.iterator();
81     while (roleIterator.hasNext()) {
82       Role role = (Role) roleIterator.next();
83       if (role.getName().equals(identity.getRoleName())) {
84         result.addGoodDetails(smh.getLocalString
85             ("tests.componentNameConstructor",
86              "For [ {0} ]",
87              new Object JavaDoc[] {compName.toString()}));
88         result.passed(smh.getLocalString(
89               "com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.passed",
90               "Security identity run-as specified identity [ {0} ] role is found in the list of roles",
91               new Object JavaDoc[] {role.getName()}));
92         return result;
93       }
94     }
95     result.addErrorDetails(smh.getLocalString
96         ("tests.componentNameConstructor",
97          "For [ {0} ]",
98          new Object JavaDoc[] {compName.toString()}));
99     result.failed(smh.getLocalString(
100           "com.sun.enterprise.tools.verifier.tests.ejb.SecurityIdentityRefs.failed",
101           "Security identity run-as specified identity [ {0} ] role is not valid",
102           new Object JavaDoc[] {identity.getRoleName()}));
103     return result;
104   }
105
106 }
107
Popular Tags