Exemplo n.º 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);
    }
  }
Exemplo n.º 2
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);
   }
 }
Exemplo n.º 3
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);
 }
Exemplo n.º 4
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());
 }
Exemplo n.º 5
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);
    }
  }
Exemplo n.º 6
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;
 }
Exemplo n.º 7
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);
   }
 }
Exemplo n.º 8
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);
   }
 }
Exemplo n.º 9
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);
   }
 }
Exemplo n.º 10
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);
   }
 }
Exemplo n.º 11
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);
   }
 }
Exemplo n.º 12
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);
   }
 }
Exemplo n.º 13
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);
   }
 }
Exemplo n.º 14
0
 public List<Group> getAssignedGroupsToResource(PerunSession perunSession, Resource resource)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups join "
             + " groups_resources on groups.id=groups_resources.group_id "
             + " where groups_resources.resource_id=?",
         GROUP_MAPPER,
         resource.getId());
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
Exemplo n.º 15
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);
    }
  }
Exemplo n.º 16
0
 public List<Group> getGroupsByAttribute(PerunSession sess, Attribute attribute)
     throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + " from groups "
             + "join group_attr_values on groups.id=group_attr_values.group_id where group_attr_values.attr_id=? and "
             + "group_attr_values.attr_value=?",
         GROUP_MAPPER,
         attribute.getId(),
         BeansUtils.attributeValueToString(attribute));
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Group>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }
Exemplo n.º 17
0
 public List<Pair<Group, Resource>> getGroupResourcePairsByAttribute(
     PerunSession sess, Attribute attribute) throws InternalErrorException {
   try {
     return jdbc.query(
         "select "
             + groupMappingSelectQuery
             + ", "
             + ResourcesManagerImpl.resourceMappingSelectQuery
             + " from group_resource_attr_values "
             + "join groups on groups.id=group_resource_attr_values.group_id "
             + "join resources on resources.id=group_resource_attr_values.resource_id "
             + "where group_resource_attr_values.attr_id=? and group_resource_attr_values.attr_value=?",
         GROUP_RESOURCE_MAPPER,
         attribute.getId(),
         BeansUtils.attributeValueToString(attribute));
   } catch (EmptyResultDataAccessException e) {
     return new ArrayList<Pair<Group, Resource>>();
   } catch (RuntimeException e) {
     throw new InternalErrorException(e);
   }
 }