Skip to content

Commit

Permalink
Add search executor namespace support.
Browse files Browse the repository at this point in the history
See #56.
  • Loading branch information
dfish3r committed Dec 1, 2015
1 parent 6c17b1d commit 96d99b1
Show file tree
Hide file tree
Showing 5 changed files with 112 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.ldaptive.BindConnectionInitializer;
import org.ldaptive.ConnectionConfig;
import org.ldaptive.DefaultConnectionFactory;
import org.ldaptive.SearchExecutor;
import org.ldaptive.SearchFilter;
import org.ldaptive.ad.handler.ObjectGuidHandler;
import org.ldaptive.ad.handler.ObjectSidHandler;
import org.ldaptive.auth.AuthenticationResponseHandler;
Expand Down Expand Up @@ -54,6 +56,7 @@ public void init()
registerBeanDefinitionParser("ad-authenticator", new ADAuthenticatorBeanDefinitionParser());
registerBeanDefinitionParser("pooled-connection-factory", new PooledConnectionFactoryBeanDefinitionParser());
registerBeanDefinitionParser("connection-factory", new ConnectionFactoryBeanDefinitionParser());
registerBeanDefinitionParser("search-executor", new SearchExecutorBeanDefinitionParser());
}


Expand Down Expand Up @@ -220,7 +223,7 @@ protected void doParse(


/**
* Parser for <pre>pooled-connection-factory</pre> elements.
* Parser for <pre>connection-factory</pre> elements.
*/
private static class ConnectionFactoryBeanDefinitionParser extends AbstractConnectionFactoryBeanDefinitionParser
{
Expand Down Expand Up @@ -499,4 +502,58 @@ protected BeanDefinition parseProvider(final Element element)
return provider.getBeanDefinition();
}
}


/**
* Parser for <pre>search-executor</pre> elements.
*/
private static class SearchExecutorBeanDefinitionParser extends AbstractSingleBeanDefinitionParser
{


@Override
protected String resolveId(
final Element element,
// CheckStyle:IllegalTypeCheck OFF
final AbstractBeanDefinition definition,
// CheckStyle:IllegalTypeCheck ON
final ParserContext parserContext)
throws BeanDefinitionStoreException
{
final String idAttrValue = element.getAttribute("id");
return StringUtils.hasText(idAttrValue) ? idAttrValue : "search-executor";
}


@Override
protected Class<?> getBeanClass(final Element element)
{
return SearchExecutor.class;
}


@Override
protected void doParse(
final Element element,
final ParserContext context,
final BeanDefinitionBuilder builder)
{
builder.addPropertyValue("baseDn", element.getAttribute("baseDn"));
if (element.hasAttribute("searchFilter")) {
final BeanDefinitionBuilder filter = BeanDefinitionBuilder.genericBeanDefinition(SearchFilter.class);
filter.addPropertyValue("filter", element.getAttribute("searchFilter"));
builder.addPropertyValue("searchFilter", filter.getBeanDefinition());
}
if (element.hasAttribute("returnAttributes")) {
builder.addPropertyValue("returnAttributes", element.getAttribute("returnAttributes"));
}
builder.addPropertyValue("searchScope", element.getAttribute("searchScope"));
builder.addPropertyValue("timeLimit", element.getAttribute("timeLimit"));
builder.addPropertyValue("sizeLimit", element.getAttribute("sizeLimit"));
if (element.hasAttribute("binaryAttributes")) {
builder.addPropertyValue("binaryAttributes", element.getAttribute("binaryAttributes"));
}
builder.addPropertyValue("sortBehavior", element.getAttribute("sortBehavior"));
}
}
}
13 changes: 13 additions & 0 deletions beans/src/main/resources/org/ldaptive/beans/spring/spring-ext.xsd
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<xsd:element name="ad-authenticator" type="adAuthenticatorType"/>
<xsd:element name="pooled-connection-factory" type="pooledConnectionFactoryType"/>
<xsd:element name="connection-factory" type="connectionFactoryType"/>
<xsd:element name="search-executor" type="searchExecutorType"/>

<xsd:complexType name="anonymousSearchAuthenticatorType">
<xsd:complexContent>
Expand Down Expand Up @@ -94,4 +95,16 @@
<xsd:attribute name="provider" type="xsd:string" use="optional" default="org.ldaptive.provider.jndi.JndiProvider"/>
</xsd:complexType>

<xsd:complexType name="searchExecutorType">
<xsd:attribute name="id" type="xsd:ID" use="optional"/>
<xsd:attribute name="baseDn" type="xsd:string" use="optional" default=""/>
<xsd:attribute name="searchFilter" type="xsd:string" use="optional"/>
<xsd:attribute name="returnAttributes" type="xsd:string" use="optional"/>
<xsd:attribute name="searchScope" type="xsd:string" use="optional" default="SUBTREE"/>
<xsd:attribute name="timeLimit" type="xsd:string" use="optional" default="0"/>
<xsd:attribute name="sizeLimit" type="xsd:string" use="optional" default="0"/>
<xsd:attribute name="binaryAttributes" type="xsd:string" use="optional"/>
<xsd:attribute name="sortBehavior" type="xsd:string" use="optional" default="UNORDERED"/>
</xsd:complexType>

</xsd:schema>
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
import org.ldaptive.ConnectionConfig;
import org.ldaptive.DefaultConnectionFactory;
import org.ldaptive.LdapException;
import org.ldaptive.SearchExecutor;
import org.ldaptive.SearchScope;
import org.ldaptive.SortBehavior;
import org.ldaptive.auth.AuthenticationHandler;
import org.ldaptive.auth.Authenticator;
import org.ldaptive.auth.DnResolver;
Expand Down Expand Up @@ -126,6 +129,10 @@ public void testSpringWiring()
DefaultConnectionFactory.class);
AssertJUnit.assertNotNull(connectionFactory);
testConnectionConfig(connectionFactory.getConnectionConfig());

final SearchExecutor executor = context.getBean("search-executor", SearchExecutor.class);
AssertJUnit.assertNotNull(executor);
testSearchExecutor(executor);
}


Expand Down Expand Up @@ -210,4 +217,22 @@ private void testConnectionConfig(final ConnectionConfig connectionConfig)
AssertJUnit.assertNotNull(((KeyStoreCredentialConfig) credentialConfig).getTrustStore());
}
}


/**
* Runs asserts against the search executor.
*
* @param executor to test
*/
private void testSearchExecutor(final SearchExecutor executor)
{
AssertJUnit.assertTrue(executor.getBaseDn().length() > 0);
AssertJUnit.assertNotNull(executor.getSearchFilter());
AssertJUnit.assertTrue(executor.getReturnAttributes().length > 0);
AssertJUnit.assertEquals(SearchScope.ONELEVEL, executor.getSearchScope());
AssertJUnit.assertEquals(5000, executor.getTimeLimit());
AssertJUnit.assertEquals(10, executor.getSizeLimit());
AssertJUnit.assertTrue(executor.getBinaryAttributes().length > 0);
AssertJUnit.assertEquals(SortBehavior.ORDERED, executor.getSortBehavior());
}
}
11 changes: 11 additions & 0 deletions integration/src/test/resources/spring-ext-context.xml
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,15 @@
trustCertificates="classpath:/ldaptive.trust.crt"
/>

<ldaptive:search-executor
baseDn="${ldap.baseDn}"
searchFilter="(mail=*)"
returnAttributes="cn,givenName,sn"
searchScope="ONELEVEL"
timeLimit="${ldap.timeLimit}"
sizeLimit="${ldap.sizeLimit}"
binaryAttributes="jpegPhoto,userCertificate"
sortBehavior="ORDERED"
/>

</beans>
6 changes: 5 additions & 1 deletion integration/src/test/resources/spring-ext.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ ldap.ppolicy=true
ldap.trustCertificates=classpath:/ldaptive.trust.crt
ldap.trustStore=classpath:/ldaptive.truststore
ldap.trustStorePassword=changeit
ldap.trustStoreType=BKS
ldap.trustStoreType=BKS

# search executor
ldap.timeLimit=5000
ldap.sizeLimit=10

0 comments on commit 96d99b1

Please sign in to comment.