类javax.naming.ldap.SortControl源码实例Demo

下面列出了怎么用javax.naming.ldap.SortControl的API类实例代码及写法,或者点击链接到github查看源代码。

@Test
public void testCreateRequestControl() throws Exception {
    SortControl result = (SortControl) tested.createRequestControl();
    assertThat(result).isNotNull();
    assertThat(result.getID()).isEqualTo("1.2.840.113556.1.4.473");
    assertThat(result.getEncodedValue().length).isEqualTo(9);
}
 
protected void applyRequestControls(AbstractQuery<?, ?> query) {

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

      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);
    }
  }
 
 类所在包
 同包方法