use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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.codec.api.ResponseCarryingException 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.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class StoreModifyDnRequestNewSuperior 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 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);
}
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class InitSaslBind method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<BindRequestDecorator> container) throws DecoderException {
BindRequest bindRequestMessage = container.getMessage();
TLV tlv = container.getCurrentTLV();
// We will check that the sasl is not null
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04079);
LOG.error(msg);
BindResponseImpl response = new BindResponseImpl(bindRequestMessage.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_CREDENTIALS, bindRequestMessage.getDn(), null);
}
bindRequestMessage.setSimple(false);
if (IS_DEBUG) {
LOG.debug("The SaslCredential has been created");
}
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class LdapProtocolDecoder method decode.
/**
* Decode an incoming buffer into LDAP messages. The result can be 0, 1 or many
* LDAP messages, which will be stored into the array the caller has created.
*
* @param buffer The incoming byte buffer
* @param messageContainer The LdapMessageContainer which will be used to store the
* message being decoded. If the message is not fully decoded, the ucrrent state
* is stored into this container
* @param decodedMessages The list of decoded messages
* @throws Exception If the decoding failed
*/
private void decode(ByteBuffer buffer, LdapMessageContainer<MessageDecorator<? extends Message>> messageContainer, List<Message> decodedMessages) throws DecoderException {
buffer.mark();
while (buffer.hasRemaining()) {
try {
if (IS_DEBUG) {
CODEC_LOG.debug(I18n.msg(I18n.MSG_14000_DECODING_PDU));
int size = buffer.limit();
int position = buffer.position();
int pduLength = size - position;
byte[] array = new byte[pduLength];
System.arraycopy(buffer.array(), position, array, 0, pduLength);
if (array.length == 0) {
CODEC_LOG.debug(I18n.msg(I18n.MSG_14001_NULL_BUFFER));
} else {
CODEC_LOG.debug(Strings.dumpBytes(array));
}
}
asn1Decoder.decode(buffer, messageContainer);
if (messageContainer.getState() == TLVStateEnum.PDU_DECODED) {
if (IS_DEBUG) {
CODEC_LOG.debug(I18n.msg(I18n.MSG_14002_DECODED_LDAP_MESSAGE, messageContainer.getMessage()));
}
Message message = messageContainer.getMessage();
decodedMessages.add(message);
messageContainer.clean();
}
} catch (ResponseCarryingException rce) {
buffer.clear();
messageContainer.clean();
// Transform the DecoderException message to a MessageException
ResponseCarryingMessageException rcme = new ResponseCarryingMessageException(rce.getMessage(), rce);
rcme.setResponse(rce.getResponse());
throw rcme;
} catch (DecoderException de) {
buffer.clear();
messageContainer.clean();
// TODO : This is certainly not the way we should handle such an exception !
throw new ResponseCarryingException(de.getMessage(), de);
}
}
}
Aggregations