use of org.ldaptive.handler.CaseChangeEntryHandler 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;
}
use of org.ldaptive.handler.CaseChangeEntryHandler 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;
}
Aggregations