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>Portlet 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:dlestrat@apache.org">David Le Strat</a>
30: */
31: public class PortletPermission extends PortalResourcePermission {
32:
33: /**
34: * <p>Constructor for PortletPermission.</p>
35: *
36: * @param name The portlet name.
37: * @param actions The actions on the portlet.
38: */
39: public PortletPermission(String name, String actions) {
40: super (name, actions);
41: }
42:
43: /**
44: * <p>Constructor for PortletPermission.</p>
45: *
46: * @param name The portlet name.
47: * @param mask The mask of actions on the portlet.
48: */
49: public PortletPermission(String name, int mask) {
50: super (name, mask);
51: }
52:
53: public boolean implies(Permission permission) {
54: // The permission must be an instance
55: // of the PortletPermission.
56: if (!(permission instanceof PortletPermission)) {
57: return false;
58: }
59:
60: String name = getName();
61: if (name != null) {
62: int index = name.indexOf('*');
63: if (index > -1) {
64: if (!(permission.getName().startsWith(name.substring(0,
65: index)))) {
66: return false;
67: }
68: } else if (!(permission.getName().equals(name))) {
69: // The portlet name must be the same.
70: return false;
71: }
72: }
73:
74: PortletPermission portletPerm = (PortletPermission) permission;
75:
76: // The action bits in portletPerm (permission)
77: // must be set in the current mask permission.
78: return (mask & portletPerm.mask) == portletPerm.mask;
79:
80: }
81:
82: /**
83: * @see java.security.Permission#equals(Object)
84: */
85: public boolean equals(Object object) {
86: if (!(object instanceof PortletPermission))
87: return false;
88:
89: PortletPermission p = (PortletPermission) object;
90: return ((p.mask == mask) && (p.getName().equals(getName())));
91: }
92:
93: }
|