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;
}
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);
}
}
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);
}
}
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());
}
}
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());
}
}
Aggregations