public LdapNetworkConnection connect(LdapConnectionConfig config) throws LdapException { final LdapNetworkConnection connection = new LdapNetworkConnection(config); connection.setTimeOut(connectionTimeout); connection.bind();
boolean connected = connection.isConnected(); boolean systemAuthenticated = connection.isAuthenticated(); if (connection != null) { try { connection.close(); } catch (IOException e) { LOG.warn("Unable to close LDAP connection.", e);
@Override public Boolean call() throws Exception { return connection.connect(); } }, Callable.class,
public boolean authenticate(LdapNetworkConnection connection, String principal, String credentials) throws LdapException { checkArgument(!isNullOrEmpty(principal), "Binding with empty principal is forbidden."); checkArgument(!isNullOrEmpty(credentials), "Binding with empty credentials is forbidden."); final BindRequestImpl bindRequest = new BindRequestImpl(); bindRequest.setName(principal); bindRequest.setCredentials(credentials); LOG.trace("Re-binding with DN {} using password", principal); final BindResponse bind = connection.bind(bindRequest); if (!bind.getLdapResult().getResultCode().equals(ResultCodeEnum.SUCCESS)) { LOG.trace("Re-binding DN {} failed", principal); throw new RuntimeException(bind.toString()); } LOG.trace("Binding DN {} did not throw, connection authenticated: {}", principal, connection.isAuthenticated()); return connection.isAuthenticated(); } }
/** * {@inheritDoc} */ @Override public ExtendedFuture extendedAsync( ExtendedRequest extendedRequest ) throws LdapException { if ( extendedRequest == null ) { String msg = I18n.err( I18n.ERR_04154_CANNOT_PROCESS_NULL_EXT_REQ ); if ( LOG.isDebugEnabled() ) { LOG.debug( msg ); } throw new IllegalArgumentException( msg ); } // try to connect, if we aren't already connected. connect(); checkSession(); int newId = messageId.incrementAndGet(); extendedRequest.setMessageId( newId ); ExtendedFuture extendedFuture = new ExtendedFuture( this, newId ); addToFutureMap( newId, extendedFuture ); // Send the request to the server writeRequest( extendedRequest ); // Ok, done return the future return extendedFuture; }
/** * Creates a new LdapDao. Its connection will use the given parameters. * */ public LdapDao(String host, int port) { this.connection = new LdapNetworkConnection(host, port); }
public static boolean doUserAuth(String user, String pwd) throws HasException, IOException, LdapInvalidAttributeValueException { LdapNetworkConnection connection = new LdapNetworkConnection( ldapServerConf.getHost(), Integer.parseInt(ldapServerConf.getPort())); try { connection.bind(ldapServerConf.getBindDN(), ldapServerConf.getBindPwd()); } catch (LdapException e) { connection.close(); throw new HasException("Failed to bind. " + e.getMessage()); new Dn(ldapServerConf.getBaseDN())); } catch (LdapInvalidDnException e) { connection.close(); throw new HasException(e.getMessage()); entry = connection.lookup(dn); } catch (LdapException e) { throw new HasException(e.getMessage()); } finally { connection.close();
connectionConfig.setTrustManagers( new NoVerificationTrustManager() ); ldapConnection = new LdapNetworkConnection( connectionConfig ); ldapConnection.connect(); ldapConnection.startTls(); connectionConfig.setTrustManagers( new NoVerificationTrustManager() ); ldapConnection = new LdapNetworkConnection( connectionConfig ); ldapConnection.connect(); connectionConfig.setLdapPort( delegatePort ); ldapConnection = new LdapNetworkConnection( delegateHost, delegatePort ); ldapConnection.connect(); ldapConnection.setTimeOut( 0L ); ldapConnection.bind( bindDn, Strings.utf8ToString( bindContext.getCredentials() ) ); ldapConnection.unBind(); ldapConnection.close();
ldapConnection = new LdapNetworkConnection( ldapConnectionConfig ); boolean connected = ldapConnection.connect(); if ( !connected ) ldapConnection.close();
boolean closeConn = false; try { final LdapNetworkConnection lc = new LdapNetworkConnection(ldapConnectionConfig); conn = new ApacheLdapConnection(lc, getProviderConfig()); lc.connect(); if (useStartTLS) { lc.startTls(); lc.setTimeOut(responseTimeOut.toMillis());
config.setName(endpoint.getProperty("loginPW")); LdapNetworkConnection connection = new LdapNetworkConnection(config); try { connection.bind(); } catch (Exception e) { throw new DataRetrievalException("LDAP connnection could not be bind", e); if (connection.isAuthenticated()) { return connection; } else {
/** * {@inheritDoc} */ @Override public void anonymousBind() throws LdapException { if ( LOG.isDebugEnabled() ) { LOG.debug( I18n.msg( I18n.MSG_04109_ANONYMOUS_BIND ) ); } // Create the BindRequest BindRequest bindRequest = createBindRequest( StringConstants.EMPTY, Strings.EMPTY_BYTES ); BindResponse bindResponse = bind( bindRequest ); processResponse( bindResponse ); }
@Override public void close(final RequestControl[] controls) throws LdapException { if (controls != null) { throw new UnsupportedOperationException("Provider does not support unbind with controls"); } if (connection != null) { try { if (connection.isConnected()) { connection.unBind(); } } catch (org.apache.directory.api.ldap.model.exception.LdapException e) { logger.error("Error unbinding from LDAP", e); } try { connection.close(); } catch (IOException e) { throw new LdapException(e); } finally { connection = null; } } }
/** * Creates a new {@link LdapNetworkConnection} and authenticates as admin user. * The caller is responsible for closing the connection, use closeConnection(). * * @param ldapServer the LDAP server instance, used to obtain the port used * @return the created connection * @throws LdapException the LDAP exception */ public static LdapNetworkConnection createAdminConnection( LdapServer ldapServer ) throws LdapException { LdapNetworkConnection conn = new LdapNetworkConnection( Network.LOOPBACK_HOSTNAME, ldapServer.getPort() ); conn.bind( DEFAULT_ADMIN, DEFAULT_PASSWORD ); return conn; }
/** * Bind to the server using the SASL DIGEST-MD5 mechanism. * * @param userName The user name * @param credentials The user credentials * @return A LdapResponse containing the result * @throws LdapException if some error occurred */ public BindResponse bindSaslDigestMd5( String userName, String credentials ) throws LdapException { SaslDigestMd5Request request = new SaslDigestMd5Request(); request.setUsername( userName ); request.setCredentials( "secret" ); return bind( request ); }
/** * {@inheritDoc} */ public LdapConnection makeObject() throws LdapException { LdapNetworkConnection connection = config.isUseTls() ? new TlsGuardingConnection(config) : new LdapNetworkConnection(config); connection.connect(); log.debug("creating new connection: {}", connection); return connection; }
final Set<String> groups = Sets.newHashSet(); try (final EntryCursor groupSearch = connection.search( groupSearchBase, groupSearchPattern,