use of org.ldaptive.ConnectionFactory in project cas by apereo.
the class CasSupportActionsAcceptableUsagePolicyLdapConfiguration method acceptableUsagePolicyRepository.
@RefreshScope
@Bean
public AcceptableUsagePolicyRepository acceptableUsagePolicyRepository() {
final AcceptableUsagePolicyProperties.Ldap ldap = casProperties.getAcceptableUsagePolicy().getLdap();
final ConnectionFactory connectionFactory = Beans.newLdaptivePooledConnectionFactory(ldap);
final LdapAcceptableUsagePolicyRepository r = new LdapAcceptableUsagePolicyRepository(ticketRegistrySupport, connectionFactory, ldap.getUserFilter(), ldap.getBaseDn());
r.setAupAttributeName(casProperties.getAcceptableUsagePolicy().getAupAttributeName());
return r;
}
use of org.ldaptive.ConnectionFactory in project cas by apereo.
the class LdapUtils method executeModifyOperation.
/**
* Execute modify operation boolean.
*
* @param currentDn the current dn
* @param connectionFactory the connection factory
* @param attributes the attributes
* @return true/false
*/
public static boolean executeModifyOperation(final String currentDn, final ConnectionFactory connectionFactory, final Map<String, Set<String>> attributes) {
try (Connection modifyConnection = createConnection(connectionFactory)) {
final ModifyOperation operation = new ModifyOperation(modifyConnection);
final List<AttributeModification> mods = attributes.entrySet().stream().map(entry -> new AttributeModification(AttributeModificationType.REPLACE, new LdapAttribute(entry.getKey(), entry.getValue().toArray(new String[] {})))).collect(Collectors.toList());
final ModifyRequest request = new ModifyRequest(currentDn, mods.toArray(new AttributeModification[] {}));
request.setReferralHandler(new ModifyReferralHandler());
operation.execute(request);
return true;
} catch (final LdapException e) {
LOGGER.error(e.getMessage(), e);
}
return false;
}
use of org.ldaptive.ConnectionFactory in project cas by apereo.
the class LdapServiceRegistryConfiguration method serviceRegistryDao.
@Bean
@RefreshScope
@Autowired
public ServiceRegistryDao serviceRegistryDao(@Qualifier("ldapServiceRegistryMapper") final LdapRegisteredServiceMapper mapper) {
final LdapServiceRegistryProperties ldap = casProperties.getServiceRegistry().getLdap();
final ConnectionFactory connectionFactory = Beans.newLdaptivePooledConnectionFactory(ldap);
return new LdapServiceRegistryDao(connectionFactory, ldap.getBaseDn(), mapper, ldap);
}
use of org.ldaptive.ConnectionFactory in project cas by apereo.
the class CasManagementLdapAuthorizationConfiguration method authorizationGenerator.
@RefreshScope
@Bean
public AuthorizationGenerator authorizationGenerator() {
final LdapAuthorizationProperties ldapAuthz = casProperties.getMgmt().getLdap().getLdapAuthz();
final ConnectionFactory connectionFactory = Beans.newLdaptivePooledConnectionFactory(casProperties.getMgmt().getLdap());
if (StringUtils.isNotBlank(ldapAuthz.getGroupFilter()) && StringUtils.isNotBlank(ldapAuthz.getGroupAttribute())) {
return new LdapUserGroupsToRolesAuthorizationGenerator(connectionFactory, ldapAuthorizationGeneratorUserSearchExecutor(), ldapAuthz.isAllowMultipleResults(), ldapAuthz.getGroupAttribute(), ldapAuthz.getGroupPrefix(), ldapAuthorizationGeneratorGroupSearchExecutor());
}
return new LdapUserAttributesToRolesAuthorizationGenerator(connectionFactory, ldapAuthorizationGeneratorUserSearchExecutor(), ldapAuthz.isAllowMultipleResults(), ldapAuthz.getRoleAttribute(), ldapAuthz.getRolePrefix());
}
use of org.ldaptive.ConnectionFactory in project cas by apereo.
the class LdapPasswordManagementService method getSecurityQuestions.
@Override
public Map<String, String> getSecurityQuestions(final String username) {
final Map<String, String> set = new LinkedHashMap<>();
try {
final PasswordManagementProperties.Ldap ldap = passwordManagementProperties.getLdap();
final SearchFilter filter = Beans.newLdaptiveSearchFilter(ldap.getUserFilter(), Beans.LDAP_SEARCH_FILTER_DEFAULT_PARAM_NAME, Arrays.asList(username));
LOGGER.debug("Constructed LDAP filter [{}] to locate security questions", filter);
final ConnectionFactory factory = Beans.newLdaptivePooledConnectionFactory(ldap);
final Response<SearchResult> response = LdapUtils.executeSearchOperation(factory, ldap.getBaseDn(), filter);
LOGGER.debug("LDAP response for security questions [{}]", response);
if (LdapUtils.containsResultEntry(response)) {
final LdapEntry entry = response.getResult().getEntry();
LOGGER.debug("Located LDAP entry [{}] in the response", entry);
final Map<String, String> qs = passwordManagementProperties.getLdap().getSecurityQuestionsAttributes();
LOGGER.debug("Security question attributes are defined to be [{}]", qs);
qs.forEach((k, v) -> {
final LdapAttribute q = entry.getAttribute(k);
final LdapAttribute a = entry.getAttribute(v);
if (q != null && a != null && StringUtils.isNotBlank(q.getStringValue()) && StringUtils.isNotBlank(a.getStringValue())) {
LOGGER.debug("Added security question [{}]", q.getStringValue());
set.put(q.getStringValue(), a.getStringValue());
}
});
} else {
LOGGER.debug("LDAP response did not contain a result for security questions");
}
} catch (final Exception e) {
LOGGER.error(e.getMessage(), e);
}
return set;
}
Aggregations