use of org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl in project directory-ldap-api by apache.
the class ModifyDNRequestTest method testDecodeModifyDNRequestBadDN.
/**
* Test the decoding of a bad Dn ModifyDNRequest
*/
@Test
public void testDecodeModifyDNRequestBadDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x48);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x46, 0x02, 0x01, // messageID MessageID
0x01, 0x6C, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
0x41, // entry LDAPDN,
0x04, 0x20, 'c', 'n', ':', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', // newrdn RelativeLDAPDN,
0x04, 0x0F, 'c', 'n', '=', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01, // deleteoldrdn BOOLEAN,
0x00, // newSuperior [0] LDAPDN OPTIONAL }
(byte) 0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' });
stream.flip();
// Allocate a ModifyRequest Container
LdapMessageContainer<ModifyDnRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyDnRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof ModifyDnResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((ModifyDnResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl in project directory-ldap-api by apache.
the class ModifyDNRequestTest method testDecodeModifyDNRequestBadRDN.
/**
* Test the decoding of a bad Rdn ModifyDNRequest
*/
@Test
public void testDecodeModifyDNRequestBadRDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x48);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x46, 0x02, 0x01, // messageID MessageID
0x01, 0x6C, // CHOICE { ..., modifyDNRequest ModifyDNRequest,
0x41, // entry LDAPDN,
0x04, 0x20, 'c', 'n', '=', 't', 'e', 's', 't', 'M', 'o', 'd', 'i', 'f', 'y', ',', 'o', 'u', '=', 'u', 's', 'e', 'r', 's', ',', 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm', // newrdn RelativeLDAPDN,
0x04, 0x0F, 'c', 'n', ':', 't', 'e', 's', 't', 'D', 'N', 'M', 'o', 'd', 'i', 'f', 'y', 0x01, 0x01, // deleteoldrdn BOOLEAN,
0x00, // newSuperior [0] LDAPDN OPTIONAL }
(byte) 0x80, 0x09, 'o', 'u', '=', 's', 'y', 's', 't', 'e', 'm' });
stream.flip();
// Allocate a ModifyRequest Container
LdapMessageContainer<ModifyDnRequestDecorator> ldapMessageContainer = new LdapMessageContainer<ModifyDnRequestDecorator>(codec);
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof ModifyDnResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((ModifyDnResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl in project directory-ldap-api by apache.
the class StoreModifyDnRequestEntryName method action.
/**
* {@inheritDoc}
*/
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;
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);
}
}
use of org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl in project directory-ldap-api by apache.
the class StoreModifyDnRequestNewRdn method action.
/**
* {@inheritDoc}
*/
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;
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(dn.size() - 1);
} 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);
}
}
use of org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl in project directory-ldap-api by apache.
the class InitModifyDnResponse method action.
/**
* {@inheritDoc}
*/
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 ");
}
Aggregations