| 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 |
|
|
| 24 |
|
|
| 25 |
|
|
| 26 |
|
|
| 27 |
|
public class SimpleAclEntry extends AbstractBasicAclEntry { |
| 28 |
|
|
| 29 |
|
|
| 30 |
2 |
private static final Log logger = LogFactory.getLog(SimpleAclEntry.class); |
| 31 |
|
|
| 32 |
|
|
| 33 |
|
public static final int NOTHING = 0; |
| 34 |
1 |
public static final int ADMINISTRATION = (int) Math.pow(2, 0); |
| 35 |
1 |
public static final int READ = (int) Math.pow(2, 1); |
| 36 |
1 |
public static final int WRITE = (int) Math.pow(2, 2); |
| 37 |
1 |
public static final int CREATE = (int) Math.pow(2, 3); |
| 38 |
1 |
public static final int DELETE = (int) Math.pow(2, 4); |
| 39 |
|
|
| 40 |
|
|
| 41 |
1 |
public static final int READ_WRITE_CREATE_DELETE = READ | WRITE | CREATE | DELETE; |
| 42 |
1 |
public static final int READ_WRITE_CREATE = READ | WRITE | CREATE; |
| 43 |
1 |
public static final int READ_WRITE = READ | WRITE; |
| 44 |
1 |
public static final int READ_WRITE_DELETE = READ | WRITE | DELETE; |
| 45 |
|
|
| 46 |
|
|
| 47 |
1 |
private static final int[] VALID_PERMISSIONS = { |
| 48 |
|
NOTHING, ADMINISTRATION, READ, WRITE, CREATE, DELETE, READ_WRITE_CREATE_DELETE, READ_WRITE_CREATE, |
| 49 |
|
READ_WRITE, READ_WRITE_DELETE |
| 50 |
|
}; |
| 51 |
|
|
| 52 |
1 |
private static final String[] VALID_PERMISSIONS_AS_STRING = { |
| 53 |
|
"NOTHING", "ADMINISTRATION", "READ", "WRITE", "CREATE", "DELETE", "READ_WRITE_CREATE_DELETE", |
| 54 |
|
"READ_WRITE_CREATE", "READ_WRITE", "READ_WRITE_DELETE" }; |
| 55 |
|
|
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
public SimpleAclEntry() { |
| 67 |
30 |
super(); |
| 68 |
30 |
} |
| 69 |
|
|
| 70 |
|
public SimpleAclEntry(Object recipient, AclObjectIdentity aclObjectIdentity, |
| 71 |
|
AclObjectIdentity aclObjectParentIdentity, int mask) { |
| 72 |
166 |
super(recipient, aclObjectIdentity, aclObjectParentIdentity, mask); |
| 73 |
164 |
} |
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
|
|
| 78 |
|
|
| 79 |
|
|
| 80 |
|
public int[] getValidPermissions() { |
| 81 |
196 |
return (int[]) VALID_PERMISSIONS.clone(); |
| 82 |
|
} |
| 83 |
|
|
| 84 |
|
public String printPermissionsBlock(int i) { |
| 85 |
6 |
StringBuffer sb = new StringBuffer(); |
| 86 |
|
|
| 87 |
6 |
if (isPermitted(i, ADMINISTRATION)) { |
| 88 |
1 |
sb.append('A'); |
| 89 |
|
} else { |
| 90 |
5 |
sb.append('-'); |
| 91 |
|
} |
| 92 |
|
|
| 93 |
6 |
if (isPermitted(i, READ)) { |
| 94 |
2 |
sb.append('R'); |
| 95 |
|
} else { |
| 96 |
4 |
sb.append('-'); |
| 97 |
|
} |
| 98 |
|
|
| 99 |
6 |
if (isPermitted(i, WRITE)) { |
| 100 |
2 |
sb.append('W'); |
| 101 |
|
} else { |
| 102 |
4 |
sb.append('-'); |
| 103 |
|
} |
| 104 |
|
|
| 105 |
6 |
if (isPermitted(i, CREATE)) { |
| 106 |
2 |
sb.append('C'); |
| 107 |
|
} else { |
| 108 |
4 |
sb.append('-'); |
| 109 |
|
} |
| 110 |
|
|
| 111 |
6 |
if (isPermitted(i, DELETE)) { |
| 112 |
1 |
sb.append('D'); |
| 113 |
|
} else { |
| 114 |
5 |
sb.append('-'); |
| 115 |
|
} |
| 116 |
|
|
| 117 |
6 |
return sb.toString(); |
| 118 |
|
} |
| 119 |
|
|
| 120 |
|
|
| 121 |
|
|
| 122 |
|
|
| 123 |
|
|
| 124 |
|
|
| 125 |
|
|
| 126 |
|
|
| 127 |
|
|
| 128 |
|
public static int parsePermission(String permission) { |
| 129 |
83 |
for (int i = 0; i < VALID_PERMISSIONS_AS_STRING.length; i++) { |
| 130 |
81 |
if (VALID_PERMISSIONS_AS_STRING[i].equalsIgnoreCase(permission)) { |
| 131 |
15 |
return VALID_PERMISSIONS[i]; |
| 132 |
|
} |
| 133 |
|
} |
| 134 |
2 |
throw new IllegalArgumentException("Permission provided does not exist: " + permission); |
| 135 |
|
} |
| 136 |
|
|
| 137 |
|
|
| 138 |
|
|
| 139 |
|
|
| 140 |
|
|
| 141 |
|
|
| 142 |
|
|
| 143 |
|
public static int[] parsePermissions(String[] permissions) { |
| 144 |
8 |
int[] requirepermissionAsIntArray = new int[permissions.length]; |
| 145 |
16 |
for (int i = 0; i < requirepermissionAsIntArray.length; i++) { |
| 146 |
9 |
requirepermissionAsIntArray[i] = parsePermission(permissions[i]); |
| 147 |
|
} |
| 148 |
7 |
return requirepermissionAsIntArray; |
| 149 |
|
} |
| 150 |
|
} |