use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.
the class CompareRequestTest method testDecodeCompareRequestEmptyAttributeDesc.
/**
* Test the decoding of an empty attributeDesc ava
*/
@Test
public void testDecodeCompareRequestEmptyAttributeDesc() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2D);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x2B, 0x02, 0x01, // messageID MessageID
0x01, // CHOICE { ..., compareRequest CompareRequest, ...
0x6E, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
0x26, // 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', // ava AttributeValueAssertion }
0x30, // AttributeValueAssertion ::= SEQUENCE {
0x02, 0x04, 0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<CompareRequestDecorator> container = new LdapMessageContainer<CompareRequestDecorator>(codec);
// Decode the CompareRequest PDU
try {
ldapDecoder.decode(stream, container);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof CompareResponseImpl);
assertEquals(ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, ((CompareResponseImpl) response).getLdapResult().getResultCode());
return;
}
}
use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.
the class InitCompareResponse method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<CompareResponseDecorator> container) throws DecoderException {
// Now, we can allocate the CompareResponse Object
CompareResponseDecorator compareResponse = new CompareResponseDecorator(container.getLdapCodecService(), new CompareResponseImpl(container.getMessageId()));
container.setMessage(compareResponse);
// We will check that the request is not null
TLV tlv = container.getCurrentTLV();
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04094);
LOG.error(msg);
throw new DecoderException(msg);
}
LOG.debug("Compare response ");
}
use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.
the class StoreCompareRequestAttributeDesc method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
// Get the CompareRequest Object
CompareRequest compareRequest = container.getMessage();
// Get the Value and store it in the CompareRequest
TLV tlv = container.getCurrentTLV();
// Dn
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04093);
LOG.error(msg);
CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, compareRequest.getName(), null);
}
String type = Strings.utf8ToString(tlv.getValue().getData());
compareRequest.setAttributeId(type);
if (IS_DEBUG) {
LOG.debug("Comparing attribute description {}", compareRequest.getAttributeId());
}
}
use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.
the class StoreCompareRequestEntryName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<CompareRequestDecorator> container) throws DecoderException {
CompareRequest compareRequest = container.getMessage();
// Get the Value and store it in the CompareRequest
TLV tlv = container.getCurrentTLV();
Dn entry;
// Dn
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());
CompareResponseImpl response = new CompareResponseImpl(compareRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
compareRequest.setName(entry);
}
if (IS_DEBUG) {
LOG.debug("Comparing Dn {}", entry);
}
}
use of org.apache.directory.api.ldap.model.message.CompareResponseImpl in project directory-ldap-api by apache.
the class CompareRequestTest method testDecodeCompareRequestInvalidDN.
/**
* Test the decoding of an empty ava
*/
@Test
public void testDecodeCompareRequestInvalidDN() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x2B);
stream.put(new byte[] { 0x30, // LDAPMessage ::= SEQUENCE {
0x29, 0x02, 0x01, // messageID MessageID
0x01, // CHOICE { ..., compareRequest CompareRequest, ...
0x6E, // CompareRequest ::= [APPLICATION 14] SEQUENCE {
0x24, // 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', // ava AttributeValueAssertion }
0x30, // AttributeValueAssertion ::= SEQUENCE {
0x00 });
stream.flip();
// Allocate a LdapMessage Container
LdapMessageContainer<CompareRequestDecorator> container = new LdapMessageContainer<CompareRequestDecorator>(codec);
// Decode the CompareRequest PDU
try {
ldapDecoder.decode(stream, container);
fail("We should never reach this point !!!");
} catch (DecoderException de) {
assertTrue(de instanceof ResponseCarryingException);
Message response = ((ResponseCarryingException) de).getResponse();
assertTrue(response instanceof CompareResponseImpl);
assertEquals(ResultCodeEnum.INVALID_DN_SYNTAX, ((CompareResponseImpl) response).getLdapResult().getResultCode());
return;
}
}
Aggregations