use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class LdapUrl method parseDN.
/**
* Parse a string and check that it complies with RFC 2253. Here, we will
* just call the Dn parser to do the job.
*
* @param chars The char array to be checked
* @param pos the starting position
* @return -1 if the char array does not contains a Dn
*/
private int parseDN(char[] chars, int pos) {
int end = pos;
for (int i = pos; (i < chars.length) && (chars[i] != '?'); i++) {
end++;
}
try {
String dnStr = new String(chars, pos, end - pos);
dn = new Dn(decode(dnStr));
} catch (LdapUriException | LdapInvalidDnException e) {
return -1;
}
return end;
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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);
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class StoreModifyDnRequestEntryName 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 entry;
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());
ModifyDnResponseImpl response = new ModifyDnResponseImpl(modifyDnRequest.getMessageId());
throw new ResponseCarryingException(msg, response, ResultCodeEnum.INVALID_DN_SYNTAX, Dn.EMPTY_DN, ine);
}
modifyDnRequest.setName(entry);
}
if (IS_DEBUG) {
LOG.debug("Modifying Dn {}", entry);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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);
}
}
Aggregations