Search in sources :

Example 1 with LdapInvalidDnException

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

Example 2 with LdapInvalidDnException

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

Example 3 with LdapInvalidDnException

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

Example 4 with LdapInvalidDnException

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);
    }
}
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 5 with LdapInvalidDnException

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