Package org.apache.directory.shared.asn1

Examples of org.apache.directory.shared.asn1.DecoderException


        if ( tlv.getLength() == 0 )
        {
            LOG.error( I18n.err( I18n.ERR_04066 ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( I18n.err( I18n.ERR_04067 ) );
        }

        Value value = tlv.getValue();

        try
        {
            int number = IntegerDecoder.parse( value, minValue, maxValue );

            if ( IS_DEBUG )
            {
                LOG.debug( "read integer value : {}", number );
            }

            setIntegerValue( number, container );
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n.err( I18n.ERR_04070, Strings.dumpBytes( value.getData() ), ide
                .getLocalizedMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
    }
View Full Code Here


                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04031, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            });
    }
View Full Code Here

                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04037, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from time offline to delay
         *
         * GracefulShutdown ::= SEQUENCE {
         *     ...
         *     delay [0] INTEGER (0..86400) DEFAULT 0 }
         *
         * Set the delay value into the GracefulShutdown
         * object.
         */
        super.transitions[GracefulShutdownStatesEnum.TIME_OFFLINE_STATE.ordinal()][GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] =
            new GrammarTransition<GracefulShutdownContainer>( GracefulShutdownStatesEnum.TIME_OFFLINE_STATE,
                                    GracefulShutdownStatesEnum.DELAY_STATE,
                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG,

                new GrammarAction<GracefulShutdownContainer>( "Set Graceful Shutdown Delay" )
            {
                public void action( GracefulShutdownContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    try
                    {
                        int delay = IntegerDecoder.parse( value, 0, 86400 );

                        if ( IS_DEBUG )
                        {
                            LOG.debug( "Delay = " + delay );
                        }

                        container.getGracefulShutdown().setDelay( delay );
                        container.setGrammarEndAllowed( true );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04036, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            } );
       
        /**
         * Transition from graceful shutdown to delay
         *
         * GracefulShutdown ::= SEQUENCE {
         *     ...
         *     delay [0] INTEGER (0..86400) DEFAULT 0 }
         *
         * Set the delay value into the GracefulShutdown
         * object.
         */
        super.transitions[GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE.ordinal()]
                         [GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG] =
            new GrammarTransition<GracefulShutdownContainer>( GracefulShutdownStatesEnum.GRACEFUL_SHUTDOWN_SEQUENCE_STATE,
                                    GracefulShutdownStatesEnum.DELAY_STATE,
                                    GracefulActionConstants.GRACEFUL_ACTION_DELAY_TAG,

                new GrammarAction<GracefulShutdownContainer>( "Set Graceful Shutdown Delay" )
            {
                public void action( GracefulShutdownContainer container ) throws DecoderException
                {
                    GracefulShutdownContainer gracefulShutdownContainer = ( GracefulShutdownContainer ) container;
                    Value value = gracefulShutdownContainer.getCurrentTLV().getValue();

                    try
                    {
                        int delay = IntegerDecoder.parse( value, 0, 86400 );

                        if ( IS_DEBUG )
                        {
                            LOG.debug( "Delay = " + delay );
                        }

                        gracefulShutdownContainer.getGracefulShutdown().setDelay( delay );
                        gracefulShutdownContainer.setGrammarEndAllowed( true );
                    }
                    catch ( IntegerDecoderException e )
                    {
                        String msg = I18n.err( I18n.ERR_04036, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            } );
    }
View Full Code Here

                    {
                        if( !Dn.isValid(targetDN) )
                        {
                            String msg = I18n.err( I18n.ERR_04032, targetDN );
                            LOG.error( msg );
                            throw new DecoderException( msg );
                        }
                       
                        container.getCertGenerationObject().setTargetDN( targetDN );
                    }
                    else
                    {
                        String msg = I18n.err( I18n.ERR_04033, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
         * Transition from targetDN state to issuerDN
         *
         * CertGenerationObject ::= SEQUENCE {
         *     ...
         *     issuerDN IA5String,
         *     ...
         *    
         * Set the issuerDN value into the CertGenerationObject instance.
         */
        super.transitions[CertGenerationStatesEnum.TARGETDN_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<CertGenerationContainer>( CertGenerationStatesEnum.TARGETDN_STATE,
                CertGenerationStatesEnum.ISSUER_STATE, UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<CertGenerationContainer>( "Set Cert Generation issuer Dn value" )
            {
                public void action( CertGenerationContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    String issuerDN = Strings.utf8ToString(value.getData());

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "Issuer Dn = " + issuerDN );
                    }

                    if ( ( issuerDN != null ) && ( issuerDN.trim().length() > 0 ) )
                    {
                        if( !Dn.isValid(issuerDN) )
                        {
                            String msg = I18n.err( I18n.ERR_04034, issuerDN );
                            LOG.error( msg );
                            throw new DecoderException( msg );
                        }
                       
                        container.getCertGenerationObject().setIssuerDN( issuerDN );
                    }
                }
            } );

        /**
         * Transition from issuerDN state to subjectDN
         *
         * CertGenerationObject ::= SEQUENCE {
         *     ...
         *     subjectDN IA5String,
         *     ...
         *    
         * Set the subjectDN value into the CertGenerationObject instance.
         */
        super.transitions[CertGenerationStatesEnum.ISSUER_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<CertGenerationContainer>( CertGenerationStatesEnum.ISSUER_STATE,
                CertGenerationStatesEnum.SUBJECT_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<CertGenerationContainer>( "Set Cert Generation subject Dn value" )
            {
                public void action( CertGenerationContainer container ) throws DecoderException
                {
                    Value value = container.getCurrentTLV().getValue();

                    String subjectDN = Strings.utf8ToString(value.getData());

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "subject Dn = " + subjectDN );
                    }

                    if ( ( subjectDN != null ) && ( subjectDN.trim().length() > 0 ) )
                    {
                        if( !Dn.isValid(subjectDN) )
                        {
                            String msg = I18n.err( I18n.ERR_04035, subjectDN );
                            LOG.error( msg );
                            throw new DecoderException( msg );
                        }

                        container.getCertGenerationObject().setSubjectDN( subjectDN );
                    }
                    else
                    {
                        String msg = I18n.err( I18n.ERR_04033, Strings.dumpBytes(value.getData()) );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                }
            } );

        /**
 
View Full Code Here

                    if ( tlv.getLength() == 0 )
                    {
                        // We can't have a void language !
                        String msg = I18n.err( I18n.ERR_04038 );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                    else
                    {
                        // Only this field's type is String by default
                        String language = Strings.utf8ToString(tlv.getValue().getData());

                        if ( LOG.isDebugEnabled() )
                        {
                            LOG.debug( "SP language found: " + language );
                        }

                        storedProcedure.setLanguage( language );
                    }
                }
            } );

        //    procedure OCTETSTRING, (Value)
        //    ...
        // Stores the procedure.
        super.transitions[StoredProcedureStatesEnum.LANGUAGE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<StoredProcedureContainer>( StoredProcedureStatesEnum.LANGUAGE_STATE,
                                    StoredProcedureStatesEnum.PROCEDURE_STATE,
                                    UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<StoredProcedureContainer>( "Stores the procedure" )
            {
                public void action( StoredProcedureContainer container ) throws DecoderException
                {
                    TLV tlv = container.getCurrentTLV();

                    StoredProcedureRequestDecorator storedProcedure = container.getStoredProcedure();

                    // Store the value.
                    if ( tlv.getLength() == 0 )
                    {
                        // We can't have a void procedure !
                        String msg = I18n.err( I18n.ERR_04039 );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                    else
                    {
                        byte[] procedure = tlv.getValue().getData();

                        storedProcedure.setProcedure( procedure );
                    }

                    if ( LOG.isDebugEnabled() )
                    {
                        LOG.debug( "Procedure found : " + storedProcedure.getProcedureSpecification() );
                    }
                }
            } );

        // parameters SEQUENCE OF Parameter { (Value)
        //    ...
        // The list of parameters will be created with the first parameter.
        // We can have an empty list of parameters, so the PDU can be empty
        super.transitions[StoredProcedureStatesEnum.PROCEDURE_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
            new GrammarTransition<StoredProcedureContainer>( StoredProcedureStatesEnum.PROCEDURE_STATE,
                                    StoredProcedureStatesEnum.PARAMETERS_STATE,
                                    UniversalTag.SEQUENCE.getValue(),
            new GrammarAction<StoredProcedureContainer>( "Stores the parameters" )
            {
                public void action( StoredProcedureContainer container ) throws DecoderException
                {
                    container.setGrammarEndAllowed( true );
                }
            } );
       
        // parameter SEQUENCE OF { (Value)
        //    ...
        // Nothing to do.
        super.transitions[StoredProcedureStatesEnum.PARAMETERS_STATE.ordinal()][UniversalTag.SEQUENCE.getValue()] =
            new GrammarTransition<StoredProcedureContainer>( StoredProcedureStatesEnum.PARAMETERS_STATE,
                                    StoredProcedureStatesEnum.PARAMETER_STATE,
                                    UniversalTag.SEQUENCE.getValue(),
                                    null );

        // Parameter ::= {
        //    type OCTETSTRING, (Value)
        //    ...
        //
        // We can create a parameter, and store its type
        super.transitions[StoredProcedureStatesEnum.PARAMETER_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<StoredProcedureContainer>( StoredProcedureStatesEnum.PARAMETER_STATE,
                                    StoredProcedureStatesEnum.PARAMETER_TYPE_STATE,
                                    UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<StoredProcedureContainer>( "Store parameter type" )
            {
                public void action( StoredProcedureContainer container ) throws DecoderException
                {
                    TLV tlv = container.getCurrentTLV();
                    StoredProcedureRequestDecorator storedProcedure = container.getStoredProcedure();

                    // Store the value.
                    if ( tlv.getLength() == 0 )
                    {
                        // We can't have a void parameter type !
                        String msg = I18n.err( I18n.ERR_04040 );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                    else
                    {
                        StoredProcedureParameter parameter = new StoredProcedureParameter();

                        byte[] parameterType = tlv.getValue().getData();

                        parameter.setType( parameterType );

                        // We store the type in the current parameter.
                        storedProcedure.setCurrentParameter( parameter );

                        if ( LOG.isDebugEnabled() )
                        {
                            LOG.debug( "Parameter type found : " + Strings.dumpBytes(parameterType) );
                        }

                    }
                }
            } );

        // Parameter ::= {
        //    ...
        //    value OCTETSTRING (Tag)
        // }
        // Store the parameter value
        super.transitions[StoredProcedureStatesEnum.PARAMETER_TYPE_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] =
            new GrammarTransition<StoredProcedureContainer>( StoredProcedureStatesEnum.PARAMETER_TYPE_STATE,
                                    StoredProcedureStatesEnum.PARAMETER_VALUE_STATE,
                                    UniversalTag.OCTET_STRING.getValue(),
                new GrammarAction<StoredProcedureContainer>( "Store parameter value" )
            {
                public void action( StoredProcedureContainer container ) throws DecoderException
                {
                    StoredProcedureContainer storedProcedureContainer = ( StoredProcedureContainer ) container;

                    TLV tlv = storedProcedureContainer.getCurrentTLV();
                    StoredProcedureRequestDecorator storedProcedure = storedProcedureContainer.getStoredProcedure();

                    // Store the value.
                    if ( tlv.getLength() == 0 )
                    {
                        // We can't have a void parameter value !
                        String msg = I18n.err( I18n.ERR_04041 );
                        LOG.error( msg );
                        throw new DecoderException( msg );
                    }
                    else
                    {
                        byte[] parameterValue = tlv.getValue().getData();

                        if ( parameterValue.length != 0 )
                        {
                            StoredProcedureParameter parameter = storedProcedure.getCurrentParameter();
                            parameter.setValue( parameterValue );

                            // We can now add a new Parameter to the procedure
                            storedProcedure.addParameter( parameter );

                            if ( LOG.isDebugEnabled() )
                            {
                                LOG.debug( "Parameter value found : " + Strings.dumpBytes(parameterValue) );
                            }
                        }
                        else
                        {
                            String msg = I18n.err( I18n.ERR_04042 );
                            LOG.error( msg );
                            throw new DecoderException( msg );
                        }
                    }

                    // The only possible END state for the grammar is here
                    container.setGrammarEndAllowed( true );
View Full Code Here

        {
            String msg = I18n.err( I18n.ERR_04075 );
            LOG.error( msg );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( msg );
        }

        try
        {
            int abandonnedMessageId = IntegerDecoder.parse( value, 0, Integer.MAX_VALUE );

            abandonRequest.setAbandoned( abandonnedMessageId );

            if ( IS_DEBUG )
            {
                LOG
                    .debug( "AbandonMessage Id has been decoded : {}", Integer
                        .valueOf( abandonnedMessageId ) );
            }

            container.setGrammarEndAllowed( true );

            return;
        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n
                .err( I18n.ERR_04076, Strings.dumpBytes(value.getData()), ide.getMessage() ) );

            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( ide.getMessage() );
        }
    }
View Full Code Here

        }
        catch ( IntegerDecoderException ide )
        {
            LOG.error( I18n.err( I18n.ERR_04018, Strings.dumpBytes(value.getData()), ide.getMessage() ) );

            throw new DecoderException( ide.getMessage() );
        }

        // Treat the 'normal' cases !
        switch ( resultCode )
        {
View Full Code Here

        }
        catch ( Exception e )
        {
            String message = I18n.err( I18n.ERR_04060, e.getLocalizedMessage() );
            LOG.error( message );
            throw new DecoderException( message, e );
        }

        if ( container.getState() == TLVStateEnum.PDU_DECODED )
        {
            if ( IS_DEBUG )
            {
                LOG.debug( "Decoded LdapMessage : " + container );
            }

            return container.getMessage();
        }
        else
        {
            LOG.error( I18n.err( I18n.ERR_04062 ) );
            throw new DecoderException( I18n.err( I18n.ERR_04063 ) );
        }
    }
View Full Code Here

        if ( tlv.getLength() == 0 )
        {
            String msg = I18n.err( I18n.ERR_04095 );
            LOG.error( msg );
            // This will generate a PROTOCOL_ERROR
            throw new DecoderException( msg );
        }
        else
        {
            byte[] requestNameBytes = tlv.getValue().getData();

            try
            {
                String requestName = Strings.utf8ToString(requestNameBytes);

                if ( !Oid.isOid( requestName ) )
                {

                    String msg = "The Request name is not a valid OID : "
                        + Strings.utf8ToString(requestNameBytes) + " ("
                        + Strings.dumpBytes(requestNameBytes) + ") is invalid";
                    LOG.error( msg );

                    // throw an exception, we will get a PROTOCOL_ERROR
                    throw new DecoderException( msg );
                }

                req = LdapCodecServiceFactory.getSingleton().newExtendedRequest( requestName, null );
                req.setMessageId( container.getMessageId() );
                container.setMessage( LdapCodecServiceFactory.getSingleton().decorate( req ) );
View Full Code Here

     */
    public void setOID( byte[] oid ) throws DecoderException
    {
        if ( oid == null )
        {
            throw new DecoderException( I18n.err( I18n.ERR_00032_NULL_OID ) );
        }

        if ( oid.length < 1 )
        {
            throw new DecoderException( I18n.err( I18n.ERR_00033_INVALID_OID, Asn1StringUtils.dumpBytes( oid ) ) );
        }

        // First, we have to calculate the number of int to allocate
        int nbValues = 1;
        int pos = 0;
View Full Code Here

TOP

Related Classes of org.apache.directory.shared.asn1.DecoderException

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.