use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException 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.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class Ava method apply.
/**
* Apply a SchemaManager to the Ava. It will normalize the Ava.<br/>
* If the Ava already had a SchemaManager, then the new SchemaManager will be
* used instead.
*
* @param schemaManager The SchemaManager instance to use
* @throws LdapInvalidDnException If the Ava can't be normalized accordingly
* to the given SchemaManager
*/
private void apply(SchemaManager schemaManager) throws LdapInvalidDnException {
if (schemaManager != null) {
this.schemaManager = schemaManager;
AttributeType tmpAttributeType = null;
try {
tmpAttributeType = schemaManager.lookupAttributeTypeRegistry(normType);
} catch (LdapException le) {
if (schemaManager.isRelaxed()) {
// No attribute in the schema, but the schema is relaxed : get out
return;
} else {
String message = I18n.err(I18n.ERR_13600_TYPE_IS_NULL_OR_EMPTY);
LOG.error(message);
throw new LdapInvalidDnException(ResultCodeEnum.INVALID_DN_SYNTAX, message, le);
}
}
if (this.attributeType == tmpAttributeType) {
// No need to normalize again
return;
} else {
this.attributeType = tmpAttributeType;
}
try {
value = new Value(tmpAttributeType, value);
} catch (LdapException le) {
String message = I18n.err(I18n.ERR_13600_TYPE_IS_NULL_OR_EMPTY);
LOG.error(message);
throw new LdapInvalidDnException(ResultCodeEnum.INVALID_DN_SYNTAX, message, le);
}
hashCode();
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class LdapNetworkConnection method move.
/**
* {@inheritDoc}
*/
@Override
public void move(String entryDn, String newSuperiorDn) throws LdapException {
if (entryDn == null) {
String msg = "Cannot process a move of a null Dn";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
if (newSuperiorDn == null) {
String msg = "Cannot process a move to a null newSuperior";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
try {
move(new Dn(entryDn), new Dn(newSuperiorDn));
} catch (LdapInvalidDnException e) {
LOG.error(e.getMessage(), e);
throw new LdapException(e.getMessage(), e);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class LdapNetworkConnection method rename.
/**
* {@inheritDoc}
*/
@Override
public void rename(String entryDn, String newRdn, boolean deleteOldRdn) throws LdapException {
if (entryDn == null) {
String msg = "Cannot process a rename of a null Dn";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
if (newRdn == null) {
String msg = "Cannot process a rename with a null Rdn";
LOG.debug(msg);
throw new IllegalArgumentException(msg);
}
try {
rename(new Dn(entryDn), new Rdn(newRdn), deleteOldRdn);
} catch (LdapInvalidDnException e) {
LOG.error(e.getMessage(), e);
throw new LdapException(e.getMessage(), e);
}
}
use of org.apache.directory.api.ldap.model.exception.LdapInvalidDnException in project directory-ldap-api by apache.
the class LdapNetworkConnection method deleteTree.
/**
* deletes the entry with the given Dn, and all its children
*
* @param dn the target entry's Dn as a String
* @throws LdapException If the Dn is not valid or if the deletion failed
*/
public void deleteTree(String dn) throws LdapException {
try {
String treeDeleteOid = "1.2.840.113556.1.4.805";
Dn newDn = new Dn(dn);
if (isControlSupported(treeDeleteOid)) {
DeleteRequest deleteRequest = new DeleteRequestImpl();
deleteRequest.setName(newDn);
deleteRequest.addControl(new OpaqueControl(treeDeleteOid));
DeleteResponse deleteResponse = delete(deleteRequest);
processResponse(deleteResponse);
} else {
String msg = "The subtreeDelete control (1.2.840.113556.1.4.805) is not supported by the server\n" + " The deletion has been aborted";
LOG.error(msg);
throw new LdapException(msg);
}
} catch (LdapInvalidDnException e) {
LOG.error(e.getMessage(), e);
throw new LdapException(e.getMessage(), e);
}
}
Aggregations