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

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


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


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

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

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

                        modifyDnRequest.setName( entry );
                    }

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "Modifying Dn {}", entry );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from EntryModDN to NewRDN
        // --------------------------------------------------------------------------------------------
        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { ...
        //     ...
        //     newrdn  RelativeRDN,
        //     ...
        //
        // RelativeRDN :: LDAPString
        //
        // Stores the new Rdn
        super.transitions[LdapStatesEnum.ENTRY_MOD_DN_STATE.ordinal()][UniversalTag.OCTET_STRING.getValue()] = new GrammarTransition(
            LdapStatesEnum.ENTRY_MOD_DN_STATE, LdapStatesEnum.NEW_RDN_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<LdapMessageContainer<ModifyDnRequestDecorator>>( "Store new Rdn" )
            {
                public void action( LdapMessageContainer<ModifyDnRequestDecorator> container ) throws DecoderException
                {
                    ModifyDnRequest modifyDnRequest = container.getMessage();

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

                    // We have to handle the special case of a 0 length matched
                    // newDN
                    Rdn newRdn = null;

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

                        ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
                        throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                            modifyDnRequest.getName(), null );
                    }
                    else
                    {
                        byte[] dnBytes = tlv.getValue().getData();
                        String dnStr = Strings.utf8ToString(dnBytes);

                        try
                        {
                            Dn dn = new Dn( dnStr );
                            newRdn = dn.getRdn( 0 );
                        }
                        catch ( LdapInvalidDnException ine )
                        {
                            String msg = "Invalid new Rdn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes)
                                + ") is invalid";
                            LOG.error( "{} : {}", msg, ine.getMessage() );

                            ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
                            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                                modifyDnRequest.getName(), ine );
                        }

                        modifyDnRequest.setNewRdn( newRdn );
                    }

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "Modifying with new Rdn {}", newRdn );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from NewRDN to DeleteOldRDN
        // --------------------------------------------------------------------------------------------
        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { ...
        //     ...
        //     deleteoldrdn BOOLEAN,
        //     ...
        //
        // Stores the deleteOldRDN flag
        super.transitions[LdapStatesEnum.NEW_RDN_STATE.ordinal()][UniversalTag.BOOLEAN.getValue()] = new GrammarTransition(
            LdapStatesEnum.NEW_RDN_STATE, LdapStatesEnum.DELETE_OLD_RDN_STATE, UniversalTag.BOOLEAN.getValue(),
            new GrammarAction<LdapMessageContainer<ModifyDnRequestDecorator>>( "Store matching dnAttributes Value" )
            {
                public void action( LdapMessageContainer<ModifyDnRequestDecorator> container ) throws DecoderException
                {
                    ModifyDnRequest modifyDnRequest = container.getMessage();

                    TLV tlv = container.getCurrentTLV();

                    // We get the value. If it's a 0, it's a FALSE. If it's
                    // a FF, it's a TRUE. Any other value should be an error,
                    // but we could relax this constraint. So if we have
                    // something
                    // which is not 0, it will be interpreted as TRUE, but we
                    // will generate a warning.
                    Value value = tlv.getValue();

                    try
                    {
                        modifyDnRequest.setDeleteOldRdn( BooleanDecoder.parse( value ) );
                    }
                    catch ( BooleanDecoderException bde )
                    {
                        LOG.error( I18n
                            .err( I18n.ERR_04091, Strings.dumpBytes(value.getData()), bde.getMessage() ) );

                        // This will generate a PROTOCOL_ERROR                       
                        throw new DecoderException( bde.getMessage() );
                    }

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

                    if ( IS_DEBUG )
                    {
                        if ( modifyDnRequest.getDeleteOldRdn() )
                        {
                            LOG.debug( " Old Rdn attributes will be deleted" );
                        }
                        else
                        {
                            LOG.debug( " Old Rdn attributes will be retained" );
                        }
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from DeleteOldRDN to NewSuperior
        // --------------------------------------------------------------------------------------------
        // ModifyDNRequest ::= [APPLICATION 12] SEQUENCE { ...
        //     ...
        //     newSuperior [0] LDAPDN OPTIONAL }
        //
        // Stores the new superior
        super.transitions[LdapStatesEnum.DELETE_OLD_RDN_STATE.ordinal()][LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG] = new GrammarTransition(
            LdapStatesEnum.DELETE_OLD_RDN_STATE, LdapStatesEnum.NEW_SUPERIOR_STATE,
            LdapConstants.MODIFY_DN_REQUEST_NEW_SUPERIOR_TAG,
            new GrammarAction<LdapMessageContainer<ModifyDnRequestDecorator>>( "Store new superior" )
            {
                public void action( LdapMessageContainer<ModifyDnRequestDecorator> container ) throws DecoderException
                {
                    ModifyDnRequest modifyDnRequest = container.getMessage();

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

                    // We have to handle the special case of a 0 length matched
                    // Dn
                    Dn newSuperior = Dn.EMPTY_DN;

                    if ( tlv.getLength() == 0 )
                    {

                        if ( modifyDnRequest.getDeleteOldRdn() )
                        {
                            // This will generate a PROTOCOL_ERROR
                            throw new DecoderException( I18n.err( I18n.ERR_04092 ) );
                        }
                        else
                        {
                            LOG.warn( "The new superior is null, so we will change the entry" );
                        }

                        modifyDnRequest.setNewSuperior( newSuperior );
                    }
                    else
                    {
                        byte[] dnBytes = tlv.getValue().getData();
                        String dnStr = Strings.utf8ToString(dnBytes);

                        try
                        {
                            newSuperior = new Dn( dnStr );
                        }
                        catch ( LdapInvalidDnException ine )
                        {
                            String msg = "Invalid new superior Dn given : " + dnStr + " ("
                                + Strings.dumpBytes(dnBytes) + ") is invalid";
                            LOG.error( "{} : {}", msg, ine.getMessage() );

                            ModifyDnResponseImpl response = new ModifyDnResponseImpl( modifyDnRequest.getMessageId() );
                            throw new ResponseCarryingException( msg, response, ResultCodeEnum.INVALID_DN_SYNTAX,
                                modifyDnRequest.getName(), ine );
                        }

                        modifyDnRequest.setNewSuperior( newSuperior );
                    }

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

                    if ( IS_DEBUG )
                    {
                        LOG.debug( "New superior Dn {}", newSuperior );
                    }
                }
            } );

        // --------------------------------------------------------------------------------------------
        // Transition from DeleteOldRDN to Controls
        // --------------------------------------------------------------------------------------------
        //     modifyDNRequest ModifyDNRequest,
        //     ... },
        // controls   [0] Controls OPTIONAL }
        //
        // Stores the new superior
        super.transitions[LdapStatesEnum.DELETE_OLD_RDN_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
            LdapStatesEnum.DELETE_OLD_RDN_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
            new ControlsInitAction() );

        // --------------------------------------------------------------------------------------------
        // Transition from DeleteOldRDN to Controls
        // --------------------------------------------------------------------------------------------
        //     modifyDNRequest ModifyDNRequest,
        //     ... },
        // controls   [0] Controls OPTIONAL }
        //
        // Stores the new superior
        super.transitions[LdapStatesEnum.NEW_SUPERIOR_STATE.ordinal()][LdapConstants.CONTROLS_TAG] = new GrammarTransition(
            LdapStatesEnum.NEW_SUPERIOR_STATE, LdapStatesEnum.CONTROLS_STATE, LdapConstants.CONTROLS_TAG,
            new ControlsInitAction() );

        // --------------------------------------------------------------------------------------------
        // Transition from MessageID to ModifyDNResponse Message.
        // --------------------------------------------------------------------------------------------
        // ModifyDNResponse ::= [APPLICATION 13] SEQUENCE {
        //     ...
        //
        // Creates the ModifyDNResponse
        super.transitions[LdapStatesEnum.MESSAGE_ID_STATE.ordinal()][LdapConstants.MODIFY_DN_RESPONSE_TAG] = new GrammarTransition(
            LdapStatesEnum.MESSAGE_ID_STATE, LdapStatesEnum.MODIFY_DN_RESPONSE_STATE,
            LdapConstants.MODIFY_DN_RESPONSE_TAG, new GrammarAction<LdapMessageContainer<ModifyDnResponseDecorator>>( "Init ModifyDNResponse" )
            {
                public void action( LdapMessageContainer<ModifyDnResponseDecorator> container )
                {
                    // Now, we can allocate the ModifyDnResponse Object
                    ModifyDnResponseDecorator modifyDnResponse = new ModifyDnResponseDecorator(
                        container.getLdapCodecService(), new ModifyDnResponseImpl( container.getMessageId() ) );
                    container.setMessage( modifyDnResponse );

                    LOG.debug( "Modify Dn response " );
                }
            } );
View Full Code Here

            throw new IllegalArgumentException( msg );
        }

        int newId = messageId.incrementAndGet();

        ModifyDnResponse resp = new ModifyDnResponseImpl( newId );
        LdapResult result = resp.getLdapResult();
        result.setResultCode( ResultCodeEnum.SUCCESS );

        if ( modDnRequest.getName().isEmpty() )
        {
            // it is not allowed to modify the name of the Root DSE
            String msg = "Modify Dn is not allowed on Root DSE.";
            result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
            result.setDiagnosticMessage( msg );
            return resp;
        }

        try
        {
            Dn newRdn = null;

            if ( modDnRequest.getNewRdn() != null )
            {
                newRdn = new Dn( schemaManager, modDnRequest.getNewRdn().getName() );
            }

            Dn oldRdn = new Dn( schemaManager, modDnRequest.getName().getRdn().getName() );

            boolean rdnChanged = modDnRequest.getNewRdn() != null
                && !newRdn.getNormName().equals( oldRdn.getNormName() );

            if ( rdnChanged )
            {
                if ( modDnRequest.getNewSuperior() != null )
                {
                    session.moveAndRename( modDnRequest );
                }
                else
                {
                    session.rename( modDnRequest );
                }
            }
            else if ( modDnRequest.getNewSuperior() != null )
            {
                modDnRequest.setNewRdn( null );
                session.move( modDnRequest );
            }
            else
            {
                result.setDiagnosticMessage( "Attempt to move entry onto itself." );
                result.setResultCode( ResultCodeEnum.ENTRY_ALREADY_EXISTS );
                result.setMatchedDn( modDnRequest.getName() );
            }

        }
        catch ( LdapException e )
        {
            LOG.warn( e.getMessage(), e );

            resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
            resp.getLdapResult().setDiagnosticMessage( e.getMessage() );
        }

        addResponseControls( modDnRequest, resp );
        return resp;
    }
View Full Code Here

        if ( newDn.isRootDSE() )
        {
            throw new IllegalArgumentException( "The RootDSE cannot be the target" );
        }

        ModifyDnResponse resp = new ModifyDnResponseImpl();
        resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );

        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();

        modifyDnRequest.setName( entryDn );
        modifyDnRequest.setNewRdn( newDn.getRdn() );
View Full Code Here

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

            throw new IllegalArgumentException( msg );
        }

        int newId = messageId.incrementAndGet();

        ModifyDnResponse resp = new ModifyDnResponseImpl( newId );
        LdapResult result = resp.getLdapResult();
        result.setResultCode( ResultCodeEnum.SUCCESS );

        if ( modDnRequest.getName().isEmpty() )
        {
            // it is not allowed to modify the name of the Root DSE
            String msg = "Modify Dn is not allowed on Root DSE.";
            result.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
            result.setDiagnosticMessage( msg );
            return resp;
        }

        try
        {
            Dn newRdn = null;

            if ( modDnRequest.getNewRdn() != null )
            {
                newRdn = new Dn( schemaManager, modDnRequest.getNewRdn().getName() );
            }

            Dn oldRdn = new Dn( schemaManager, modDnRequest.getName().getRdn().getName() );

            boolean rdnChanged = modDnRequest.getNewRdn() != null
                && !newRdn.getNormName().equals( oldRdn.getNormName() );

            if ( rdnChanged )
            {
                if ( modDnRequest.getNewSuperior() != null )
                {
                    session.moveAndRename( modDnRequest );
                }
                else
                {
                    session.rename( modDnRequest );
                }
            }
            else if ( modDnRequest.getNewSuperior() != null )
            {
                modDnRequest.setNewRdn( null );
                session.move( modDnRequest );
            }
            else
            {
                // This might be a simple change, we will update the DN and the entry
                // with the new provided value by using a modify operation later on
                session.rename( modDnRequest );
            }

        }
        catch ( LdapException e )
        {
            LOG.warn( e.getMessage(), e );

            resp.getLdapResult().setResultCode( ResultCodeEnum.getResultCode( e ) );
            resp.getLdapResult().setDiagnosticMessage( e.getMessage() );
        }

        addResponseControls( modDnRequest, resp );
        return resp;
    }
View Full Code Here

        if ( newDn.isRootDse() )
        {
            throw new IllegalArgumentException( "The RootDSE cannot be the target" );
        }

        ModifyDnResponse resp = new ModifyDnResponseImpl();
        resp.getLdapResult().setResultCode( ResultCodeEnum.SUCCESS );

        ModifyDnRequest modifyDnRequest = new ModifyDnRequestImpl();

        modifyDnRequest.setName( entryDn );
        modifyDnRequest.setNewRdn( newDn.getRdn() );
View Full Code Here

     */
    public void action( LdapMessageContainer<ModifyDnResponseDecorator> container )
    {
        // Now, we can allocate the ModifyDnResponse Object
        ModifyDnResponseDecorator modifyDnResponse = new ModifyDnResponseDecorator(
            container.getLdapCodecService(), new ModifyDnResponseImpl( container.getMessageId() ) );
        container.setMessage( modifyDnResponse );

        LOG.debug( "Modify Dn response " );
    }
View Full Code Here

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

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

            modifyDnRequest.setName( entry );
View Full Code Here

TOP

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

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.