KickJava   Java API By Example, From Geeks To Geeks.

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


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 java.util.HashSet JavaDoc;
21 import java.util.Set JavaDoc;
22 import java.util.Collections JavaDoc;
23 import java.util.concurrent.ConcurrentHashMap JavaDoc;
24
25 /**
26  * Used to cache up authorizations so that subsequent requests are faster.
27  *
28  * @version $Revision$
29  */

30 abstract public class SecurityContext {
31
32     public static final SecurityContext BROKER_SECURITY_CONTEXT = new SecurityContext("ActiveMQBroker") {
33         @Override JavaDoc
34         public boolean isBrokerContext() {
35             return true;
36         }
37
38         public Set JavaDoc getPrincipals() {
39             return Collections.EMPTY_SET;
40         }
41     };
42
43     final String JavaDoc userName;
44     
45     final ConcurrentHashMap JavaDoc authorizedReadDests = new ConcurrentHashMap JavaDoc();
46     final ConcurrentHashMap JavaDoc authorizedWriteDests = new ConcurrentHashMap JavaDoc();
47
48     public SecurityContext(String JavaDoc userName) {
49         this.userName = userName;
50     }
51
52     public boolean isInOneOf(Set JavaDoc allowedPrincipals) {
53         HashSet JavaDoc set = new HashSet JavaDoc(getPrincipals());
54         set.retainAll(allowedPrincipals);
55         return set.size()>0;
56     }
57
58     abstract public Set JavaDoc getPrincipals();
59     
60     public String JavaDoc getUserName() {
61         return userName;
62     }
63
64     public ConcurrentHashMap JavaDoc getAuthorizedReadDests() {
65         return authorizedReadDests;
66     }
67
68     public ConcurrentHashMap JavaDoc getAuthorizedWriteDests() {
69         return authorizedWriteDests;
70     }
71
72     public boolean isBrokerContext() {
73         return false;
74     }
75 }
76
Popular Tags