use of org.ldaptive.LdapEntry 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.LdapEntry in project cas by apereo.
the class LdapServiceRegistryDao method update.
/**
* Update the ldap entry with the given registered service.
*
* @param rs the rs
* @return the registered service
*/
private RegisteredService update(final RegisteredService rs) {
String currentDn = null;
try {
final Response<SearchResult> response = searchForServiceById(rs.getId());
if (LdapUtils.containsResultEntry(response)) {
currentDn = response.getResult().getEntry().getDn();
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
if (StringUtils.isNotBlank(currentDn)) {
LOGGER.debug("Updating registered service at [{}]", currentDn);
final LdapEntry entry = this.ldapServiceMapper.mapFromRegisteredService(this.baseDn, rs);
LdapUtils.executeModifyOperation(currentDn, this.connectionFactory, entry);
}
return rs;
}
use of org.ldaptive.LdapEntry in project cas by apereo.
the class LdapConsentRepository method deleteConsentDecision.
@Override
public boolean deleteConsentDecision(final long id, final String principal) {
LOGGER.debug("Deleting consent decision [{}] for principal [{}]", id, principal);
final LdapEntry entry = readConsentEntry(principal);
if (entry != null) {
final Set<String> newConsent = removeDecision(entry.getAttribute(this.ldap.getConsentAttributeName()), id);
return executeModifyOperation(newConsent, entry);
}
return false;
}
use of org.ldaptive.LdapEntry in project cas by apereo.
the class LdapConsentRepository method readConsentEntries.
/**
* Fetches all user entries that contain consent attributes along with these.
*
* @return the collection of user entries
*/
private Collection<LdapEntry> readConsentEntries() {
try {
final String att = this.ldap.getConsentAttributeName();
final SearchFilter filter = LdapUtils.newLdaptiveSearchFilter('(' + att + "=*)");
LOGGER.debug("Locating consent LDAP entries via filter [{}] based on attribute [{}]", filter, att);
final Response<SearchResult> response = LdapUtils.executeSearchOperation(this.connectionFactory, this.ldap.getBaseDn(), filter, att);
if (LdapUtils.containsResultEntry(response)) {
final Collection<LdapEntry> results = response.getResult().getEntries();
LOGGER.debug("Locating [{}] consent LDAP entries", results.size());
return results;
}
} catch (final LdapException e) {
LOGGER.debug(e.getMessage(), e);
}
return new HashSet<>(0);
}
use of org.ldaptive.LdapEntry in project cas by apereo.
the class OptionalWarningLdapLdapAccountStateHandlerTests method verifyWarningOnMatch.
@Test
public void verifyWarningOnMatch() {
final OptionalWarningLdapLdapAccountStateHandler h = new OptionalWarningLdapLdapAccountStateHandler();
h.setWarnAttributeName("attribute");
h.setWarningAttributeValue("value");
h.setDisplayWarningOnMatch(true);
final AuthenticationResponse response = mock(AuthenticationResponse.class);
final LdapEntry entry = mock(LdapEntry.class);
when(response.getLdapEntry()).thenReturn(entry);
when(entry.getAttribute(anyString())).thenReturn(new LdapAttribute("attribute", "value"));
final List<MessageDescriptor> messages = new ArrayList<>();
final LdapPasswordPolicyConfiguration config = new LdapPasswordPolicyConfiguration();
config.setPasswordWarningNumberOfDays(5);
h.handleWarning(new AccountState.DefaultWarning(ZonedDateTime.now(), 1), response, config, messages);
assertEquals(2, messages.size());
}
Aggregations