1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
35 * <p>Constructor for PortletPermission.</p>
36 *
37 * @param name The portlet name.
38 * @param actions The actions on the portlet.
39 */
40 public PortletPermission(String name, String actions)
41 {
42 super(name, actions);
43 }
44
45 /***
46 * <p>Constructor for PortletPermission.</p>
47 *
48 * @param name The portlet name.
49 * @param mask The mask of actions on the portlet.
50 */
51 public PortletPermission(String name, int mask)
52 {
53 super(name, mask);
54 }
55
56 public boolean implies(Permission permission)
57 {
58
59
60 if (!(permission instanceof PortletPermission))
61 {
62 return false;
63 }
64
65 String name = getName();
66 if (name != null)
67 {
68 int index = name.indexOf('*');
69 if (index > -1)
70 {
71 if (!(permission.getName().startsWith(name.substring(0, index))))
72 {
73 return false;
74 }
75 }
76 else if (!(permission.getName().equals(name)))
77 {
78
79 return false;
80 }
81 }
82
83 PortletPermission portletPerm = (PortletPermission) permission;
84
85
86
87 return (mask & portletPerm.mask) == portletPerm.mask;
88
89 }
90
91 /***
92 * @see java.security.Permission#equals(Object)
93 */
94 public boolean equals(Object object)
95 {
96 if (!(object instanceof PortletPermission))
97 return false;
98
99 PortletPermission p = (PortletPermission) object;
100 return ((p.mask == mask) && (p.getName().equals(getName())));
101 }
102
103 }