Search in sources :

Example 1 with LdapRuntimeException

use of org.apache.directory.ldap.client.template.exception.LdapRuntimeException in project directory-ldap-api by apache.

the class LdapConnectionTemplate method modifyPassword.

/**
 * {@inheritDoc}
 */
@Override
public void modifyPassword(Dn userDn, char[] oldPassword, char[] newPassword, boolean asAdmin) throws PasswordException {
    LdapConnection connection = null;
    try {
        connection = connectionPool.getConnection();
        if (!asAdmin) {
            authenticateConnection(connection, userDn, oldPassword);
        }
        modifyPassword(connection, userDn, newPassword);
    } catch (LdapException e) {
        throw new LdapRuntimeException(e);
    } finally {
        returnLdapConnection(connection);
    }
}
Also used : LdapRuntimeException(org.apache.directory.ldap.client.template.exception.LdapRuntimeException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 2 with LdapRuntimeException

use of org.apache.directory.ldap.client.template.exception.LdapRuntimeException in project directory-ldap-api by apache.

the class LdapConnectionTemplate method search.

/**
 * {@inheritDoc}
 */
@Override
public <T> List<T> search(SearchRequest searchRequest, EntryMapper<T> entryMapper) {
    List<T> entries = new ArrayList<>();
    LdapConnection connection = null;
    try {
        connection = connectionPool.getConnection();
        for (Entry entry : new EntryCursorImpl(connection.search(searchRequest))) {
            entries.add(entryMapper.map(entry));
        }
    } catch (LdapException e) {
        throw new LdapRuntimeException(e);
    } finally {
        returnLdapConnection(connection);
    }
    return entries;
}
Also used : EntryCursorImpl(org.apache.directory.ldap.client.api.EntryCursorImpl) Entry(org.apache.directory.api.ldap.model.entry.Entry) ArrayList(java.util.ArrayList) LdapRuntimeException(org.apache.directory.ldap.client.template.exception.LdapRuntimeException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 3 with LdapRuntimeException

use of org.apache.directory.ldap.client.template.exception.LdapRuntimeException in project directory-ldap-api by apache.

the class LdapConnectionTemplate method lookup.

/**
 * {@inheritDoc}
 */
@Override
public <T> T lookup(Dn dn, String[] attributes, EntryMapper<T> entryMapper) {
    LdapConnection connection = null;
    try {
        connection = connectionPool.getConnection();
        Entry entry = attributes == null ? connection.lookup(dn) : connection.lookup(dn, attributes);
        return entry == null ? null : entryMapper.map(entry);
    } catch (LdapException e) {
        throw new LdapRuntimeException(e);
    } finally {
        returnLdapConnection(connection);
    }
}
Also used : Entry(org.apache.directory.api.ldap.model.entry.Entry) LdapRuntimeException(org.apache.directory.ldap.client.template.exception.LdapRuntimeException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)3 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)3 LdapRuntimeException (org.apache.directory.ldap.client.template.exception.LdapRuntimeException)3 Entry (org.apache.directory.api.ldap.model.entry.Entry)2 ArrayList (java.util.ArrayList)1 EntryCursorImpl (org.apache.directory.ldap.client.api.EntryCursorImpl)1