Code example for SearchControls

Methods: setSearchScopesetTimeLimit

0
 
    @Test
    public void testSearchComplexFilter() throws ExceptionLdapContext ctx = getWiredContext( getLdapServer() );
        SearchControls controls = new SearchControls();
        controls.setSearchScope( SearchControls.OBJECT_SCOPE );
        controls.setTimeLimit( 10 );
 
        NamingEnumeration<SearchResult> result = ctx.search( "cn=Kim Wilde,ou=system",
            "(&(&(ObjectClass=person)(!(ObjectClass=strongAuthenticationUser))(sn=Wilde)))", controls );
 
        assertTrue( result.hasMore() );
        SearchResult sr = result.next();
        assertNotNull( sr );
        assertEquals( "Kim Wilde", sr.getAttributes().get( "cn" ).get() );
 
        // Now check with another version of the filter 
        result = ctx.search( "cn=Kim Wilde,ou=system",
            "(&(sn=Wilde)(&(objectClass=person)(!(objectClass=strongAuthenticationUser))))", controls );
 
        assertTrue( result.hasMore() );
        sr = result.next();
        assertNotNull( sr );