Search in sources :

Example 16 with LdapInvalidDnException

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

Example 17 with LdapInvalidDnException

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

Example 18 with LdapInvalidDnException

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

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

Example 20 with LdapInvalidDnException

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);
    }
}
Also used : DecoderException(org.apache.directory.api.asn1.DecoderException) CompareRequest(org.apache.directory.api.ldap.model.message.CompareRequest) ResponseCarryingException(org.apache.directory.api.ldap.codec.api.ResponseCarryingException) CompareResponseImpl(org.apache.directory.api.ldap.model.message.CompareResponseImpl) Dn(org.apache.directory.api.ldap.model.name.Dn) 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