1 31 32 package org.opencms.security; 33 34 import org.opencms.util.CmsUUID; 35 36 import java.util.StringTokenizer ; 37 38 60 public class CmsAccessControlEntry { 61 62 63 public static final int ACCESS_FLAGS_DELETED = 1; 64 65 66 public static final int ACCESS_FLAGS_GROUP = 32; 67 68 69 public static final int ACCESS_FLAGS_INHERIT = 2; 70 71 72 public static final int ACCESS_FLAGS_INHERITED = 8; 73 74 75 public static final int ACCESS_FLAGS_OVERWRITE = 4; 76 77 78 public static final int ACCESS_FLAGS_RESPONSIBLE = 64; 79 80 81 public static final int ACCESS_FLAGS_USER = 16; 82 83 86 private int m_flags; 87 88 91 private CmsPermissionSetCustom m_permissions; 92 93 96 private CmsUUID m_principal; 97 98 101 private CmsUUID m_resource; 102 103 110 public CmsAccessControlEntry(CmsUUID resource, CmsAccessControlEntry base) { 111 112 m_resource = resource; 113 m_principal = base.m_principal; 114 m_permissions = base.m_permissions; 115 m_flags = base.m_flags; 116 } 117 118 127 public CmsAccessControlEntry(CmsUUID resource, CmsUUID principal, CmsPermissionSet permissions, int flags) { 128 129 m_resource = resource; 130 m_principal = principal; 131 m_permissions = new CmsPermissionSetCustom(permissions); 132 m_flags = flags; 133 } 134 135 147 public CmsAccessControlEntry(CmsUUID resource, CmsUUID principal, int allowed, int denied, int flags) { 148 149 m_resource = resource; 150 m_principal = principal; 151 m_permissions = new CmsPermissionSetCustom(allowed, denied); 152 m_flags = flags; 153 } 154 155 163 public CmsAccessControlEntry(CmsUUID resource, CmsUUID principal, String acPermissionString) { 164 165 m_resource = resource; 166 m_principal = principal; 167 m_flags = 0; 168 169 StringTokenizer tok = new StringTokenizer (acPermissionString, "+-", true); 170 StringBuffer permissionString = new StringBuffer (); 171 172 while (tok.hasMoreElements()) { 173 String prefix = tok.nextToken(); 174 String suffix = tok.nextToken(); 175 switch (suffix.charAt(0)) { 176 case 'I': 177 case 'i': 178 if (prefix.charAt(0) == '+') { 179 m_flags |= CmsAccessControlEntry.ACCESS_FLAGS_INHERIT; 180 } 181 if (prefix.charAt(0) == '-') { 182 m_flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_INHERIT; 183 } 184 break; 185 case 'O': 186 case 'o': 187 if (prefix.charAt(0) == '+') { 188 m_flags |= CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE; 189 } 190 if (prefix.charAt(0) == '-') { 191 m_flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_OVERWRITE; 192 } 193 break; 194 case 'L': 195 case 'l': 196 if (prefix.charAt(0) == '+') { 197 m_flags |= CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE; 198 } 199 if (prefix.charAt(0) == '-') { 200 m_flags &= ~CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE; 201 } 202 break; 203 default: 204 permissionString.append(prefix); 205 permissionString.append(suffix); 206 break; 207 } 208 } 209 210 m_permissions = new CmsPermissionSetCustom(permissionString.toString()); 211 } 212 213 218 public void denyPermissions(int denied) { 219 220 m_permissions.denyPermissions(denied); 221 } 222 223 226 public boolean equals(Object obj) { 227 228 if (obj == this) { 229 return true; 230 } 231 if (obj instanceof CmsAccessControlEntry) { 232 CmsAccessControlEntry other = (CmsAccessControlEntry)obj; 233 if (other.m_flags != m_flags) { 234 return false; 235 } 236 if (other.getPermissions().getAllowedPermissions() != getPermissions().getAllowedPermissions()) { 237 return false; 238 } 239 if (other.getPermissions().getDeniedPermissions() != getPermissions().getDeniedPermissions()) { 240 return false; 241 } 242 if (!other.m_resource.equals(m_resource)) { 243 return false; 244 } 245 if (!other.m_principal.equals(m_principal)) { 246 return false; 247 } 248 return true; 249 } 250 return false; 251 } 252 253 258 public int getAllowedPermissions() { 259 260 return m_permissions.getAllowedPermissions(); 261 } 262 263 268 public int getDeniedPermissions() { 269 270 return m_permissions.getDeniedPermissions(); 271 } 272 273 278 public int getFlags() { 279 280 return m_flags; 281 } 282 283 288 public CmsPermissionSet getPermissions() { 289 290 return m_permissions; 291 } 292 293 298 public CmsUUID getPrincipal() { 299 300 return m_principal; 301 } 302 303 308 public CmsUUID getResource() { 309 310 return m_resource; 311 } 312 313 318 public String getResponsibleString() { 319 320 if (isResponsible()) { 321 return "+l"; 322 } else { 323 return "-l"; 324 } 325 } 326 327 332 public void grantPermissions(int allowed) { 333 334 m_permissions.grantPermissions(allowed); 335 } 336 337 340 public int hashCode() { 341 342 if (m_permissions != null) { 343 return m_permissions.hashCode() * m_flags; 344 } 345 return CmsUUID.getNullUUID().hashCode(); 346 } 347 348 355 public boolean isInherited() { 356 357 return ((m_flags & CmsAccessControlEntry.ACCESS_FLAGS_INHERITED) > 0); 358 } 359 360 365 public boolean isResponsible() { 366 367 return ((m_flags & CmsAccessControlEntry.ACCESS_FLAGS_RESPONSIBLE) > 0); 368 } 369 370 375 public void resetFlags(int flags) { 376 377 m_flags &= ~flags; 378 } 379 380 385 public void setFlags(int flags) { 386 387 m_flags |= flags; 388 } 389 390 395 public void setFlagsForPrincipal(I_CmsPrincipal principal) { 396 397 setFlags(principal.isGroup() ? CmsAccessControlEntry.ACCESS_FLAGS_GROUP 398 : CmsAccessControlEntry.ACCESS_FLAGS_USER); 399 } 400 401 406 public void setPermissions(CmsPermissionSet permissions) { 407 408 m_permissions.setPermissions(permissions); 409 } 410 411 415 public String toString() { 416 417 return "[Ace:] " 418 + "ResourceId=" 419 + m_resource 420 + ", PrincipalId=" 421 + m_principal 422 + ", Permissions=" 423 + m_permissions.toString() 424 + ", Flags=" 425 + m_flags; 426 } 427 } | Popular Tags |