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

Examples of org.apache.directory.api.ldap.model.message.BindRequestImpl


     * Test a valid bind followed by another valid bind
     */
    @Test
    public void testDoubleSimpleBindValid() throws Exception
    {
        BindRequest br1 = new BindRequestImpl();
        br1.setDn( new Dn( "uid=admin,ou=system" ) );
        br1.setCredentials( Strings.getBytesUtf8( "secret" ) );

        BindResponse response1 = connection.bind( br1 );
        assertTrue( connection.isAuthenticated() );
        int messageId1 = response1.getMessageId();

        // The messageId must have been incremented
        BindRequest br2 = new BindRequestImpl();
        br2.setDn( new Dn( "uid=admin,ou=system" ) );
        br2.setCredentials( Strings.getBytesUtf8( "secret" ) );

        BindResponse response2 = connection.bind( br2 );
        int messageId2 = response2.getMessageId();

        assertTrue( messageId2 > messageId1 );
        assertTrue( connection.isAuthenticated() );

        // Now, unbind
        connection.unBind();
        assertFalse( connection.isAuthenticated() );
        assertFalse( connection.isConnected() );

        // And Bind again. The messageId should be 1
        BindRequest br3 = new BindRequestImpl();
        br3.setDn( new Dn( "uid=admin,ou=system" ) );
        br3.setCredentials( Strings.getBytesUtf8( "secret" ) );

        BindResponse response3 = connection.bind( br3 );
        int messageId = response3.getMessageId();
        assertEquals( 1, messageId );
        assertTrue( connection.isAuthenticated() );
View Full Code Here


            };

            getService().addFirst( interceptor );

            // Send another BindRequest
            BindRequest bindRequest = new BindRequestImpl();
            bindRequest.setDn( new Dn( "uid=admin,ou=system" ) );
            bindRequest.setCredentials( "secret" );

            BindFuture bindFuture = connection.bindAsync( bindRequest );

            // Wait a bit to be sure the server is processing the bind request
            Thread.sleep( 200 );
View Full Code Here

    /**
     * {@inheritDoc}
     */
    public void anonymousBind() throws LdapException, IOException
    {
        BindRequest bindRequest = new BindRequestImpl();
        bindRequest.setName( "" );
        bindRequest.setCredentials( ( byte[] ) null );

        BindResponse bindResponse = bind( bindRequest );

        processResponse( bindResponse );
    }
View Full Code Here

     * {@inheritDoc}
     */
    public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
    {
        // Create the BindRequest LdapMessage instance and store it in the container
        BindRequest internalBindRequest = new BindRequestImpl();
        internalBindRequest.setMessageId( container.getMessageId() );
        BindRequestDecorator bindRequest = new BindRequestDecorator(
            container.getLdapCodecService(), internalBindRequest );
        container.setMessage( bindRequest );

        // We will check that the request is not null
View Full Code Here

     */
    public void bind( Dn name ) throws LdapException
    {
        byte[] credBytes = StringConstants.EMPTY_BYTES;

        BindRequest bindRequest = new BindRequestImpl();
        bindRequest.setDn( name );
        bindRequest.setCredentials( credBytes );

        BindResponse bindResponse = bind( bindRequest );

        processResponse( bindResponse );
    }
View Full Code Here

     */
    public void bind( Dn name, String credentials ) throws LdapException
    {
        byte[] credBytes = ( credentials == null ? StringConstants.EMPTY_BYTES : Strings.getBytesUtf8( credentials ) );

        BindRequest bindRequest = new BindRequestImpl();
        bindRequest.setDn( name );
        bindRequest.setCredentials( credBytes );

        BindResponse bindResponse = bind( bindRequest );

        processResponse( bindResponse );
    }
View Full Code Here

     */
    protected BindRequest createBindRequest( String name, byte[] credentials, String saslMechanism, Control... controls )
        throws LdapException
    {
        // Set the new messageId
        BindRequest bindRequest = new BindRequestImpl();

        // Set the version
        bindRequest.setVersion3( true );

        // Set the name
        bindRequest.setName( name );

        // Set the credentials
        if ( Strings.isEmpty( saslMechanism ) )
        {
            // Simple bind
            bindRequest.setSimple( true );
            bindRequest.setCredentials( credentials );
        }
        else
        {
            // SASL bind
            bindRequest.setSimple( false );
            bindRequest.setCredentials( credentials );
            bindRequest.setSaslMechanism( saslMechanism );
        }

        // Add the controls
        if ( ( controls != null ) && ( controls.length != 0 ) )
        {
            bindRequest.addAllControls( controls );
        }

        return bindRequest;
    }
View Full Code Here

        long t0 = System.currentTimeMillis();

        for ( int i = 0; i < nbLoops; i++ )
        {
            // Check the decoded BindRequest
            BindRequest bindRequest = new BindRequestImpl();
            bindRequest.setMessageId( 1 );

            bindRequest.setSimple( true );
            bindRequest.setDn( dn );
            bindRequest.setCredentials( Strings.getBytesUtf8( "password" ) );
            Control control = new OpaqueControl( "2.16.840.1.113730.3.4.2" );

            bindRequest.addControl( control );

            // Check the encoding
            try
            {
                encoder.encodeMessage( bindRequest );
View Full Code Here

                result = bindResponse.getLdapResult().getResultCode();
            }
            else
            {
                // Copy the bindRequest without setting the credentials
                BindRequest bindRequestCopy = new BindRequestImpl();
                bindRequestCopy.setMessageId( newId );

                bindRequestCopy.setName( bindRequest.getName() );
                bindRequestCopy.setSaslMechanism( bindRequest.getSaslMechanism() );
                bindRequestCopy.setSimple( bindRequest.isSimple() );
                bindRequestCopy.setVersion3( bindRequest.getVersion3() );
                bindRequestCopy.addAllControls( bindRequest.getControls().values().toArray( new Control[0] ) );

                writeRequest( bindRequestCopy );

                bindResponse = bindFuture.get( timeout, TimeUnit.MILLISECONDS );
View Full Code Here

    /**
     * Creates a new getDecoratedMessage() of AuthRequestDsml.
     */
    public BindRequestDsml( LdapApiService codec )
    {
        super( codec, new BindRequestImpl() );
    }
View Full Code Here

TOP

Related Classes of org.apache.directory.api.ldap.model.message.BindRequestImpl

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.