KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > servicemix > jbi > security > acl > impl > DefaultAuthorizationMap


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

17 package org.apache.servicemix.jbi.security.acl.impl;
18
19 import java.util.HashSet JavaDoc;
20 import java.util.Iterator JavaDoc;
21 import java.util.List JavaDoc;
22 import java.util.Set JavaDoc;
23 import java.util.regex.Pattern JavaDoc;
24
25 import javax.jbi.servicedesc.ServiceEndpoint;
26 import javax.xml.namespace.QName JavaDoc;
27
28 import org.apache.servicemix.jbi.security.acl.AuthorizationMap;
29
30
31 /**
32  *
33  * @author gnodet
34  * @org.apache.xbean.XBean element="authorizationMap"
35  */

36 public class DefaultAuthorizationMap implements AuthorizationMap {
37
38     private AuthorizationEntry defaultEntry;
39     private List JavaDoc authorizationEntries;
40
41     public DefaultAuthorizationMap() {
42     }
43     
44     public DefaultAuthorizationMap(List JavaDoc authorizationEntries) {
45         this.authorizationEntries = authorizationEntries;
46     }
47     
48     /**
49      * @return the authorizationEntries
50      */

51     public List JavaDoc getAuthorizationEntries() {
52         return authorizationEntries;
53     }
54
55     /**
56      * @param authorizationEntries the authorizationEntries to set
57      * @org.apache.xbean.ElementType class="org.apache.servicemix.jbi.security.AuthorizationEntry"
58      */

59     public void setAuthorizationEntries(List JavaDoc authorizationEntries) {
60         this.authorizationEntries = authorizationEntries;
61     }
62
63     /**
64      * @return the defaultEntry
65      */

66     public AuthorizationEntry getDefaultEntry() {
67         return defaultEntry;
68     }
69
70     /**
71      * @param defaultEntry the defaultEntry to set
72      */

73     public void setDefaultEntry(AuthorizationEntry defaultEntry) {
74         this.defaultEntry = defaultEntry;
75     }
76
77     public Set JavaDoc getAcls(ServiceEndpoint endpoint) {
78         Set JavaDoc acls = new HashSet JavaDoc();
79         if (defaultEntry != null) {
80             acls.add(defaultEntry);
81         }
82         for (Iterator JavaDoc iter = authorizationEntries.iterator(); iter.hasNext();) {
83             AuthorizationEntry entry = (AuthorizationEntry) iter.next();
84             if (match(entry, endpoint)) {
85                 if (AuthorizationEntry.TYPE_ADD.equalsIgnoreCase(entry.getType())) {
86                     acls.addAll(entry.getAcls());
87                 } else if (AuthorizationEntry.TYPE_SET.equalsIgnoreCase(entry.getType())) {
88                     acls.clear();
89                     acls.addAll(entry.getAcls());
90                 } else if (AuthorizationEntry.TYPE_REM.equalsIgnoreCase(entry.getType())) {
91                     acls.removeAll(entry.getAcls());
92                 }
93             }
94         }
95         return acls;
96     }
97
98     protected boolean match(AuthorizationEntry entry, ServiceEndpoint endpoint) {
99         return match(entry.getService(), endpoint.getServiceName()) &&
100                match(entry.getEndpoint(), endpoint.getEndpointName());
101     }
102
103     private boolean match(QName JavaDoc acl, QName JavaDoc target) {
104         return match(acl.getNamespaceURI(), target.getNamespaceURI()) &&
105                match(acl.getLocalPart(), target.getLocalPart());
106     }
107
108     private boolean match(String JavaDoc acl, String JavaDoc target) {
109         return acl == null ||
110                acl.equals("*") ||
111                Pattern.matches(acl, target);
112     }
113
114 }
115
Popular Tags