use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeBadTagTransition.
/**
* Test the decoding of a PDU with a bad primitive Length. The second TLV
* has a length of 0x02 when the PDU is 0x01 bytes long.
*/
@Test
public void testDecodeBadTagTransition() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x35);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x33, // Length should be 0x01...
0x02, 0x01, // messageID MessageID
0x01, 0x2D, // CHOICE { ..., bindRequest BindRequest, ...
0x2D, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0x80, // authentication
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r', 'd' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertEquals("ERR_01200_BAD_TRANSITION_FROM_STATE Bad transition from state MESSAGE_ID_STATE, tag 0x2D", de.getMessage());
return;
}
fail("Should never reach this point.");
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class LdapDecoderTest method testDecodeBadPrimitiveLengthTooBig.
/**
* Test the decoding of a PDU with a bad primitive Length. The second TLV
* has a length of 0x02 when the PDU is 0x01 bytes long.
*/
@Test
public void testDecodeBadPrimitiveLengthTooBig() {
Asn1Decoder ldapDecoder = new Asn1Decoder();
ByteBuffer stream = ByteBuffer.allocate(0x35);
stream.put(new byte[] { 0x30, // LDAPMessage ::=SEQUENCE {
0x33, // Length should be 0x01...
0x02, 0x02, // messageID MessageID
0x01, 0x60, // CHOICE { ..., bindRequest BindRequest, ...
0x2E, // BindRequest ::= APPLICATION[0] SEQUENCE {
0x02, 0x01, // version INTEGER (1..127),
0x03, 0x04, // name LDAPDN,
0x1F, 'u', 'i', 'd', '=', 'a', 'k', 'a', 'r', 'a', 's', 'u', 'l', 'u', ',', 'd', 'c', '=', 'e', 'x', 'a', 'm', 'p', 'l', 'e', ',', 'd', 'c', '=', 'c', 'o', 'm', (byte) 0x80, // authentication AuthenticationChoice
0x08, // ...
'p', 'a', 's', 's', 'w', 'o', 'r' });
stream.flip();
// Allocate a LdapMessage Container
Asn1Container ldapMessageContainer = new LdapMessageContainer<MessageDecorator<? extends Message>>(codec);
// Decode a BindRequest PDU
try {
ldapDecoder.decode(stream, ldapMessageContainer);
} catch (DecoderException de) {
assertEquals("ERR_01200_BAD_TRANSITION_FROM_STATE Bad transition from state MESSAGE_ID_STATE, tag 0x2E", de.getMessage());
return;
}
fail("Should never reach this point.");
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class InitReferrals method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
// If we hae a Referrals sequence, then it should not be empty
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04011);
LOG.error(msg);
// This will generate a PROTOCOL_ERROR
throw new DecoderException(msg);
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
Referral referral = new ReferralImpl();
ldapResult.setReferral(referral);
if (IS_DEBUG) {
LOG.debug("Initialising a referrals list");
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreErrorMessage method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// Get the Value and store it in the BindResponse
TLV tlv = container.getCurrentTLV();
String errorMessage;
// message
if (tlv.getLength() == 0) {
errorMessage = "";
} else {
errorMessage = Strings.utf8ToString(tlv.getValue().getData());
}
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
ldapResult.setDiagnosticMessage(errorMessage);
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("The error message is : " + errorMessage);
}
}
use of org.apache.directory.api.asn1.ber.tlv.TLV in project directory-ldap-api by apache.
the class StoreMatchedDN method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
// Get the Value and store it in the BindResponse
TLV tlv = container.getCurrentTLV();
Dn matchedDn;
ResultCodeEnum resultCode;
ResultResponse response = (ResultResponse) container.getMessage();
LdapResult ldapResult = response.getLdapResult();
resultCode = ldapResult.getResultCode();
// Dn
if (tlv.getLength() == 0) {
matchedDn = Dn.EMPTY_DN;
} else {
switch(resultCode) {
case NO_SUCH_OBJECT:
case ALIAS_PROBLEM:
case INVALID_DN_SYNTAX:
case ALIAS_DEREFERENCING_PROBLEM:
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
matchedDn = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
// This is for the client side. We will never decode LdapResult on the server
String msg = I18n.err(I18n.ERR_04013, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
LOG.error(msg);
throw new DecoderException(I18n.err(I18n.ERR_04014, ine.getLocalizedMessage()), ine);
}
break;
default:
LOG.warn("The matched Dn should not be set when the result code is not one of NoSuchObject," + " AliasProblem, InvalidDNSyntax or AliasDreferencingProblem");
matchedDn = Dn.EMPTY_DN;
break;
}
}
if (IS_DEBUG) {
LOG.debug("The matchedDn is " + matchedDn);
}
ldapResult.setMatchedDn(matchedDn);
}
Aggregations