com.unboundid.ldap.sdk.LDAPConnection.bind()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(11.5k)|赞(0)|评价(0)|浏览(291)

本文整理了Java中com.unboundid.ldap.sdk.LDAPConnection.bind()方法的一些代码示例,展示了LDAPConnection.bind()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。LDAPConnection.bind()方法的具体详情如下:
包路径:com.unboundid.ldap.sdk.LDAPConnection
类名称:LDAPConnection
方法名:bind

LDAPConnection.bind介绍

[英]Processes the provided bind request.

The LDAP protocol specification forbids clients from attempting to perform a bind on a connection in which one or more other operations are already in progress. If a bind is attempted while any operations are in progress, then the directory server may or may not abort processing for those operations, depending on the type of operation and how far along the server has already gotten while processing that operation (unless the bind request is one that will not cause the server to attempt to change the identity of this connection, for example by including the retain identity request control in the bind request if using the Commercial Edition of the LDAP SDK in conjunction with a Ping Identity, UnboundID, or Alcatel-Lucent 8661 Directory Server). It is recommended that all active operations be abandoned, canceled, or allowed to complete before attempting to perform a bind on an active connection.
[中]处理提供的绑定请求。
LDAP协议规范禁止客户端尝试对已在进行一个或多个其他操作的连接执行绑定。如果在进行任何操作时尝试绑定,则目录服务器可能会也可能不会中止这些操作的处理,这取决于操作的类型以及处理该操作时服务器已经走了多远(除非绑定请求不会导致服务器尝试更改此连接的标识,例如,如果将LDAP SDK的商业版与Ping标识、Unbounded或Alcatel-Lucent 8661目录服务器结合使用,则在绑定请求中包含保留标识请求控制)。建议在尝试对活动连接执行绑定之前放弃、取消或允许完成所有活动操作。

代码示例

代码示例来源:origin: otto-de/edison-microservice

boolean authenticate(final LDAPConnection ldap, final String userDN, final String password) throws LDAPException {
    final BindResult bindResult = ldap.bind(userDN, password);
    if (bindResult.getResultCode().equals(ResultCode.SUCCESS)) {
      LOG.debug("Login successful: " + userDN); // don't expose user names at successful login as this is a security issue
      return true;
    } else {
      LOG.warn("Access denied: " + userDN);
      return false;
    }
  }
}

代码示例来源:origin: com.gitblit.fathom/fathom-security-ldap

private boolean isAuthenticated(LDAPConnection ldapConnection, String userDn, String password) {
  try {
    // Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
    ldapConnection.bind(userDn, password);
    return true;
  } catch (LDAPException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Error authenticating user", e);
    }
    return false;
  }
}

代码示例来源:origin: gitblit/fathom

private boolean isAuthenticated(LDAPConnection ldapConnection, String userDn, String password) {
  try {
    // Binding will stop any LDAP-Injection Attacks since the searched-for user needs to bind to that DN
    ldapConnection.bind(userDn, password);
    return true;
  } catch (LDAPException e) {
    if (!Strings.isNullOrEmpty(e.getDiagnosticMessage())) {
      log.error(e.getDiagnosticMessage());
    } else {
      log.error("Error authenticating user", e);
    }
    return false;
  }
}

代码示例来源:origin: com.btmatthews.ldapunit/ldapunit

/**
 * Initialise the LDAP directory tester by connecting to the LDAP directory server using the {@code hostname} and
 * {@code port} and bind to it using the {@code bindDN} and {@code password}. The connection attempt is retried
 * a maximum of {@code retries} times with a timeout of {@code timeout} for each attempt.
 *
 * @param hostname The host name of the directory server.
 * @param port     The TCP port number of the directory server.
 * @param bindDN   The DN used to bind to the LDAP directory server.
 * @param password The password used to bind to the LDAP directory server.
 * @param retries  The maximum number of connection attempts.
 * @param timeout  The timeout for each connection attempt.
 * @throws DirectoryTesterException If there was a problem connecting to the LDAP directory server.
 * @since 1.0.1
 */
public DirectoryTester(final String hostname,
            final int port,
            final String bindDN,
            final String password,
            final int retries,
            final int timeout) {
  this(hostname, port, retries, timeout);
  try {
    connection.bind(bindDN, password);
  } catch (final LDAPException e) {
    throw new DirectoryTesterException("Could not bind to LDAP directory server", e);
  }
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-minimal-edition

throws LDAPException
return bind(new SimpleBindRequest(bindDN, password));

代码示例来源:origin: otto-de/edison-microservice

private LDAPConnection someLdapConnectionReturning(final ResultCode resultCode) throws LDAPException {
  final LDAPConnection ldap = mock(LDAPConnection.class);
  final BindResult mockBindResult = mock(BindResult.class);
  when(mockBindResult.getResultCode()).thenReturn(resultCode);
  when(ldap.bind(anyString(), anyString())).thenReturn(mockBindResult);
  return ldap;
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

throws LDAPException
return bind(new SimpleBindRequest(bindDN, password));

代码示例来源:origin: otto-de/edison-microservice

private LDAPConnection someLdapConnectionReturningSuccessOrThrowingBindException(final String bindDnSuccess, final String bindDnException) throws LDAPException {
  final LDAPConnection ldap = mock(LDAPConnection.class);
  final BindResult mockBindResultSuccess = mock(BindResult.class);
  when(mockBindResultSuccess.getResultCode()).thenReturn(ResultCode.SUCCESS);
  when(ldap.bind(contains(bindDnSuccess), anyString())).thenReturn(mockBindResultSuccess);
  final BindResult mockBindResultInvalid = mock(BindResult.class);
  when(mockBindResultInvalid.getResultCode()).thenReturn(ResultCode.INVALID_CREDENTIALS);
  final LDAPBindException mockBindException = mock(LDAPBindException.class);
  when(mockBindException.getBindResult()).thenReturn(mockBindResultInvalid);
  when(ldap.bind(contains(bindDnException), anyString())).thenThrow(mockBindException);
  return ldap;
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

/**
 * Creates a new LDAP connection based on the JSON specification.  The
 * connection will be authenticated if appropriate.
 *
 * @return  The LDAP connection that was created.
 *
 * @throws  LDAPException  If a problem is encountered while trying to
 *                         establish or authenticate the connection.
 */
public LDAPConnection createConnection()
    throws LDAPException
{
 final LDAPConnection connection = createUnauthenticatedConnection();
 if (bindRequest != null)
 {
  try
  {
   connection.bind(bindRequest);
  }
  catch (final LDAPException le)
  {
   Debug.debugException(le);
   connection.close();
   throw le;
  }
 }
 return connection;
}

代码示例来源:origin: otto-de/edison-microservice

@Test
public void shouldApplyFilterToAuthenticatedUserWithAdditionallyConfiguredBaseDn() throws IOException, ServletException, GeneralSecurityException, LDAPException {
  // given
  final LdapProperties ldapProperties = ldapProperties("someHost", 389, asList("exceptionBaseDn", "successBaseDn"), null, "someRdnIdentifier", singletonList("/internal"), StartTLS, WHITELISTED_PATH);
  final LdapConnectionFactory connectionFactory = mock(LdapConnectionFactory.class);
  final LDAPConnection ldapConnection = someLdapConnectionReturningSuccessOrThrowingBindException("successBaseDn", "exceptionBaseDn");
  when(connectionFactory.buildLdapConnection()).thenReturn(ldapConnection);
  testee = new LdapAuthenticationFilter(ldapProperties, connectionFactory);
  // when
  final HttpServletRequest request = requestWithAuthorizationHeader();
  when(request.getServletPath()).thenReturn("/foo");
  final FilterChain filterChain = mock(FilterChain.class);
  testee.doFilter(request, response, filterChain);
  // then
  verify(ldapConnection).bind(contains("exceptionBaseDn"), anyString());
  verify(ldapConnection).bind(contains("successBaseDn"), anyString());
  verify(filterChain).doFilter(any(HttpServletRequest.class), any(HttpServletResponse.class));
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

connection.bind(bindRequest[serverIndex]);

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

connection.bind(bindRequest);

代码示例来源:origin: org.geomajas.plugin/geomajas-plugin-staticsecurity-ldap

protected SearchResult execute(SearchRequest request, String bindDN, String password) {
  LDAPConnection connection = null;
  try {
    if (allowAllSocketFactory) {
      SSLUtil sslUtil = new SSLUtil(new TrustAllTrustManager());
      connection = new LDAPConnection(sslUtil.createSSLSocketFactory(), serverHost, serverPort);
    } else {
      connection = new LDAPConnection(serverHost, serverPort);
    }
    if (bindDN != null) {
      BindResult auth = connection.bind(bindDN, password);
      if (!auth.getResultCode().isConnectionUsable()) {
        log.error("Connection not usable, result code : " + auth.getResultCode());
      }
    }
    return connection.search(request);
  } catch (LDAPException le) {
    String message = le.getMessage();
    if (!message.startsWith("Unable to bind as user ")) {
      log.error(le.getMessage(), le);
    }
  } catch (GeneralSecurityException gse) {
    log.error(gse.getMessage(), gse);
  } finally {
    if (null != connection) {
      connection.close();
    }
  }
  return null;
}

代码示例来源:origin: de.otto.edison/edison-togglz

BindResult bindResult = ldapConnection.bind(
    ldapProperties.getRdnIdentifier() + "=" + credentials.getUsername() + "," +
        ldapProperties.getBaseDn(),

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

try
 bindResult = ldapConnection.bind(bindRequest);

代码示例来源:origin: apiman/apiman

public void connect(final IAsyncResultHandler<ILdapResult> handler) {
  try {
    connection = LDAPConnectionFactory.build(socketFactory, config);
    BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword());
    evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler);
  } catch (LDAPException e) {
    evalBindReturn(e.getResultCode(), e.getMessage(), e, handler);
  } catch (Exception e) {
    LDAPConnectionFactory.releaseDefunct(connection);
    handler.handle(AsyncResultImpl.<ILdapResult>create(e));
  }
}

代码示例来源:origin: com.unboundid/unboundid-ldapsdk-commercial-edition

final BindResult bindResult = conn.bind(bindRequest);
setResponseControls(bindResult);
if (bindResult.getResultCode() == ResultCode.SUCCESS)

代码示例来源:origin: io.apiman/apiman-gateway-engine-core

public void connect(final IAsyncResultHandler<ILdapResult> handler) {
  try {
    connection = LDAPConnectionFactory.build(socketFactory, config);
    BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword());
    evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler);
  } catch (LDAPException e) {
    evalBindReturn(e.getResultCode(), e.getMessage(), e, handler);
  } catch (Exception e) {
    LDAPConnectionFactory.releaseDefunct(connection);
    handler.handle(AsyncResultImpl.<ILdapResult>create(e));
  }
}

代码示例来源:origin: io.apiman/apiman-gateway-engine-core

public static void bind(SSLSocketFactory socketFactory, LdapConfigBean config,
    IAsyncResultHandler<ILdapResult> handler) {
  LDAPConnection connection = null;
  try {
    connection = LDAPConnectionFactory.build(socketFactory, config);
    BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword());
    evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler);
    LDAPConnectionFactory.releaseConnection(connection);
  } catch (LDAPException e) { // generally errors as an exception, also potentially normal return(!).
    evalBindReturn(e.getResultCode(), e.getMessage(), e, handler);
    LDAPConnectionFactory.releaseConnectionAfterException(connection, e);
  } catch (Exception e) {
    LDAPConnectionFactory.releaseDefunct(connection);
    handler.handle(AsyncResultImpl.<ILdapResult>create(e));
  }
}

代码示例来源:origin: apiman/apiman

public static void bind(SSLSocketFactory socketFactory, LdapConfigBean config,
    IAsyncResultHandler<ILdapResult> handler) {
  LDAPConnection connection = null;
  try {
    connection = LDAPConnectionFactory.build(socketFactory, config);
    BindResult bindResponse = connection.bind(config.getBindDn(), config.getBindPassword());
    evalBindReturn(bindResponse.getResultCode(), bindResponse.getDiagnosticMessage(), null, handler);
    LDAPConnectionFactory.releaseConnection(connection);
  } catch (LDAPException e) { // generally errors as an exception, also potentially normal return(!).
    evalBindReturn(e.getResultCode(), e.getMessage(), e, handler);
    LDAPConnectionFactory.releaseConnectionAfterException(connection, e);
  } catch (Exception e) {
    LDAPConnectionFactory.releaseDefunct(connection);
    handler.handle(AsyncResultImpl.<ILdapResult>create(e));
  }
}

相关文章

LDAPConnection类方法