Package org.apache.directory.api.ldap.model.cursor

Examples of org.apache.directory.api.ldap.model.cursor.EntryCursor


     *  wire
     */
    @Test
    public void testSearchEmptyDNWithOneLevelScopeAndNoObjectClassPresenceFilter() throws Exception
    {
        EntryCursor cursor = connection.search( "", "(objectClass=*)", SearchScope.ONELEVEL, "*", "+" );
        HashMap<String, Entry> map = new HashMap<String, Entry>();

        while ( cursor.next() )
        {
            Entry result = cursor.get();
            map.put( result.getDn().getName(), result );
        }
        cursor.close();

        assertEquals( 2, map.size() );

        assertTrue( map.containsKey( "ou=system" ) );
        assertTrue( map.containsKey( "ou=schema" ) );
View Full Code Here


* "c=usa, ou=system", and ask for a subtree search
*/
@Test
public void testSearchWithReferralThrow() throws Exception
{
    EntryCursor cursor = connection.search( "ou=Countries,ou=system", "(objectClass=*)",
        SearchScope.SUBTREE, "*", "+" );
    int count = 0;
    Entry entry = null;
    List<String> refs = new ArrayList<String>();

    while ( cursor.next() )
    {
        try
        {
            entry = cursor.get();

            assertNotNull( entry );
            count++;
        }
        catch ( CursorLdapReferralException clre )
        {
            count++;

            do
            {
                String ref = clre.getReferralInfo();
                refs.add( ref );
            }
            while ( clre.skipReferral() );
        }
    }

    assertEquals( 3, count );
    assertEquals( 2, refs.size() );
    assertTrue( refs.contains( "ldap://localhost:52489/c=usa,ou=system??sub" ) );
    assertTrue( refs.contains( "ldap://localhost:52489/c=france,ou=system??sub" ) );
    cursor.close();
}
View Full Code Here

        Entry entry1 = null;
        Entry entry2 = null;
        Entry entry3 = null;

        long ns0 = System.currentTimeMillis();
        EntryCursor results = connection.search( "dc=example,dc=com",
            "(displayName=1234Awg-Rosli, Awg-Abd-Rahim SMDS-UIA/G/MMO52D)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            if ( entry1 == null )
            {
                entry1 = results.get();
            }
        }

        results.close();

        long ns1 = System.currentTimeMillis();

        System.out.println( "Delta search : " + ( ns1 - ns0 ) );

        long ns2 = System.currentTimeMillis();
        results = connection.search( "dc=example,dc=com", "(displayName=3456*)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            if ( entry2 == null )
            {
                entry2 = results.get();
            }
        }

        results.close();
        long ns3 = System.currentTimeMillis();

        System.out.println( "Delta search substring : " + ( ns3 - ns2 ) );

        long ns4 = System.currentTimeMillis();
        results = connection.search( "dc=example,dc=com", "(uid=6789)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            if ( entry3 == null )
            {
                entry3 = results.get();
            }
        }

        results.close();
        long ns5 = System.currentTimeMillis();

        System.out.println( "Delta search no index : " + ( ns5 - ns4 ) );

        //System.out.println( "Entry 1 : " + entry1 );
        //System.out.println( "Entry 2 : " + entry2 );
        //System.out.println( "Entry 3 : " + entry3 );
        connection.close();

        // Now, shutdown and restart the server once more
        System.out.println( "--------------> Shuting Down" );
        long ns6 = System.currentTimeMillis();
        getService().shutdown();
        long ns7 = System.currentTimeMillis();
        System.out.println( "--------------> completed in " + ( ns7 - ns6 ) );

        long ns8 = System.currentTimeMillis();
        getService().startup();
        long ns9 = System.currentTimeMillis();
        System.out.println( "--------------> Starting up completed in " + ( ns9 - ns8 ) );

        // and do a search again
        connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );

        long ns10 = System.currentTimeMillis();
        results = connection.search( "dc=example,dc=com", "(displayName=345*)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            entry3 = results.get();
            break;
        }

        results.close();
        long ns11 = System.currentTimeMillis();
        System.out.println( "New Delta search substring : " + ( ns11 - ns10 ) );

        connection.close();

        // And again

        // Now, shutdown and restart the server once more
        System.out.println( "--------------> Shuting Down 2" );
        long ns12 = System.currentTimeMillis();
        getService().shutdown();
        long ns13 = System.currentTimeMillis();
        System.out.println( "--------------> completed in " + ( ns13 - ns12 ) );

        long ns14 = System.currentTimeMillis();
        getService().startup();
        long ns15 = System.currentTimeMillis();
        System.out.println( "--------------> Starting up completed in " + ( ns15 - ns14 ) );

        // and do a search again
        connection = ( LdapNetworkConnection ) LdapApiIntegrationUtils.getPooledAdminConnection( getLdapServer() );

        long ns16 = System.currentTimeMillis();
        results = connection.search( "dc=example,dc=com", "(displayName=345*)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            entry3 = results.get();
            break;
        }

        results.close();
        long ns17 = System.currentTimeMillis();
        System.out.println( "New Delta search substring : " + ( ns17 - ns16 ) );

        connection.close();
    }
View Full Code Here

            "employeeNumber: Test user",
            "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );

        connection.add( entry );

        EntryCursor results = connection.search( "dc=example,dc=com", "(displayName=T*)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "displayName", "testUser" ) );
        }

        results.close();

        // Now, modify it
        connection
            .modify( dn,
                new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "displayName", "anotherTest" ) );

        results = connection.search( "dc=example,dc=com", "(displayName=a*)", SearchScope.SUBTREE, "*" );

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "displayName", "anotherTest" ) );
        }

        results.close();

        results = connection.search( "dc=example,dc=com", "(displayName=T*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Delete the entry
        connection.delete( dn );
    }
View Full Code Here

            "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );

        connection.add( entry );

        // Check the search using the cn index
        EntryCursor results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        int nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        results.close();

        assertEquals( 1, nbFound );

        // Ok, now replace the cn
        Modification modification = new DefaultModification( ModificationOperation.REPLACE_ATTRIBUTE, "cn", "New cn" );

        connection.modify( dn, modification );

        // The Substring index on CN should still work
        // The old cn should not be present anymore
        results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Check that we can find the new cn
        results = connection.search( "dc=example,dc=com", "(cn=n*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "New cn" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Now, check the presence index
        results = connection.search( "dc=example,dc=com", "(cn=*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "New cn" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Delete the entry
        connection.delete( dn );
    }
View Full Code Here

     */
    @Test
    public void testAbandonnedRequest() throws Exception
    {
        LdapConnection asyncCnx = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        EntryCursor cursor = null;
   
        try
        {
            // Use the client API as JNDI cannot be used to do a search without
            // first binding. (hmmm, even client API won't allow searching without binding)
            asyncCnx.bind( "uid=admin,ou=system", "secret" );
   
            // First, add 100 entries in the server
            for ( int i = 0; i < 100; i++ )
            {
                String dn = "cn=user" + i + "," + BASE;
                Entry kate = new DefaultEntry( dn );
   
                kate.add( "objectclass", "top", "person" );
                kate.add( "sn", "Bush" );
                kate.add( "cn", "user" + i );
   
                asyncCnx.add( kate );
            }
   
            // Searches for all the entries in ou=system
            cursor = asyncCnx.search( "ou=system", "(ObjectClass=*)", SearchScope.SUBTREE, "*" );
   
            // Now loop on all the elements found, and abandon after 10 elements returned
            int count = 0;
   
            while ( cursor.next() )
            {
                count++;
   
                if ( count == 10 )
                {
                    // the message ID = 1 bind op + 100 add ops + 1 search op
                    asyncCnx.abandon( 102 );
                }
            }
   
            assertEquals( 10, count );
        }
        catch ( LdapException e )
        {
            e.printStackTrace();
            fail( "Should not have caught exception." );
        }
        finally
        {
            asyncCnx.unBind();
            asyncCnx.close();
            cursor.close();
        }
    }
View Full Code Here

            "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );

        connection.add( entry );

        // Check the search using the cn index
        EntryCursor results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        int nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        results.close();

        assertEquals( 1, nbFound );

        // Ok, now replace the cn
        Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "cn", "New cn" );

        connection.modify( dn, modification );

        // The Substring index on CN should still work
        // The old cn should still be present anymore
        results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Check that we can find the new cn
        results = connection.search( "dc=example,dc=com", "(cn=n*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "New cn" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Now, check the presence index
        results = connection.search( "dc=example,dc=com", "(cn=*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "New cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Now, check that the index on displayName is correctly updated
        modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "displayName", "testUser" );

        connection.modify( dn, modification );

        // Check the displayName index
        results = connection.search( "dc=example,dc=com", "(displayName=t*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "displayName", "testUser" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Now, check the presence index
        results = connection.search( "dc=example,dc=com", "(displayName=*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "displayName", "testUser" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Delete the entry
        connection.delete( dn );
    }
View Full Code Here

            "pwdPolicySubEntry: ads-pwdId=cproint,ou=passwordPolicies,ads-interceptorId=authenticationInterceptor,ou=interceptors,ads-directoryServiceId=default,ou=config" );

        connection.add( entry );

        // Check the search using the cn index
        EntryCursor results = connection.search( "dc=example,dc=com", "(cn=e*)", SearchScope.SUBTREE, "*" );

        int nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        results.close();

        assertEquals( 1, nbFound );

        // Ok, now replace the cn
        Modification modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, "displayName",
            "testEntry" );

        connection.modify( dn, modification );

        // We should not find anything using the substring filter for the displayName AT
        results = connection.search( "dc=example,dc=com", "(displayName=t*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Check that we cannot find the displayName using the presence index
        results = connection.search( "dc=example,dc=com", "(displayName=n*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Now, Delete one value from the cn index
        modification = new DefaultModification( ModificationOperation.REMOVE_ATTRIBUTE, "cn", "test2" );

        connection.modify( dn, modification );

        // Check the cn index using the remaining value
        results = connection.search( "dc=example,dc=com", "(cn=E*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertFalse( result.contains( "cn", "test2" ) );
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Check the cn index using the removed value
        results = connection.search( "dc=example,dc=com", "(cn=t*)", SearchScope.SUBTREE, "*" );

        assertFalse( results.next() );

        results.close();

        // Now, check the presence index
        results = connection.search( "dc=example,dc=com", "(cn=*)", SearchScope.SUBTREE, "*" );

        nbFound = 0;

        while ( results.next() )
        {
            Entry result = results.get();
            assertFalse( result.contains( "cn", "test2" ) );
            assertTrue( result.contains( "cn", "entryTest" ) );
            nbFound++;
        }

        assertEquals( 1, nbFound );

        results.close();

        // Delete the entry
        connection.delete( dn );
    }
View Full Code Here

        try
        {
            // Retrieve locally the moved or renamed entry
            String filter = "(entryUuid=" + entryUuid + ")";
            EntryCursor cursor = connection.search( Dn.ROOT_DSE, filter, SearchScope.SUBTREE,
                SchemaConstants.ALL_ATTRIBUTES_ARRAY );

            Entry localEntry = cursor.get();

            // Compute the DN, parentDn and Rdn for both entries
            Dn localDn = localEntry.getDn();
            Dn remoteDn = remoteEntry.getDn();
View Full Code Here

        }
   
        Entry loadedEntry = null;
   
        Set<String> csnSet = new HashSet<String>( expectedCsns.length );
        EntryCursor cursor = connection.search( "ou=system", filter.toString(), SearchScope.ONELEVEL, "*", "+" );
   
        while ( cursor.next() )
        {
            loadedEntry = cursor.get();
            csnSet.add( loadedEntry.get( SchemaConstants.ENTRY_CSN_AT ).getString() );
        }
   
        cursor.close();
   
        assertTrue( csnSet.size() >= expectedCsns.length );
   
        for ( String csn : expectedCsns )
        {
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.cursor.EntryCursor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.