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

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


     * non-success result code.
     */
    @Test
    public void testOnReferral() throws Exception
    {
        LdapConnection conn = getWiredConnection( getLdapServer() );

        // referrals failure
        // modify success
        ModifyRequest modifyRequest = new ModifyRequestImpl();
        modifyRequest.setName( new Dn( "uid=akarasuluref,ou=users,ou=system" ) );
        modifyRequest.add( "description", "referral to akarasulu" );

        ModifyResponse modifyResponse = conn.modify( modifyRequest );

        assertEquals( ResultCodeEnum.REFERRAL, modifyResponse.getLdapResult().getResultCode() );

        assertTrue( modifyResponse.getLdapResult().getReferral().getLdapUrls()
            .contains( "ldap://localhost:10389/uid=akarasulu,ou=users,ou=system" ) );
        assertTrue( modifyResponse.getLdapResult().getReferral().getLdapUrls()
            .contains( "ldap://foo:10389/uid=akarasulu,ou=users,ou=system" ) );
        assertTrue( modifyResponse.getLdapResult().getReferral().getLdapUrls()
            .contains( "ldap://bar:10389/uid=akarasulu,ou=users,ou=system" ) );

        conn.close();
    }
View Full Code Here


    @Test
    public void testIllegalMove() throws Exception
    {

        LdapConnection con = getAdminConnection( getLdapServer() );

        //now do something bad: make the parent a child of its own child
        try
        {
            con.move( "ou=parent,ou=system", "ou=child,ou=parent,ou=system" );
            fail();
        }
        catch ( LdapUnwillingToPerformException lutpe )
        {
            assertTrue( true );
        }

        con.close();
    }
View Full Code Here


    @Test
    public void testIllegalMoveToSameDN() throws Exception
    {
        LdapConnection con = getAdminConnection( getLdapServer() );

        //now do something bad: try to move the entry to the same Dn
        try
        {
            con.move( "ou=parent,ou=system", "ou=parent,ou=system" );
            fail();
        }
        catch ( LdapUnwillingToPerformException lutpe )
        {
            assertTrue( true );
        }
        con.close();
    }
View Full Code Here

     * Test that the WhoAmI extended operation is handled correctly
     */
    @Test
    public void testRbacCreateSessionExtendedOperation() throws Exception
    {
        LdapConnection adminConnection = getAdminNetworkConnection( getLdapServer() );

        adminConnection.setTimeOut( 0L );

        // Create a new RBAC session
        WhoAmIRequest whoAmIRequest = new WhoAmIRequestImpl();

        // Send the request
        WhoAmIResponse whoAmIResponse = ( WhoAmIResponse ) adminConnection.extended( whoAmIRequest );

        assertEquals( ResultCodeEnum.SUCCESS, whoAmIResponse.getLdapResult().getResultCode() );
        assertTrue( whoAmIResponse.isDnAuthzId() );
        assertEquals( "uid=admin,ou=system", whoAmIResponse.getDn().toString() );
        adminConnection.close();
    }
View Full Code Here

        {
            try
            {
                for ( int i = 0; i < 100; i++ )
                {
                    LdapConnection connection = pool.getConnection();

                    connection.lookup( Dn.ROOT_DSE, "1.1 " );

                    pool.releaseConnection( connection );

                    counter.countDown();
                }
View Full Code Here

     * @throws IOException
     */
    @Test
    public void testBindRequest() throws Exception
    {
        LdapConnection connection = new LdapNetworkConnection( "localhost", getLdapServer().getPort() );
        try
        {
            connection.bind( ADMIN_DN, "secret" );

            assertTrue( connection.isAuthenticated() );
        }
        finally
        {
            if ( connection != null )
            {
                connection.close();
            }
        }
    }
View Full Code Here

        config.setLdapPort( ldapServer.getPort() );
        config.setName( ServerDNConstants.ADMIN_SYSTEM_DN );
        config.setCredentials( "secret" );
        config.setBinaryAttributeDetector( new DefaultConfigurableBinaryAttributeDetector() );

        LdapConnection myConnection = new LdapNetworkConnection( config );

        // Remove the UserPassword from the list
        ( ( ConfigurableBinaryAttributeDetector ) config.getBinaryAttributeDetector() ).
            removeBinaryAttribute( "userPassword" );
        myConnection.bind( "uid=admin,ou=system", "secret" );
        Entry entry = myConnection.lookup( "uid=admin,ou=system" );
        assertTrue( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );

        // Now, load a new binary Attribute
        ( ( ConfigurableBinaryAttributeDetector ) config.getBinaryAttributeDetector() ).
            addBinaryAttribute( "userPassword" );
        entry = myConnection.lookup( "uid=admin,ou=system" );
        assertFalse( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );

        // Now, test using the scerver's schema
        ( ( LdapNetworkConnection ) connection ).loadSchema();
        connection.bind( "uid=admin,ou=system", "secret" );

        // Use the default list of binary Attributes
        entry = connection.lookup( "uid=admin,ou=system" );
        assertFalse( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );
       
        myConnection.close();
    }
View Full Code Here

        LdapConnectionConfig config = new LdapConnectionConfig();
        config.setLdapHost( "localhost" );
        config.setLdapPort( ldapServer.getPort() );
        config.setBinaryAttributeDetector( new DefaultConfigurableBinaryAttributeDetector() );

        LdapConnection ldapConnection = new LdapNetworkConnection( config );

        ldapConnection.bind( "uid=admin,ou=system", "secret" );

        // Try to retrieve a binary attribute : it should be seen as a byte[]
        Entry entry = ldapConnection.lookup( "uid=admin,ou=system" );
        assertFalse( entry.get( SchemaConstants.USER_PASSWORD_AT ).get().isHumanReadable() );
       
        ldapConnection.close();
    }
View Full Code Here

            "entryCSN", new CsnFactory( 1 ).newInstance().toString(),
            "entryUUID", UUID.randomUUID().toString() );

        partition.add( new AddOperationContext( getService().getAdminSession(), ctxEntry ) );

        LdapConnection connection = IntegrationUtils.getAdminConnection( getService() );

        assertNotNull( connection.lookup( "ou=removable" ) );

        // Test removeContextPartition
        getService().removePartition( partition );

        assertNull( connection.lookup( "ou=removable" ) );
    }
View Full Code Here


    @Test
    public void testModifyAddWithNullValues() 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( "uid=12345,ou=system",
            "ObjectClass: top",
            "ObjectClass: person",
            "ObjectClass: person",
            "ObjectClass: OrganizationalPerson",
            "ObjectClass: inetOrgPerson",
            "uid: 12345",
            "cn: test",
            "sn: Test",
            "userPassword: 12345" );

        connection.add( entry );

        // Now modify the entry : we should add two null values
        connection.modify( new Dn( "uid=12345,ou=system" ),
            new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "userPassword", Strings.EMPTY_BYTES ),
            new DefaultModification( ModificationOperation.ADD_ATTRIBUTE, "mail", ( String ) null )
            );

        // Get back the entry
        Entry found = connection.lookup( "uid=12345,ou=system" );

        assertNotNull( found );
        assertNotNull( found.get( "mail" ) );
        assertNotNull( found.get( "userPassword" ) );
        assertTrue( found.contains( "mail", Strings.EMPTY_BYTES ) );
        assertTrue( found.contains( "userPassword", "12345", "" ) );

        connection.close();
    }
View Full Code Here

TOP

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

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.