示例#1
0
 @Override
 public void deleteGroupReservedLogins(PerunSession sess, Group group) {
   // remove all reserved logins first
   for (Integer appId : getGroupApplicationIds(sess, group)) {
     jdbc.update("delete from application_reserved_logins where app_id=?", appId);
   }
 }
示例#2
0
 public Member addMember(
     PerunSession sess, Group group, Member member, MembershipType type, int sourceGroupId)
     throws InternalErrorException, AlreadyMemberException, WrongAttributeValueException,
         WrongReferenceAttributeValueException {
   // TODO already member exception
   member.setMembershipType(type);
   try {
     jdbc.update(
         "insert into groups_members (group_id, member_id, created_by, created_at, modified_by, modified_at, created_by_uid, modified_by_uid, membership_type, source_group_id) "
             + "values (?,?,?,"
             + Compatibility.getSysdate()
             + ",?,"
             + Compatibility.getSysdate()
             + ",?,?,?,?)",
         group.getId(),
         member.getId(),
         sess.getPerunPrincipal().getActor(),
         sess.getPerunPrincipal().getActor(),
         sess.getPerunPrincipal().getUserId(),
         sess.getPerunPrincipal().getUserId(),
         type.getCode(),
         sourceGroupId);
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
   return member;
 }
示例#3
0
  public Group updateGroupName(PerunSession sess, Group group) throws InternalErrorException {
    Utils.notNull(group.getName(), "group.getName()");

    // Get the group stored in the DB
    Group dbGroup;
    try {
      dbGroup = this.getGroupById(sess, group.getId());
    } catch (GroupNotExistsException e) {
      throw new InternalErrorException("Group existence was checked at the higher level", e);
    }

    if (!dbGroup.getName().equals(group.getName())) {
      dbGroup.setName(group.getName());
      try {
        jdbc.update(
            "update groups set name=?,modified_by=?, modified_by_uid=?, modified_at="
                + Compatibility.getSysdate()
                + " where id=?",
            dbGroup.getName(),
            sess.getPerunPrincipal().getActor(),
            sess.getPerunPrincipal().getUserId(),
            dbGroup.getId());
      } catch (RuntimeException e) {
        throw new InternalErrorException(e);
      }
    }
    return dbGroup;
  }
示例#4
0
  public void deleteGroup(PerunSession sess, Vo vo, Group group)
      throws InternalErrorException, GroupAlreadyRemovedException {
    Utils.notNull(group.getName(), "group.getName()");

    try {
      // Delete group's members
      jdbc.update("delete from groups_members where source_group_id=?", group.getId());

      // Delete authz entries for this group
      AuthzResolverBlImpl.removeAllAuthzForGroup(sess, group);

      int rowAffected = jdbc.update("delete from groups where id=?", group.getId());
      if (rowAffected == 0)
        throw new GroupAlreadyRemovedException("Group: " + group + " , Vo: " + vo);
    } catch (RuntimeException err) {
      throw new InternalErrorException(err);
    }
  }
示例#5
0
 public void removeMember(PerunSession sess, Group group, Member member)
     throws InternalErrorException, NotGroupMemberException {
   int ret;
   try {
     ret =
         jdbc.update(
             "delete from groups_members where source_group_id=? and member_id=?",
             group.getId(),
             member.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
   if (ret == 0) {
     throw new NotGroupMemberException(member);
   } else if (ret >= 1) {
     return;
   } else {
     throw new ConsistencyErrorException(
         member + " and " + group + " have " + ret + " rows in groups_members table");
   }
 }
示例#6
0
  public Group createGroup(PerunSession sess, Vo vo, Group group)
      throws GroupExistsException, InternalErrorException {
    Utils.notNull(group, "group");
    Utils.notNull(group.getName(), "group.getName()");

    // Check if the group already exists
    if (group.getParentGroupId() == null) {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id IS NULL",
              group.getName(),
              vo.getId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id is [NULL]");
      }
    } else {
      if (1
          == jdbc.queryForInt(
              "select count('x') from groups where lower(name)=lower(?) and vo_id=? and parent_group_id=?",
              group.getName(),
              vo.getId(),
              group.getParentGroupId())) {
        throw new GroupExistsException(
            "Group ["
                + group.getName()
                + "] already exists under VO ["
                + vo.getShortName()
                + "] and has parent Group with id ["
                + group.getParentGroupId()
                + "]");
      }
    }

    // Check the group name, it can contain only a-Z0-9_- and space
    if (!group.getShortName().matches("^[- a-zA-Z.0-9_]+$")) {
      throw new InternalErrorException(
          new IllegalArgumentException(
              "Wrong group name, group name can contain only a-Z0-9.-_: and space characters. "
                  + group));
    }

    try {
      // Store the group into the DB
      int newId = Utils.getNewId(jdbc, "groups_id_seq");

      jdbc.update(
          "insert into groups (id, parent_group_id, name, dsc, vo_id, created_by,created_at,modified_by,modified_at,created_by_uid,modified_by_uid) "
              + "values (?,?,?,?,?,?,"
              + Compatibility.getSysdate()
              + ",?,"
              + Compatibility.getSysdate()
              + ",?,?)",
          newId,
          group.getParentGroupId(),
          group.getName(),
          group.getDescription(),
          vo.getId(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getActor(),
          sess.getPerunPrincipal().getUserId(),
          sess.getPerunPrincipal().getUserId());
      group.setId(newId);

      group.setVoId(vo.getId());

      return group;
    } catch (RuntimeException err) {
      throw new InternalErrorException(err);
    }
  }