KickJava   Java API By Example, From Geeks To Geeks.

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


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.Set JavaDoc;
22 import java.util.StringTokenizer JavaDoc;
23
24 import javax.xml.XMLConstants JavaDoc;
25 import javax.xml.namespace.QName JavaDoc;
26
27 import org.apache.servicemix.jbi.security.GroupPrincipal;
28
29 /**
30  *
31  * @author gnodet
32  * @org.apache.xbean.XBean
33  */

34 public class AuthorizationEntry {
35     
36     /**
37      * Add the roles to the ACLs list
38      */

39     public static final String JavaDoc TYPE_ADD = "add";
40     /**
41      * Set the ACLs to the given roles
42      */

43     public static final String JavaDoc TYPE_SET = "set";
44     /**
45      * Remove the given roles from the ACLs list
46      */

47     public static final String JavaDoc TYPE_REM = "rem";
48
49     private Set JavaDoc acls;
50     private QName JavaDoc service;
51     private String JavaDoc endpoint;
52     private String JavaDoc type = TYPE_ADD;
53
54     public AuthorizationEntry() {
55     }
56     
57     public AuthorizationEntry(QName JavaDoc service, String JavaDoc endpoint, String JavaDoc roles) {
58         this.service = service;
59         this.endpoint = endpoint;
60         setRoles(roles);
61     }
62     
63     public AuthorizationEntry(QName JavaDoc service, String JavaDoc endpoint, String JavaDoc roles, String JavaDoc type) {
64         this.service = service;
65         this.endpoint = endpoint;
66         setRoles(roles);
67         this.type = type;
68     }
69     
70     /**
71      * @return the type
72      */

73     public String JavaDoc getType() {
74         return type;
75     }
76
77     /**
78      * @param type the type to set
79      */

80     public void setType(String JavaDoc type) {
81         this.type = type;
82     }
83
84     /**
85      * @return the endpoint
86      */

87     public String JavaDoc getEndpoint() {
88         return endpoint;
89     }
90
91     /**
92      * @param endpoint the endpoint to set
93      */

94     public void setEndpoint(String JavaDoc endpoint) {
95         this.endpoint = endpoint;
96     }
97
98     /**
99      * @return the service
100      */

101     public QName JavaDoc getService() {
102         return service;
103     }
104
105     /**
106      * @param service the service to set
107      */

108     public void setService(QName JavaDoc service) {
109         // Hack a bit to support wildcards
110
// If the attribute was service="*:*", then the namespace is not found, but the prefix is set
111
if (XMLConstants.NULL_NS_URI.equals(service.getNamespaceURI()) &&
112             service.getPrefix() != null && service.getPrefix().length() > 0) {
113             service = new QName JavaDoc(service.getPrefix(), service.getLocalPart());
114         }
115         this.service = service;
116     }
117
118     /**
119      * @return the acls
120      */

121     public Set JavaDoc getAcls() {
122         return acls;
123     }
124
125     /**
126      * @param acls the acls to set
127      */

128     public void setAcls(Set JavaDoc acls) {
129         this.acls = acls;
130     }
131     
132     public void setRoles(String JavaDoc roles) {
133         this.acls = new HashSet JavaDoc();
134         StringTokenizer JavaDoc iter = new StringTokenizer JavaDoc(roles, ",");
135         while (iter.hasMoreTokens()) {
136             String JavaDoc name = iter.nextToken().trim();
137             this.acls.add(new GroupPrincipal(name));
138         }
139     }
140     
141     public String JavaDoc getRoles() {
142         StringBuffer JavaDoc sb = new StringBuffer JavaDoc();
143         if (this.acls != null) {
144             for (Iterator JavaDoc iter = this.acls.iterator(); iter.hasNext();) {
145                 GroupPrincipal p = (GroupPrincipal) iter.next();
146                 sb.append(p);
147                 if (iter.hasNext()) {
148                     sb.append(",");
149                 }
150             }
151         }
152         return sb.toString();
153     }
154     
155     public String JavaDoc toString() {
156         return "AuthorizationEntry[service=" + service + ", endpoint=" + endpoint + ", roles=" + getRoles() + "]";
157     }
158 }
159
Popular Tags