KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > enterprise > security > acl > WebResource


1 /*
2  * The contents of this file are subject to the terms
3  * of the Common Development and Distribution License
4  * (the License). You may not use this file except in
5  * compliance with the License.
6  *
7  * You can obtain a copy of the license at
8  * https://glassfish.dev.java.net/public/CDDLv1.0.html or
9  * glassfish/bootstrap/legal/CDDLv1.0.txt.
10  * See the License for the specific language governing
11  * permissions and limitations under the License.
12  *
13  * When distributing Covered Code, include this CDDL
14  * Header Notice in each file and include the License file
15  * at glassfish/bootstrap/legal/CDDLv1.0.txt.
16  * If applicable, add the following below the CDDL Header,
17  * with the fields enclosed by brackets [] replaced by
18  * you own identifying information:
19  * "Portions Copyrighted [year] [name of copyright owner]"
20  *
21  * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
22  */

23 package com.sun.enterprise.security.acl;
24
25 import java.security.Principal JavaDoc;
26 /**
27  * @author Harish Prabandham
28  */

29 public class WebResource extends Resource {
30     private transient boolean wildcard;
31     private transient String JavaDoc path;
32
33     public WebResource(String JavaDoc app, String JavaDoc name, String JavaDoc method) {
34         super(app,name,method);
35         init(name);
36     }
37
38     private void init(String JavaDoc name)
39     {
40         if (name == null)
41             throw new IllegalArgumentException JavaDoc("name can't be null");
42                                                                          
43         if (name.endsWith("/*") || name.equals("*")) {
44             wildcard = true;
45             if (name.length() == 1) {
46                 path = "";
47             } else {
48                 path = name.substring(0, name.length()-1);
49             }
50         } else {
51             path = name;
52         }
53     }
54
55     public boolean equals(Object JavaDoc obj) {
56         if(obj == this)
57             return true;
58         
59         if ((obj == null) || (obj.getClass() != getClass()))
60             return false;
61         
62         Resource r = (Resource) obj;
63         
64         return getApplication().equals(r.getApplication()) &&
65             getMethod().equals(r.getMethod()) &&
66             getName().equals(r.getName());
67     }
68
69     public boolean implies(Resource resource) {
70     if(( resource == null) || (resource.getClass() != getClass()))
71         return false;
72
73     WebResource that = (WebResource) resource;
74
75     // Application name is not an issue in implies .....
76
if(!getMethod().equals(that.getMethod()))
77             return false;
78         
79     if(this.wildcard) {
80             if (that.wildcard)
81                 // one wildcard can imply another
82
return that.path.startsWith(path);
83             else
84                 // make sure ap.path is longer so a/b/* doesn't imply a/b
85
return (that.path.length() > this.path.length()) &&
86                     that.path.startsWith(this.path);
87     } else {
88         if (that.wildcard) {
89                 // a non-wildcard can't imply a wildcard
90
return false;
91             }
92             else {
93                 return this.path.equals(that.path);
94             }
95     }
96     }
97 }
98
Popular Tags