Search in sources :

Example 1 with ConnectionFactory

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;
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) LdapAcceptableUsagePolicyRepository(org.apereo.cas.web.flow.LdapAcceptableUsagePolicyRepository) AcceptableUsagePolicyProperties(org.apereo.cas.configuration.model.support.aup.AcceptableUsagePolicyProperties) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 2 with ConnectionFactory

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;
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) SearchOperation(org.ldaptive.SearchOperation) ReturnAttributes(org.ldaptive.ReturnAttributes) UnicodePwdAttribute(org.ldaptive.ad.UnicodePwdAttribute) URL(java.net.URL) AttributeModificationType(org.ldaptive.AttributeModificationType) LoggerFactory(org.slf4j.LoggerFactory) AddRequest(org.ldaptive.AddRequest) Beans(org.apereo.cas.configuration.support.Beans) StringUtils(org.apache.commons.lang3.StringUtils) HashSet(java.util.HashSet) ModifyOperation(org.ldaptive.ModifyOperation) SearchReferralHandler(org.ldaptive.referral.SearchReferralHandler) SearchResult(org.ldaptive.SearchResult) Map(java.util.Map) PasswordModifyRequest(org.ldaptive.extended.PasswordModifyRequest) ModifyReferralHandler(org.ldaptive.referral.ModifyReferralHandler) URI(java.net.URI) DeleteRequest(org.ldaptive.DeleteRequest) Logger(org.slf4j.Logger) ResultCode(org.ldaptive.ResultCode) ModifyRequest(org.ldaptive.ModifyRequest) AttributeModification(org.ldaptive.AttributeModification) Set(java.util.Set) AbstractLdapProperties(org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties) PasswordModifyOperation(org.ldaptive.extended.PasswordModifyOperation) SearchRequest(org.ldaptive.SearchRequest) Collectors(java.util.stream.Collectors) Response(org.ldaptive.Response) StandardCharsets(java.nio.charset.StandardCharsets) Connection(org.ldaptive.Connection) List(java.util.List) DeleteOperation(org.ldaptive.DeleteOperation) DeleteReferralHandler(org.ldaptive.referral.DeleteReferralHandler) AddOperation(org.ldaptive.AddOperation) Credential(org.ldaptive.Credential) LdapAttribute(org.ldaptive.LdapAttribute) NumberUtils(org.apache.commons.lang3.math.NumberUtils) LdapEntry(org.ldaptive.LdapEntry) LdapException(org.ldaptive.LdapException) SearchFilter(org.ldaptive.SearchFilter) ModifyReferralHandler(org.ldaptive.referral.ModifyReferralHandler) AttributeModification(org.ldaptive.AttributeModification) Connection(org.ldaptive.Connection) LdapAttribute(org.ldaptive.LdapAttribute) ModifyOperation(org.ldaptive.ModifyOperation) PasswordModifyOperation(org.ldaptive.extended.PasswordModifyOperation) PasswordModifyRequest(org.ldaptive.extended.PasswordModifyRequest) ModifyRequest(org.ldaptive.ModifyRequest) LdapException(org.ldaptive.LdapException)

Example 3 with ConnectionFactory

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);
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) LdapServiceRegistryProperties(org.apereo.cas.configuration.model.support.ldap.serviceregistry.LdapServiceRegistryProperties) LdapServiceRegistryDao(org.apereo.cas.adaptors.ldap.services.LdapServiceRegistryDao) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Autowired(org.springframework.beans.factory.annotation.Autowired) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) Bean(org.springframework.context.annotation.Bean)

Example 4 with ConnectionFactory

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());
}
Also used : LdapUserAttributesToRolesAuthorizationGenerator(org.apereo.cas.authorization.LdapUserAttributesToRolesAuthorizationGenerator) LdapAuthorizationProperties(org.apereo.cas.configuration.model.support.ldap.LdapAuthorizationProperties) ConnectionFactory(org.ldaptive.ConnectionFactory) LdapUserGroupsToRolesAuthorizationGenerator(org.apereo.cas.authorization.LdapUserGroupsToRolesAuthorizationGenerator) RefreshScope(org.springframework.cloud.context.config.annotation.RefreshScope) Bean(org.springframework.context.annotation.Bean)

Example 5 with ConnectionFactory

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;
}
Also used : ConnectionFactory(org.ldaptive.ConnectionFactory) PasswordManagementProperties(org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties) LdapAttribute(org.ldaptive.LdapAttribute) SearchFilter(org.ldaptive.SearchFilter) SearchResult(org.ldaptive.SearchResult) LdapEntry(org.ldaptive.LdapEntry) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

ConnectionFactory (org.ldaptive.ConnectionFactory)9 SearchFilter (org.ldaptive.SearchFilter)5 SearchResult (org.ldaptive.SearchResult)4 RefreshScope (org.springframework.cloud.context.config.annotation.RefreshScope)4 Bean (org.springframework.context.annotation.Bean)4 PasswordManagementProperties (org.apereo.cas.configuration.model.support.pm.PasswordManagementProperties)3 LdapAttribute (org.ldaptive.LdapAttribute)3 LdapEntry (org.ldaptive.LdapEntry)3 LdapUserAttributesToRolesAuthorizationGenerator (org.apereo.cas.authorization.LdapUserAttributesToRolesAuthorizationGenerator)2 LdapUserGroupsToRolesAuthorizationGenerator (org.apereo.cas.authorization.LdapUserGroupsToRolesAuthorizationGenerator)2 LdapAuthorizationProperties (org.apereo.cas.configuration.model.support.ldap.LdapAuthorizationProperties)2 URI (java.net.URI)1 URL (java.net.URL)1 StandardCharsets (java.nio.charset.StandardCharsets)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1