KickJava   Java API By Example, From Geeks To Geeks.

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


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 com.sun.enterprise.deployment.*;
27 import com.sun.enterprise.tools.verifier.*;
28 import com.sun.enterprise.tools.verifier.tests.ejb.EjbCheck;
29 import com.sun.enterprise.deployment.MethodDescriptor;
30 import java.util.*;
31
32 /**
33  * Session Bean transaction demarcation type for all methods of remote
34  * interface test.
35  * The transaction attributes must be specified for the methods defined
36  * in the bean's remote interface and all the direct and indirect
37  * superinterfaces of the remote interface, excluding the methods of
38  * the javax.ejb.EJBObject interface.
39  */

40 public class MethodPermissionComponentInterface extends EjbTest implements EjbCheck {
41     Result result = null;
42     
43     /**
44      * All methods should have a
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 = getInitializedResult();
52 // boolean oneFailed = false;
53

54         try {
55             if (descriptor instanceof EjbSessionDescriptor || descriptor instanceof EjbEntityDescriptor) {
56                 
57                 Set methods = descriptor.getMethodDescriptors();
58 // Set methodPermissions = new HashSet();
59
boolean noPermissions = false;
60                 
61                 for (Iterator i = methods.iterator(); i.hasNext();) {
62                     MethodDescriptor md = (MethodDescriptor) i.next();
63                     Set permissions = descriptor.getMethodPermissionsFor(md);
64                     if (permissions.isEmpty() || (permissions == null)) {
65                         result.addWarningDetails(smh.getLocalString
66                                 (getClass().getName() + ".failed",
67                                         "Warning: Method [ {0} ] of EJB [ {1} ] does not have assigned security-permissions",
68                                         new Object JavaDoc[] {md.getName(), descriptor.getName()}));
69                         result.setStatus(result.WARNING);
70                         noPermissions = true;
71                     }
72                 }
73                 
74                 if (!noPermissions) {
75                     result.passed(smh.getLocalString
76                             (getClass().getName() + ".passed",
77                                     "Valid: All [ {0} ]EJB interfaces methods have security-permissions assigned.",
78                                     new Object JavaDoc[] {descriptor.getName()}));
79                 }
80                 
81             } else {
82                 result.notApplicable(smh.getLocalString(
83                         getClass().getName() + ".notApplicable",
84                         "The bean [ {0} ] is neither a Session nor Entity Bean",
85                         new Object JavaDoc[] {descriptor.getName()}));
86                 return result;
87             }
88         } catch (Exception JavaDoc e) {
89             result.failed(smh.getLocalString(
90                     getClass().getName() + ".exception",
91                     "The test generated the following exception [ {0} ]",
92                     new Object JavaDoc[] {e.getLocalizedMessage()}));
93         }
94         return result;
95     }
96     
97 }
98
Popular Tags