Exemplo n.º 1
0
  public void setSocketFactory(final LDAPSocketFactory socketFactory) {
    this.socketFactory = socketFactory;

    if (socketFactory == null) {
      conn.setSocketFactory(null);
    } else {
      conn.setSocketFactory(new LDAPToJavaSocketFactory(socketFactory));
    }
  }
Exemplo n.º 2
0
  public void setConnectTimeout(final int timeout) {
    final LDAPConnectionOptions options = conn.getConnectionOptions();

    if (timeout > 0) {
      options.setConnectTimeoutMillis(1000 * timeout);
    } else {
      options.setConnectTimeoutMillis(0);
    }

    conn.setConnectionOptions(options);
  }
Exemplo n.º 3
0
  public LDAPEntry read(
      final String dn, final String[] attrs, final LDAPSearchConstraints constraints)
      throws LDAPException {
    final Filter filter =
        Filter.createORFilter(
            Filter.createPresenceFilter("objectClass"),
            Filter.createEqualityFilter("objectClass", "ldapSubentry"));

    final SearchRequest searchRequest = new SearchRequest(dn, SearchScope.BASE, filter, attrs);
    update(searchRequest, constraints);

    try {
      final SearchResult searchResult = conn.search(searchRequest);
      setResponseControls(searchResult);

      if (searchResult.getEntryCount() != 1) {
        throw new LDAPException(null, LDAPException.NO_RESULTS_RETURNED);
      }

      return new LDAPEntry(searchResult.getSearchEntries().get(0));
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 4
0
  public LDAPSearchResults search(
      final String baseDN,
      final int scope,
      final String filter,
      final String[] attributes,
      final boolean typesOnly,
      final LDAPSearchConstraints constraints)
      throws LDAPException {
    final LDAPSearchResults results;
    final LDAPSearchConstraints c = (constraints == null) ? searchConstraints : constraints;
    results = new LDAPSearchResults(c.getTimeLimit());

    try {
      final SearchRequest searchRequest =
          new SearchRequest(results, baseDN, SearchScope.valueOf(scope), filter, attributes);

      searchRequest.setDerefPolicy(DereferencePolicy.valueOf(c.getDereference()));
      searchRequest.setSizeLimit(c.getMaxResults());
      searchRequest.setTimeLimitSeconds(c.getServerTimeLimit());
      searchRequest.setTypesOnly(typesOnly);

      update(searchRequest, constraints);

      conn.asyncSearch(searchRequest);
      return results;
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 5
0
 public void abandon(final int id) throws LDAPException {
   try {
     conn.abandon(InternalSDKHelper.createAsyncRequestID(id, conn), getControls(null));
   } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
     debugException(le);
     throw new LDAPException(le);
   }
 }
Exemplo n.º 6
0
 public int getConnectTimeout() {
   final int connectTimeoutMillis = conn.getConnectionOptions().getConnectTimeoutMillis();
   if (connectTimeoutMillis > 0) {
     return Math.max(1, (connectTimeoutMillis / 1000));
   } else {
     return 0;
   }
 }
Exemplo n.º 7
0
  public void connect(final String host, final int port) throws LDAPException {
    authDN = null;
    authPW = null;
    responseControls = null;

    try {
      conn.connect(host, port);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 8
0
  public void add(final LDAPEntry entry, final LDAPConstraints constraints) throws LDAPException {
    final AddRequest addRequest = new AddRequest(entry.toEntry());
    update(addRequest, constraints);

    try {
      final LDAPResult result = conn.add(addRequest);
      setResponseControls(result);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 9
0
  public void delete(final String dn, final LDAPConstraints constraints) throws LDAPException {
    final DeleteRequest deleteRequest = new DeleteRequest(dn);
    update(deleteRequest, constraints);

    try {
      final LDAPResult result = conn.delete(deleteRequest);
      setResponseControls(result);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 10
0
  public void reconnect() throws LDAPException {
    final String host = getHost();
    final int port = getPort();
    final String dn = authDN;
    final String pw = authPW;

    conn.close();

    if ((dn == null) || (pw == null)) {
      connect(host, port);
    } else {
      connect(host, port, dn, pw);
    }
  }
Exemplo n.º 11
0
  public boolean compare(
      final String dn, final LDAPAttribute attribute, final LDAPConstraints constraints)
      throws LDAPException {
    final CompareRequest compareRequest =
        new CompareRequest(dn, attribute.getName(), attribute.getByteValueArray()[0]);
    update(compareRequest, constraints);

    try {
      final CompareResult result = conn.compare(compareRequest);
      setResponseControls(result);
      return result.compareMatched();
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 12
0
  public void connect(
      final int version,
      final String host,
      final int port,
      final String dn,
      final String password,
      final LDAPConstraints constraints)
      throws LDAPException {
    connect(host, port);

    try {
      if ((dn != null) && (password != null)) {
        bind(version, dn, password, constraints);
      }
    } catch (LDAPException le) {
      conn.close();
      throw le;
    }
  }
Exemplo n.º 13
0
  public void rename(
      final String dn,
      final String newRDN,
      final String newParentDN,
      final boolean deleteOldRDN,
      final LDAPConstraints constraints)
      throws LDAPException {
    final ModifyDNRequest modifyDNRequest =
        new ModifyDNRequest(dn, newRDN, deleteOldRDN, newParentDN);
    update(modifyDNRequest, constraints);

    try {
      final LDAPResult result = conn.modifyDN(modifyDNRequest);
      setResponseControls(result);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 14
0
  public void modify(
      final String dn, final LDAPModification[] mods, final LDAPConstraints constraints)
      throws LDAPException {
    final Modification[] m = new Modification[mods.length];
    for (int i = 0; i < mods.length; i++) {
      m[i] = mods[i].toModification();
    }

    final ModifyRequest modifyRequest = new ModifyRequest(dn, m);
    update(modifyRequest, constraints);

    try {
      final LDAPResult result = conn.modify(modifyRequest);
      setResponseControls(result);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 15
0
  public void bind(
      final int version, final String dn, final String password, final LDAPConstraints constraints)
      throws LDAPException {
    final SimpleBindRequest bindRequest =
        new SimpleBindRequest(dn, password, getControls(constraints));
    authDN = null;
    authPW = null;

    try {
      final BindResult bindResult = conn.bind(bindRequest);
      setResponseControls(bindResult);
      if (bindResult.getResultCode() == ResultCode.SUCCESS) {
        authDN = dn;
        authPW = password;
      }
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 16
0
  public LDAPExtendedOperation extendedOperation(
      final LDAPExtendedOperation extendedOperation, final LDAPConstraints constraints)
      throws LDAPException {
    final ExtendedRequest extendedRequest =
        new ExtendedRequest(
            extendedOperation.getID(),
            new ASN1OctetString(extendedOperation.getValue()),
            getControls(constraints));

    try {
      final ExtendedResult result = conn.processExtendedOperation(extendedRequest);
      setResponseControls(result);

      if (result.getResultCode() != ResultCode.SUCCESS) {
        throw new LDAPException(
            result.getDiagnosticMessage(),
            result.getResultCode().intValue(),
            result.getDiagnosticMessage(),
            result.getMatchedDN());
      }

      final byte[] valueBytes;
      final ASN1OctetString value = result.getValue();
      if (value == null) {
        valueBytes = null;
      } else {
        valueBytes = value.getValue();
      }

      return new LDAPExtendedOperation(result.getOID(), valueBytes);
    } catch (com.hwlcn.ldap.ldap.sdk.LDAPException le) {
      debugException(le);
      setResponseControls(le);
      throw new LDAPException(le);
    }
  }
Exemplo n.º 17
0
 public boolean isConnected() {
   return conn.isConnected();
 }
Exemplo n.º 18
0
  @Override()
  protected void finalize() throws Throwable {
    conn.close();

    super.finalize();
  }
Exemplo n.º 19
0
 public void disconnect() throws LDAPException {
   conn.close();
   authDN = null;
   authPW = null;
 }
Exemplo n.º 20
0
 public String getHost() {
   return conn.getConnectedAddress();
 }
Exemplo n.º 21
0
 public int getPort() {
   return conn.getConnectedPort();
 }