001: /**
002: * EasyBeans
003: * Copyright (C) 2006 Bull S.A.S.
004: * Contact: easybeans@ow2.org
005: *
006: * This library is free software; you can redistribute it and/or
007: * modify it under the terms of the GNU Lesser General Public
008: * License as published by the Free Software Foundation; either
009: * version 2.1 of the License, or any later version.
010: *
011: * This library is distributed in the hope that it will be useful,
012: * but WITHOUT ANY WARRANTY; without even the implied warranty of
013: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014: * Lesser General Public License for more details.
015: *
016: * You should have received a copy of the GNU Lesser General Public
017: * License along with this library; if not, write to the Free Software
018: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
019: * USA
020: *
021: * --------------------------------------------------------------------------
022: * $Id: SecurityInfo.java 1970 2007-10-16 11:49:25Z benoitf $
023: * --------------------------------------------------------------------------
024: */package org.ow2.easybeans.container.info.security;
025:
026: import java.security.Principal;
027: import java.security.acl.Group;
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: import javax.security.auth.Subject;
032:
033: import org.ow2.easybeans.api.bean.info.IMethodSecurityInfo;
034: import org.ow2.easybeans.api.bean.info.ISecurityInfo;
035: import org.ow2.easybeans.security.struct.JGroup;
036: import org.ow2.easybeans.security.struct.JPrincipal;
037:
038: /**
039: * Runtime info about security.
040: * @author Florent Benoit
041: */
042: public class SecurityInfo implements ISecurityInfo {
043:
044: /**
045: * List of roles.
046: */
047: private List<String> declaredRoles = null;
048:
049: /**
050: * List of methods.
051: */
052: private List<IMethodSecurityInfo> methodSecurityInfos = null;
053:
054: /**
055: * Name of the run-as role.
056: */
057: private String runAsRole = null;
058:
059: /**
060: * Subject for run-as role.
061: */
062: private Subject runAsSubject = null;
063:
064: /**
065: * Default constructor.
066: */
067: public SecurityInfo() {
068: this .methodSecurityInfos = new ArrayList<IMethodSecurityInfo>();
069: }
070:
071: /**
072: * Adds a method containing security.
073: * @param methodSecurityInfo the info about security.
074: */
075: public void addMethodSecurityInfo(
076: final IMethodSecurityInfo methodSecurityInfo) {
077: methodSecurityInfos.add(methodSecurityInfo);
078: }
079:
080: /**
081: * @return list of security infos on all methods.
082: */
083: public List<IMethodSecurityInfo> getMethodSecurityInfos() {
084: return methodSecurityInfos;
085: }
086:
087: /**
088: * Sets the name of the run-as security role.
089: * @param runAsRole the name of the role.
090: */
091: public void setRunAsRole(final String runAsRole) {
092: this .runAsRole = runAsRole;
093: this .runAsSubject = new Subject();
094: // Add principal name
095: Principal principalName = new JPrincipal(runAsRole);
096: runAsSubject.getPrincipals().add(principalName);
097:
098: // Add roles for this principal
099: Group roles = new JGroup("roles");
100: roles.addMember(new JPrincipal(runAsRole));
101: runAsSubject.getPrincipals().add(roles);
102:
103: }
104:
105: /**
106: * Gets run-as name.
107: * @return the name of the security role for the run-as.
108: */
109: public String getRunAsRole() {
110: return runAsRole;
111: }
112:
113: /**
114: * Gets run-as role subject.
115: * @return a subject with run-as role as role.
116: */
117: public Subject getRunAsSubject() {
118: return runAsSubject;
119: }
120:
121: /**
122: * Adds a role for this bean (for isCallerInRole).
123: * @param roleName the name of a role.
124: */
125: public void addDeclaredRole(final String roleName) {
126: declaredRoles.add(roleName);
127: }
128:
129: /**
130: * @return list of roles declared for this bean.
131: */
132: public List<String> getDeclaredRoles() {
133: return declaredRoles;
134: }
135:
136: /**
137: * Sets the list of declared roles.
138: * @param declaredRoles list of declared roles.
139: */
140: public void setDeclaredRole(final List<String> declaredRoles) {
141: this.declaredRoles = declaredRoles;
142: }
143: }
|