use of org.apache.directory.api.ldap.model.message.AddResponseImpl in project directory-ldap-api by apache.
the class AddRequestTest method testDecodeAddRequestbadDN.
/**
* Test the decoding of a AddRequest
*/
@Test
public void testDecodeAddRequestbadDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x59);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x57, 0x02, 0x01, // messageID MessageID
0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
0x52, // 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', // attributes AttributeList }
0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
0x2E, 0x30, // attribute 1
0x0c, 0x04, 0x01, // type AttributeDescription,
'l', 0x31, // vals SET OF AttributeValue }
0x07, 0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x30, // attribute 2
0x1E, // type AttributeDescription,
0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, // vals SET
0x15, // }
0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's', 't', '3' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a AddRequest message
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof AddResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((AddResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.model.message.AddResponseImpl in project directory-ldap-api by apache.
the class AddRequestTest method testDecodeAddRequestNullEntry.
/**
* Test the decoding of a AddRequest with a null entry
*/
@Test
public void testDecodeAddRequestNullEntry() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x39);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x37, 0x02, 0x01, // messageID MessageID
0x01, 0x68, // CHOICE { ..., addRequest AddRequest, ...
0x26, // entry LDAPDN,
0x04, 0x00, // attributes AttributeList }
0x30, // AttributeList ::= SEQUENCE OF SEQUENCE {
0x2E, 0x30, // attribute 1
0x0c, 0x04, 0x01, // type AttributeDescription,
'l', 0x31, // vals SET OF AttributeValue }
0x07, 0x04, 0x05, 'P', 'a', 'r', 'i', 's', 0x30, // attribute 2
0x1E, // type AttributeDescription,
0x04, 0x05, 'a', 't', 't', 'r', 's', 0x31, // vals SET
0x15, // }
0x04, 0x05, 't', 'e', 's', 't', '1', 0x04, 0x05, 't', 'e', 's', 't', '2', 0x04, 0x05, 't', 'e', 's', 't', '3' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a AddRequest message
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof AddResponseImpl);
assertEquals(ResultCodeEnum.NAMING_VIOLATION, ((AddResponseImpl) response).getLdapResult().getResultCode());
return;
}
fail("We should not reach this point");
}
use of org.apache.directory.api.ldap.model.message.AddResponseImpl in project directory-ldap-api by apache.
the class AddAddRequestAttributeType method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
AddRequestDecorator addRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the type. It can't be null.
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04086);
LOG.error(msg);
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), null);
}
String type = Strings.utf8ToString(tlv.getValue().getData());
try {
addRequest.addAttributeType(type);
} catch (LdapException ne) {
String msg = I18n.err(I18n.ERR_04087);
LOG.error(msg);
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, addRequest.getEntry().getDn(), ne);
}
if (IS_DEBUG) {
LOG.debug("Adding type {}", type);
}
}
use of org.apache.directory.api.ldap.model.message.AddResponseImpl in project directory-ldap-api by apache.
the class StoreAddRequestEntryName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddRequestDecorator> container) throws DecoderException {
AddRequestDecorator addRequest = container.getMessage();
TLV tlv = container.getCurrentTLV();
// Store the entry. It can't be null
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04085);
LOG.error(msg);
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
// Not 100% sure though ...
throw new ResponseCarryingException(msg, response, ResultCodeEnum.NAMING_VIOLATION, Dn.EMPTY_DN, null);
} else {
Dn entryDn = null;
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
entryDn = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
AddResponseImpl response = new AddResponseImpl(addRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
addRequest.setEntryDn(entryDn);
}
LOG.debug("Adding an entry with Dn : {}", addRequest.getEntry());
}
use of org.apache.directory.api.ldap.model.message.AddResponseImpl in project directory-ldap-api by apache.
the class InitAddResponse method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<AddResponseDecorator> container) throws DecoderException {
// Now, we can allocate the AddResponse Object
AddResponseDecorator addResponse = new AddResponseDecorator(container.getLdapCodecService(), new AddResponseImpl(container.getMessageId()));
container.setMessage(addResponse);
// We will check that the request is not null
TLV tlv = container.getCurrentTLV();
int expectedLength = tlv.getLength();
if (expectedLength == 0) {
String msg = I18n.err(I18n.ERR_04088);
LOG.error(msg);
throw new DecoderException(msg);
}
LOG.debug("Add Response");
}
Aggregations