use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-fortress-core by apache.
the class OrgUnitDAO method getDn.
/**
* Creates a new Dn for the given orgUnit
*
* @param orgUnit The orgUnit
* @return A Dn
* @throws LdapInvalidDnException If the DN is invalid
*/
private Dn getDn(OrgUnit orgUnit) {
Dn dn = null;
try {
switch(orgUnit.type) {
case USER:
dn = new Dn(SchemaConstants.OU_AT + "=" + orgUnit.getName(), getRootDn(orgUnit.getContextId(), GlobalIds.OSU_ROOT));
break;
case PERM:
dn = new Dn(SchemaConstants.OU_AT + "=" + orgUnit.getName(), getRootDn(orgUnit.getContextId(), GlobalIds.PSU_ROOT));
break;
default:
String warning = "getDn invalid type";
LOG.warn(warning);
break;
}
return dn;
} catch (LdapInvalidDnException lide) {
LOG.error(lide.getMessage());
throw new RuntimeException(lide.getMessage());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class StoreSearchResultEntryObjectName method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<SearchResultEntryDecorator> container) throws DecoderException {
SearchResultEntryDecorator searchResultEntry = container.getMessage();
TLV tlv = container.getCurrentTLV();
Dn objectName = Dn.EMPTY_DN;
// Store the value.
if (tlv.getLength() == 0) {
searchResultEntry.setObjectName(objectName);
} else {
byte[] dnBytes = tlv.getValue().getData();
String dnStr = Strings.utf8ToString(dnBytes);
try {
objectName = new Dn(dnStr);
} catch (LdapInvalidDnException ine) {
// This is for the client side. We will never decode LdapResult on the server
String msg = "The Dn " + Strings.dumpBytes(dnBytes) + "is invalid : " + ine.getMessage();
LOG.error("{} : {}", msg, ine.getMessage());
throw new DecoderException(msg, ine);
}
searchResultEntry.setObjectName(objectName);
}
if (IS_DEBUG) {
LOG.debug("Search Result Entry Dn found : {}", searchResultEntry.getObjectName());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class UniqueMemberComparator method compare.
/**
* {@inheritDoc}
*/
public int compare(String dnstr1, String dnstr2) {
int dash1 = dnstr1.lastIndexOf('#');
int dash2 = dnstr2.lastIndexOf('#');
if ((dash1 == -1) && (dash2 == -1)) {
// no UID part
try {
Dn dn1 = getDn(dnstr1);
Dn dn2 = getDn(dnstr2);
if (dn1.equals(dn2)) {
return 0;
} else {
return -1;
}
} catch (LdapInvalidDnException ne) {
return -1;
}
} else {
// Now, check that we don't have another '#'
if (dnstr1.indexOf('#') != dash1) {
// escaped.
return -1;
}
if (dnstr2.indexOf('#') != dash1) {
// escaped.
return 1;
}
Dn dn1;
Dn dn2;
// This is an UID if the '#' is immediatly
// followed by a BitString, except if the '#' is
// on the last position
String uid1 = dnstr1.substring(dash1 + 1);
if (dash1 > 0) {
try {
dn1 = new Dn(dnstr1.substring(0, dash1));
} catch (LdapException ne) {
return -1;
}
} else {
return -1;
}
// This is an UID if the '#' is immediatly
// followed by a BitString, except if the '#' is
// on the last position
String uid2 = dnstr2.substring(dash2 + 1);
if (dash2 > 0) {
try {
dn2 = new Dn(dnstr1.substring(0, dash2));
} catch (LdapException ne) {
return 1;
}
} else {
return 1;
}
if (dn1.equals(dn2)) {
return uid1.compareTo(uid2);
}
return -1;
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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());
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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);
}
}
Aggregations