Search in sources :

Example 21 with LdapInvalidDnException

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);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) Dn(org.apache.directory.api.ldap.model.name.Dn) ModifyDnResponseImpl(org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl) ModifyDnRequest(org.apache.directory.api.ldap.model.message.ModifyDnRequest) TLV(org.apache.directory.api.asn1.ber.tlv.TLV) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 22 with LdapInvalidDnException

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();
    }
}
Also used : AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) Value(org.apache.directory.api.ldap.model.entry.Value) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 23 with LdapInvalidDnException

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);
    }
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 24 with LdapInvalidDnException

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);
    }
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) Rdn(org.apache.directory.api.ldap.model.name.Rdn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Example 25 with LdapInvalidDnException

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);
    }
}
Also used : DeleteResponse(org.apache.directory.api.ldap.model.message.DeleteResponse) DeleteRequestImpl(org.apache.directory.api.ldap.model.message.DeleteRequestImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) OpaqueControl(org.apache.directory.api.ldap.model.message.controls.OpaqueControl) DeleteRequest(org.apache.directory.api.ldap.model.message.DeleteRequest) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)

Aggregations

LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)25 Dn (org.apache.directory.api.ldap.model.name.Dn)18 TLV (org.apache.directory.api.asn1.ber.tlv.TLV)10 ResponseCarryingException (org.apache.directory.api.ldap.codec.api.ResponseCarryingException)8 DecoderException (org.apache.directory.api.asn1.DecoderException)6 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)5 Rdn (org.apache.directory.api.ldap.model.name.Rdn)4 Value (org.apache.directory.api.ldap.model.entry.Value)3 ModifyDnRequest (org.apache.directory.api.ldap.model.message.ModifyDnRequest)3 ModifyDnResponseImpl (org.apache.directory.api.ldap.model.message.ModifyDnResponseImpl)3 LdapInvalidAttributeValueException (org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException)2 Control (org.apache.directory.api.ldap.model.message.Control)2 Ava (org.apache.directory.api.ldap.model.name.Ava)2 IOException (java.io.IOException)1 Field (java.lang.reflect.Field)1 ParseException (java.text.ParseException)1 SimpleDateFormat (java.text.SimpleDateFormat)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1