/**
   * Retrieves whole application object from DB (authz in parent methods)
   *
   * @param sess PerunSession for Authz and to resolve User
   * @param vo VO to get application for
   * @param group Group
   * @return application object / null if not exists
   */
  private Application getLatestApplication(
      PerunSession sess, Vo vo, Group group, Application.AppType type) {
    try {

      if (sess.getPerunPrincipal().getUser() != null) {

        if (group != null) {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and user_id=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              group.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getUserId());

        } else {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and apptype=? and user_id=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getUserId());
        }

      } else {

        if (group != null) {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and group_id=? and apptype=? and created_by=? and extsourcename=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              group.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getActor(),
              sess.getPerunPrincipal().getExtSourceName());

        } else {

          return jdbc.queryForObject(
              RegistrarManagerImpl.APP_SELECT
                  + " where a.id=(select max(id) from application where vo_id=? and apptype=? and created_by=? and extsourcename=? )",
              RegistrarManagerImpl.APP_MAPPER,
              vo.getId(),
              String.valueOf(type),
              sess.getPerunPrincipal().getActor(),
              sess.getPerunPrincipal().getExtSourceName());
        }
      }

    } catch (EmptyResultDataAccessException ex) {
      return null;
    }
  }
Example #2
0
 public int getGroupsCount(PerunSession sess, Vo vo) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select count(1) from groups where vo_id=?", vo.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
Example #3
0
 public Group getGroupByName(PerunSession sess, Vo vo, String name)
     throws GroupNotExistsException, InternalErrorException {
   try {
     return jdbc.queryForObject(
         "select "
             + groupMappingSelectQuery
             + " from groups where groups.name=? and groups.vo_id=?",
         GROUP_MAPPER,
         name,
         vo.getId());
   } catch (EmptyResultDataAccessException err) {
     throw new GroupNotExistsException("Group name=" + name + ", vo id=" + vo.getId());
   } catch (RuntimeException err) {
     throw new InternalErrorException(err);
   }
 }
Example #4
0
 public void deleteVo(Vo vo) throws InternalErrorException {
   try {
     ldapTemplate.unbind(getVoDNByVoId(String.valueOf(vo.getId())));
     log.debug("Entry deleted from LDAP: Vo {}.", vo);
   } catch (NameNotFoundException e) {
     throw new InternalErrorException(e);
   }
 }
Example #5
0
 public List<Group> getAllGroups(PerunSession sess, Vo vo) throws InternalErrorException {
   try {
     return jdbc.query(
         "select " + groupMappingSelectQuery + " from groups where vo_id=?",
         GROUP_MAPPER,
         vo.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
Example #6
0
  public List<Group> getGroups(PerunSession sess, Vo vo) throws InternalErrorException {
    try {
      return jdbc.query(
          "select  "
              + groupMappingSelectQuery
              + " from groups where vo_id=? order by "
              + Compatibility.orderByBinary("groups.name" + Compatibility.castToVarchar()),
          GROUP_MAPPER,
          vo.getId());

    } catch (RuntimeException ex) {
      throw new InternalErrorException(ex);
    }
  }
Example #7
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);
    }
  }
Example #8
0
  @Override
  public List<Group> getGroupsWithAssignedExtSourceInVo(PerunSession sess, ExtSource source, Vo vo)
      throws InternalErrorException {
    try {
      return jdbc.query(
          "select "
              + groupMappingSelectQuery
              + " from group_ext_sources g_exts inner join groups on g_exts.group_id=groups.id "
              + " where g_exts.ext_source_id=? and groups.vo_id=?",
          GROUP_MAPPER,
          source.getId(),
          vo.getId());

    } catch (RuntimeException e) {
      throw new InternalErrorException(e);
    }
  }
Example #9
0
 @Override
 public boolean equals(Object obj) {
   if (obj == null) {
     return false;
   }
   if (getClass() != obj.getClass()) {
     return false;
   }
   final Vo other = (Vo) obj;
   if (this.getId() != other.getId()) {
     return false;
   }
   if ((this.name == null) ? (other.name != null) : !this.name.equals(other.name)) {
     return false;
   }
   if ((this.shortName == null)
       ? (other.shortName != null)
       : !this.shortName.equals(other.shortName)) {
     return false;
   }
   return true;
 }
Example #10
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);
    }
  }
Example #11
0
 public void updateVo(Vo vo, ModificationItem[] modificationItems) {
   ldapTemplate.modifyAttributes(getVoDNByVoId(String.valueOf(vo.getId())), modificationItems);
   log.debug("Entry modified in LDAP: Vo {}.", vo);
 }