KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > objectweb > easybeans > container > info > security > SecurityInfoHelper


1 /**
2  * EasyBeans
3  * Copyright (C) 2006 Bull S.A.S.
4  * Contact: easybeans@objectweb.org
5  *
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or any later version.
10  *
11  * This library is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this library; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
19  * USA
20  *
21  * --------------------------------------------------------------------------
22  * $Id: SecurityInfoHelper.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.container.info.security;
27
28 import java.util.Collection JavaDoc;
29 import java.util.List JavaDoc;
30
31 import javax.security.jacc.EJBMethodPermission JavaDoc;
32
33 import org.objectweb.easybeans.api.bean.info.IMethodSecurityInfo;
34 import org.objectweb.easybeans.api.bean.info.ISecurityInfo;
35 import org.objectweb.easybeans.deployment.annotations.metadata.ClassAnnotationMetadata;
36 import org.objectweb.easybeans.deployment.annotations.metadata.MethodAnnotationMetadata;
37
38 /**
39  * Class that creates the runtime security info from the bean metadata.
40  * @author Florent Benoit
41  */

42 public final class SecurityInfoHelper {
43
44     /**
45      * Utility class, no public constructor.
46      */

47     private SecurityInfoHelper() {
48
49     }
50
51     /**
52      * Extract security info from the bean's metadata.
53      * @param bean the metadata of the current bean.
54      * @return the security info.
55      */

56     public static ISecurityInfo getSecurityInfo(final ClassAnnotationMetadata bean) {
57         ISecurityInfo securityInfo = new SecurityInfo();
58
59         // Add each declared role
60
securityInfo.setDeclaredRole(bean.getDeclareRoles());
61
62         // Sets the run-as role.
63
String JavaDoc runAsRole = bean.getRunAs();
64         if (runAsRole != null) {
65             securityInfo.setRunAsRole(runAsRole);
66         }
67
68
69         // For each business method, add info.
70
Collection JavaDoc<MethodAnnotationMetadata> methods = bean.getMethodAnnotationMetadataCollection();
71         // No methods, break now
72
if (methods == null) {
73             return securityInfo;
74         }
75
76         for (MethodAnnotationMetadata method : methods) {
77             // Match only business method
78
if (!method.isBusinessMethod()) {
79                 continue;
80             }
81
82             IMethodSecurityInfo methodSecurityInfo = new MethodSecurityInfo();
83             securityInfo.addMethodSecurityInfo(methodSecurityInfo);
84
85             // Set meta-info
86
methodSecurityInfo.setExcluded(method.hasDenyAll());
87             methodSecurityInfo.setUnchecked(method.hasPermitAll());
88             List JavaDoc<String JavaDoc> roles = method.getRolesAllowed();
89             if (roles != null) {
90                 for (String JavaDoc role : roles) {
91                     methodSecurityInfo.addRole(role);
92                 }
93             }
94
95             // Build permission
96
String JavaDoc ejbName = bean.getJCommonBean().getName();
97             String JavaDoc methodName = method.getMethodName();
98             //TODO: fixme
99
String JavaDoc methodInterface = null;
100             //TODO: fixme
101
String JavaDoc[] methodParams = null;
102
103             EJBMethodPermission JavaDoc permission = new EJBMethodPermission JavaDoc(ejbName, methodName, methodInterface, methodParams);
104             methodSecurityInfo.setPermission(permission);
105         }
106
107         return securityInfo;
108     }
109 }
110
Popular Tags