當前位置: 首頁>>代碼示例>>Java>>正文


Java Control.NONCRITICAL屬性代碼示例

本文整理匯總了Java中javax.naming.ldap.Control.NONCRITICAL屬性的典型用法代碼示例。如果您正苦於以下問題:Java Control.NONCRITICAL屬性的具體用法?Java Control.NONCRITICAL怎麽用?Java Control.NONCRITICAL使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在javax.naming.ldap.Control的用法示例。


在下文中一共展示了Control.NONCRITICAL屬性的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: testConnectControls3

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,代碼行數:20,代碼來源:LdapContextServerMockedTest.java

示例2: getSample

/**
 * 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,代碼行數:62,代碼來源:LdapUserTester.java

示例3: testReconnect

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,代碼行數:48,代碼來源:LdapContextServerMockedTest.java

示例4: getSample

/**
 * 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,代碼行數:62,代碼來源:LdapUserTester.java


注:本文中的javax.naming.ldap.Control.NONCRITICAL屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。