Package org.apache.directory.shared.ldap.codec.bind

Examples of org.apache.directory.shared.ldap.codec.bind.BindRequestCodec


     *
     * @param messageId The message Id
     */
    private void bind( int messageId ) throws NamingException, EncoderException, DecoderException, IOException
    {
        BindRequestCodec bindRequest = new BindRequestCodec();
        LdapAuthentication authentication = null;

        if ( "simple".equals( auth ) )
        {
            authentication = new SimpleAuthentication();
            ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( password ) );
        }

        bindRequest.setAuthentication( authentication );
        bindRequest.setName( new DN( user ) );
        bindRequest.setVersion( 3 );

        bindRequest.setMessageId( messageId );

        // Encode and send the bind request
        ByteBuffer bb = bindRequest.encode();
        bb.flip();

        connect();
        sendMessage( bb );

View Full Code Here


     * Create a BindRequest ready to be sent.
     */
    private BindRequestCodec createBindMessage( BindRequest bindRequest ) throws LdapException
    {
        // Create a new codec BindRequest object
        BindRequestCodec bindRequestCodec = new BindRequestCodec();

        // clear the mappings if any (in case of a second call to bind() without calling unBind())
        //clearMaps();
       
        // Set the new messageId
        int newId = messageId.incrementAndGet();
        bindRequest.setMessageId( newId );
        bindRequestCodec.setMessageId( newId );

        // Set the version
        bindRequestCodec.setVersion( LdapConnectionConfig.LDAP_V3 );

        // Set the name
        try
        {
            DN dn = new DN( bindRequest.getName() );
            bindRequestCodec.setName( dn );
        }
        catch ( InvalidNameException ine )
        {
            String msg = "The given dn '" + bindRequest.getName() + "' is not valid";
            LOG.error( msg );
            LdapException ldapException = new LdapException( msg );
            ldapException.initCause( ine );

            throw ldapException;
        }

        // Set the credentials
        LdapAuthentication authentication = null;

        if ( bindRequest.isSimple() )
        {
            // Simple bind
            authentication = new SimpleAuthentication();
            ( ( SimpleAuthentication ) authentication ).setSimple( bindRequest.getCredentials() );
        }
        else
        {
            // SASL bind
            authentication = new SaslCredentials();
            ( ( SaslCredentials ) authentication ).setCredentials( bindRequest.getCredentials() );
            ( ( SaslCredentials ) authentication ).setMechanism( bindRequest.getSaslMechanism() );
        }

        // The authentication
        bindRequestCodec.setAuthentication( authentication );

        // Add the controls
        setControls( bindRequest.getControls(), bindRequestCodec );

        return bindRequestCodec;
View Full Code Here

     *
     * @param messageId The message Id
     */
    private void bind( int messageId ) throws LdapInvalidDnException, EncoderException, DecoderException, IOException
    {
        BindRequestCodec bindRequest = new BindRequestCodec();
        LdapAuthentication authentication = null;

        if ( "simple".equals( auth ) )
        {
            authentication = new SimpleAuthentication();
            ( ( SimpleAuthentication ) authentication ).setSimple( StringTools.getBytesUtf8( password ) );
        }

        bindRequest.setAuthentication( authentication );
        bindRequest.setName( new DN( user ) );
        bindRequest.setVersion( 3 );

        bindRequest.setMessageId( messageId );

        // Encode and send the bind request
        ByteBuffer bb = bindRequest.encode();
        bb.flip();

        connect();
        sendMessage( bb );

View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.codec.bind.BindRequestCodec

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.