KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > metadata > AssemblyDescriptorMetaData


1 /*
2 * JBoss, Home of Professional Open Source
3 * Copyright 2005, JBoss Inc., and individual contributors as indicated
4 * by the @authors tag. See the copyright.txt in the distribution for a
5 * full listing of individual contributors.
6 *
7 * This is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU Lesser General Public License as
9 * published by the Free Software Foundation; either version 2.1 of
10 * the License, or (at your option) any later version.
11 *
12 * This software is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with this software; if not, write to the Free
19 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21 */

22 package org.jboss.metadata;
23
24 import java.security.Principal JavaDoc;
25 import java.util.HashMap JavaDoc;
26 import java.util.HashSet JavaDoc;
27 import java.util.Iterator JavaDoc;
28 import java.util.Map JavaDoc;
29 import java.util.Set JavaDoc;
30
31 /**
32  * The meta data object for the assembly-descriptor element.
33  * This implementation only contains the security-role meta data
34  *
35  * @author Thomas.Diesler@jboss.org
36  * @author Anil.Saldhana@jboss.org
37  * @version $Revision: 58441 $
38  */

39 public class AssemblyDescriptorMetaData extends MetaData
40 {
41    /** The assembly-descriptor/security-roles */
42    private HashMap JavaDoc securityRoles = new HashMap JavaDoc();
43
44    /** The message destinations */
45    private HashMap JavaDoc messageDestinations = new HashMap JavaDoc();
46    
47    public void addSecurityRoleMetaData(SecurityRoleMetaData srMetaData)
48    {
49       securityRoles.put(srMetaData.getRoleName(), srMetaData);
50    }
51
52    public Map JavaDoc getSecurityRoles()
53    {
54       return new HashMap JavaDoc(securityRoles);
55    }
56
57    /**
58     * Merge the security role/principal mapping defined in jboss.xml
59     * with the one defined at jboss-app.xml.
60     */

61    public void mergeSecurityRoles(Map JavaDoc applRoles)
62    {
63       Iterator JavaDoc it = applRoles.entrySet().iterator();
64       while (it.hasNext())
65       {
66          Map.Entry JavaDoc entry = (Map.Entry JavaDoc) it.next();
67          String JavaDoc roleName = (String JavaDoc)entry.getKey();
68          SecurityRoleMetaData appRole = (SecurityRoleMetaData)entry.getValue();
69          SecurityRoleMetaData srMetaData = (SecurityRoleMetaData)securityRoles.get(roleName);
70          if (srMetaData != null)
71          {
72             Set JavaDoc principalNames = appRole.getPrincipals();
73             srMetaData.addPrincipalNames(principalNames);
74          }
75          else
76          {
77             securityRoles.put(roleName, entry.getValue());
78          }
79       }
80    }
81
82    public SecurityRoleMetaData getSecurityRoleByName(String JavaDoc roleName)
83    {
84       return (SecurityRoleMetaData)securityRoles.get(roleName);
85    }
86
87    public Set JavaDoc getSecurityRoleNamesByPrincipal(String JavaDoc userName)
88    {
89       HashSet JavaDoc roleNames = new HashSet JavaDoc();
90       Iterator JavaDoc it = securityRoles.values().iterator();
91       while (it.hasNext())
92       {
93          SecurityRoleMetaData srMetaData = (SecurityRoleMetaData) it.next();
94          if (srMetaData.getPrincipals().contains(userName))
95             roleNames.add(srMetaData.getRoleName());
96       }
97       return roleNames;
98    }
99    
100    /**
101     * Generate a Map of Principal keyed against a set of role names
102     * @return
103     */

104    public Map JavaDoc getPrincipalVersusRolesMap()
105    {
106       Map JavaDoc principalRolesMap = null;
107       
108       Iterator JavaDoc iter = securityRoles.keySet().iterator();
109       while(iter.hasNext())
110       {
111          if(principalRolesMap == null)
112             principalRolesMap = new HashMap JavaDoc();
113          String JavaDoc rolename = (String JavaDoc)iter.next();
114          SecurityRoleMetaData srm = (SecurityRoleMetaData) securityRoles.get(rolename);
115          Iterator JavaDoc principalIter = srm.getPrincipals().iterator();
116          while(principalIter.hasNext())
117          {
118             String JavaDoc pr = (String JavaDoc)principalIter.next();
119             Set JavaDoc roleset = (Set JavaDoc)principalRolesMap.get(pr);
120             if(roleset == null)
121                roleset = new HashSet JavaDoc();
122             if(!roleset.contains(rolename))
123                roleset.add(rolename);
124             principalRolesMap.put(pr, roleset);
125          }
126       }
127       return principalRolesMap;
128    }
129    
130    public void addMessageDestinationMetaData(MessageDestinationMetaData metaData)
131    {
132       messageDestinations.put(metaData.getName(), metaData);
133    }
134    
135    public MessageDestinationMetaData getMessageDestinationMetaData(String JavaDoc name)
136    {
137       return (MessageDestinationMetaData) messageDestinations.get(name);
138    }
139 }
140
Popular Tags