01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * 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.jetspeed.security;
18:
19: import java.security.Permission;
20:
21: /**
22: * <p>Folder permission.</p>
23: * <p>This code was partially inspired from articles from:</p>
24: * <ul>
25: * <li><a href="http://www-106.ibm.com/developerworks/library/j-jaas/">
26: * Extend JAAS for class instance-level authorization.</a></li>
27: * </ul>
28: *
29: * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
30: */
31: public class PagePermission extends PortalResourcePermission {
32: /**
33: * <p>Constructor for PagePermission.</p>
34: *
35: * @param name The portlet name.
36: * @param actions The actions on the portlet.
37: */
38: public PagePermission(String name, String actions) {
39: super (name, actions);
40: }
41:
42: /**
43: * <p>Constructor for PagePermission.</p>
44: *
45: * @param name The portlet name.
46: * @param mask The mask for actions on the portlet.
47: */
48: public PagePermission(String name, int mask) {
49: super (name, mask);
50: }
51:
52: public boolean implies(Permission permission) {
53: // The permission must be an instance
54: // of the PortletPermission.
55: if (!(permission instanceof PagePermission)) {
56: return false;
57: }
58:
59: // The page name must be the same.
60: if (!(permission.getName().equals(getName()))) {
61: return false;
62: }
63:
64: PagePermission pagePerm = (PagePermission) permission;
65:
66: // The action bits in PagePerm (permission)
67: // must be set in the current mask permission.
68: return (mask & pagePerm.mask) == pagePerm.mask;
69:
70: }
71:
72: /**
73: * @see java.security.Permission#equals(Object)
74: */
75: public boolean equals(Object object) {
76: if (!(object instanceof PagePermission))
77: return false;
78:
79: PagePermission p = (PagePermission) object;
80: return ((p.mask == mask) && (p.getName().equals(getName())));
81: }
82:
83: }
|