// exception handling not shown LDAPConnection ldapConnection = new LDAPConnection(hostname,port); BindRequest bindRequest = new SimpleBindRequest(username,password); BindResult bindResult = ldapConnection.bind(bindRequest); if(bindResult.getResultCode().equals(ResultCode.SUCCESS)) { /// successful authentication } ldapConnection.close();
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; } } }
@Override public User check(@NotNull String userName, @NotNull String password) throws SVNException { return findUser(userName, userDN -> pool.bindAndRevertAuthentication(userDN, password).getResultCode() == ResultCode.SUCCESS); }
// exception handling is not shown final String dn = ....; final byte[] password = ....; final BindRequest bindRequest = new SimpleBindRequest(dn,password); final LDAPConnection ldapConnection = new LDAPConnection(hostname,port); final BindResult bindResult = ldapConnection.bind(bindRequest); final ResultCode resultCode = bindResult.getResultCode(); if(resultCode.equals(ResultCode.SUCCESS)) { // user is authenticated } ldapConnection.close();
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; }
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; }
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; }
BindResult bindResult = ldapConnection.bind(bindRequest); if(bindResult.getResultCode() == ResultCode.SUCCESS) { System.out.println("authentication successful");
if(bindResult.getResultCode().equals(ResultCode.SUCCESS)) { log.info("Authenticated {} ({}) from LDAP in {} ms", userLogin, endUserDN, System.currentTimeMillis() - start); return true;
throws LDAPException if (bindResult.getResultCode() == ResultCode.SUCCESS)
if (bindResult.getResultCode().equals(ResultCode.SUCCESS)) if (bindResult.getResultCode().equals(ResultCode.SASL_BIND_IN_PROGRESS))
if (bindResult != null && bindResult.getResultCode() != ResultCode.SUCCESS) { LOGGER.error("Error binding to LDAP" + bindResult.getResultCode()); throw new LDAPException(bindResult.getResultCode(), "Error binding to LDAP");
credentials.getPassword() ); if (bindResult.getResultCode().equals(ResultCode.SUCCESS)) { LOG.info("Login successful: " + credentials.getUsername()); authOK = true;
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)); } }
if (bindResult.getResultCode() == ResultCode.SUCCESS)
BindResult bindResult = ldapConnection.bind(bindRequest); if (bindResult.getResultCode() != ResultCode.SUCCESS) { LOGGER.error("Error binding to LDAP" + bindResult.getResultCode()); throw new LDAPException(bindResult.getResultCode(), "Error binding to LDAP");
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)); } }
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)); } }
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)); } }
bindResult.getResultCode()); if (retryResult != null)