Search in sources :

Example 1 with ObjectGuidHandler

use of org.ldaptive.ad.handler.ObjectGuidHandler in project cas by apereo.

the class LdapUtils method newLdaptiveSearchEntryResolver.

/**
 * New dn resolver entry resolver.
 * Creates the necessary search entry resolver.
 *
 * @param l       the ldap settings
 * @param factory the factory
 * @return the entry resolver
 */
public static EntryResolver newLdaptiveSearchEntryResolver(final AbstractLdapAuthenticationProperties l, final PooledConnectionFactory factory) {
    if (StringUtils.isBlank(l.getBaseDn())) {
        throw new IllegalArgumentException("To create a search entry resolver, base dn cannot be empty/blank ");
    }
    if (StringUtils.isBlank(l.getSearchFilter())) {
        throw new IllegalArgumentException("To create a search entry resolver, user filter cannot be empty/blank");
    }
    final PooledSearchEntryResolver entryResolver = new PooledSearchEntryResolver();
    entryResolver.setBaseDn(l.getBaseDn());
    entryResolver.setUserFilter(l.getSearchFilter());
    entryResolver.setSubtreeSearch(l.isSubtreeSearch());
    entryResolver.setConnectionFactory(factory);
    if (StringUtils.isNotBlank(l.getDerefAliases())) {
        entryResolver.setDerefAliases(DerefAliases.valueOf(l.getDerefAliases()));
    }
    final List<SearchEntryHandler> handlers = new ArrayList<>();
    l.getSearchEntryHandlers().forEach(h -> {
        switch(h.getType()) {
            case CASE_CHANGE:
                final CaseChangeEntryHandler eh = new CaseChangeEntryHandler();
                eh.setAttributeNameCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(h.getCasChange().getAttributeNameCaseChange()));
                eh.setAttributeNames(h.getCasChange().getAttributeNames().toArray(new String[] {}));
                eh.setAttributeValueCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(h.getCasChange().getAttributeValueCaseChange()));
                eh.setDnCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(h.getCasChange().getDnCaseChange()));
                handlers.add(eh);
                break;
            case DN_ATTRIBUTE_ENTRY:
                final DnAttributeEntryHandler ehd = new DnAttributeEntryHandler();
                ehd.setAddIfExists(h.getDnAttribute().isAddIfExists());
                ehd.setDnAttributeName(h.getDnAttribute().getDnAttributeName());
                handlers.add(ehd);
                break;
            case MERGE:
                final MergeAttributeEntryHandler ehm = new MergeAttributeEntryHandler();
                ehm.setAttributeNames(h.getMergeAttribute().getAttributeNames().toArray(new String[] {}));
                ehm.setMergeAttributeName(h.getMergeAttribute().getMergeAttributeName());
                handlers.add(ehm);
                break;
            case OBJECT_GUID:
                handlers.add(new ObjectGuidHandler());
                break;
            case OBJECT_SID:
                handlers.add(new ObjectSidHandler());
                break;
            case PRIMARY_GROUP:
                final PrimaryGroupIdHandler ehp = new PrimaryGroupIdHandler();
                ehp.setBaseDn(h.getPrimaryGroupId().getBaseDn());
                ehp.setGroupFilter(h.getPrimaryGroupId().getGroupFilter());
                handlers.add(ehp);
                break;
            case RANGE_ENTRY:
                handlers.add(new RangeEntryHandler());
                break;
            case RECURSIVE_ENTRY:
                handlers.add(new RecursiveEntryHandler(h.getRecursive().getSearchAttribute(), h.getRecursive().getMergeAttributes().toArray(new String[] {})));
                break;
            default:
                break;
        }
    });
    if (!handlers.isEmpty()) {
        LOGGER.debug("Search entry handlers defined for the entry resolver of [{}] are [{}]", l.getLdapUrl(), handlers);
        entryResolver.setSearchEntryHandlers(handlers.toArray(new SearchEntryHandler[] {}));
    }
    entryResolver.setReferralHandler(new SearchReferralHandler());
    return entryResolver;
}
Also used : SearchEntryHandler(org.ldaptive.handler.SearchEntryHandler) DnAttributeEntryHandler(org.ldaptive.handler.DnAttributeEntryHandler) ArrayList(java.util.ArrayList) RangeEntryHandler(org.ldaptive.ad.handler.RangeEntryHandler) ObjectSidHandler(org.ldaptive.ad.handler.ObjectSidHandler) ObjectGuidHandler(org.ldaptive.ad.handler.ObjectGuidHandler) RecursiveEntryHandler(org.ldaptive.handler.RecursiveEntryHandler) PrimaryGroupIdHandler(org.ldaptive.ad.handler.PrimaryGroupIdHandler) PooledSearchEntryResolver(org.ldaptive.auth.PooledSearchEntryResolver) CaseChangeEntryHandler(org.ldaptive.handler.CaseChangeEntryHandler) MergeAttributeEntryHandler(org.ldaptive.handler.MergeAttributeEntryHandler) SearchReferralHandler(org.ldaptive.referral.SearchReferralHandler)

Example 2 with ObjectGuidHandler

use of org.ldaptive.ad.handler.ObjectGuidHandler in project cas by apereo.

the class Beans method newLdaptiveSearchEntryResolver.

/**
     * New dn resolver entry resolver.
     * Creates the necessary search entry resolver.
     *
     * @param l       the ldap settings
     * @param factory the factory
     * @return the entry resolver
     */
public static EntryResolver newLdaptiveSearchEntryResolver(final AbstractLdapAuthenticationProperties l, final PooledConnectionFactory factory) {
    if (StringUtils.isBlank(l.getBaseDn())) {
        throw new IllegalArgumentException("To create a search entry resolver, base dn cannot be empty/blank ");
    }
    if (StringUtils.isBlank(l.getUserFilter())) {
        throw new IllegalArgumentException("To create a search entry resolver, user filter cannot be empty/blank");
    }
    final PooledSearchEntryResolver entryResolver = new PooledSearchEntryResolver();
    entryResolver.setBaseDn(l.getBaseDn());
    entryResolver.setUserFilter(l.getUserFilter());
    entryResolver.setSubtreeSearch(l.isSubtreeSearch());
    entryResolver.setConnectionFactory(factory);
    final List<SearchEntryHandler> handlers = new ArrayList<>();
    l.getSearchEntryHandlers().forEach(h -> {
        switch(h.getType()) {
            case CASE_CHANGE:
                final CaseChangeEntryHandler eh = new CaseChangeEntryHandler();
                eh.setAttributeNameCaseChange(h.getCasChange().getAttributeNameCaseChange());
                eh.setAttributeNames(h.getCasChange().getAttributeNames());
                eh.setAttributeValueCaseChange(h.getCasChange().getAttributeValueCaseChange());
                eh.setDnCaseChange(h.getCasChange().getDnCaseChange());
                handlers.add(eh);
                break;
            case DN_ATTRIBUTE_ENTRY:
                final DnAttributeEntryHandler ehd = new DnAttributeEntryHandler();
                ehd.setAddIfExists(h.getDnAttribute().isAddIfExists());
                ehd.setDnAttributeName(h.getDnAttribute().getDnAttributeName());
                handlers.add(ehd);
                break;
            case MERGE:
                final MergeAttributeEntryHandler ehm = new MergeAttributeEntryHandler();
                ehm.setAttributeNames(h.getMergeAttribute().getAttributeNames());
                ehm.setMergeAttributeName(h.getMergeAttribute().getMergeAttributeName());
                handlers.add(ehm);
                break;
            case OBJECT_GUID:
                handlers.add(new ObjectGuidHandler());
                break;
            case OBJECT_SID:
                handlers.add(new ObjectSidHandler());
                break;
            case PRIMARY_GROUP:
                final PrimaryGroupIdHandler ehp = new PrimaryGroupIdHandler();
                ehp.setBaseDn(h.getPrimaryGroupId().getBaseDn());
                ehp.setGroupFilter(h.getPrimaryGroupId().getGroupFilter());
                handlers.add(ehp);
                break;
            case RANGE_ENTRY:
                handlers.add(new RangeEntryHandler());
                break;
            case RECURSIVE_ENTRY:
                handlers.add(new RecursiveEntryHandler(h.getRecursive().getSearchAttribute(), h.getRecursive().getMergeAttributes()));
                break;
            default:
                break;
        }
    });
    if (!handlers.isEmpty()) {
        LOGGER.debug("Search entry handlers defined for the entry resolver of [{}] are [{}]", l.getLdapUrl(), handlers);
        entryResolver.setSearchEntryHandlers(handlers.toArray(new SearchEntryHandler[] {}));
    }
    return entryResolver;
}
Also used : SearchEntryHandler(org.ldaptive.handler.SearchEntryHandler) DnAttributeEntryHandler(org.ldaptive.handler.DnAttributeEntryHandler) ArrayList(java.util.ArrayList) RangeEntryHandler(org.ldaptive.ad.handler.RangeEntryHandler) ObjectSidHandler(org.ldaptive.ad.handler.ObjectSidHandler) ObjectGuidHandler(org.ldaptive.ad.handler.ObjectGuidHandler) RecursiveEntryHandler(org.ldaptive.handler.RecursiveEntryHandler) PrimaryGroupIdHandler(org.ldaptive.ad.handler.PrimaryGroupIdHandler) PooledSearchEntryResolver(org.ldaptive.auth.PooledSearchEntryResolver) CaseChangeEntryHandler(org.ldaptive.handler.CaseChangeEntryHandler) MergeAttributeEntryHandler(org.ldaptive.handler.MergeAttributeEntryHandler)

Example 3 with ObjectGuidHandler

use of org.ldaptive.ad.handler.ObjectGuidHandler in project cas by apereo.

the class LdapUtils method newLdaptiveEntryHandlers.

/**
 * New list of ldap entry handlers derived from the supplied properties.
 *
 * @param properties to inspect
 * @return the list of entry handlers
 */
public static List<LdapEntryHandler> newLdaptiveEntryHandlers(final List<LdapSearchEntryHandlersProperties> properties) {
    val entryHandlers = new ArrayList<LdapEntryHandler>();
    properties.forEach(h -> {
        switch(h.getType()) {
            case ACTIVE_DIRECTORY:
                entryHandlers.add(new ActiveDirectoryLdapEntryHandler());
                break;
            case CASE_CHANGE:
                val eh = new CaseChangeEntryHandler();
                val caseChange = h.getCaseChange();
                eh.setAttributeNameCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(caseChange.getAttributeNameCaseChange()));
                eh.setAttributeNames(caseChange.getAttributeNames().toArray(ArrayUtils.EMPTY_STRING_ARRAY));
                eh.setAttributeValueCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(caseChange.getAttributeValueCaseChange()));
                eh.setDnCaseChange(CaseChangeEntryHandler.CaseChange.valueOf(caseChange.getDnCaseChange()));
                entryHandlers.add(eh);
                break;
            case DN_ATTRIBUTE_ENTRY:
                val ehd = new DnAttributeEntryHandler();
                val dnAttribute = h.getDnAttribute();
                ehd.setAddIfExists(dnAttribute.isAddIfExists());
                ehd.setDnAttributeName(dnAttribute.getDnAttributeName());
                entryHandlers.add(ehd);
                break;
            case MERGE:
                val ehm = new MergeAttributeEntryHandler();
                val mergeAttribute = h.getMergeAttribute();
                ehm.setAttributeNames(mergeAttribute.getAttributeNames().toArray(ArrayUtils.EMPTY_STRING_ARRAY));
                ehm.setMergeAttributeName(mergeAttribute.getMergeAttributeName());
                entryHandlers.add(ehm);
                break;
            case OBJECT_GUID:
                entryHandlers.add(new ObjectGuidHandler());
                break;
            case OBJECT_SID:
                entryHandlers.add(new ObjectSidHandler());
                break;
            default:
                break;
        }
    });
    return entryHandlers;
}
Also used : lombok.val(lombok.val) ObjectGuidHandler(org.ldaptive.ad.handler.ObjectGuidHandler) DnAttributeEntryHandler(org.ldaptive.handler.DnAttributeEntryHandler) ActiveDirectoryLdapEntryHandler(org.apereo.services.persondir.support.ldap.ActiveDirectoryLdapEntryHandler) ArrayList(java.util.ArrayList) CaseChangeEntryHandler(org.ldaptive.handler.CaseChangeEntryHandler) MergeAttributeEntryHandler(org.ldaptive.handler.MergeAttributeEntryHandler) ObjectSidHandler(org.ldaptive.ad.handler.ObjectSidHandler)

Aggregations

ArrayList (java.util.ArrayList)3 ObjectGuidHandler (org.ldaptive.ad.handler.ObjectGuidHandler)3 ObjectSidHandler (org.ldaptive.ad.handler.ObjectSidHandler)3 CaseChangeEntryHandler (org.ldaptive.handler.CaseChangeEntryHandler)3 DnAttributeEntryHandler (org.ldaptive.handler.DnAttributeEntryHandler)3 MergeAttributeEntryHandler (org.ldaptive.handler.MergeAttributeEntryHandler)3 PrimaryGroupIdHandler (org.ldaptive.ad.handler.PrimaryGroupIdHandler)2 RangeEntryHandler (org.ldaptive.ad.handler.RangeEntryHandler)2 PooledSearchEntryResolver (org.ldaptive.auth.PooledSearchEntryResolver)2 RecursiveEntryHandler (org.ldaptive.handler.RecursiveEntryHandler)2 SearchEntryHandler (org.ldaptive.handler.SearchEntryHandler)2 lombok.val (lombok.val)1 ActiveDirectoryLdapEntryHandler (org.apereo.services.persondir.support.ldap.ActiveDirectoryLdapEntryHandler)1 SearchReferralHandler (org.ldaptive.referral.SearchReferralHandler)1