Changeset 477
- Timestamp:
- 05/15/06 00:25:17
- Files:
-
- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java (modified) (6 diffs)
- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java (modified) (5 diffs)
- trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java (modified) (5 diffs)
- trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java (modified) (1 diff)
- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java (modified) (7 diffs)
- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java (modified) (3 diffs)
- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java (modified) (1 diff)
- trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/HibSession.java (modified) (1 diff)
- trunk/calendar3/calFacade/src/org/bedework/calfacade/BwCalendar.java (modified) (4 diffs)
- trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java (modified) (1 diff)
- trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java (modified) (1 diff)
- trunk/calendar3/webcommon/src/org/bedework/webcommon/access/AccessAction.java (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java
r448 r477 298 298 */ 299 299 public PrivilegeSet getHow() { 300 if (how == null) { 301 how = new PrivilegeSet(); 302 } 303 300 304 return how; 301 305 } … … 326 330 public void addPriv(Privilege val) { 327 331 getPrivs().add(val); 332 getHow().setPrivilege(val); 328 333 } 329 334 … … 510 515 } 511 516 512 /* ==================================================================== 513 * Object methods 514 * ==================================================================== */ 515 516 public int compareTo(Object o) { 517 if (this == o) { 518 return 0; 519 } 520 521 if (!(o instanceof Ace)) { 522 return 1; 523 } 524 525 Ace that = (Ace)o; 526 if (notWho != that.notWho) { 517 /** 518 * @param whoMatch 519 * @return int -1, 0, 1 520 */ 521 public int compareWho(Ace whoMatch) { 522 if (notWho != whoMatch.notWho) { 527 523 if (notWho) { 528 524 return -1; … … 531 527 } 532 528 533 if (whoType < that.whoType) {529 if (whoType < whoMatch.whoType) { 534 530 return -1; 535 531 } 536 532 537 if (whoType > that.whoType) {533 if (whoType > whoMatch.whoType) { 538 534 return 1; 539 535 } 540 536 541 return compareWho(who, that.who); 537 return compareWho(who, whoMatch.who); 538 } 539 540 /* ==================================================================== 541 * Object methods 542 * ==================================================================== */ 543 544 public int compareTo(Object o) { 545 if (this == o) { 546 return 0; 547 } 548 549 if (!(o instanceof Ace)) { 550 return 1; 551 } 552 553 Ace that = (Ace)o; 554 555 int res = compareWho(that); 556 if (res == 0) { 557 res = getHow().compareTo(that.getHow()); 558 } 559 560 return res; 542 561 } 543 562 … … 557 576 558 577 public boolean equals(Object o) { 559 if (this == o) { 560 return true; 561 } 562 563 if (!(o instanceof Ace)) { 564 return false; 565 } 566 567 Ace that = (Ace)o; 568 569 return sameWho(who, that.who) && 570 (notWho == that.notWho) && 571 (whoType == that.whoType); 578 return compareTo(o) == 0; 572 579 } 573 580 … … 608 615 * ==================================================================== */ 609 616 610 private boolean sameWho(String who1, String who2) {611 return compareWho(who1, who2) == 0;612 }617 // private boolean sameWho(String who1, String who2) { 618 // return compareWho(who1, who2) == 0; 619 // } 613 620 614 621 private int compareWho(String who1, String who2) { trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java
r448 r477 362 362 } 363 363 364 /* * Remove access for a given 'who' entry364 /* * Remove access for a given 'who' entry 365 365 * 366 366 * @param who … … 368 368 * @param whoType 369 369 * @return boolean true if removed 370 * /371 public boolean remove Access(String who, boolean notWho, int whoType) {370 * / 371 public boolean removeWho(String who, boolean notWho, int whoType) { 372 372 if (aces == null) { 373 373 return false; … … 375 375 376 376 return aces.remove(new Ace(who, notWho, whoType, (PrivilegeSet)null)); 377 } 377 }*/ 378 378 379 379 /** Remove access for a given 'who' entry … … 382 382 * @return boolean true if removed 383 383 */ 384 public boolean remove Access(Ace whoDef) {384 public boolean removeWho(Ace whoDef) { 385 385 if (aces == null) { 386 386 return false; 387 387 } 388 388 389 return aces.remove(whoDef); 389 /* We're called to remove any 'who' entries before adding. Usually there will 390 * be nothing to remove (I assume) so check first. 391 * 392 * We can't remove as we check or we get concurrent mod exception. 393 */ 394 boolean remove = false; 395 Iterator it = aces.iterator(); 396 while (it.hasNext()) { 397 Ace ace = (Ace)it.next(); 398 399 if (ace.compareWho(whoDef) == 0) { 400 remove = true; 401 break; 402 } 403 } 404 405 if (!remove) { 406 return false; 407 } 408 409 TreeSet newAces = new TreeSet(); 410 it = aces.iterator(); 411 while (it.hasNext()) { 412 Ace ace = (Ace)it.next(); 413 414 if (ace.compareWho(whoDef) != 0) { 415 newAces.add(ace); 416 } 417 } 418 419 aces = newAces; 420 return remove; 390 421 } 391 422 … … 477 508 * <p>Also note the encoded value will not reflect the eventual Acl. 478 509 * 479 * @param val char[] val to decode andmerge510 * @param val Acl to merge 480 511 * @throws AccessException 481 512 */ trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java
r448 r477 60 60 * @author Mike Douglass douglm@rpi.edu 61 61 */ 62 public class PrivilegeSet implements Serializable, PrivilegeDefs {62 public class PrivilegeSet implements Serializable, PrivilegeDefs, Comparable { 63 63 private char[] privileges; 64 64 … … 168 168 } 169 169 170 /** 171 */ 172 public PrivilegeSet() { 173 privileges = (char[])defaultNonOwnerPrivileges.getPrivileges().clone(); 174 } 175 170 176 /** Default privs for an owner 171 177 * … … 205 211 206 212 privileges[index] = val; 213 } 214 215 /** Set the given privilege 216 * 217 * @param priv Privilege object 218 */ 219 public void setPrivilege(Privilege priv) { 220 if (privileges == null) { 221 privileges = (char[])defaultNonOwnerPrivileges.getPrivileges().clone(); 222 } 223 224 if (priv.getDenial()) { 225 privileges[priv.getIndex()] = denied; 226 } else { 227 privileges[priv.getIndex()] = allowed; 228 } 207 229 } 208 230 … … 307 329 } 308 330 331 /* ==================================================================== 332 * Object methods 333 * ==================================================================== */ 334 335 public int compareTo(Object o) { 336 if (this == o) { 337 return 0; 338 } 339 340 if (!(o instanceof PrivilegeSet)) { 341 return 1; 342 } 343 344 PrivilegeSet that = (PrivilegeSet)o; 345 if (privileges == null) { 346 if (that.privileges != null) { 347 return -1; 348 } 349 350 return 0; 351 } 352 353 if (that.privileges != null) { 354 return -1; 355 } 356 357 for (int pi = 0; pi < privileges.length; pi++) { 358 char thisp = privileges[pi]; 359 char thatp = that.privileges[pi]; 360 361 if (thisp < thatp) { 362 return -1; 363 } 364 365 if (thisp > thatp) { 366 return -1; 367 } 368 } 369 370 return 0; 371 } 372 373 public int hashCode() { 374 int hc = 7; 375 376 if (privileges == null) { 377 return hc; 378 } 379 380 for (int pi = 0; pi < privileges.length; pi++) { 381 hc *= privileges[pi]; 382 } 383 384 return hc; 385 } 386 387 public boolean equals(Object o) { 388 return compareTo(o) == 0; 389 } 390 309 391 public Object clone() { 310 392 return new PrivilegeSet((char[])getPrivileges().clone()); … … 320 402 } 321 403 } 322 trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java
r448 r477 338 338 339 339 if (tagOpen) { 340 // XXX Wrong - need to encode an href in the acl 341 /* 342 if (ace.getInherited()) { 343 xml.emptyTag(WebdavTags.inherited); 344 } 345 */ 340 346 xml.closeTag(tag); 341 347 } trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java
r448 r477 111 111 } 112 112 113 private HashMap pathInfoTable = new HashMap(); 113 private static class PathInfoMap extends HashMap { 114 synchronized PathInfo getInfo(String path) { 115 return (PathInfo)get(path); 116 } 117 118 synchronized void putInfo(String path, PathInfo pi) { 119 put(path, pi); 120 } 121 122 synchronized void flush() { 123 clear(); 124 } 125 } 126 127 private PathInfoMap pathInfoMap = new PathInfoMap(); 114 128 115 129 /* ==================================================================== … … 181 195 182 196 /** Change the access to the given calendar entity using the supplied aces. 197 * We are changing access so we remove all access for each who in the list and 198 * then add the new aces. 183 199 * 184 200 * @param ent BwShareableDbentity … … 191 207 Acl acl = checkAccess(ent, privWriteAcl, false).acl; 192 208 209 /* First remove for all whos */ 193 210 Iterator it = aces.iterator(); 194 211 while (it.hasNext()) { 195 212 Ace ace = (Ace)it.next(); 196 213 197 acl.removeAccess(ace); 214 acl.removeWho(ace); 215 } 216 217 /* Now add the access */ 218 it = aces.iterator(); 219 while (it.hasNext()) { 220 Ace ace = (Ace)it.next(); 221 198 222 acl.addAce(ace); 199 223 } … … 201 225 ent.setAccess(new String(acl.encode())); 202 226 203 if (ent instanceof BwCalendar) { 204 updatePathInfo((BwCalendar)ent, acl); 205 } 227 pathInfoMap.flush(); 206 228 } catch (Throwable t) { 207 229 throw new CalFacadeException(t); … … 348 370 349 371 String path = container.getPath(); 350 PathInfo pi = (PathInfo)pathInfoTable.get(path);372 PathInfo pi = pathInfoMap.getInfo(path); 351 373 352 374 if (pi == null) { 353 375 pi = getPathInfo(container); 354 pathInfo Table.put(path, pi);376 pathInfoMap.putInfo(path, pi); 355 377 } 356 378 … … 475 497 476 498 /* Update the merged Acl for the given calendar. 477 * /499 * Doesn't work because any children in the table need the access changing. 478 500 private void updatePathInfo(BwCalendar cal, Acl acl) throws CalFacadeException { 479 501 try { 480 502 String path = cal.getPath(); 481 PathInfo pi = (PathInfo)pathInfoTable.get(path);503 PathInfo pi = pathInfoMap.getInfo(path); 482 504 483 505 if (pi == null) { … … 490 512 pi.encoded = acl.encodeAll(); 491 513 492 pathInfo Table.put(path, pi);514 pathInfoMap.putInfo(path, pi); 493 515 } catch (Throwable t) { 494 516 throw new CalFacadeException(t); 495 517 } 496 518 } 519 */ 497 520 498 521 private Logger getLog() { trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java
r469 r477 395 395 } 396 396 397 public void changeAccess(BwCalendar cal, 398 Collection aces) throws CalFacadeException { 399 HibSession sess = getSess(); 400 401 cal = getCalendar(cal.getPath(), privWriteAcl, false); 402 access.changeAccess(cal, aces); 403 sess.saveOrUpdate(cal); 404 } 405 397 406 public boolean deleteCalendar(BwCalendar val) throws CalFacadeException { 398 407 HibSession sess = getSess(); … … 472 481 /* Returns the cloned (sub)tree of calendars to which user has access 473 482 * 483 * <p>This needs a rethink - cloning effectively disables optimistic 484 * locking - at least I think so. 485 * 474 486 * @return BwCalendar (sub)root with all accessible children attached 475 487 * @throws CalFacadeException … … 490 502 491 503 BwCalendar cal = (BwCalendar)subroot.shallowClone(); 492 // XXX Temp fix - add id to the clone 504 // XXX Temp fix - add id to the clone - only until we get rid of ids in 505 // admin preferred calendars 493 506 cal.setId(subroot.getId()); 494 507 trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java
r469 r477 698 698 public void changeAccess(BwShareableDbentity ent, 699 699 Collection aces) throws CalFacadeException { 700 checkOpen(); 700 if (ent instanceof BwCalendar) { 701 changeAccess((BwCalendar)ent, aces); 702 return; 703 } 704 checkOpen(); 705 checkAccess(ent, privWriteAcl, false); 701 706 access.changeAccess(ent, aces); 702 707 sess.saveOrUpdate(ent); 708 } 709 710 public void changeAccess(BwCalendar cal, 711 Collection aces) throws CalFacadeException { 712 checkOpen(); 713 calendars.changeAccess(cal, aces); 703 714 } 704 715 trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/HibSession.java
r436 r477 686 686 * 687 687 * @param obj 688 * @throws CalFacadeException 689 */ 690 public void merge(Object obj) throws CalFacadeException { 691 if (exc != null) { 692 // Didn't hear me last time? 693 throw new CalFacadeException(exc); 694 } 695 696 try { 697 sess.merge(obj); 698 } catch (Throwable t) { 699 handleException(t); 688 * @return Object the persiatent object 689 * @throws CalFacadeException 690 */ 691 public Object merge(Object obj) throws CalFacadeException { 692 if (exc != null) { 693 // Didn't hear me last time? 694 throw new CalFacadeException(exc); 695 } 696 697 try { 698 return sess.merge(obj); 699 } catch (Throwable t) { 700 handleException(t); 701 return null; 700 702 } 701 703 } trunk/calendar3/calFacade/src/org/bedework/calfacade/BwCalendar.java
r464 r477 418 418 */ 419 419 public BwCalendar shallowClone() { 420 returnnew BwCalendar((BwUser)getOwner().clone(),420 BwCalendar cal = new BwCalendar((BwUser)getOwner().clone(), 421 421 getPublick(), 422 422 (BwUser)getCreator().clone(), … … 431 431 null, 432 432 getCalType()); 433 434 cal.setId(getId()); // Add to constructor 435 cal.setSeq(getSeq()); // Add to constructor 436 return cal; 433 437 } 434 438 … … 505 509 506 510 public Object clone() { 507 returnnew BwCalendar((BwUser)getOwner().clone(),511 BwCalendar cal = new BwCalendar((BwUser)getOwner().clone(), 508 512 getPublick(), 509 513 (BwUser)getCreator().clone(), … … 518 522 getChildren(), 519 523 getCalType()); 524 525 cal.setId(getId()); // Add to constructor 526 cal.setSeq(getSeq()); // Add to constructor 527 return cal; 520 528 } 521 529 } trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java
r469 r477 489 489 } 490 490 491 public void changeAccess(BwCalendar cal, 492 Collection aces) throws CalFacadeException { 493 checkOpen(); 494 throw new CalFacadeUnimplementedException(); 495 } 496 491 497 public boolean deleteCalendar(BwCalendar val) throws CalFacadeException { 492 498 checkOpen(); trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java
r469 r477 222 222 public void updateCalendar(BwCalendar val) throws CalFacadeException; 223 223 224 /** Change the access to the given calendar entity. 225 * 226 * @param cal Bwcalendar 227 * @param aces Collection of ace 228 * @throws CalFacadeException 229 */ 230 public void changeAccess(BwCalendar cal, 231 Collection aces) throws CalFacadeException; 232 224 233 /** Delete the given calendar 225 234 * trunk/calendar3/webcommon/src/org/bedework/webcommon/access/AccessAction.java
r436 r477 184 184 char[] howchs = how.toCharArray(); 185 185 186 for (int hi = 0; hi < =howchs.length; hi++) {186 for (int hi = 0; hi < howchs.length; hi++) { 187 187 char howch = howchs[hi]; 188 188 boolean found = false; … … 195 195 break; 196 196 } 197 198 if (!found) { 199 form.getErr().emit("org.bedework.client.error.badhow");200 return "error";201 }197 } 198 199 if (!found) { 200 form.getErr().emit("org.bedework.client.error.badhow"); 201 return "error"; 202 202 } 203 203 } … … 206 206 if (ev != null) { 207 207 svci.changeAccess(ev, aces); 208 svci.updateEvent(ev);208 //svci.updateEvent(ev); 209 209 } else { 210 210 svci.changeAccess(cal, aces); 211 svci.updateCalendar(cal);211 //svci.updateCalendar(cal); 212 212 } 213 213
