use of org.ldaptive.LdapException in project cas by apereo.
the class LdapServiceRegistryDao method save.
@Override
public RegisteredService save(final RegisteredService rs) {
if (rs.getId() != RegisteredService.INITIAL_IDENTIFIER_VALUE) {
return update(rs);
}
try {
final LdapEntry entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
LdapUtils.executeAddOperation(this.connectionFactory, entry);
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
}
return rs;
}
use of org.ldaptive.LdapException in project cas by apereo.
the class LdapConsentRepository method readConsentEntry.
/**
* Fetches a user entry along with its consent attributes.
*
* @param principal user name
* @return the user's LDAP entry
*/
private LdapEntry readConsentEntry(final String principal) {
try {
final SearchFilter filter = LdapUtils.newLdaptiveSearchFilter(this.searchFilter, CollectionUtils.wrap(Arrays.asList(principal)));
LOGGER.debug("Locating consent LDAP entry via filter [{}] based on attribute [{}]", filter, this.ldap.getConsentAttributeName());
final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory, this.ldap.getBaseDn(), filter, this.ldap.getConsentAttributeName());
if (LdapUtils.containsResultEntry(response)) {
final LdapEntry entry = response.getResult().getEntry();
LOGGER.debug("Locating consent LDAP entry [{}]", entry);
return entry;
}
} catch (final LdapException e) {
LOGGER.debug(e.getMessage(), e);
}
return null;
}
use of org.ldaptive.LdapException in project cas by apereo.
the class LdapUtils method executeDeleteOperation.
/**
* Execute delete operation boolean.
*
* @param connectionFactory the connection factory
* @param entry the entry
* @return true/false
*/
public static boolean executeDeleteOperation(final ConnectionFactory connectionFactory, final LdapEntry entry) {
try (Connection connection = createConnection(connectionFactory)) {
final DeleteOperation delete = new DeleteOperation(connection);
final DeleteRequest request = new DeleteRequest(entry.getDn());
request.setReferralHandler(new DeleteReferralHandler());
final Response<Void> res = delete.execute(request);
return res.getResultCode() == ResultCode.SUCCESS;
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.ldaptive.LdapException in project cas by apereo.
the class LdaptiveResourceCRLFetcher method fetchCRLFromLdap.
/**
* Downloads a CRL from given LDAP url.
*
* @param r the resource that is the ldap url.
* @return the x 509 cRL
* @throws IOException the exception thrown if resources cant be fetched
* @throws CRLException the exception thrown if resources cant be fetched
* @throws CertificateException if connection to ldap fails, or attribute to get the revocation list is unavailable
*/
protected X509CRL fetchCRLFromLdap(final Object r) throws CertificateException, IOException, CRLException {
try {
final String ldapURL = r.toString();
LOGGER.debug("Fetching CRL from ldap [{}]", ldapURL);
final Response<SearchResult> result = performLdapSearch(ldapURL);
if (result.getResultCode() == ResultCode.SUCCESS) {
final LdapEntry entry = result.getResult().getEntry();
final LdapAttribute attribute = entry.getAttribute(this.certificateAttribute);
if (attribute.isBinary()) {
LOGGER.debug("Located entry [{}]. Retrieving first attribute [{}]", entry, attribute);
return fetchX509CRLFromAttribute(attribute);
}
LOGGER.warn("Found certificate attribute [{}] but it is not marked as a binary attribute", this.certificateAttribute);
}
LOGGER.debug("Failed to execute the search [{}]", result);
throw new CertificateException("Failed to establish a connection ldap and search.");
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
throw new CertificateException(e.getMessage());
}
}
use of org.ldaptive.LdapException in project cas by apereo.
the class LdapUtils method executePasswordModifyOperation.
/**
* Execute a password modify operation.
*
* @param currentDn the current dn
* @param connectionFactory the connection factory
* @param oldPassword the old password
* @param newPassword the new password
* @param type the type
* @return true /false
*/
public static boolean executePasswordModifyOperation(final String currentDn, final ConnectionFactory connectionFactory, final String oldPassword, final String newPassword, final AbstractLdapProperties.LdapType type) {
try (Connection modifyConnection = createConnection(connectionFactory)) {
if (!modifyConnection.getConnectionConfig().getUseSSL() && !modifyConnection.getConnectionConfig().getUseStartTLS()) {
LOGGER.warn("Executing password modification op under a non-secure LDAP connection; " + "To modify password attributes, the connection to the LDAP server SHOULD be secured and/or encrypted.");
}
if (type == AbstractLdapProperties.LdapType.AD) {
LOGGER.debug("Executing password modification op for active directory based on " + "[https://support.microsoft.com/en-us/kb/269190]");
final ModifyOperation operation = new ModifyOperation(modifyConnection);
final Response response = operation.execute(new ModifyRequest(currentDn, new AttributeModification(AttributeModificationType.REPLACE, new UnicodePwdAttribute(newPassword))));
LOGGER.debug("Result code [{}], message: [{}]", response.getResult(), response.getMessage());
return response.getResultCode() == ResultCode.SUCCESS;
}
LOGGER.debug("Executing password modification op for generic LDAP");
final PasswordModifyOperation operation = new PasswordModifyOperation(modifyConnection);
final Response response = operation.execute(new PasswordModifyRequest(currentDn, StringUtils.isNotBlank(oldPassword) ? new Credential(oldPassword) : null, new Credential(newPassword)));
LOGGER.debug("Result code [{}], message: [{}]", response.getResult(), response.getMessage());
return response.getResultCode() == ResultCode.SUCCESS;
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
Aggregations