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 org.apache.jetspeed.JetspeedActions;
20
21 import java.security.Permission;
22 import java.security.PermissionCollection;
23
24 /***
25 * <p>Generalized Portlet Resoure permission.</p>
26 * <p>This code was partially inspired from articles from:</p>
27 * <ul>
28 * <li><a href="http://www-106.ibm.com/developerworks/library/j-jaas/">
29 * Extend JAAS for class instance-level authorization.</a></li>
30 * </ul>
31 *
32 * @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
33 * @author <a href="mailto:taylor@apache.org">David Sean Taylor</a>
34 */
35 public abstract class PortalResourcePermission extends Permission
36 {
37 /***
38 * <p>Mask used for determining what actions are allowed or requested.</p>
39 */
40 protected final int mask;
41
42 /***
43 * <p>Constructor for PortletPermission.</p>
44 *
45 * @param name The portlet name.
46 * @param actions The actions on the portlet.
47 */
48 public PortalResourcePermission(String name, String actions)
49 {
50 super(name);
51 mask = parseActions(actions);
52 }
53
54 /***
55 * <p>Constructor for PortletPermission.</p>
56 *
57 * @param name The portlet name.
58 * @param mask The mask representing actions on the portlet.
59 */
60 public PortalResourcePermission(String name, int mask)
61 {
62 super(name);
63 this.mask = mask;
64 }
65
66 /***
67 * @see java.security.Permission#hashCode()
68 */
69 public int hashCode()
70 {
71 StringBuffer value = new StringBuffer(getName());
72 return value.toString().hashCode() ^ mask;
73 }
74
75 /***
76 * @see java.security.Permission#getActions()
77 */
78 public String getActions()
79 {
80 return JetspeedActions.getContainerActions(mask);
81 }
82
83
84
85
86 public boolean implies(Permission permission)
87 {
88 throw new IllegalStateException("Permission class did not implement implies");
89 }
90
91 /***
92 * <p>Parses the actions string.</p>
93 * <p>Actions are separated by commas or white space.</p>
94 *
95 * @param actions The actions
96 */
97 public static int parseActions(String actions)
98 {
99 return JetspeedActions.getContainerActionsMask(actions);
100 }
101
102 /***
103 * <p>Overrides <code>Permission.newPermissionCollection()</code>.</p>
104 *
105 * @see java.security.Permission#newPermissionCollection()
106 */
107 public PermissionCollection newPermissionCollection()
108 {
109 return new PortalResourcePermissionCollection();
110 }
111 }