当前位置: 首页>>代码示例>>Java>>正文


Java SortControl类代码示例

本文整理汇总了Java中javax.naming.ldap.SortControl的典型用法代码示例。如果您正苦于以下问题:Java SortControl类的具体用法?Java SortControl怎么用?Java SortControl使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


SortControl类属于javax.naming.ldap包,在下文中一共展示了SortControl类的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: setRequestControls

import javax.naming.ldap.SortControl; //导入依赖的package包/类
/** 
 * Set the standard request controls
 */
private void setRequestControls(byte[] cookie) throws TranslatorException {
	List<Control> ctrl = new ArrayList<Control>();
	SortKey[] keys = searchDetails.getSortKeys();
	try {			
		if (keys != null) {
			ctrl.add(new SortControl(keys, Control.NONCRITICAL));
		}
		if (this.executionFactory.usePagination()) {
			ctrl.add(new PagedResultsControl(this.executionContext.getBatchSize(), cookie, Control.CRITICAL));
		}
		if (!ctrl.isEmpty()) {
			this.ldapCtx.setRequestControls(ctrl.toArray(new Control[ctrl.size()]));
			LogManager.logTrace(LogConstants.CTX_CONNECTOR, "Sort/pagination controls were created successfully."); //$NON-NLS-1$
		}
	} catch (NamingException ne) {
           final String msg = LDAPPlugin.Util.getString("LDAPSyncQueryExecution.setControlsError") +  //$NON-NLS-1$
           " : "+ne.getExplanation(); //$NON-NLS-1$
		throw new TranslatorException(ne, msg);
	} catch(IOException e) {
		throw new TranslatorException(e);
	}
}
 
开发者ID:kenweezy,项目名称:teiid,代码行数:26,代码来源:LDAPQueryExecution.java

示例2: testConnectControls2

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testConnectControls2() throws Exception {
    // set connect controls by property "java.naming.ldap.control.connect"
    env.put("java.naming.ldap.control.connect",
            new Control[] { new SortControl("", Control.NONCRITICAL) });

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    InitialDirContext initialDirContext = new InitialDirContext(env);

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_SEARCH_RESULT_DONE,
            new EncodableLdapResult(), null) });
    LdapContext context = (LdapContext) initialDirContext.lookup("");

    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    Control c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, c.isCritical());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:23,代码来源:LdapContextServerMockedTest.java

示例3: testConnectControls3

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testConnectControls3() throws Exception {
    // set connect controls by InitialLdapContext
    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    InitialLdapContext initialDirContext = new InitialLdapContext(env,
            new Control[] { new SortControl("", Control.NONCRITICAL) });

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_SEARCH_RESULT_DONE,
            new EncodableLdapResult(), null) });
    LdapContext context = (LdapContext) initialDirContext.lookup("");

    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    Control c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, c.isCritical());

}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:LdapContextServerMockedTest.java

示例4: testSortControlStringArrayBoolean002

import javax.naming.ldap.SortControl; //导入依赖的package包/类
/**
 * @tests isCritical()
 */
public void testSortControlStringArrayBoolean002() throws Exception {
    assertTrue(new SortControl("", true).isCritical());
    assertFalse(new SortControl("", false).isCritical());

    assertTrue(new SortControl(new String[0], true).isCritical());
    assertFalse(new SortControl(new String[0], false).isCritical());

    assertTrue(new SortControl(new SortKey[0], true).isCritical());
    assertFalse(new SortControl(new SortKey[0], false).isCritical());

}
 
开发者ID:shannah,项目名称:cn1,代码行数:15,代码来源:SortControlTest.java

示例5: test_reconnect

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void test_reconnect() throws Exception {
    Hashtable<Object, Object> env = new Hashtable<Object, Object>();
    env
    .put("java.naming.ldap.control.connect",
            new Control[] { new PagedResultsControl(10,
                    Control.NONCRITICAL) });

    MockLdapClient client = new MockLdapClient();
    context = new LdapContextImpl(client, env, "cn=test");
    
    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    Control c = controls[0];
    assertTrue(c instanceof PagedResultsControl);
    assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c).isCritical());

    context.reconnect(new Control[] { new SortControl("",
            Control.NONCRITICAL) });
    
    controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
    
    context.reconnect(null);
    
    assertNull(context.getConnectControls());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:31,代码来源:LdapContextImplTest.java

示例6: testnewInstance

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testnewInstance() throws Exception {
    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    InitialLdapContext initialDirContext = new InitialLdapContext(env, null);
    Control[] reqCtls = initialDirContext.getRequestControls();
    assertEquals(1, reqCtls.length);
    assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
    assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    LdapContext context = initialDirContext
            .newInstance(new Control[] { new SortControl("",
                    Control.NONCRITICAL) });

    assertNotSame(initialDirContext, context);
    reqCtls = context.getRequestControls();
    assertEquals(2, reqCtls.length);
    Control control = reqCtls[0];
    if (control instanceof SortControl) {
        assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
        assertEquals("2.16.840.1.113730.3.4.2", reqCtls[1].getID());
        assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
    } else {
        assertEquals("2.16.840.1.113730.3.4.2", control.getID());
        assertEquals(Control.NONCRITICAL, control.isCritical());
        assertTrue(reqCtls[1] instanceof SortControl);
        assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
    }

}
 
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:LdapContextServerMockedTest.java

示例7: testCreateRequestControl

import javax.naming.ldap.SortControl; //导入依赖的package包/类
@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);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:8,代码来源:SortControlDirContextProcessorTest.java

示例8: applyRequestControls

import javax.naming.ldap.SortControl; //导入依赖的package包/类
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);
    }
  }
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:31,代码来源:LdapIdentityProviderSession.java

示例9: getSample

import javax.naming.ldap.SortControl; //导入依赖的package包/类
/**
 * Returns a list of usernames with a sample of the users found in LDAP.
 *
 * @param maxSample the max size of the sample to return.
 * @return a list of usernames with a sample of the users found in LDAP.
 * @throws NamingException if something goes wrong....
 */
public List<String> getSample(int maxSample) throws NamingException {
    List<String> usernames = new ArrayList<>();
    LdapContext ctx = null;

    try {
        ctx = manager.getContext();

        // Sort on username field.
        Control[] searchControl;
        try {
            searchControl = new Control[]{
                    new SortControl(new String[]{manager.getUsernameField()}, Control.NONCRITICAL)
            };
        } catch (IOException e) {
            Log.error(e.getMessage(), e);
            return Collections.emptyList();
        }
        ctx.setRequestControls(searchControl);

        // Search for the dn based on the username.
        SearchControls searchControls = new SearchControls();
        // See if recursive searching is enabled. Otherwise, only search one level.
        if (manager.isSubTreeSearch()) {
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }
        searchControls.setReturningAttributes(new String[]{manager.getUsernameField()});
        // Limit results to those we'll need to process
        searchControls.setCountLimit(maxSample);
        String filter = MessageFormat.format(manager.getSearchFilter(), "*");
        NamingEnumeration answer = ctx.search("", filter, searchControls);

        while (answer.hasMoreElements()) {
            // Get the next userID.
            String username = (String) ((SearchResult) answer.next()).getAttributes().get(
                    manager.getUsernameField()).get();
            // Escape username and add to results.
            usernames.add(JID.escapeNode(username));
        }
        // Close the enumeration.
        answer.close();
    } finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
    return usernames;
}
 
开发者ID:igniterealtime,项目名称:Openfire,代码行数:63,代码来源:LdapUserTester.java

示例10: testGetReferralContext3

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testGetReferralContext3() throws Exception {
    Hashtable<Object, Object> initialEnv = new Hashtable<Object, Object>();

    initialEnv.put(Context.REFERRAL, "throw");
    initialEnv.put("test.getReferralContext", "GetReferralContext");

    String[] referrals = new String[] { server.getURL() };
    ReferralExceptionImpl ex = new ReferralExceptionImpl("cn=dn",
            referrals, initialEnv);

    Hashtable<Object, Object> env = new Hashtable<Object, Object>();

    env.put(Context.REFERRAL, "follow");
    env.put("test.getReferralContext", "changed");

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    assertEquals(referrals[0], ex.getReferralInfo());
    Context refContext = ex.getReferralContext(env, new Control[] {
            new PagedResultsControl(1, true),
            new SortControl("hello", true) });

    Hashtable<Object, Object> refEnv = (Hashtable<Object, Object>) refContext
            .getEnvironment();

    assertEquals(env.get(Context.REFERRAL), refEnv.get(Context.REFERRAL));
    assertEquals(env.get("test.getReferralContext"), refEnv
            .get("test.getReferralContext"));
    Control[] cs = (Control[]) refEnv
            .get("java.naming.ldap.control.connect");
    
    assertNotNull(cs);
    assertEquals(2, cs.length);
    assertTrue(cs[0] instanceof PagedResultsControl);
    assertTrue(cs[1] instanceof SortControl);

    assertFalse(ex.skipReferral());

    assertNull(ex.getReferralInfo());
    
    // do nothing
    ex.retryReferral();
}
 
开发者ID:shannah,项目名称:cn1,代码行数:45,代码来源:ReferralExceptionTest.java

示例11: testRequestControls

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testRequestControls() throws Exception {

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

        InitialLdapContext initialContext = new InitialLdapContext(env, null);

        Control[] reqCtls = initialContext.getRequestControls();
        assertEquals(1, reqCtls.length);
        assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
        assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());

        initialContext.setRequestControls(new Control[] { new SortControl("",
                Control.NONCRITICAL) });

        reqCtls = initialContext.getRequestControls();
        assertEquals(2, reqCtls.length);
        Control control = reqCtls[0];
        if (control instanceof SortControl) {
            assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
            assertEquals("2.16.840.1.113730.3.4.2", reqCtls[1].getID());
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        } else {
            assertEquals("2.16.840.1.113730.3.4.2", control.getID());
            assertEquals(Control.NONCRITICAL, control.isCritical());
            assertTrue(reqCtls[1] instanceof SortControl);
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        }

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });

        LdapContext context = (LdapContext) initialContext.lookup("");
        // request controls are not inherited
        reqCtls = context.getRequestControls();
        assertEquals(1, reqCtls.length);
        assertEquals("2.16.840.1.113730.3.4.2", reqCtls[0].getID());
        assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        context = context.newInstance(new Control[] { new SortControl("",
                Control.NONCRITICAL) });
        reqCtls = context.getRequestControls();

        assertEquals(2, reqCtls.length);
        control = reqCtls[0];
        if (control instanceof SortControl) {
            assertEquals(Control.NONCRITICAL, reqCtls[0].isCritical());
            assertEquals("2.16.840.1.113730.3.4.2", reqCtls[1].getID());
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        } else {
            assertEquals("2.16.840.1.113730.3.4.2", control.getID());
            assertEquals(Control.NONCRITICAL, control.isCritical());
            assertTrue(reqCtls[1] instanceof SortControl);
            assertEquals(Control.NONCRITICAL, reqCtls[1].isCritical());
        }
    }
 
开发者ID:shannah,项目名称:cn1,代码行数:60,代码来源:LdapContextServerMockedTest.java

示例12: testReconnect

import javax.naming.ldap.SortControl; //导入依赖的package包/类
public void testReconnect() throws Exception {
    Control[] expected = new Control[] { new PagedResultsControl(10,
            Control.NONCRITICAL) };
    env.put("java.naming.ldap.control.connect", expected);

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    LdapContext context = new InitialLdapContext(env, null);

    Control[] controls = context.getConnectControls();
    assertNotNull(controls);
    assertNotSame(expected, controls);

    Control c = controls[0];
    assertTrue(c instanceof PagedResultsControl);
    assertEquals(Control.NONCRITICAL, ((PagedResultsControl) c)
            .isCritical());
    assertEquals(expected[0], c);

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });

    expected = new Control[] { new SortControl("", Control.NONCRITICAL) };
    context.reconnect(expected);

    controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());
    assertNotSame(expected, controls);
    assertEquals(expected[0], c);

    expected[0] = new PagedResultsControl(10, Control.NONCRITICAL);
    controls = context.getConnectControls();
    assertNotNull(controls);
    assertEquals(1, controls.length);
    c = controls[0];
    assertTrue(c instanceof SortControl);
    assertEquals(Control.NONCRITICAL, ((SortControl) c).isCritical());

    server.setResponseSeq(new LdapMessage[] { new LdapMessage(
            LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
    context.reconnect(null);

    assertNull(context.getConnectControls());
}
 
开发者ID:shannah,项目名称:cn1,代码行数:49,代码来源:LdapContextServerMockedTest.java

示例13: getSample

import javax.naming.ldap.SortControl; //导入依赖的package包/类
/**
 * Returns a list of usernames with a sample of the users found in LDAP.
 *
 * @param maxSample the max size of the sample to return.
 * @return a list of usernames with a sample of the users found in LDAP.
 * @throws NamingException if something goes wrong....
 */
public List<String> getSample(int maxSample) throws NamingException {
    List<String> usernames = new ArrayList<String>();
    LdapContext ctx = null;

    try {
        ctx = manager.getContext();

        // Sort on username field.
        Control[] searchControl;
        try {
            searchControl = new Control[]{
                    new SortControl(new String[]{manager.getUsernameField()}, Control.NONCRITICAL)
            };
        } catch (IOException e) {
            Log.error(e.getMessage(), e);
            return Collections.emptyList();
        }
        ctx.setRequestControls(searchControl);

        // Search for the dn based on the username.
        SearchControls searchControls = new SearchControls();
        // See if recursive searching is enabled. Otherwise, only search one level.
        if (manager.isSubTreeSearch()) {
            searchControls.setSearchScope(SearchControls.SUBTREE_SCOPE);
        } else {
            searchControls.setSearchScope(SearchControls.ONELEVEL_SCOPE);
        }
        searchControls.setReturningAttributes(new String[]{manager.getUsernameField()});
        // Limit results to those we'll need to process
        searchControls.setCountLimit(maxSample);
        String filter = MessageFormat.format(manager.getSearchFilter(), "*");
        NamingEnumeration answer = ctx.search("", filter, searchControls);

        while (answer.hasMoreElements()) {
            // Get the next userID.
            String username = (String) ((SearchResult) answer.next()).getAttributes().get(
                    manager.getUsernameField()).get();
            // Escape username and add to results.
            usernames.add(JID.escapeNode(username));
        }
        // Close the enumeration.
        answer.close();
    } finally {
        try {
            if (ctx != null) {
                ctx.setRequestControls(null);
                ctx.close();
            }
        }
        catch (Exception ignored) {
            // Ignore.
        }
    }
    return usernames;
}
 
开发者ID:coodeer,项目名称:g3server,代码行数:63,代码来源:LdapUserTester.java

示例14: testEncodedValueOfSortControl001

import javax.naming.ldap.SortControl; //导入依赖的package包/类
/**
 * <p>
 * Test method for 'javax.naming.ldap.SortControl.getEncodedValue()'
 * </p>
 * <p>
 * Here we are testing if this method retrieves the control's ASN.1 BER
 * encoded value. In this case we create a sort control using an array of
 * sortkey.
 * </p>
 * <p>
 * The expecting result is the control's ASN.1 BER encoded value.
 * </p>
 */
public void testEncodedValueOfSortControl001() throws Exception {
    SortKey[] sk = { new SortKey("pepe", false, "leo") };

    SortControl sc = new SortControl(sk, true);
    assertEquals("30 10 30 0e 04 04 70 65 70 65 80 03 6c 65 6f 81 01 ff",
            toHexString(sc.getEncodedValue()));
}
 
开发者ID:shannah,项目名称:cn1,代码行数:21,代码来源:SortControlTest.java


注:本文中的javax.naming.ldap.SortControl类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。