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

Examples of org.apache.directory.shared.ldap.model.message.BindResponseImpl


    /**
     * Creates a new getDecoratedMessage() of AuthResponseDsml.
     */
    public BindResponseDsml( LdapCodecService codec )
    {
        super( codec, new BindResponseImpl() );
    }
View Full Code Here


                        {
                            String msg = "Incorrect Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes)
                                + ") is invalid";
                            LOG.error( "{} : {}", msg, ine.getMessage() );

                            BindResponseImpl response = new BindResponseImpl( bindRequestMessage.getMessageId() );

                            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                                Dn.EMPTY_DN, ine );
                        }
                    }

                    if ( IS_DEBUG )
                    {
                        LOG.debug( " The Bind name is {}", bindRequestMessage.getName() );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from name to Simple Authentication
        // --------------------------------------------------------------------------------------------
        // BindRequest ::= [APPLICATION 0] SEQUENCE {
        //     ....
        //     authentication          AuthenticationChoice }
        //
        // AuthenticationChoice ::= CHOICE {
        //     simple                  [0] OCTET STRING,
        //     ...
        //
        // We have to create an Authentication Object to store the credentials.
        super.transitions[LdapStatesEnum.NAME_STATE.ordinal()][LdapConstants.BIND_REQUEST_SIMPLE_TAG] = new GrammarTransition(
            LdapStatesEnum.NAME_STATE, LdapStatesEnum.SIMPLE_STATE, LdapConstants.BIND_REQUEST_SIMPLE_TAG,
            new GrammarAction<LdapMessageContainer<BindRequestDecorator>>( "Store Bind Simple Authentication value" )
            {
                public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
                {
                    BindRequest bindRequestMessage = container.getMessage();
                    TLV tlv = container.getCurrentTLV();

                    // Allocate the Authentication Object
                    bindRequestMessage.setSimple( true );

                    // We have to handle the special case of a 0 length simple
                    if ( tlv.getLength() == 0 )
                    {
                        bindRequestMessage.setCredentials( StringConstants.EMPTY_BYTES );
                    }
                    else
                    {
                        bindRequestMessage.setCredentials( tlv.getValue().getData() );
                    }

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "The simple authentication is : {}", Strings.dumpBytes(bindRequestMessage
                                .getCredentials()) );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // transition from Simple Authentication to Controls.
        // --------------------------------------------------------------------------------------------
        //         bindRequest   BindRequest,
        //         ... },
        //     controls       [0] Controls OPTIONAL }
        //
        super.transitions[LdapStatesEnum.SIMPLE_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
            LdapStatesEnum.SIMPLE_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
            new ControlsInitAction() );

        // --------------------------------------------------------------------------------------------
        // Transition from name to SASL Authentication
        // --------------------------------------------------------------------------------------------
        // BindRequest ::= [APPLICATION 0] SEQUENCE {
        //     ....
        //     authentication          AuthenticationChoice }
        //
        // AuthenticationChoice ::= CHOICE {
        //     ...
        //     sasl                  [3] SaslCredentials }
        //     ...
        //
        // We have to create an Authentication Object to store the credentials.
        super.transitions[LdapStatesEnum.NAME_STATE.ordinal()][LdapConstants.BIND_REQUEST_SASL_TAG] = new GrammarTransition(
            LdapStatesEnum.NAME_STATE, LdapStatesEnum.SASL_STATE, LdapConstants.BIND_REQUEST_SASL_TAG,
            new GrammarAction<LdapMessageContainer<BindRequestDecorator>>( "Initialize Bind SASL Authentication" )
            {
                public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
                {
                    BindRequest bindRequestMessage = container.getMessage();
                    TLV tlv = container.getCurrentTLV();

                    // We will check that the sasl is not null
                    if ( tlv.getLength() == 0 )
                    {
                        String msg = I18n.err( I18n.ERR_04079 );
                        LOG.error( msg );

                        BindResponseImpl response = new BindResponseImpl( bindRequestMessage.getMessageId() );

                        throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_CREDENTIALS,
                            bindRequestMessage.getName(), null );
                    }

                    bindRequestMessage.setSimple( false );

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "The SaslCredential has been created" );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from SASL Authentication to Mechanism
        // --------------------------------------------------------------------------------------------
        // SaslCredentials ::= SEQUENCE {
        //     mechanism   LDAPSTRING,
        //     ...
        //
        // We have to store the mechanism.
        super.transitions[LdapStatesEnum.SASL_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
            LdapStatesEnum.SASL_STATE, LdapStatesEnum.MECHANISM_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<LdapMessageContainer<BindRequestDecorator>>( "Store SASL mechanism" )
            {
                public void action( LdapMessageContainer<BindRequestDecorator> container ) throws DecoderException
                {
                    BindRequest bindRequestMessage = container.getMessage();
                    TLV tlv = container.getCurrentTLV();

                    // We have to handle the special case of a 0 length
                    // mechanism
                    if ( tlv.getLength() == 0 )
                    {
                        bindRequestMessage.setSaslMechanism( "" );
                    }
                    else
                    {
                        bindRequestMessage.setSaslMechanism( Strings.utf8ToString(tlv.getValue().getData()) );
                    }

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "The mechanism is : {}", bindRequestMessage.getSaslMechanism() );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from Mechanism to Credentials
        // --------------------------------------------------------------------------------------------
        // SaslCredentials ::= SEQUENCE {
        //     ...
        //     credentials OCTET STRING OPTIONAL }
        //
        // We have to store the mechanism.
        super.transitions[LdapStatesEnum.MECHANISM_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
            LdapStatesEnum.MECHANISM_STATE, LdapStatesEnum.CREDENTIALS_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<LdapMessageContainer<BindRequestDecorator>>( "Store SASL credentials" )
            {
                public void action( LdapMessageContainer<BindRequestDecorator> container )
                {
                    BindRequest bindRequestMessage = container.getMessage();

                    // Get the Value and store it in the BindRequest
                    TLV tlv = container.getCurrentTLV();

                    // We have to handle the special case of a 0 length
                    // credentials
                    if ( tlv.getLength() == 0 )
                    {
                        bindRequestMessage.setCredentials( StringConstants.EMPTY_BYTES );
                    }
                    else
                    {
                        bindRequestMessage.setCredentials( tlv.getValue().getData() );
                    }

                    // We can have an END transition
                    container.setGrammarEndAllowed( true );

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "The credentials are : {}", Strings.dumpBytes(bindRequestMessage
                                .getCredentials()) );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // transition from from Mechanism to Controls.
        // --------------------------------------------------------------------------------------------
        //         bindRequest   BindRequest,
        //         ... },
        //     controls       [0] Controls OPTIONAL }
        //
        super.transitions[LdapStatesEnum.MECHANISM_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
            LdapStatesEnum.MECHANISM_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
            new ControlsInitAction() );

        // --------------------------------------------------------------------------------------------
        // transition from credentials to Controls.
        // --------------------------------------------------------------------------------------------
        //         bindRequest   BindRequest,
        //         ... },
        //     controls       [0] Controls OPTIONAL }
        //
        super.transitions[LdapStatesEnum.CREDENTIALS_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
            LdapStatesEnum.CREDENTIALS_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
            new ControlsInitAction() );

        // --------------------------------------------------------------------------------------------
        // Transition from MessageId to BindResponse message
        // --------------------------------------------------------------------------------------------
        // LdapMessage ::= ... BindResponse ...
        // BindResponse ::= [APPLICATION 1] SEQUENCE { ...
        // We have to switch to the BindResponse grammar
        super.transitions[LdapStatesEnum.MESSAGE_ID_STATE.ordinal()][LdapConstants.BIND_RESPONSE_TAG] = new GrammarTransition(
            LdapStatesEnum.MESSAGE_ID_STATE, LdapStatesEnum.BIND_RESPONSE_STATE, LdapConstants.BIND_RESPONSE_TAG,
            new GrammarAction<LdapMessageContainer<BindResponseDecorator>>( "Init BindReponse" )
            {
                public void action( LdapMessageContainer<BindResponseDecorator> container )
                {
                    // Now, we can allocate the BindResponse Object
                    BindResponseDecorator bindResponse = new BindResponseDecorator(
                        container.getLdapCodecService(), new BindResponseImpl( container.getMessageId() ) );
                    container.setMessage( bindResponse );
                }
            } );

        // --------------------------------------------------------------------------------------------
View Full Code Here

        bindContext.setCredentials( bindRequest.getCredentials() );
        bindContext.setDn( bindRequest.getName() );

        OperationManager operationManager = directoryService.getOperationManager();

        BindResponse bindResp = new BindResponseImpl( newId );
        bindResp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );

        try
        {
            if ( !bindRequest.isSimple() )
            {
                bindContext.setSaslMechanism( bindRequest.getSaslMechanism() );
            }

            operationManager.bind( bindContext );
            session = bindContext.getSession();

            bindResp.addAllControls( bindContext.getResponseControls() );
        }
        catch ( LdapOperationException e )
        {
            LOG.warn( e.getMessage(), e );
            LdapResult res = bindResp.getLdapResult();
            res.setDiagnosticMessage( e.getMessage() );
            res.setResultCode( e.getResultCode() );
        }

        return bindResp;
View Full Code Here

    /**
     * Creates a new getDecoratedMessage() of AuthResponseDsml.
     */
    public BindResponseDsml( LdapApiService codec )
    {
        super( codec, new BindResponseImpl() );
    }
View Full Code Here

            // SASL BindRequest
            if ( !( message instanceof BindRequest ) || ( ( BindRequest ) message ).isSimple()
                || ldapSession.isSimpleAuthPending() )
            {
                LOG.error( I18n.err( I18n.ERR_732 ) );
                BindResponse bindResponse = new BindResponseImpl( message.getMessageId() );
                LdapResult bindResult = bindResponse.getLdapResult();
                bindResult.setResultCode( ResultCodeEnum.UNWILLING_TO_PERFORM );
                bindResult.setDiagnosticMessage( I18n.err( I18n.ERR_732 ) );
                ldapSession.getIoSession().write( bindResponse );
                return;
            }
View Full Code Here

        bindContext.setDn( bindRequest.getDn() );
        bindContext.setInterceptors( directoryService.getInterceptors( OperationEnum.BIND ) );

        OperationManager operationManager = directoryService.getOperationManager();

        BindResponse bindResp = new BindResponseImpl( newId );
        bindResp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );

        try
        {
            if ( !bindRequest.isSimple() )
            {
                bindContext.setSaslMechanism( bindRequest.getSaslMechanism() );
            }

            operationManager.bind( bindContext );
            session = bindContext.getSession();

            bindResp.addAllControls( bindContext.getResponseControls() );
        }
        catch ( LdapOperationException e )
        {
            LOG.warn( e.getMessage(), e );
            LdapResult res = bindResp.getLdapResult();
            res.setDiagnosticMessage( e.getMessage() );
            res.setResultCode( e.getResultCode() );
        }

        return bindResp;
View Full Code Here

            holder = new BindResponseHolder( resp, connection );
        }
        catch ( Exception e )
        {
            resp = new BindResponseImpl();

            LdapResult result = resp.getLdapResult();
            result.setDiagnosticMessage( e.getMessage() );
            result.setResultCode( ResultCodeEnum.getResultCode( e ) );
View Full Code Here

            {
                String msg = "Incorrect Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes)
                    + ") is invalid";
                LOG.error( "{} : {}", msg, ine.getMessage() );

                BindResponseImpl response = new BindResponseImpl( bindRequestMessage.getMessageId() );

                throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                    Dn.EMPTY_DN, ine );
            }
        }
View Full Code Here

        if ( tlv.getLength() == 0 )
        {
            String msg = I18n.err( I18n.ERR_04079 );
            LOG.error( msg );

            BindResponseImpl response = new BindResponseImpl( bindRequestMessage.getMessageId() );

            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_CREDENTIALS,
                bindRequestMessage.getName(), null );
        }
View Full Code Here

            holder = new BindResponseHolder( resp, connection );
        }
        catch ( Exception e )
        {
            resp = new BindResponseImpl();

            LdapResult result = resp.getLdapResult();
            result.setDiagnosticMessage( e.getMessage() );
            result.setResultCode( ResultCodeEnum.getResultCode(e) );
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.ldap.model.message.BindResponseImpl

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.