use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException 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.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class StoreSearchRequestBaseObject method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchRequestDecorator> container) throws DecoderException {
SearchRequestDecorator searchRequestDecorator = container.getMessage();
SearchRequest searchRequest = searchRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
// We have to check that this is a correct Dn
Dn baseObject;
// root.
if (tlv.getLength() != 0) {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
baseObject = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid root Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
SearchResultDoneImpl response = new SearchResultDoneImpl(searchRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
} else {
baseObject = Dn.EMPTY_DN;
}
searchRequest.setBase(baseObject);
LOG.debug("Searching with root Dn : {}", baseObject);
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class InitDelRequest method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<DeleteRequestDecorator> container) throws DecoderException {
// Create the DeleteRequest LdapMessage instance and store it in the container
DeleteRequest internaldelRequest = new DeleteRequestImpl();
internaldelRequest.setMessageId(container.getMessageId());
DeleteRequestDecorator delRequest = new DeleteRequestDecorator(container.getLdapCodecService(), internaldelRequest);
container.setMessage(delRequest);
// And store the Dn into it
// Get the Value and store it in the DelRequest
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_04073));
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
entry = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = I18n.err(I18n.ERR_04074, dnStr, Strings.dumpBytes(dnBytes), ine.getLocalizedMessage());
LOG.error(msg);
DeleteResponseImpl response = new DeleteResponseImpl(delRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
delRequest.setName(entry);
}
// We can have an END transition
container.setGrammarEndAllowed(true);
if (IS_DEBUG) {
LOG.debug("Deleting Dn {}", entry);
}
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class AddModifyRequestAttribute method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
// Store the value. It can't be null
String type;
if (tlv.getLength() == 0) {
String msg = I18n.err(I18n.ERR_04083);
LOG.error(msg);
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, modifyRequest.getName(), null);
} else {
type = Strings.utf8ToString(tlv.getValue().getData());
modifyRequestDecorator.addAttributeTypeAndValues(type);
}
if (IS_DEBUG) {
LOG.debug("Modifying type : {}", type);
}
}
use of org.apache.directory.api.ldap.codec.api.ResponseCarryingException in project directory-ldap-api by apache.
the class StoreModifyRequestObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<ModifyRequestDecorator> container) throws DecoderException {
ModifyRequestDecorator modifyRequestDecorator = container.getMessage();
ModifyRequest modifyRequest = modifyRequestDecorator.getDecorated();
TLV tlv = container.getCurrentTLV();
Dn object = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
(modifyRequestDecorator.getDecorated()).setName(object);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
object = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
String msg = "Invalid Dn given : " + dnStr + " (" + Strings.dumpBytes(dnBytes) + ") is invalid";
LOG.error("{} : {}", msg, ine.getMessage());
ModifyResponseImpl response = new ModifyResponseImpl(modifyRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyRequest.setName(object);
}
if (IS_DEBUG) {
LOG.debug("Modification of Dn {}", modifyRequest.getName());
}
}
Aggregations