{
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 " );
}
} );