@SuppressWarnings("rawtypes")
  protected void applyRequestControls(AbstractQuery query) {

    try {
      List<Control> controls = new ArrayList<Control>();

      String orderBy = query.getOrderBy();
      if (orderBy != null) {
        orderBy = orderBy.substring(0, orderBy.length() - 4);
        if (UserQueryProperty.USER_ID.getName().equals(orderBy)) {
          controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL));

        } else if (UserQueryProperty.EMAIL.getName().equals(orderBy)) {
          controls.add(
              new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL));

        } else if (UserQueryProperty.FIRST_NAME.getName().equals(orderBy)) {
          controls.add(
              new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL));

        } else if (UserQueryProperty.LAST_NAME.getName().equals(orderBy)) {
          controls.add(
              new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL));
        }
      }

      initialContext.setRequestControls(controls.toArray(new Control[0]));

    } catch (Exception e) {
      throw new IdentityProviderException("Exception while setting paging settings", e);
    }
  }
  protected void applyRequestControls(AbstractQuery<?, ?> query) {

    try {
      List<Control> controls = new ArrayList<Control>();

      List<QueryOrderingProperty> orderBy = query.getOrderingProperties();
      if (orderBy != null) {
        for (QueryOrderingProperty orderingProperty : orderBy) {
          String propertyName = orderingProperty.getQueryProperty().getName();
          if (UserQueryProperty.USER_ID.getName().equals(propertyName)) {
            controls.add(new SortControl(ldapConfiguration.getUserIdAttribute(), Control.CRITICAL));

          } else if (UserQueryProperty.EMAIL.getName().equals(propertyName)) {
            controls.add(
                new SortControl(ldapConfiguration.getUserEmailAttribute(), Control.CRITICAL));

          } else if (UserQueryProperty.FIRST_NAME.getName().equals(propertyName)) {
            controls.add(
                new SortControl(ldapConfiguration.getUserFirstnameAttribute(), Control.CRITICAL));

          } else if (UserQueryProperty.LAST_NAME.getName().equals(propertyName)) {
            controls.add(
                new SortControl(ldapConfiguration.getUserLastnameAttribute(), Control.CRITICAL));
          }
        }
      }

      initialContext.setRequestControls(controls.toArray(new Control[0]));

    } catch (Exception e) {
      throw new IdentityProviderException("Exception while setting paging settings", e);
    }
  }