KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jmanage > core > auth > ACLContext


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

16 package org.jmanage.core.auth;
17
18 import org.jmanage.core.util.Expression;
19
20 /**
21  *
22  * Date: Apr 8, 2005
23  * @author Rakesh Kalra
24  */

25 public class ACLContext {
26
27     private static final String JavaDoc WILDCARD = Expression.WILDCARD;
28
29     private String JavaDoc appName = WILDCARD;
30     /* object name or configured name */
31     private String JavaDoc mbeanName = WILDCARD;
32     /* this could be attribute or operation name */
33     private String JavaDoc targetName = WILDCARD;
34
35     public ACLContext(String JavaDoc aclContext){
36         Expression expr = new Expression(aclContext);
37         if(expr.getAppName() != null){
38             appName = expr.getAppName();
39         }
40         if(expr.getMBeanName() != null){
41             // todo: we need to convert the MBean name to canonical name
42
// for comparision. It will be good to further improve
43
// the comparision by allowing wild card comparisions.
44
mbeanName = expr.getMBeanName();
45         }
46         if(expr.getTargetName() != null){
47             targetName = expr.getTargetName();
48         }
49     }
50
51     public ACLContext(String JavaDoc appName, String JavaDoc mbeanName, String JavaDoc targetName) {
52         if(appName != null){
53             this.appName = appName;
54         }
55         if(mbeanName != null){
56             this.mbeanName = mbeanName;
57         }
58         if(targetName != null){
59             this.targetName = targetName;
60         }
61     }
62
63     public boolean equals(Object JavaDoc obj){
64         if(obj instanceof ACLContext){
65             ACLContext context = (ACLContext)obj;
66             return compare(context.appName, this.appName) &&
67                    compare(context.mbeanName, this.mbeanName) &&
68                    compare(context.targetName, this.targetName);
69         }
70         return false;
71     }
72
73     private boolean compare(String JavaDoc a, String JavaDoc b){
74         boolean equals = false;
75         if(a == null && b == null){
76             /* both are null */
77             equals = true;
78         }else if(a == null || b == null){
79             /* one of them is not null */
80             equals = false;
81         }else if(a.equals(WILDCARD) || b.equals(WILDCARD)){
82             /* one of them is wild card */
83             equals = true;
84         }else if(a.equals(b)){
85             /* they are the same */
86             equals = true;
87         }
88         return equals;
89     }
90 }
91
Popular Tags