1 23 24 package org.apache.slide.security; 25 26 import java.io.Serializable ; 27 28 import org.apache.slide.common.ObjectValidationFailedException; 29 import org.apache.slide.content.NodeRevisionNumber; 30 import org.apache.slide.structure.ActionNode; 31 import org.apache.slide.structure.ObjectNode; 32 import org.apache.slide.structure.SubjectNode; 33 import org.apache.slide.util.Messages; 34 35 40 public final class NodePermission implements Serializable , Cloneable { 41 42 43 45 46 53 public NodePermission(String objectUri, String subjectUri, 54 String actionUri) { 55 if (objectUri != null) { 56 this.objectUri = objectUri; 57 } 58 if (subjectUri != null) { 59 setSubject(subjectUri); 60 } 61 if (actionUri != null) { 62 setAction(actionUri); 63 } 64 inheritable = true; 65 negative = false; 66 } 67 68 69 77 public NodePermission(String objectUri, String subjectUri, 78 String actionUri, boolean inheritable) { 79 this(objectUri, subjectUri, actionUri); 80 this.inheritable = inheritable; 81 } 82 83 84 93 public NodePermission(String objectUri, String subjectUri, 94 String actionUri, boolean inheritable, 95 boolean negative) { 96 this(objectUri, subjectUri, actionUri); 97 this.inheritable = inheritable; 98 this.negative = negative; 99 } 100 101 102 109 public NodePermission(ObjectNode object, SubjectNode subject, 110 ActionNode action) { 111 this(object.getUri(), subject.getUri(), action.getUri()); 112 } 113 114 115 123 public NodePermission(ObjectNode object, SubjectNode subject, 124 ActionNode action, boolean inheritable) { 125 this(object, subject, action); 126 this.inheritable = inheritable; 127 } 128 129 130 139 public NodePermission(ObjectNode object, SubjectNode subject, 140 ActionNode action, boolean inheritable, 141 boolean negative) { 142 this(object, subject, action); 143 this.inheritable = inheritable; 144 this.negative = negative; 145 } 146 147 148 158 public NodePermission(ObjectNode object, NodeRevisionNumber revisionNumber, 159 SubjectNode subject, ActionNode action, 160 boolean inheritable, boolean negative) { 161 this(object, subject, action); 162 this.inheritable = inheritable; 163 if (revisionNumber != null) 164 this.inheritable = false; 165 this.negative = negative; 166 this.revisionNumber = revisionNumber; 167 } 168 169 170 179 public NodePermission(String objectUri, String revisionNumber, 180 String subjectUri, String actionUri, 181 boolean inheritable, boolean negative) { 182 this(objectUri, subjectUri, actionUri); 183 this.inheritable = inheritable; 184 if (revisionNumber != null) { 185 this.revisionNumber = new NodeRevisionNumber(revisionNumber); 186 this.inheritable = false; 187 } 188 this.negative = negative; 189 } 190 191 192 194 195 198 protected String objectUri; 199 200 201 204 protected NodeRevisionNumber revisionNumber; 205 206 207 210 protected String subjectUri; 211 212 213 216 protected String actionUri; 217 218 219 222 protected boolean inheritable; 223 224 228 protected transient String inheritedFrom; 229 230 231 234 protected boolean negative; 235 236 237 240 protected boolean invert; 241 242 245 protected boolean protect = false; 246 247 248 250 251 256 public void setInheritable(boolean inheritable) { 257 this.inheritable = inheritable; 258 } 259 260 261 266 public boolean isInheritable() { 267 return inheritable; 268 } 269 270 276 public void setInheritedFrom(String uri) { 277 this.inheritedFrom = uri; 278 } 279 280 286 public String getInheritedFrom() { 287 return inheritedFrom; 288 } 289 290 291 296 public void setNegative(boolean negative) { 297 this.negative = negative; 298 } 299 300 301 306 public boolean isNegative() { 307 return negative; 308 } 309 310 311 316 public void setInvert(boolean invert) { 317 this.invert = invert; 318 } 319 320 325 public boolean isInvert() { 326 return invert; 327 } 328 329 335 public void setProtected(boolean protect) { 336 this.protect = protect; 337 } 338 339 345 public boolean isProtected() { 346 return protect; 347 } 348 349 350 355 public String getObjectUri() { 356 return objectUri; 357 } 358 359 360 365 void setObject(ObjectNode object) { 366 if (object != null) { 367 this.objectUri = object.getUri(); 368 } 369 } 370 371 372 377 public void setObject(String objectUri) { 378 this.objectUri = objectUri; 379 } 380 381 382 387 public String getSubjectUri() { 388 return subjectUri; 389 } 390 391 392 397 void setSubject(SubjectNode subject) { 398 if (subject != null) { 399 setSubject(subject.getUri()); 400 } 401 } 402 403 404 409 void setSubject(String subjectUri) { 410 this.subjectUri = SubjectNode.getSubjectNode(subjectUri).getUri(); 411 } 412 413 SubjectNode getSubjectNode() { 414 return SubjectNode.getSubjectNode(subjectUri); 415 } 416 417 422 public NodeRevisionNumber getRevisionNumber() { 423 return revisionNumber; 424 } 425 426 427 432 void setRevisionNumber(NodeRevisionNumber revisionNumber) { 433 this.revisionNumber = revisionNumber; 434 } 435 436 437 442 public String getActionUri() { 443 return actionUri; 444 } 445 446 ActionNode getActionNode() { 447 return ActionNode.getActionNode(actionUri); 448 } 449 450 451 456 void setAction(ActionNode action) { 457 if (action != null) { 458 setAction(action.getUri()); 459 } 460 } 461 462 463 468 void setAction(String actionUri) { 469 this.actionUri = actionUri; 470 } 471 472 473 475 476 484 public boolean equals(Object obj) { 485 boolean result = false; 486 if ((obj != null) && (obj instanceof NodePermission)) { 487 NodePermission permission = (NodePermission) obj; 488 result = (this.objectUri.equals(permission.getObjectUri())) 489 && (this.subjectUri.equals(permission.getSubjectUri())) 490 && (this.actionUri.equals(permission.getActionUri())) 491 && (this.isNegative() == permission.isNegative()); 492 } 493 return result; 494 } 495 496 497 502 public int hashCode() { 503 return toString().hashCode(); 504 } 505 506 507 514 public String toString() { 515 return "[object="+objectUri+", subject="+subjectUri+", action="+actionUri+", ->"+(negative?"DENY":"GRANT")+"]"; 518 } 519 520 521 526 public NodePermission cloneObject() { 527 NodePermission result = null; 528 try { 529 result = (NodePermission) super.clone(); 530 } catch(CloneNotSupportedException e) { 531 } 532 return result; 533 } 534 535 536 541 public void validate(String expectedUri) { 542 543 if (objectUri == null) 544 throw new ObjectValidationFailedException 545 (expectedUri, Messages.message 546 (NodePermission.class.getName() + ".nullObjectUri")); 547 548 if (!objectUri.equals(expectedUri)) { 549 String tmpObjectUri=objectUri; 551 if (tmpObjectUri.endsWith("/")) 552 tmpObjectUri=tmpObjectUri.substring(0,tmpObjectUri.length()-1); 553 String tmpExpectedUri=expectedUri; 554 if (tmpExpectedUri.endsWith("/")) 555 tmpExpectedUri=tmpExpectedUri.substring(0,tmpExpectedUri.length()-1); 556 557 if (!tmpObjectUri.equals(tmpExpectedUri)) 558 throw new ObjectValidationFailedException 559 (expectedUri, Messages.message 560 (NodePermission.class.getName() + ".incorrectObjectUri")); 561 } 562 563 if (subjectUri == null) 564 throw new ObjectValidationFailedException 565 (expectedUri, Messages.message 566 (NodePermission.class.getName() + ".nullSubjectUri")); 567 568 if (actionUri == null) 569 throw new ObjectValidationFailedException 570 (expectedUri, Messages.message 571 (NodePermission.class.getName() + ".nullActionUri")); 572 573 } 574 575 576 } 577 | Popular Tags |