KickJava   Java API By Example, From Geeks To Geeks.

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


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: SecurityInfo.java 1121 2006-09-27 08:51:06Z benoitf $
23  * --------------------------------------------------------------------------
24  */

25
26 package org.objectweb.easybeans.container.info.security;
27
28 import java.security.Principal JavaDoc;
29 import java.security.acl.Group JavaDoc;
30 import java.util.ArrayList JavaDoc;
31 import java.util.List JavaDoc;
32
33 import javax.security.auth.Subject JavaDoc;
34
35 import org.objectweb.easybeans.api.bean.info.IMethodSecurityInfo;
36 import org.objectweb.easybeans.api.bean.info.ISecurityInfo;
37 import org.objectweb.easybeans.security.struct.JGroup;
38 import org.objectweb.easybeans.security.struct.JPrincipal;
39
40 /**
41  * Runtime info about security.
42  * @author Florent Benoit
43  */

44 public class SecurityInfo implements ISecurityInfo {
45
46     /**
47      * List of roles.
48      */

49     private List JavaDoc<String JavaDoc> declaredRoles = null;
50
51     /**
52      * List of methods.
53      */

54     private List JavaDoc<IMethodSecurityInfo> methodSecurityInfos = null;
55
56     /**
57      * Name of the run-as role.
58      */

59     private String JavaDoc runAsRole = null;
60
61     /**
62      * Subject for run-as role.
63      */

64     private Subject JavaDoc runAsSubject = null;
65
66     /**
67      * Default constructor.
68      */

69     public SecurityInfo() {
70         this.methodSecurityInfos = new ArrayList JavaDoc<IMethodSecurityInfo>();
71     }
72
73     /**
74      * Adds a method containing security.
75      * @param methodSecurityInfo the info about security.
76      */

77     public void addMethodSecurityInfo(final IMethodSecurityInfo methodSecurityInfo) {
78         methodSecurityInfos.add(methodSecurityInfo);
79     }
80
81     /**
82      * @return list of security infos on all methods.
83      */

84     public List JavaDoc<IMethodSecurityInfo> getMethodSecurityInfos() {
85         return methodSecurityInfos;
86     }
87
88     /**
89      * Sets the name of the run-as security role.
90      * @param runAsRole the name of the role.
91      */

92     public void setRunAsRole(final String JavaDoc runAsRole) {
93         this.runAsRole = runAsRole;
94         this.runAsSubject = new Subject JavaDoc();
95         // Add principal name
96
Principal JavaDoc principalName = new JPrincipal(runAsRole);
97         runAsSubject.getPrincipals().add(principalName);
98
99         // Add roles for this principal
100
Group JavaDoc roles = new JGroup("roles");
101         roles.addMember(new JPrincipal(runAsRole));
102         runAsSubject.getPrincipals().add(roles);
103
104     }
105
106     /**
107      * Gets run-as name.
108      * @return the name of the security role for the run-as.
109      */

110     public String JavaDoc getRunAsRole() {
111         return runAsRole;
112     }
113
114     /**
115      * Gets run-as role subject.
116      * @return a subject with run-as role as role.
117      */

118     public Subject JavaDoc getRunAsSubject() {
119         return runAsSubject;
120     }
121
122     /**
123      * Adds a role for this bean (for isCallerInRole).
124      * @param roleName the name of a role.
125      */

126     public void addDeclaredRole(final String JavaDoc roleName) {
127         declaredRoles.add(roleName);
128     }
129
130     /**
131      * @return list of roles declared for this bean.
132      */

133     public List JavaDoc<String JavaDoc> getDeclaredRoles() {
134         return declaredRoles;
135     }
136
137     /**
138      * Sets the list of declared roles.
139      * @param declaredRoles list of declared roles.
140      */

141     public void setDeclaredRole(final List JavaDoc<String JavaDoc> declaredRoles) {
142         this.declaredRoles = declaredRoles;
143     }
144 }
145
Popular Tags