示例#1
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;
  }
示例#2
0
 public void removeMemberFromGroup(Member member, Group group) throws InternalErrorException {
   // Remove member from group
   Attribute uniqueMember =
       new BasicAttribute(
           "uniqueMember",
           "perunUserId=" + member.getUserId() + ",ou=People," + ldapProperties.getLdapBase());
   ModificationItem uniqueMemberItem =
       new ModificationItem(DirContext.REMOVE_ATTRIBUTE, uniqueMember);
   this.updateGroup(group, new ModificationItem[] {uniqueMemberItem});
   // Remove member from vo if this group is membersGroup
   if (group.getName().equals(VosManager.MEMBERS_GROUP) && group.getParentGroupId() == null) {
     // Remove info from vo
     this.updateVo(group.getVoId(), new ModificationItem[] {uniqueMemberItem});
     // Remove also information from user
     Attribute memberOfPerunVo =
         new BasicAttribute("memberOfPerunVo", String.valueOf(group.getVoId()));
     ModificationItem memberOfPerunVoItem =
         new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOfPerunVo);
     this.updateUserWithUserId(
         String.valueOf(member.getUserId()), new ModificationItem[] {memberOfPerunVoItem});
   }
   // Remove group info from member
   Attribute memberOf =
       new BasicAttribute(
           "memberOf",
           "perunGroupId="
               + group.getId()
               + ",perunVoId="
               + group.getVoId()
               + ","
               + ldapProperties.getLdapBase());
   ModificationItem memberOfItem = new ModificationItem(DirContext.REMOVE_ATTRIBUTE, memberOf);
   this.updateUserWithUserId(
       String.valueOf(member.getUserId()), new ModificationItem[] {memberOfItem});
 }
示例#3
0
  public void addGroup(Group group) throws InternalErrorException {
    // Create a set of attributes
    Attributes attributes = new BasicAttributes();

    // Create the objectclass to add
    Attribute objClasses = new BasicAttribute("objectClass");
    objClasses.add("top");
    objClasses.add("perunGroup");

    // Add attributes
    attributes.put(objClasses);
    attributes.put("cn", group.getName());
    attributes.put("perunGroupId", String.valueOf(group.getId()));
    attributes.put(
        "perunUniqueGroupName",
        new String(this.getVoShortName(group.getVoId()) + ":" + group.getName()));
    attributes.put("perunVoId", String.valueOf(group.getVoId()));
    if (group.getDescription() != null && !group.getDescription().isEmpty())
      attributes.put("description", group.getDescription());
    if (group.getParentGroupId() != null) {
      attributes.put(
          "perunParentGroup",
          "perunGroupId="
              + group.getParentGroupId().toString()
              + ",perunVoId="
              + group.getVoId()
              + ","
              + ldapProperties.getLdapBase());
      attributes.put("perunParentGroupId", group.getParentGroupId().toString());
    }

    // Create the entry
    try {
      ldapTemplate.bind(
          getGroupDN(String.valueOf(group.getVoId()), String.valueOf(group.getId())),
          null,
          attributes);
      log.debug(
          "New entry created in LDAP: Group {} in Vo with Id=" + group.getVoId() + ".", group);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
示例#4
0
 public Group mapRow(ResultSet rs, int i) throws SQLException {
   Group g = new Group();
   g.setId(rs.getInt("groups_id"));
   // ParentGroup with ID=0 is not supported
   if (rs.getInt("groups_parent_group_id") != 0)
     g.setParentGroupId(rs.getInt("groups_parent_group_id"));
   else g.setParentGroupId(null);
   g.setName(rs.getString("groups_name"));
   g.setShortName(g.getName().substring(g.getName().lastIndexOf(":") + 1));
   g.setDescription(rs.getString("groups_dsc"));
   g.setVoId(rs.getInt("groups_vo_id"));
   g.setCreatedAt(rs.getString("groups_created_at"));
   g.setCreatedBy(rs.getString("groups_created_by"));
   g.setModifiedAt(rs.getString("groups_modified_at"));
   g.setModifiedBy(rs.getString("groups_modified_by"));
   if (rs.getInt("groups_modified_by_uid") == 0) g.setModifiedByUid(null);
   else g.setModifiedByUid(rs.getInt("groups_modified_by_uid"));
   if (rs.getInt("groups_created_by_uid") == 0) g.setCreatedByUid(null);
   else g.setCreatedByUid(rs.getInt("groups_created_by_uid"));
   return g;
 }
示例#5
0
  /*
   * Create a subgroup
   *
   * @see cz.metacentrum.perun.core.implApi.GroupsManagerImplApi#createGroup(cz.metacentrum.perun.core.api.PerunSession, cz.metacentrum.perun.core.api.Vo, cz.metacentrum.perun.core.api.Group, cz.metacentrum.perun.core.api.Group)
   */
  public Group createGroup(PerunSession sess, Vo vo, Group parentGroup, Group group)
      throws GroupExistsException, InternalErrorException {
    // Create new subGroup

    group.setParentGroupId(parentGroup.getId());

    group.setName(parentGroup.getName() + ":" + group.getShortName());

    group = createGroup(sess, vo, group);

    return group;
  }
示例#6
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);
    }
  }
示例#7
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);
    }
  }