Package org.apache.directory.ldap.client.api

Examples of org.apache.directory.ldap.client.api.LdapNetworkConnection


        {
            int connectionIndex = rand.nextInt( connections.size() );
           
            int entryIndex = rand.nextInt( batch );
           
            LdapNetworkConnection nc = connections.get( connectionIndex );
           
            String cn = RDN_PREFIX + entryIndex;
            Dn personDn = new Dn( "cn=" + cn + "," + REPL_AREA_SUFFIX );

            if ( verbose )
            {
                System.out.println( "modifying " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() );
            }
           
            ModifyRequest modReq = new ModifyRequestImpl();
            modReq.setName( personDn );
            modReq.replace( SchemaConstants.SN_AT, "sn_" + i );
           
            ModifyResponse resp = nc.modify( modReq );
            ResultCodeEnum rc = resp.getLdapResult().getResultCode();
            if( rc != ResultCodeEnum.SUCCESS )
            {
                System.out.println( "Error modifying " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + " with result code " + rc );
            }

            modified.add( personDn );
        }
       
View Full Code Here


       
        for( int i=0; i < batch; i++ )
        {
            int connectionIndex = rand.nextInt( connections.size() );
           
            LdapNetworkConnection nc = connections.get( connectionIndex );
           
            String cn = RDN_PREFIX + i;
            Dn personDn = new Dn( "cn=" + cn + "," + REPL_AREA_SUFFIX );
           
            if( verbose )
            {
                System.out.println( "moving " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + ":" + nc.getConfig().getLdapPort() );
            }
           
            ModifyDnRequest modReq = new ModifyDnRequestImpl();
            modReq.setName( personDn );
            modReq.setNewRdn( personDn.getRdn() );
            modReq.setNewSuperior( superiorDn );
           
            ModifyDnResponse resp = nc.modifyDn( modReq );
            ResultCodeEnum rc = resp.getLdapResult().getResultCode();
            if( rc != ResultCodeEnum.SUCCESS )
            {
                System.out.println( "Error moving " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + ":" + nc.getConfig().getLdapPort() + " with result code " + rc );
            }
           
            moved.add( superiorDn.add( personDn.getRdn() ) );
        }
       
View Full Code Here

        List<Dn> renamed = new ArrayList<Dn>();
        List<Dn> present = new ArrayList<Dn>();
       
        int connectionIndex = rand.nextInt( connections.size() );

        LdapNetworkConnection nc = connections.get( connectionIndex );
        EntryCursor cursor = nc.search( containerDn, "(cn=" + RDN_PREFIX + "*)", SearchScope.ONELEVEL, SchemaConstants.NO_ATTRIBUTE_ARRAY );
       
        while( cursor.next() )
        {
            present.add( cursor.get().getDn() );
        }
       
        cursor.close();
       
        for( int i=0; i < present.size(); i++ )
        {
            connectionIndex = rand.nextInt( connections.size() );
            nc = connections.get( connectionIndex );
           
            Dn personDn = present.get( i );
           
            ModifyDnRequest modReq = new ModifyDnRequestImpl();
            Rdn newRdn = new Rdn( "cn=p_rename" + i );
            modReq.setName( personDn );
            modReq.setNewRdn( newRdn );
           
            if( verbose )
            {
                System.out.println( "renaming " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() );   
            }
           
            ModifyDnResponse resp = nc.modifyDn( modReq );
            ResultCodeEnum rc = resp.getLdapResult().getResultCode();
            if( rc != ResultCodeEnum.SUCCESS )
            {
                System.out.println( "Error renaming " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + " with result code " + rc );
            }
           
            renamed.add( personDn.getParent().add( newRdn ) );
        }
       
View Full Code Here

        int count = present.size();//( present.size() - 2 );
        for( int i=0; i < count; i++ )
        {
            int connectionIndex = rand.nextInt( connections.size() );
           
            LdapNetworkConnection nc = connections.get( connectionIndex );
           
            Dn personDn = present.get( i );
           
            DeleteRequest delReq = new DeleteRequestImpl();
            delReq.setName( personDn );
           
            if( verbose )
            {
                System.out.println( "deleting " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() );
            }
           
            DeleteResponse resp = nc.delete( delReq );
            ResultCodeEnum rc = resp.getLdapResult().getResultCode();

            if( rc != ResultCodeEnum.SUCCESS )
            {
                System.out.println( "Error deleting " + personDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + " with result code " + rc );
            }
           
            deleted.add( personDn );
        }
       
View Full Code Here

    {
        Dn parentDn = new Dn( "ou=parent,ou=children,ou=grandchildren");
       
        Dn currentDn = new Dn( REPL_AREA_SUFFIX );
       
        LdapNetworkConnection nc = connections.get( 0 );
       
        for( Rdn rdn : parentDn.getRdns() )
        {
            currentDn = new Dn( rdn.getName() + "," + currentDn.getName() );
            Entry e = new DefaultEntry( currentDn.getName(),
            "objectclass: top",
            "objectclass: organizationalUnit",
            "ou: " + rdn.getAva().getValue().getString() );
            nc.add( e );
        }
       
        compareEntries( Collections.singletonList( currentDn ) );
       
        Dn ouDn = currentDn.getParent().getParent();
       
        if( verbose )
        {
            System.out.println( "moving " + ouDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + ":" + nc.getConfig().getLdapPort() );
        }
       
        ModifyDnRequest modReq = new ModifyDnRequestImpl();
        modReq.setName( ouDn );
        modReq.setNewRdn( ouDn.getRdn() );
        modReq.setNewSuperior( ouDn.getParent().getParent() );
       
        ModifyDnResponse resp = nc.modifyDn( modReq );
        ResultCodeEnum rc = resp.getLdapResult().getResultCode();
        if( rc != ResultCodeEnum.SUCCESS )
        {
            System.out.println( "Error moving " + ouDn + " on the server " + nc.getConfig().getLdapHost() + ":" + nc.getConfig().getLdapPort() + ":" + nc.getConfig().getLdapPort() + " with result code " + rc );
        }

        Thread.sleep( 2000 );
        verifyDeleted( Collections.singletonList( ouDn ) );
    }
View Full Code Here

    {
        for( Dn dn : injected )
        {
            Entry baseEntry = null;
            Iterator<LdapNetworkConnection> itr = connections.iterator();
            LdapNetworkConnection c = itr.next();
            baseEntry = lookupWithWait( c, dn );
           
            while( itr.hasNext() )
            {
                c = itr.next();
View Full Code Here

        for( Dn dn : injected )
        {
            Iterator<LdapNetworkConnection> itr = connections.iterator();
            outer: while( itr.hasNext() )
            {
                LdapNetworkConnection c = itr.next();
                try
                {
                    for( int i = 1; i <= 10; i++ )
                    {
                        if( !c.exists( dn ) )
                        {
                            System.out.println( dn + " doesn't exist in the server " + c.getConfig().getLdapHost() + ":" + c.getConfig().getLdapPort() );
                            continue outer;
                        }
                       
                        Thread.sleep( 1000 * i );
                    }
                   
                    throw new RuntimeException( "deleted Entry " + dn + " found on server " + c.getConfig().getLdapHost() + ":" + c.getConfig().getLdapPort() );
                }
                catch( Exception e )
                {
                    throw new RuntimeException( e );
                }
View Full Code Here

    }
   
   
    public void injectAndWaitTillReplicates( Entry ctxEntry ) throws Exception
    {
        LdapNetworkConnection c = connections.get( 0 );
       
        if( !c.exists( ctxEntry.getDn() ) )
        {
            c.add( ctxEntry );
        }
       
        compareEntries( Collections.singletonList( ctxEntry.getDn() ) );
    }
View Full Code Here

    @Test
    public void testAddPDUExceedingMaxSizeLdapApi() throws Exception
    {
        // Limit the PDU size to 1024
        getLdapServer().getDirectoryService().setMaxPDUSize( 1024 );
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.bind( "uid=admin,ou=system", "secret" );

        // Inject a 1024 bytes long description
        StringBuilder sb = new StringBuilder();

        for ( int i = 0; i < 128; i++ )
        {
            sb.append( "0123456789ABCDEF" );
        }

        Attribute description = new DefaultAttribute( "description", sb.toString() );

        try
        {
            Modification modification = new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, description );
            connection.modify( "cn=the person, ou=system", modification );
            fail();
        }
        catch ( Exception e )
        {
            // We are expecting the session to be close here.
            if ( connection.isConnected() )
            {
                // Race condition:
                // Upon NoticeOfDisconnection the API sends an abandon request but does not immediately close the connection.
                // So at this point it is not guaranteed that the connnection is already closed.
                // TODO: This is just a workaround, better check the connection for any outstanding abandon requests
                Thread.sleep( 1000 );
            }
            assertFalse( connection.isConnected() );
        }
    }
View Full Code Here


    @Test
    public void testAddNullValue() throws LdapException, IOException
    {
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        connection.setTimeOut( 0L );

        // Use the client API
        connection.bind( "uid=admin,ou=system", "secret" );

        // Add a new entry with some null values
        Entry entry = new DefaultEntry( "cn=test,ou=system",
            "ObjectClass: top",
            "ObjectClass: person",
            "ObjectClass: person",
            "ObjectClass: OrganizationalPerson",
            "ObjectClass: inetOrgPerson",
            "cn: test",
            "sn: Test",
            "userPassword:",
            "mail:" );

        connection.add( entry );

        // Now fetch the entry
        Entry found = connection.lookup( "cn=test,ou=system" );

        assertNotNull( found );
        assertNotNull( found.get( "userPassword" ) );
        assertNotNull( found.get( "mail" ) );
        String userPassword = found.get( "userPassword" ).getString();
        String mail = found.get( "mail" ).getString();

        assertTrue( Strings.isEmpty( userPassword ) );
        assertTrue( Strings.isEmpty( mail ) );

        connection.close();
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.ldap.client.api.LdapNetworkConnection

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.