Search in sources :

Example 1 with ModifyReferralHandler

use of org.ldaptive.referral.ModifyReferralHandler 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)

Aggregations

URI (java.net.URI)1 URL (java.net.URL)1 StandardCharsets (java.nio.charset.StandardCharsets)1 HashSet (java.util.HashSet)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 Collectors (java.util.stream.Collectors)1 StringUtils (org.apache.commons.lang3.StringUtils)1 NumberUtils (org.apache.commons.lang3.math.NumberUtils)1 AbstractLdapProperties (org.apereo.cas.configuration.model.support.ldap.AbstractLdapProperties)1 Beans (org.apereo.cas.configuration.support.Beans)1 AddOperation (org.ldaptive.AddOperation)1 AddRequest (org.ldaptive.AddRequest)1 AttributeModification (org.ldaptive.AttributeModification)1 AttributeModificationType (org.ldaptive.AttributeModificationType)1 Connection (org.ldaptive.Connection)1 ConnectionFactory (org.ldaptive.ConnectionFactory)1 Credential (org.ldaptive.Credential)1 DeleteOperation (org.ldaptive.DeleteOperation)1