示例#1
0
  @Override
  public List<User> getAdmins(PerunSession sess, Group group) throws InternalErrorException {
    try {
      Set<User> setOfAdmins = new HashSet<User>();
      // direct admins
      setOfAdmins.addAll(
          jdbc.query(
              "select "
                  + UsersManagerImpl.userMappingSelectQuery
                  + " from authz join users on authz.user_id=users.id "
                  + "where authz.group_id=? and authz.role_id=(select id from roles where name='groupadmin')",
              UsersManagerImpl.USER_MAPPER,
              group.getId()));

      // admins through a group
      List<Group> listOfGroupAdmins = getGroupAdmins(sess, group);
      for (Group authorizedGroup : listOfGroupAdmins) {
        setOfAdmins.addAll(
            jdbc.query(
                "select "
                    + UsersManagerImpl.userMappingSelectQuery
                    + " from users join members on users.id=members.user_id "
                    + "join groups_members on groups_members.member_id=members.id where groups_members.group_id=?",
                UsersManagerImpl.USER_MAPPER,
                authorizedGroup.getId()));
      }

      return new ArrayList(setOfAdmins);

    } catch (EmptyResultDataAccessException e) {
      return new ArrayList<User>();
    } catch (RuntimeException e) {
      throw new InternalErrorException(e);
    }
  }
示例#2
0
  /**
   * 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;
    }
  }
示例#3
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);
   }
 }
示例#4
0
 public int getGroupsCount(PerunSession sess) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select count(*) from groups");
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#5
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);
   }
 }
示例#6
0
 public int getVoId(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.queryForInt("select vo_id from groups where id=?", group.getId());
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#7
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;
  }
示例#8
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;
 }
示例#9
0
 public int getSubGroupsCount(PerunSession sess, Group parentGroup) throws InternalErrorException {
   try {
     return jdbc.queryForInt(
         "select count(1) from groups where parent_group_id=?", parentGroup.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#10
0
 public boolean groupExists(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return 1 == jdbc.queryForInt("select 1 from groups where id=?", group.getId());
   } catch (EmptyResultDataAccessException ex) {
     return false;
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#11
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);
    }
  }
示例#12
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);
   }
 }
示例#13
0
 public boolean isUserMemberOfGroup(PerunSession sess, User user, Group group)
     throws InternalErrorException {
   try {
     return 1
         <= jdbc.queryForInt(
             "select count(1) from groups_members join members on members.id = member_id where members.user_id=? and groups_members.group_id=?",
             user.getId(),
             group.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#14
0
 @Override
 public List<Pair<String, String>> getApplicationReservedLogins(Integer appId) {
   return jdbc.query(
       "select namespace,login from application_reserved_logins where app_id=?",
       new RowMapper<Pair<String, String>>() {
         @Override
         public Pair<String, String> mapRow(ResultSet rs, int arg1) throws SQLException {
           return new Pair<String, String>(rs.getString("namespace"), rs.getString("login"));
         }
       },
       appId);
 }
示例#15
0
 public boolean isGroupMember(PerunSession sess, Group group, Member member)
     throws InternalErrorException {
   try {
     return 1
         <= jdbc.queryForInt(
             "select count(1) from groups_members where group_id=? and member_id=?",
             group.getId(),
             member.getId());
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#16
0
 public Group getParentGroup(PerunSession sess, Group group)
     throws InternalErrorException, ParentGroupNotExistsException {
   try {
     return jdbc.queryForObject(
         "select " + groupMappingSelectQuery + " from groups where groups.id=?",
         GROUP_MAPPER,
         group.getParentGroupId());
   } catch (EmptyResultDataAccessException e) {
     throw new ParentGroupNotExistsException(e);
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#17
0
 public Group getGroupById(PerunSession sess, int id)
     throws GroupNotExistsException, InternalErrorException {
   try {
     return jdbc.queryForObject(
         "select " + groupMappingSelectQuery + " from groups where groups.id=? ",
         GROUP_MAPPER,
         id);
   } catch (EmptyResultDataAccessException err) {
     throw new GroupNotExistsException("Group id=" + id);
   } catch (RuntimeException err) {
     throw new InternalErrorException(err);
   }
 }
示例#18
0
 @Override
 public List<Integer> getGroupApplicationIds(PerunSession sess, Group group) {
   // get app ids for all applications
   return jdbc.query(
       "select id from application where group_id=?",
       new RowMapper<Integer>() {
         @Override
         public Integer mapRow(ResultSet rs, int arg1) throws SQLException {
           return rs.getInt("id");
         }
       },
       group.getId());
 }
示例#19
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);
    }
  }
示例#20
0
 public String getName(int id) {
   List name =
       jdbc.query(
           "group.name as (with temp (name, id, parent_group_id) as ((select name, id, parent_group_id from GROUPS where parent_group_id is null) union all (select cast((temp.name + ':' + groups.name) as varchar(128)), "
               + "groups.id, groups.parent_group_id from groups inner join temp on temp.id = groups.parent_group_id )) select name from temp where group.id = ?",
           new RowMapper() {
             public Object mapRow(ResultSet resultSet, int i) throws SQLException {
               return resultSet.getString(1);
             }
           },
           id);
   String result = (String) name.get(0);
   return result;
 }
示例#21
0
 public List<User> getGroupUsers(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + UsersManagerImpl.userMappingSelectQuery
             + " from groups_members join members on members.id=member_id join "
             + "users on members.user_id=users.id where group_id=? order by "
             + Compatibility.orderByBinary("users.last_name")
             + ", "
             + Compatibility.orderByBinary("users.first_name"),
         UsersManagerImpl.USER_MAPPER,
         group.getId());
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#22
0
 public List<Member> getGroupMembers(PerunSession sess, Group group)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + MembersManagerImpl.memberMappingSelectQuery
             + ", groups_members.membership_type as membership_type from groups_members join members on members.id=groups_members.member_id "
             + " where groups_members.group_id=?",
         MembersManagerImpl.MEMBER_MAPPER,
         group.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Member>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#23
0
 @Override
 public List<Group> getGroupAdmins(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from authz join groups on authz.authorized_group_id=groups.id "
             + "where authz.group_id=? and authz.role_id=(select id from roles where name='groupadmin')",
         GROUP_MAPPER,
         group.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#24
0
 @Override
 public List<User> getDirectAdmins(PerunSession sess, Group group) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + UsersManagerImpl.userMappingSelectQuery
             + " from authz join users on authz.user_id=users.id "
             + "where authz.group_id=? and authz.role_id=(select id from roles where name='groupadmin')",
         UsersManagerImpl.USER_MAPPER,
         group.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<User>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#25
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);
   }
 }
示例#26
0
 public List<Group> getAllMemberGroups(PerunSession sess, Member member)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select distinct "
             + groupMappingSelectQuery
             + " from groups_members join groups on groups_members.group_id = groups.id "
             + " where groups_members.member_id=?",
         GROUP_MAPPER,
         member.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#27
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);
    }
  }
示例#28
0
 public boolean isDirectGroupMember(PerunSession sess, Group group, Member member)
     throws InternalErrorException {
   try {
     int count =
         jdbc.queryForInt(
             "select count(1) from groups_members where group_id=? and member_id=? and membership_type = ?",
             group.getId(),
             member.getId(),
             MembershipType.DIRECT.getCode());
     if (1 < count)
       throw new ConsistencyErrorException(
           "There is more than one direct member in group" + group);
     return 1 == count;
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
示例#29
0
 public List<Group> getSubGroups(PerunSession sess, Group parentGroup)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups where groups.parent_group_id=? "
             + "order by "
             + Compatibility.orderByBinary("groups.name" + Compatibility.castToVarchar()),
         GROUP_MAPPER,
         parentGroup.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException ex) {
     throw new InternalErrorException(ex);
   }
 }
示例#30
0
 /**
  * Gets all groups which have enabled synchronization.
  *
  * @param sess
  * @return list of groups to synchronize
  * @throws InternalErrorException
  */
 public List<Group> getGroupsToSynchronize(PerunSession sess) throws InternalErrorException {
   try {
     // Get all groups which have defined
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups, attr_names, group_attr_values "
             + "where attr_names.attr_name=? and attr_names.id=group_attr_values.attr_id and group_attr_values.attr_value='true' and "
             + "group_attr_values.group_id=groups.id",
         GROUP_MAPPER,
         GroupsManager.GROUPSYNCHROENABLED_ATTRNAME);
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }