1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.acegisecurity.acl.basic;
17
18 import org.apache.commons.logging.Log;
19 import org.apache.commons.logging.LogFactory;
20
21
22 /***
23 * Stores some privileges typical of a domain object.
24 *
25 * @author Ben Alex
26 * @version $Id: SimpleAclEntry.java,v 1.2 2005/11/17 00:55:47 benalex Exp $
27 */
28 public class SimpleAclEntry extends AbstractBasicAclEntry {
29
30
31 private static final Log logger = LogFactory.getLog(SimpleAclEntry.class);
32
33
34 public static final int NOTHING = 0;
35 public static final int ADMINISTRATION = (int) Math.pow(2, 0);
36 public static final int READ = (int) Math.pow(2, 1);
37 public static final int WRITE = (int) Math.pow(2, 2);
38 public static final int CREATE = (int) Math.pow(2, 3);
39 public static final int DELETE = (int) Math.pow(2, 4);
40
41
42 public static final int READ_WRITE_CREATE_DELETE = READ | WRITE | CREATE
43 | DELETE;
44 public static final int READ_WRITE_CREATE = READ | WRITE | CREATE;
45 public static final int READ_WRITE = READ | WRITE;
46 public static final int READ_WRITE_DELETE = READ | WRITE | DELETE;
47
48
49 private static final int[] validPermissions = {NOTHING, ADMINISTRATION, READ, WRITE, CREATE, DELETE, READ_WRITE_CREATE_DELETE, READ_WRITE_CREATE, READ_WRITE, READ_WRITE_DELETE};
50
51
52
53 /***
54 * Allows {@link BasicAclDao} implementations to construct this object
55 * using <code>newInstance()</code>.
56 *
57 * <P>
58 * Normal classes should <B>not</B> use this default constructor.
59 * </p>
60 */
61 public SimpleAclEntry() {
62 super();
63 }
64
65 public SimpleAclEntry(Object recipient,
66 AclObjectIdentity aclObjectIdentity,
67 AclObjectIdentity aclObjectParentIdentity, int mask) {
68 super(recipient, aclObjectIdentity, aclObjectParentIdentity, mask);
69 }
70
71
72
73 public int[] getValidPermissions() {
74 return validPermissions;
75 }
76
77 public String printPermissionsBlock(int i) {
78 StringBuffer sb = new StringBuffer();
79
80 if (isPermitted(i, ADMINISTRATION)) {
81 sb.append('A');
82 } else {
83 sb.append('-');
84 }
85
86 if (isPermitted(i, READ)) {
87 sb.append('R');
88 } else {
89 sb.append('-');
90 }
91
92 if (isPermitted(i, WRITE)) {
93 sb.append('W');
94 } else {
95 sb.append('-');
96 }
97
98 if (isPermitted(i, CREATE)) {
99 sb.append('C');
100 } else {
101 sb.append('-');
102 }
103
104 if (isPermitted(i, DELETE)) {
105 sb.append('D');
106 } else {
107 sb.append('-');
108 }
109
110 return sb.toString();
111 }
112 }