Search in sources :

Example 6 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project mxisd by kamax-io.

the class LdapThreePidProvider method populate.

@Override
public List<ThreePidMapping> populate(List<ThreePidMapping> mappings) {
    log.info("Looking up {} mappings", mappings.size());
    List<ThreePidMapping> mappingsFound = new ArrayList<>();
    try (LdapConnection conn = getConn()) {
        bind(conn);
        for (ThreePidMapping mapping : mappings) {
            try {
                lookup(conn, mapping.getMedium(), mapping.getValue()).ifPresent(id -> {
                    mapping.setMxid(id);
                    mappingsFound.add(mapping);
                });
            } catch (IllegalArgumentException e) {
                log.warn("{} is not a supported 3PID type for LDAP lookup", mapping.getMedium());
            }
        }
    } catch (LdapException | IOException e) {
        throw new InternalServerError(e);
    }
    return mappingsFound;
}
Also used : ThreePidMapping(io.kamax.mxisd.lookup.ThreePidMapping) ArrayList(java.util.ArrayList) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) InternalServerError(io.kamax.mxisd.exception.InternalServerError) LdapConnection(org.apache.directory.ldap.client.api.LdapConnection)

Example 7 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project mamute by caelum.

the class LDAPApi method updateAvatarImage.

private void updateAvatarImage(LDAPResource ldap, Entry entry, User user) {
    try {
        byte[] jpegBytes = getAvatarImage(ldap, entry);
        if (jpegBytes != null) {
            String fileName = user.getEmail() + ".jpg";
            DefaultUploadedFile avatar = new DefaultUploadedFile(new ByteArrayInputStream(jpegBytes), fileName, "image/jpeg", jpegBytes.length);
            Attachment attachment = imageStore.processAndStore(avatar, user, clientIp);
            Attachment old = user.getAvatar();
            if (old != null) {
                imageStore.delete(old);
            }
            user.setAvatar(attachment);
        }
    } catch (LdapException | IOException e) {
        // problems with avatar processing are non-fatal
        logger.warn("Error updating user avatar from LDAP: " + user.getName(), e);
    }
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultUploadedFile(br.com.caelum.vraptor.observer.upload.DefaultUploadedFile) Attachment(org.mamute.model.Attachment) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 8 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project mamute by caelum.

the class LDAPApi method authenticate.

/**
 * Attempt to authenticate against LDAP directory. Accepts email addresses
 * as well as plain usernames; emails will have the '@mail.com' portion
 * stripped off before read.
 *
 * @param username
 * @param password
 * @return
 */
public boolean authenticate(String username, String password) {
    try (LDAPResource ldap = new LDAPResource()) {
        String cn = userCn(username);
        ldap.verifyCredentials(cn, password);
        createUserIfNeeded(ldap, cn);
        return true;
    } catch (LdapAuthenticationException e) {
        logger.debug("LDAP auth attempt failed");
        return false;
    } catch (LdapException | IOException e) {
        logger.debug("LDAP connection error", e);
        throw new AuthenticationException(LDAP_AUTH, "LDAP connection error", e);
    }
}
Also used : LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 9 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method writeStringAttributes.

public void writeStringAttributes(final String entryDN, final Map<String, String> attributeValueProps, final boolean overwrite) throws ChaiOperationException, ChaiUnavailableException, IllegalStateException {
    activityPreCheck();
    getInputValidator().writeStringAttributes(entryDN, attributeValueProps, overwrite);
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        for (final Map.Entry<String, String> entry : attributeValueProps.entrySet()) {
            final String name = entry.getKey();
            final String value = entry.getValue();
            final Modification modification = new DefaultModification();
            modification.setOperation(overwrite ? ModificationOperation.REPLACE_ATTRIBUTE : ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(name, value));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Map(java.util.Map) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Example 10 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project ldapchai by ldapchai.

the class ApacheLdapProviderImpl method replaceAttributeImpl.

private void replaceAttributeImpl(final String entryDN, final String attributeName, final Value oldValue, final Value newValue) throws ChaiOperationException {
    try {
        final ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName(new Dn(entryDN));
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.REMOVE_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, oldValue));
            modifyRequest.addModification(modification);
        }
        {
            final Modification modification = new DefaultModification();
            modification.setOperation(ModificationOperation.ADD_ATTRIBUTE);
            modification.setAttribute(new DefaultAttribute(attributeName, newValue));
            modifyRequest.addModification(modification);
        }
        final ModifyResponse response = connection.modify(modifyRequest);
        processResponse(response);
    } catch (LdapException e) {
        throw ChaiOperationException.forErrorMessage(e.getMessage());
    }
}
Also used : DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Modification(org.apache.directory.api.ldap.model.entry.Modification) ModifyRequestImpl(org.apache.directory.api.ldap.model.message.ModifyRequestImpl) DefaultModification(org.apache.directory.api.ldap.model.entry.DefaultModification) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyRequest(org.apache.directory.api.ldap.model.message.ModifyRequest) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) ModifyResponse(org.apache.directory.api.ldap.model.message.ModifyResponse)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)329 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)159 ArrayList (java.util.ArrayList)93 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)91 FinderException (org.apache.directory.fortress.core.FinderException)73 Entry (org.apache.directory.api.ldap.model.entry.Entry)63 Modification (org.apache.directory.api.ldap.model.entry.Modification)63 IOException (java.io.IOException)54 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)50 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)49 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)22 ConnectException (java.net.ConnectException)21