KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > activemq > security > DefaultAuthorizationMap


1 /**
2  *
3  * Licensed to the Apache Software Foundation (ASF) under one or more
4  * contributor license agreements. See the NOTICE file distributed with
5  * this work for additional information regarding copyright ownership.
6  * The ASF licenses this file to You under the Apache License, Version 2.0
7  * (the "License"); you may not use this file except in compliance with
8  * the License. You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18 package org.apache.activemq.security;
19
20 import org.apache.activemq.command.ActiveMQDestination;
21 import org.apache.activemq.filter.DestinationMap;
22
23 import java.util.HashSet JavaDoc;
24 import java.util.Iterator JavaDoc;
25 import java.util.List JavaDoc;
26 import java.util.Set JavaDoc;
27
28 /**
29  * Represents a destination based configuration of policies so that individual
30  * destinations or wildcard hierarchies of destinations can be configured using
31  * different policies. Each entry in the map represents the authorization ACLs for each operation.
32  *
33  * @org.apache.xbean.XBean element="authorizationMap"
34  *
35  * @version $Revision: 479639 $
36  */

37 public class DefaultAuthorizationMap extends DestinationMap implements AuthorizationMap {
38
39     private AuthorizationEntry defaultEntry;
40     
41     private TempDestinationAuthorizationEntry tempDestinationAuthorizationEntry;
42     
43     public DefaultAuthorizationMap() {
44     }
45
46     public DefaultAuthorizationMap(List JavaDoc authorizationEntries) {
47         setAuthorizationEntries(authorizationEntries);
48        
49     }
50
51   
52     public void setTempDestinationAuthorizationEntry(TempDestinationAuthorizationEntry tempDestinationAuthorizationEntry) {
53         this.tempDestinationAuthorizationEntry = tempDestinationAuthorizationEntry;
54     }
55     
56     public TempDestinationAuthorizationEntry getTempDestinationAuthorizationEntry() {
57         return this.tempDestinationAuthorizationEntry;
58     }
59     
60     public Set JavaDoc getTempDestinationAdminACLs() {
61         if(tempDestinationAuthorizationEntry != null)
62             return tempDestinationAuthorizationEntry.getAdminACLs();
63         else
64             return null;
65     }
66     
67     public Set JavaDoc getTempDestinationReadACLs() {
68         if(tempDestinationAuthorizationEntry != null)
69             return tempDestinationAuthorizationEntry.getReadACLs();
70         else
71             return null;
72     }
73     
74     public Set JavaDoc getTempDestinationWriteACLs() {
75         if(tempDestinationAuthorizationEntry != null)
76             return tempDestinationAuthorizationEntry.getWriteACLs();
77         else
78             return null;
79     }
80     
81     public Set JavaDoc getAdminACLs(ActiveMQDestination destination) {
82         Set JavaDoc entries = getAllEntries(destination);
83         Set JavaDoc answer = new HashSet JavaDoc();
84         // now lets go through each entry adding individual
85
for (Iterator JavaDoc iter = entries.iterator(); iter.hasNext();) {
86             AuthorizationEntry entry = (AuthorizationEntry) iter.next();
87             answer.addAll(entry.getAdminACLs());
88         }
89         return answer;
90     }
91
92     public Set JavaDoc getReadACLs(ActiveMQDestination destination) {
93         Set JavaDoc entries = getAllEntries(destination);
94         Set JavaDoc answer = new HashSet JavaDoc();
95         
96         // now lets go through each entry adding individual
97
for (Iterator JavaDoc iter = entries.iterator(); iter.hasNext();) {
98             AuthorizationEntry entry = (AuthorizationEntry) iter.next();
99             answer.addAll(entry.getReadACLs());
100         }
101         return answer;
102     }
103
104     public Set JavaDoc getWriteACLs(ActiveMQDestination destination) {
105         Set JavaDoc entries = getAllEntries(destination);
106         Set JavaDoc answer = new HashSet JavaDoc();
107         
108         // now lets go through each entry adding individual
109
for (Iterator JavaDoc iter = entries.iterator(); iter.hasNext();) {
110             AuthorizationEntry entry = (AuthorizationEntry) iter.next();
111             answer.addAll(entry.getWriteACLs());
112         }
113         return answer;
114     }
115
116     public AuthorizationEntry getEntryFor(ActiveMQDestination destination) {
117         AuthorizationEntry answer = (AuthorizationEntry) chooseValue(destination);
118         if (answer == null) {
119             answer = getDefaultEntry();
120         }
121         return answer;
122     }
123
124     /**
125      * Sets the individual entries on the authorization map
126      *
127      * @org.apache.xbean.ElementType class="org.apache.activemq.security.AuthorizationEntry"
128      */

129     public void setAuthorizationEntries(List JavaDoc entries) {
130         super.setEntries(entries);
131     }
132
133     public AuthorizationEntry getDefaultEntry() {
134         return defaultEntry;
135     }
136
137     public void setDefaultEntry(AuthorizationEntry defaultEntry) {
138         this.defaultEntry = defaultEntry;
139     }
140
141     protected Class JavaDoc getEntryClass() {
142         return AuthorizationEntry.class;
143     }
144     protected Set JavaDoc getAllEntries(ActiveMQDestination destination) {
145         Set JavaDoc entries = get(destination);
146         if (defaultEntry != null) {
147         entries.add(defaultEntry);
148         }
149         return entries;
150     }
151
152
153 }
154
Popular Tags