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

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


            String msg = "Cannot process a rename with a null Rdn";
            LOG.debug( msg );
            throw new IllegalArgumentException( msg );
        }

        ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
        modDnRequest.setName( entryDn );
        modDnRequest.setNewRdn( newRdn );
        modDnRequest.setDeleteOldRdn( deleteOldRdn );

        return modifyDn( modDnRequest );
    }
View Full Code Here


            String msg = "Cannot process a move to a null Dn";
            LOG.debug( msg );
            throw new IllegalArgumentException( msg );
        }

        ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
        modDnRequest.setName( entryDn );
        modDnRequest.setNewSuperior( newSuperiorDn );

        //TODO not setting the below value is resulting in error
        modDnRequest.setNewRdn( entryDn.getRdn() );

        return modifyDn( modDnRequest );
    }
View Full Code Here

        {
            throw new IllegalArgumentException( "The RootDSE cannot be the target" );
        }

        // Create the request
        ModifyDnRequest modDnRequest = new ModifyDnRequestImpl();
        modDnRequest.setName( entryDn );
        modDnRequest.setNewRdn( newDn.getRdn() );
        modDnRequest.setNewSuperior( newDn.getParent() );
        modDnRequest.setDeleteOldRdn( deleteOldRdn );

        return modifyDn( modDnRequest );
    }
View Full Code Here

        {
            de.printStackTrace();
            fail( de.getMessage() );
        }

        ModifyDnRequest modifyDnRequest = ldapMessageContainer.getMessage();

        assertEquals( 1, modifyDnRequest.getMessageId() );
        assertEquals( "cn=testModify,ou=users,ou=system", modifyDnRequest.getName().toString() );
        assertEquals( false, modifyDnRequest.getDeleteOldRdn() );
        assertEquals( "cn=testDNModify", modifyDnRequest.getNewRdn().toString() );
        assertEquals( "ou=system", modifyDnRequest.getNewSuperior().toString() );

        // Check the encoding
        try
        {
            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
View Full Code Here

        {
            de.printStackTrace();
            fail( de.getMessage() );
        }

        ModifyDnRequest modifyDnRequest = ldapMessageContainer.getMessage();

        assertEquals( 1, modifyDnRequest.getMessageId() );
        assertEquals( "cn=testModify,ou=users,ou=system", modifyDnRequest.getName().toString() );
        assertEquals( false, modifyDnRequest.getDeleteOldRdn() );
        assertEquals( "cn=testDNModify", modifyDnRequest.getNewRdn().toString() );
        assertEquals( "ou=system", modifyDnRequest.getNewSuperior().toString() );

        // Check the Control
        Map<String, Control> controls = modifyDnRequest.getControls();

        assertEquals( 1, controls.size() );

        CodecControl<Control> control = (org.apache.directory.shared.ldap.codec.api.CodecControl<Control> )modifyDnRequest.getControl( "2.16.840.1.113730.3.4.2" );
        assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
        assertEquals( "", Strings.dumpBytes((byte[]) control.getValue()) );

        // Check the encoding
        try
View Full Code Here

        {
            de.printStackTrace();
            fail( de.getMessage() );
        }

        ModifyDnRequest modifyDnRequest = ldapMessageContainer.getMessage();

        assertEquals( 1, modifyDnRequest.getMessageId() );
        assertEquals( "cn=testModify,ou=users,ou=system", modifyDnRequest.getName().toString() );
        assertEquals( false, modifyDnRequest.getDeleteOldRdn() );
        assertEquals( "cn=testDNModify", modifyDnRequest.getNewRdn().toString() );

        // Check the encoding
        try
        {
            ByteBuffer bb = encoder.encodeMessage( modifyDnRequest );
View Full Code Here

        {
            de.printStackTrace();
            fail( de.getMessage() );
        }

        ModifyDnRequest modifyDnRequest = ldapMessageContainer.getMessage();

        assertEquals( 1, modifyDnRequest.getMessageId() );
        assertEquals( "cn=testModify,ou=users,ou=system", modifyDnRequest.getName().toString() );
        assertEquals( false, modifyDnRequest.getDeleteOldRdn() );
        assertEquals( "cn=testDNModify", modifyDnRequest.getNewRdn().toString() );

        // Check the Control
        Map<String, Control> controls = modifyDnRequest.getControls();

        assertEquals( 1, controls.size() );

        assertTrue( modifyDnRequest.hasControl( "2.16.840.1.113730.3.4.2" ) );

        CodecControl<Control> control = (org.apache.directory.shared.ldap.codec.api.CodecControl<Control> )modifyDnRequest.getControl( "2.16.840.1.113730.3.4.2" );
        assertEquals( "2.16.840.1.113730.3.4.2", control.getOid() );
        assertEquals( "", Strings.dumpBytes((byte[]) control.getValue()) );

        // Check the encoding
        try
View Full Code Here

     */
    public Element toDsml( Element root )
    {
        Element element = super.toDsml( root );

        ModifyDnRequest request = ( ModifyDnRequest ) getDecorated();

        // Dn
        if ( request.getName() != null )
        {
            element.addAttribute( "dn", request.getName().getName() );
        }

        // NewRDN
        if ( request.getNewRdn() != null )
        {
            element.addAttribute( "newrdn", request.getNewRdn().getName() );
        }

        // DeleteOldRDN
        element.addAttribute( "deleteoldrdn", ( request.getDeleteOldRdn() ? "true" : "false" ) );

        // NewSuperior
        if ( request.getNewRdn() != null )
        {
            element.addAttribute( "newSuperior", request.getNewSuperior().getName() );
        }

        return element;
    }
View Full Code Here

            LdapStatesEnum.MODIFY_DN_REQUEST_STATE, LdapStatesEnum.ENTRY_MOD_DN_STATE, UniversalTag.OCTET_STRING.getValue(),
            new GrammarAction<LdapMessageContainer<ModifyDnRequestDecorator>>( "Store entry" )
            {
                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 entry = null;

                    if ( tlv.getLength() == 0 )
                    {
                        // This will generate a PROTOCOL_ERROR
                        throw new DecoderException( I18n.err( I18n.ERR_04089 ) );
                    }
                    else
                    {
                        byte[] dnBytes = tlv.getValue().getData();
                        String dnStr = Strings.utf8ToString(dnBytes);

                        try
                        {
                            entry = new Dn( dnStr );
                        }
                        catch ( LdapInvalidDnException ine )
                        {
                            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 );
View Full Code Here

            String msg = "Cannot process a move to a null Dn";
            LOG.debug( msg );
            throw new IllegalArgumentException( msg );
        }

        ModifyDnRequest iModDnReq = new ModifyDnRequestImpl();
        iModDnReq.setName( entryDn );
        iModDnReq.setNewSuperior( newSuperiorDn );

        ModifyDnResponse modifyDnResponse = modifyDn( iModDnReq );
        processResponse( modifyDnResponse );
    }
View Full Code Here

TOP

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

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.