Changeset 477

Show
Ignore:
Timestamp:
05/15/06 00:25:17
Author:
douglm
Message:

Access changes to correctly handle multiple aces for a single 'who'.
Fix the access action.

Temp fix to allow updating of calendar object for access changes.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Ace.java

    r448 r477  
    298298   */ 
    299299  public PrivilegeSet getHow() { 
     300    if (how == null) { 
     301      how = new PrivilegeSet(); 
     302    } 
     303 
    300304    return how; 
    301305  } 
     
    326330  public void addPriv(Privilege val) { 
    327331    getPrivs().add(val); 
     332    getHow().setPrivilege(val); 
    328333  } 
    329334 
     
    510515  } 
    511516 
    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) { 
    527523      if (notWho) { 
    528524        return -1; 
     
    531527    } 
    532528 
    533     if (whoType < that.whoType) { 
     529    if (whoType < whoMatch.whoType) { 
    534530      return -1; 
    535531    } 
    536532 
    537     if (whoType > that.whoType) { 
     533    if (whoType > whoMatch.whoType) { 
    538534      return 1; 
    539535    } 
    540536 
    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; 
    542561  } 
    543562 
     
    557576 
    558577  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; 
    572579  } 
    573580 
     
    608615   * ==================================================================== */ 
    609616 
    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//  } 
    613620 
    614621  private int compareWho(String who1, String who2) { 
  • trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/Acl.java

    r448 r477  
    362362  } 
    363363 
    364   /** Remove access for a given 'who' entry 
     364  /* * Remove access for a given 'who' entry 
    365365   * 
    366366   * @param who 
     
    368368   * @param whoType 
    369369   * @return boolean true if removed 
    370    *
    371   public boolean removeAccess(String who, boolean notWho, int whoType) { 
     370   *
     371  public boolean removeWho(String who, boolean notWho, int whoType) { 
    372372    if (aces == null) { 
    373373      return false; 
     
    375375 
    376376    return aces.remove(new Ace(who, notWho, whoType, (PrivilegeSet)null)); 
    377   } 
     377  }*/ 
    378378 
    379379  /** Remove access for a given 'who' entry 
     
    382382   * @return boolean true if removed 
    383383   */ 
    384   public boolean removeAccess(Ace whoDef) { 
     384  public boolean removeWho(Ace whoDef) { 
    385385    if (aces == null) { 
    386386      return false; 
    387387    } 
    388388 
    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; 
    390421  } 
    391422 
     
    477508   * <p>Also note the encoded value will not reflect the eventual Acl. 
    478509   * 
    479    * @param val char[] val to decode and merge 
     510   * @param val Acl to merge 
    480511   * @throws AccessException 
    481512   */ 
  • trunk/calendar3/access/src/edu/rpi/cct/uwcal/access/PrivilegeSet.java

    r448 r477  
    6060 *  @author Mike Douglass   douglm@rpi.edu 
    6161 */ 
    62 public class PrivilegeSet implements Serializable, PrivilegeDefs
     62public class PrivilegeSet implements Serializable, PrivilegeDefs, Comparable
    6363  private char[] privileges; 
    6464 
     
    168168  } 
    169169 
     170  /** 
     171   */ 
     172  public PrivilegeSet() { 
     173    privileges = (char[])defaultNonOwnerPrivileges.getPrivileges().clone(); 
     174  } 
     175 
    170176  /** Default privs for an owner 
    171177   * 
     
    205211 
    206212    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    } 
    207229  } 
    208230 
     
    307329  } 
    308330 
     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 
    309391  public Object clone() { 
    310392    return new PrivilegeSet((char[])getPrivileges().clone()); 
     
    320402  } 
    321403} 
    322  
  • trunk/calendar3/appcommon/src/org/bedework/appcommon/AccessAppUtil.java

    r448 r477  
    338338 
    339339    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      */ 
    340346      xml.closeTag(tag); 
    341347    } 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AccessUtil.java

    r448 r477  
    111111  } 
    112112 
    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(); 
    114128 
    115129  /* ==================================================================== 
     
    181195 
    182196  /** 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. 
    183199   * 
    184200   * @param ent      BwShareableDbentity 
     
    191207      Acl acl = checkAccess(ent, privWriteAcl, false).acl; 
    192208 
     209      /* First remove for all whos */ 
    193210      Iterator it = aces.iterator(); 
    194211      while (it.hasNext()) { 
    195212        Ace ace = (Ace)it.next(); 
    196213 
    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 
    198222        acl.addAce(ace); 
    199223      } 
     
    201225      ent.setAccess(new String(acl.encode())); 
    202226 
    203       if (ent instanceof BwCalendar) { 
    204         updatePathInfo((BwCalendar)ent, acl); 
    205       } 
     227      pathInfoMap.flush(); 
    206228    } catch (Throwable t) { 
    207229      throw new CalFacadeException(t); 
     
    348370 
    349371      String path = container.getPath(); 
    350       PathInfo pi = (PathInfo)pathInfoTable.get(path); 
     372      PathInfo pi = pathInfoMap.getInfo(path); 
    351373 
    352374      if (pi == null) { 
    353375        pi = getPathInfo(container); 
    354         pathInfoTable.put(path, pi); 
     376        pathInfoMap.putInfo(path, pi); 
    355377      } 
    356378 
     
    475497 
    476498  /* Update the merged Acl for the given calendar. 
    477    */ 
     499   * Doesn't work because any children in the table need the access changing. 
    478500  private void updatePathInfo(BwCalendar cal, Acl acl) throws CalFacadeException { 
    479501    try { 
    480502      String path = cal.getPath(); 
    481       PathInfo pi = (PathInfo)pathInfoTable.get(path); 
     503      PathInfo pi = pathInfoMap.getInfo(path); 
    482504 
    483505      if (pi == null) { 
     
    490512      pi.encoded = acl.encodeAll(); 
    491513 
    492       pathInfoTable.put(path, pi); 
     514      pathInfoMap.putInfo(path, pi); 
    493515    } catch (Throwable t) { 
    494516      throw new CalFacadeException(t); 
    495517    } 
    496518  } 
     519   */ 
    497520 
    498521  private Logger getLog() { 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/Calendars.java

    r469 r477  
    395395  } 
    396396 
     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 
    397406  public boolean deleteCalendar(BwCalendar val) throws CalFacadeException { 
    398407    HibSession sess = getSess(); 
     
    472481  /* Returns the cloned (sub)tree of calendars to which user has access 
    473482   * 
     483   * <p>This needs a rethink - cloning effectively disables optimistic 
     484   * locking - at least I think so. 
     485   * 
    474486   * @return BwCalendar   (sub)root with all accessible children attached 
    475487   * @throws CalFacadeException 
     
    490502 
    491503    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 
    493506    cal.setId(subroot.getId()); 
    494507 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/CalintfImpl.java

    r469 r477  
    698698  public void changeAccess(BwShareableDbentity ent, 
    699699                           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); 
    701706    access.changeAccess(ent, aces); 
    702707    sess.saveOrUpdate(ent); 
     708  } 
     709 
     710  public void changeAccess(BwCalendar cal, 
     711                           Collection aces) throws CalFacadeException { 
     712    checkOpen(); 
     713    calendars.changeAccess(cal, aces); 
    703714  } 
    704715 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/HibSession.java

    r436 r477  
    686686   * 
    687687   * @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; 
    700702    } 
    701703  } 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/BwCalendar.java

    r464 r477  
    418418   */ 
    419419  public BwCalendar shallowClone() { 
    420     return new BwCalendar((BwUser)getOwner().clone(), 
     420    BwCalendar cal = new BwCalendar((BwUser)getOwner().clone(), 
    421421                          getPublick(), 
    422422                          (BwUser)getCreator().clone(), 
     
    431431                          null, 
    432432                          getCalType()); 
     433 
     434    cal.setId(getId()); // Add to constructor 
     435    cal.setSeq(getSeq()); // Add to constructor 
     436    return cal; 
    433437  } 
    434438 
     
    505509 
    506510  public Object clone() { 
    507     return new BwCalendar((BwUser)getOwner().clone(), 
     511    BwCalendar cal = new BwCalendar((BwUser)getOwner().clone(), 
    508512                          getPublick(), 
    509513                          (BwUser)getCreator().clone(), 
     
    518522                          getChildren(), 
    519523                          getCalType()); 
     524 
     525    cal.setId(getId()); // Add to constructor 
     526    cal.setSeq(getSeq()); // Add to constructor 
     527    return cal; 
    520528  } 
    521529} 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/base/CalintfBase.java

    r469 r477  
    489489  } 
    490490 
     491  public void changeAccess(BwCalendar cal, 
     492                           Collection aces) throws CalFacadeException { 
     493    checkOpen(); 
     494    throw new CalFacadeUnimplementedException(); 
     495  } 
     496 
    491497  public boolean deleteCalendar(BwCalendar val) throws CalFacadeException { 
    492498    checkOpen(); 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/ifs/CalendarsI.java

    r469 r477  
    222222  public void updateCalendar(BwCalendar val) throws CalFacadeException; 
    223223 
     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 
    224233  /** Delete the given calendar 
    225234   * 
  • trunk/calendar3/webcommon/src/org/bedework/webcommon/access/AccessAction.java

    r436 r477  
    184184    char[] howchs = how.toCharArray(); 
    185185 
    186     for (int hi = 0; hi <= howchs.length; hi++) { 
     186    for (int hi = 0; hi < howchs.length; hi++) { 
    187187      char howch = howchs[hi]; 
    188188      boolean found = false; 
     
    195195          break; 
    196196        } 
    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"; 
    202202      } 
    203203    } 
     
    206206    if (ev != null) { 
    207207      svci.changeAccess(ev, aces); 
    208       svci.updateEvent(ev); 
     208      //svci.updateEvent(ev); 
    209209    } else { 
    210210      svci.changeAccess(cal, aces); 
    211       svci.updateCalendar(cal); 
     211      //svci.updateCalendar(cal); 
    212212    } 
    213213