예제 #1
0
 public boolean hasRole(String roleName) {
   if (getGroupRoles() == null) {
     return false;
   }
   for (GroupRole r : getGroupRoles()) {
     if (r.getRoleName().equals(roleName)) {
       return true;
     }
   }
   return false;
 }
예제 #2
0
 public boolean hasRole(String roleName, Organisation org) {
   if (getMemberships() != null) {
     for (GroupMembership m : getMemberships()) {
       if (org.isWithin(m.getWithinOrg())) {
         for (GroupRole r : m.getGroupEntity().getGroupRoles()) {
           if (r.getRoleName().equals(roleName)) {
             return true;
           }
         }
       }
     }
   }
   return false;
 }
예제 #3
0
 public void delete(Session session) {
   if (getGroupRoles() != null) {
     for (GroupRole gr : getGroupRoles()) {
       gr.delete(session);
     }
   }
   if (getGroupMemberships() != null) {
     List<GroupMembership> list = new ArrayList<>(getGroupMemberships());
     for (GroupMembership gm : list) {
       gm.delete(session);
       session.flush();
     }
   }
   Organisation org = getOrganisation();
   if (org != null) {
     if (org.getGroups() != null) {
       org.getGroups().remove(this);
     }
   }
   for (GroupInWebsite giw : GroupInWebsite.findByGroup(this, session)) {
     session.delete(giw);
   }
   session.delete(this);
 }
예제 #4
0
  private GroupRole grantRole(
      Repository repo, Organisation withinOrg, String roleName, Session session) {
    if (getGroupRoles() == null) {
      setGroupRoles(new ArrayList<GroupRole>());
    }

    // Check if this role already exists
    for (GroupRole gr : getGroupRoles()) {
      if (gr.getRoleName().equals(roleName)) {
        if (gr.getWithinOrg() != null && gr.getWithinOrg() == withinOrg) {
          // nothing to do
          return null;
        } else if (gr.getRepository() != null && gr.getRepository() == repo) {
          // nothing to do
          return null;
        } else if (withinOrg == null
            && repo == null
            && gr.getRepository() == null
            && gr.getWithinOrg() == null) {
          return null;
        }
      }
    }
    GroupRole gr = new GroupRole();
    gr.setGrantee(this);
    gr.setRoleName(roleName);
    gr.setRepository(repo);
    gr.setWithinOrg(withinOrg);
    session.save(gr);
    getGroupRoles().add(gr);
    return gr;
  }