001: /*
002: * JBoss, Home of Professional Open Source.
003: * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004: * as indicated by the @author tags. See the copyright.txt file in the
005: * distribution for a full listing of individual contributors.
006: *
007: * This is free software; you can redistribute it and/or modify it
008: * under the terms of the GNU Lesser General Public License as
009: * published by the Free Software Foundation; either version 2.1 of
010: * the License, or (at your option) any later version.
011: *
012: * This software is distributed in the hope that it will be useful,
013: * but WITHOUT ANY WARRANTY; without even the implied warranty of
014: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015: * Lesser General Public License for more details.
016: *
017: * You should have received a copy of the GNU Lesser General Public
018: * License along with this software; if not, write to the Free
019: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020: * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021: */
022: package org.jboss.ejb3.metamodel;
023:
024: import java.util.ArrayList;
025: import java.util.Collection;
026: import java.util.HashMap;
027: import java.util.HashSet;
028: import java.util.Iterator;
029: import java.util.List;
030: import java.util.Map;
031: import java.util.Set;
032:
033: import org.jboss.logging.Logger;
034:
035: import org.jboss.security.SecurityRoleMetaData;
036: import org.jboss.metamodel.descriptor.SecurityRole;
037:
038: /**
039: * Represents <assembly-descriptor> elements of the ejb-jar.xml deployment descriptor for the 1.4
040: * schema
041: *
042: * @author <a href="mailto:bdecoste@jboss.com">William DeCoste</a>
043: * @author Anil.Saldhana@jboss.org
044: * @version <tt>$Revision: 60373 $</tt>
045: */
046: public class AssemblyDescriptor {
047: private static final Logger log = Logger
048: .getLogger(AssemblyDescriptor.class);
049:
050: private List securityRoles = new ArrayList();
051:
052: private Map<String, SecurityRoleMetaData> securityRoleMetaData = new HashMap();
053:
054: private List methodPermissions = new ArrayList();
055:
056: private List containerTransactions = new ArrayList();
057:
058: private HashMap<String, MessageDestination> messageDestinations = new HashMap();
059:
060: private ExcludeList excludeList;
061:
062: private List applicationExceptions = new ArrayList();
063:
064: private InitList initList;
065:
066: private List injects = new ArrayList();
067:
068: public Collection getMessageDestinations() {
069: return messageDestinations.values();
070: }
071:
072: public void addMessageDestination(
073: MessageDestination messageDestination) {
074: messageDestinations.put(messageDestination
075: .getMessageDestinationName(), messageDestination);
076: }
077:
078: public MessageDestination findMessageDestination(String name) {
079: return messageDestinations.get(name);
080: }
081:
082: private List interceptorBindings = new ArrayList();
083:
084: public InitList getInitList() {
085: return initList;
086: }
087:
088: public void setInitList(InitList initList) {
089: this .initList = initList;
090: }
091:
092: public ExcludeList getExcludeList() {
093: return excludeList;
094: }
095:
096: public void setExcludeList(ExcludeList excludeList) {
097: this .excludeList = excludeList;
098: }
099:
100: public List getApplicationExceptions() {
101: return applicationExceptions;
102: }
103:
104: public void addApplicationException(
105: ApplicationException applicationException) {
106: applicationExceptions.add(applicationException);
107: }
108:
109: public List getSecurityRoles() {
110: return securityRoles;
111: }
112:
113: public void setSecurityRoles(List securityRoles) {
114: this .securityRoles = securityRoles;
115: }
116:
117: public void addSecurityRole(SecurityRole securityRole) {
118: securityRoles.add(securityRole);
119: }
120:
121: public List<InterceptorBinding> getInterceptorBindings() {
122: return interceptorBindings;
123: }
124:
125: public void addInterceptorBinding(InterceptorBinding binding) {
126: interceptorBindings.add(binding);
127: }
128:
129: public List getInjects() {
130: return injects;
131: }
132:
133: public void addInject(Inject inject) {
134: injects.add(inject);
135: }
136:
137: public List getMethodPermissions() {
138: return methodPermissions;
139: }
140:
141: public void setMethodPermissions(List methodPermissions) {
142: this .methodPermissions = methodPermissions;
143: }
144:
145: public void addMethodPermission(MethodPermission methodPermission) {
146: methodPermissions.add(methodPermission);
147: }
148:
149: public List getContainerTransactions() {
150: return containerTransactions;
151: }
152:
153: public void setContainerTransactions(List containerTransactions) {
154: this .containerTransactions = containerTransactions;
155: }
156:
157: public void addContainerTransaction(
158: ContainerTransaction containerTransaction) {
159: containerTransactions.add(containerTransaction);
160: }
161:
162: public void addSecurityRoleMetaData(SecurityRoleMetaData srm) {
163: this .securityRoleMetaData.put(srm.getRoleName(), srm);
164: }
165:
166: public Set getSecurityRolesGivenPrincipal(String userName) {
167: HashSet roleNames = new HashSet();
168: Iterator it = securityRoleMetaData.values().iterator();
169: while (it.hasNext()) {
170: SecurityRoleMetaData srMetaData = (SecurityRoleMetaData) it
171: .next();
172: if (srMetaData.getPrincipals().contains(userName))
173: roleNames.add(srMetaData.getRoleName());
174: }
175: return roleNames;
176: }
177:
178: /**
179: * Get a map of principals versus set of roles
180: * that may be configured by the user at the deployment level
181: * @return
182: */
183: public Map getPrincipalVersusRolesMap() {
184: Map principalRolesMap = null;
185:
186: Iterator iter = securityRoleMetaData.keySet().iterator();
187: while (iter.hasNext()) {
188: if (principalRolesMap == null)
189: principalRolesMap = new HashMap();
190: String rolename = (String) iter.next();
191: SecurityRoleMetaData srm = (SecurityRoleMetaData) securityRoleMetaData
192: .get(rolename);
193: Iterator principalIter = srm.getPrincipals().iterator();
194: while (principalIter.hasNext()) {
195: String pr = (String) principalIter.next();
196: Set roleset = (Set) principalRolesMap.get(pr);
197: if (roleset == null)
198: roleset = new HashSet();
199: if (!roleset.contains(rolename))
200: roleset.add(rolename);
201: principalRolesMap.put(pr, roleset);
202: }
203: }
204: return principalRolesMap;
205: }
206:
207: public Map<String, SecurityRoleMetaData> getSecurityRoleMetaData() {
208: return this .securityRoleMetaData;
209: }
210:
211: public String toString() {
212: StringBuffer sb = new StringBuffer(100);
213: sb.append("[");
214: sb.append("securityRoles=").append(securityRoles);
215: sb.append(", applicationExceptions=").append(
216: applicationExceptions);
217: sb.append("]");
218: return sb.toString();
219: }
220: }
|