Code example for SearchControls

Methods: setReturningAttributessetSearchScope

0
    public void testSearchValue() throws ExceptionLdapContext ctx = ( LdapContext ) getWiredContext( getLdapServer() ).lookup( BASE );
 
        // Setting up search controls for compare op 
        SearchControls ctls = new SearchControls();
        ctls.setReturningAttributes( new String[]
            { "*" } ); // no attributes 
        ctls.setSearchScope( SearchControls.OBJECT_SCOPE );
 
        // Search for all entries 
        NamingEnumeration<SearchResult> results = ctx.search( RDN, "(cn=*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*)", ctls );
        assertTrue( results.hasMore() );
 
        // Search for all entries ending by Amos 
        results = ctx.search( RDN, "(cn=*Amos)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*Amos)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries ending by amos 
        results = ctx.search( RDN, "(cn=*amos)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*amos)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries starting by Tori 
        results = ctx.search( RDN, "(cn=Tori*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=Tori*)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries starting by tori 
        results = ctx.search( RDN, "(cn=tori*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=tori*)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries containing ori 
        results = ctx.search( RDN, "(cn=*ori*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*ori*)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries containing o and i 
        results = ctx.search( RDN, "(cn=*o*i*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*o*i*)", ctls );
        assertTrue( results.hasMore() );
 
        // Search for all entries containing o, space and o 
        results = ctx.search( RDN, "(cn=*o* *o*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*o* *o*)", ctls );
        assertFalse( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*o*-*o*)", ctls );
        assertTrue( results.hasMore() );
 
        // Search for all entries starting by To and containing A 
        results = ctx.search( RDN, "(cn=To*A*)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=To*A*)", ctls );
        assertFalse( results.hasMore() );
 
        // Search for all entries ending by os and containing ri 
        results = ctx.search( RDN, "(cn=*ri*os)", ctls );
        assertTrue( results.hasMore() );
 
        results = ctx.search( RDN2, "(cn=*ri*os)", ctls );
        assertFalse( results.hasMore() );
    } 
 
 
    /** 
Experience pair programming with AI  Get Codota for Java