Пример #1
0
  public Vo updateVo(PerunSession sess, Vo vo)
      throws VoNotExistsException, InternalErrorException, PrivilegeException {
    Utils.notNull(sess, "sess");
    vosManagerBl.checkVoExists(sess, vo);

    // Authorization - Vo admin required
    if (!AuthzResolver.isAuthorized(sess, Role.VOADMIN, vo)) {
      throw new PrivilegeException(sess, "updateVo");
    }

    if (vo.getName().length() > 128) {
      throw new InternalErrorException("VO name is too long, >128 characters");
    }

    if (!vo.getShortName().matches("^[-_a-zA-z0-9.]{1,16}$")) {
      throw new InternalErrorException(
          "Wrong VO short name - must matches [-_a-zA-z0-9.]+ and not be longer than 16 characters.");
    }

    return vosManagerBl.updateVo(sess, vo);
  }
Пример #2
0
  public void createVo(Vo vo) throws InternalErrorException {
    // Create a set of attributes for vo
    Attributes voAttributes = new BasicAttributes();

    // Create the objectclass to add
    Attribute voObjClasses = new BasicAttribute("objectClass");
    voObjClasses.add("top");
    voObjClasses.add("organization");
    voObjClasses.add("perunVO");

    // Add attributes
    voAttributes.put(voObjClasses);
    voAttributes.put("o", vo.getShortName());
    voAttributes.put("description", vo.getName());
    voAttributes.put("perunVoId", String.valueOf(vo.getId()));

    // Create the entires
    try {
      ldapTemplate.bind(getVoDNByVoId(String.valueOf(vo.getId())), null, voAttributes);
      log.debug("New entry created in LDAP: Vo {}.", vo);
    } catch (NameNotFoundException e) {
      throw new InternalErrorException(e);
    }
  }
Пример #3
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);
    }
  }