use of org.ldaptive.SearchRequest in project cas by apereo.
the class Beans method newLdaptiveBlockingConnectionPool.
/**
* New blocking connection pool connection pool.
*
* @param l the l
* @return the connection pool
*/
public static ConnectionPool newLdaptiveBlockingConnectionPool(final AbstractLdapProperties l) {
final DefaultConnectionFactory bindCf = newLdaptiveConnectionFactory(l);
final PoolConfig pc = newLdaptivePoolConfig(l);
final BlockingConnectionPool cp = new BlockingConnectionPool(pc, bindCf);
cp.setBlockWaitTime(newDuration(l.getBlockWaitTime()));
cp.setPoolConfig(pc);
final IdlePruneStrategy strategy = new IdlePruneStrategy();
strategy.setIdleTime(newDuration(l.getIdleTime()));
strategy.setPrunePeriod(newDuration(l.getPrunePeriod()));
cp.setPruneStrategy(strategy);
switch(l.getValidator().getType().trim().toLowerCase()) {
case "compare":
final CompareRequest compareRequest = new CompareRequest();
compareRequest.setDn(l.getValidator().getDn());
compareRequest.setAttribute(new LdapAttribute(l.getValidator().getAttributeName(), l.getValidator().getAttributeValues().toArray(new String[] {})));
compareRequest.setReferralHandler(new SearchReferralHandler());
cp.setValidator(new CompareValidator(compareRequest));
break;
case "none":
LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
break;
case "search":
default:
final SearchRequest searchRequest = new SearchRequest();
searchRequest.setBaseDn(l.getValidator().getBaseDn());
searchRequest.setSearchFilter(new SearchFilter(l.getValidator().getSearchFilter()));
searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
searchRequest.setSearchScope(l.getValidator().getScope());
searchRequest.setSizeLimit(1L);
searchRequest.setReferralHandler(new SearchReferralHandler());
cp.setValidator(new SearchValidator(searchRequest));
break;
}
cp.setFailFastInitialize(l.isFailFast());
if (StringUtils.isNotBlank(l.getPoolPassivator())) {
final AbstractLdapProperties.LdapConnectionPoolPassivator pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
switch(pass) {
case CLOSE:
cp.setPassivator(new ClosePassivator());
break;
case BIND:
final BindRequest bindRequest = new BindRequest();
bindRequest.setDn(l.getBindDn());
bindRequest.setCredential(new Credential(l.getBindCredential()));
cp.setPassivator(new BindPassivator(bindRequest));
break;
default:
break;
}
}
LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
cp.initialize();
return cp;
}
use of org.ldaptive.SearchRequest in project cas by apereo.
the class LdapUtils method executeSearchOperation.
/**
* Execute search operation.
*
* @param connectionFactory the connection factory
* @param baseDn the base dn
* @param filter the filter
* @param binaryAttributes the binary attributes
* @param returnAttributes the return attributes
* @return the response
* @throws LdapException the ldap exception
*/
public static Response<SearchResult> executeSearchOperation(final ConnectionFactory connectionFactory, final String baseDn, final SearchFilter filter, final String[] binaryAttributes, final String[] returnAttributes) throws LdapException {
try (Connection connection = createConnection(connectionFactory)) {
final SearchOperation searchOperation = new SearchOperation(connection);
final SearchRequest request = LdapUtils.newLdaptiveSearchRequest(baseDn, filter, binaryAttributes, returnAttributes);
request.setReferralHandler(new SearchReferralHandler());
return searchOperation.execute(request);
}
}
use of org.ldaptive.SearchRequest in project pac4j by pac4j.
the class LdaptiveAuthenticatorBuilder method newSearchRequest.
/**
* Builds a new request.
*
* @param baseDn the base dn
* @param filter the filter
* @return the search request
*/
public static SearchRequest newSearchRequest(final String baseDn, final SearchFilter filter) {
final SearchRequest sr = new SearchRequest(baseDn, filter);
sr.setBinaryAttributes(ReturnAttributes.ALL_USER.value());
sr.setReturnAttributes(ReturnAttributes.ALL_USER.value());
sr.setSearchScope(SearchScope.SUBTREE);
return sr;
}
use of org.ldaptive.SearchRequest in project cas by apereo.
the class LdapUtils method newLdaptivePooledConnectionFactory.
/**
* New pooled connection factory pooled connection factory.
*
* @param l the ldap properties
* @return the pooled connection factory
*/
public static PooledConnectionFactory newLdaptivePooledConnectionFactory(final AbstractLdapProperties l) {
val cc = newLdaptiveConnectionConfig(l);
LOGGER.debug("Creating LDAP connection pool configuration for [{}]", l.getLdapUrl());
val pooledCf = new PooledConnectionFactory(cc);
pooledCf.setMinPoolSize(l.getMinPoolSize());
pooledCf.setMaxPoolSize(l.getMaxPoolSize());
pooledCf.setValidateOnCheckOut(l.isValidateOnCheckout());
pooledCf.setValidatePeriodically(l.isValidatePeriodically());
pooledCf.setBlockWaitTime(Beans.newDuration(l.getBlockWaitTime()));
val strategy = new IdlePruneStrategy();
strategy.setIdleTime(Beans.newDuration(l.getIdleTime()));
strategy.setPrunePeriod(Beans.newDuration(l.getPrunePeriod()));
pooledCf.setPruneStrategy(strategy);
val validator = l.getValidator();
switch(validator.getType().trim().toLowerCase()) {
case "compare":
val compareRequest = new CompareRequest(validator.getDn(), validator.getAttributeName(), validator.getAttributeValue());
val compareValidator = new CompareConnectionValidator(compareRequest);
compareValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
compareValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
pooledCf.setValidator(compareValidator);
break;
case "none":
LOGGER.debug("No validator is configured for the LDAP connection pool of [{}]", l.getLdapUrl());
break;
case "search":
default:
val searchRequest = new SearchRequest();
searchRequest.setBaseDn(validator.getBaseDn());
searchRequest.setFilter(validator.getSearchFilter());
searchRequest.setReturnAttributes(ReturnAttributes.NONE.value());
searchRequest.setSearchScope(SearchScope.valueOf(validator.getScope()));
searchRequest.setSizeLimit(1);
val searchValidator = new SearchConnectionValidator(searchRequest);
searchValidator.setValidatePeriod(Beans.newDuration(l.getValidatePeriod()));
searchValidator.setValidateTimeout(Beans.newDuration(l.getValidateTimeout()));
pooledCf.setValidator(searchValidator);
break;
}
pooledCf.setFailFastInitialize(l.isFailFast());
if (StringUtils.isNotBlank(l.getPoolPassivator())) {
val pass = AbstractLdapProperties.LdapConnectionPoolPassivator.valueOf(l.getPoolPassivator().toUpperCase());
switch(pass) {
case BIND:
if (StringUtils.isNotBlank(l.getBindDn()) && StringUtils.isNoneBlank(l.getBindCredential())) {
val bindRequest = new SimpleBindRequest(l.getBindDn(), l.getBindCredential());
pooledCf.setPassivator(new BindConnectionPassivator(bindRequest));
LOGGER.debug("Created [{}] passivator for [{}]", l.getPoolPassivator(), l.getLdapUrl());
} else {
val values = Arrays.stream(AbstractLdapProperties.LdapConnectionPoolPassivator.values()).filter(v -> v != AbstractLdapProperties.LdapConnectionPoolPassivator.BIND).collect(Collectors.toList());
LOGGER.warn("[{}] pool passivator could not be created for [{}] given bind credentials are not specified. " + "If you are dealing with LDAP in such a way that does not require bind credentials, you may need to " + "set the pool passivator setting to one of [{}]", l.getPoolPassivator(), l.getLdapUrl(), values);
}
break;
default:
break;
}
}
LOGGER.debug("Initializing ldap connection pool for [{}] and bindDn [{}]", l.getLdapUrl(), l.getBindDn());
pooledCf.initialize();
return pooledCf;
}
use of org.ldaptive.SearchRequest in project cas by apereo.
the class LdapUtils method newLdaptiveSearchRequest.
/**
* Builds a new request.
*
* @param baseDn the base dn
* @param filter the filter
* @param binaryAttributes the binary attributes
* @param returnAttributes the return attributes
* @return the search request
*/
public static SearchRequest newLdaptiveSearchRequest(final String baseDn, final FilterTemplate filter, final String[] binaryAttributes, final String[] returnAttributes) {
val sr = new SearchRequest(baseDn, filter);
sr.setBinaryAttributes(binaryAttributes);
sr.setReturnAttributes(returnAttributes);
sr.setSearchScope(SearchScope.SUBTREE);
return sr;
}
Aggregations