Changeset 285

Show
Ignore:
Timestamp:
03/15/06 16:22:48
Author:
douglm
Message:

Prevent admin group loops

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/calendar3/calCore/resources/hbms/AdminGroup.hbm.xml

    r2 r285  
    5959    </composite-id> 
    6060 
     61    <property name="groupId" column="groupid" 
     62              type="integer" insert="false" update="false"/> 
     63 
    6164    <!-- 
    6265    <id name="groupId" column="groupid" unsaved-value="-1"> 
     
    103106  ]]></query> 
    104107 
     108  <query name="getGroupParents"><![CDATA[ 
     109    select ag from 
     110          org.bedework.calfacade.svc.BwAdminGroupEntry age, 
     111          org.bedework.calfacade.svc.BwAdminGroup ag 
     112        where ag.id = age.groupId and 
     113             age.memberId=:grpid 
     114  ]]></query> 
     115 
    105116  <query name="getGroupGroupMembers"><![CDATA[ 
    106117    select ag from 
  • trunk/calendar3/calCore/src/org/bedework/calcore/hibernate/AdminGroupsDbImpl.java

    r245 r285  
    212212    } 
    213213    */ 
     214     
     215    /* val must not already be present on any paths to the root.  
     216     * We'll assume the possibility of more than one parent. 
     217     */ 
     218     
     219    if (!checkPathForSelf(group, val)) { 
     220      throw new CalFacadeException(CalFacadeException.alreadyOnAdminGroupPath); 
     221    } 
    214222 
    215223    ag.addGroupMember(val); 
     
    349357    return user; 
    350358  }*/ 
     359   
     360  private boolean checkPathForSelf(BwGroup group,  
     361                                   BwPrincipal val) throws CalFacadeException { 
     362    if (group.equals(val)) { 
     363      return false; 
     364    } 
     365     
     366    /* get all parents of group and try again */ 
     367     
     368    HibSession sess = getSess(); 
     369 
     370    /* Want this 
     371    sess.createQuery("from " + BwAdminGroup.class.getName() + " ag " + 
     372                     "where mbr in elements(ag.groupMembers)"); 
     373    sess.setEntity("mbr", val); 
     374    */ 
     375 
     376    sess.namedQuery("getGroupParents"); 
     377    sess.setInt("grpid", group.getId()); 
     378 
     379    Collection parents = sess.getList(); 
     380 
     381    Iterator it = parents.iterator(); 
     382     
     383    while (it.hasNext()) { 
     384      BwAdminGroup g = (BwAdminGroup)it.next(); 
     385       
     386      if (!checkPathForSelf(g, val)) { 
     387        return false; 
     388      } 
     389    } 
     390     
     391    return true; 
     392  } 
    351393 
    352394  private HibSession getSess() throws CalFacadeException { 
  • trunk/calendar3/calFacade/src/org/bedework/calfacade/CalFacadeException.java

    r245 r285  
    6969  public static final String duplicateAdminGroup = 
    7070      "org.bedework.exception.duplicateadmingroup"; 
     71   
     72  /** The admin group is already on the path to the root (makes a loop) */ 
     73  public static final String alreadyOnAdminGroupPath = 
     74      "org.bedework.exception.alreadyonadmingrouppath"; 
    7175 
    7276  /* ****************** Calendars ****************************** */