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


Java LdapContext.reconnect方法代码示例

本文整理汇总了Java中javax.naming.ldap.LdapContext.reconnect方法的典型用法代码示例。如果您正苦于以下问题:Java LdapContext.reconnect方法的具体用法?Java LdapContext.reconnect怎么用?Java LdapContext.reconnect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.naming.ldap.LdapContext的用法示例。


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

示例1: verifyPassword

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
/**
 * Verifies that the password supplied is actually the user's password, by
 * attempting to rebind to a copy of the LDAP server context using the user's 
 * username and the supplied password.
 * 
 * @param password
 *            The password to validate.
 * @return <code>True</code> if a connection can successfully be established
 *         to the LDAP host using the user's id and the supplied password,
 *         and <code>False</code> otherwise.
 */
public boolean verifyPassword(String password) {
    boolean result = false;
    LdapContext ldapContext = null;
    try {
        ldapContext = _ldapContext.newInstance(null);
        ldapContext.addToEnvironment(Context.SECURITY_AUTHENTICATION,
                LdapConstants.SECURITY_AUTHENTICATION_SIMPLE);
        ldapContext.addToEnvironment(Context.SECURITY_PRINCIPAL, _userDN);
        ldapContext.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
        ldapContext.reconnect(null);
        result = true;
    } catch (NamingException exception) {
        // no-op
    } finally {
        if (null != ldapContext) {
            try {
                ldapContext.close();
            } catch (NamingException ex) {
                // no-op
            }
        }
    }
    return result;
}
 
开发者ID:twachan,项目名称:James,代码行数:36,代码来源:ReadOnlyLDAPUser.java

示例2: ldapApiCheck

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
private boolean ldapApiCheck(String loginId, String password) {

        boolean result = false;
        String action = "login";
        try {
            initLdapContext(action);
            LdapContext ldapCtx = ldapContexts.get(action);

            ldapCtx.addToEnvironment(Context.SECURITY_PRINCIPAL, loginId);
            ldapCtx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
            // 密码验证,不报错则为验证成功
            ldapCtx.reconnect(null);
            result = true;
            loggerInfo("LDAP信息", "校验", "成功", loginId);
        }
        catch (AuthenticationException e) {
            // 此异常为用户验证失败,因此不做ldapContext清除
            loggerError("LDAP信息校验", loginId + " (业务意义为验证失败,异常信息可以忽略)", e);
        }
        catch (Exception e1) {
            loggerError("LDAP信息校验", loginId, e1);
            clearLdapContext(action);
        }

        return result;

    }
 
开发者ID:uavorg,项目名称:uavstack,代码行数:28,代码来源:GUISSOLdapClient.java

示例3: testReconnect_share_connection

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
public void testReconnect_share_connection() throws Exception {

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

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

        // doesn't create new connection
        context.reconnect(null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_SEARCH_RESULT_DONE,
                new EncodableLdapResult(), null) });
        // another and context share the same connection now
        LdapContext another = (LdapContext) context.lookup("");

        MockLdapServer one = new MockLdapServer(server);
        one.start();

        one.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        // create new connection
        context.reconnect(null);

        server.setResponseSeq(new LdapMessage[] { new LdapMessage(
                LdapASN1Constant.OP_BIND_RESPONSE, new BindResponse(), null) });
        // use original connection
        another.reconnect(null);
    }
 
开发者ID:shannah,项目名称:cn1,代码行数:32,代码来源:LdapContextServerMockedTest.java

示例4: applyAuthentication

import javax.naming.ldap.LdapContext; //导入方法依赖的package包/类
protected void applyAuthentication(LdapContext ctx, String userDn, String password) throws NamingException {
	ctx.addToEnvironment(Context.SECURITY_AUTHENTICATION, SIMPLE_AUTHENTICATION);
	ctx.addToEnvironment(Context.SECURITY_PRINCIPAL, userDn);
	ctx.addToEnvironment(Context.SECURITY_CREDENTIALS, password);
	// Force reconnect with user credentials
	ctx.reconnect(null);
}
 
开发者ID:spring-projects,项目名称:spring-ldap,代码行数:8,代码来源:DefaultTlsDirContextAuthenticationStrategy.java

示例5: testReconnect

import javax.naming.ldap.LdapContext; //导入方法依赖的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


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