Search in sources :

Example 66 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class DefaultSchemaLoader method loadMatchingRuleUses.

private void loadMatchingRuleUses(Attribute matchingRuleUses) throws LdapException {
    if (matchingRuleUses == null) {
        return;
    }
    for (Value value : matchingRuleUses) {
        String desc = value.getValue();
        try {
            MatchingRuleUse matchingRuleUse = MRU_DESCR_SCHEMA_PARSER.parseMatchingRuleUseDescription(desc);
            updateSchemas(matchingRuleUse);
        } catch (ParseException pe) {
            throw new LdapException(pe);
        }
    }
}
Also used : MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) Value(org.apache.directory.api.ldap.model.entry.Value) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 67 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class BinaryValueTest method initAT.

/**
 * Initialize an AttributeType and the associated MatchingRule
 * and Syntax
 */
@Before
public void initAT() {
    s = EntryUtils.syntaxFactory("1.1.1.1", false);
    s.setSyntaxChecker(OctetStringSyntaxChecker.INSTANCE);
    mr = EntryUtils.matchingRuleFactory("1.1.2.1");
    mr.setSyntax(s);
    mr.setLdapComparator(new ByteArrayComparator("1.1.1"));
    mr.setNormalizer(new Normalizer("1.1.1") {

        public static final long serialVersionUID = 1L;

        public String normalize(String value) throws LdapException {
            return normalize(value, PrepareString.AssertionType.ATTRIBUTE_VALUE);
        }

        public String normalize(String value, PrepareString.AssertionType assertionType) throws LdapException {
            byte[] val = Strings.getBytesUtf8(value);
            // each byte will be changed to be > 0, and spaces will be trimmed
            byte[] newVal = new byte[val.length];
            int i = 0;
            for (byte b : val) {
                newVal[i++] = (byte) (b & 0x007F);
            }
            return Strings.utf8ToString(Strings.trim(newVal));
        }
    });
    at = new MutableAttributeType("1.1.3.1");
    at.setEquality(mr);
    at.setOrdering(mr);
    at.setSubstring(mr);
    at.setSyntax(s);
}
Also used : PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) PrepareString(org.apache.directory.api.ldap.model.schema.PrepareString) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) ByteArrayComparator(org.apache.directory.api.ldap.model.schema.comparators.ByteArrayComparator) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Before(org.junit.Before)

Example 68 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class ExtendedResponseImplTest method testEqualsDiffImpl.

/**
 * Tests for equality using different stub implementations.
 */
@Test
public void testEqualsDiffImpl() {
    ExtendedResponseImpl resp0 = createStub();
    ExtendedResponse resp1 = new ExtendedResponse() {

        public String getResponseName() {
            return "1.1.1.1";
        }

        public void setResponseName(String oid) {
        }

        public LdapResult getLdapResult() {
            LdapResultImpl result = new LdapResultImpl();
            try {
                result.setMatchedDn(new Dn("dc=example,dc=com"));
            } catch (LdapException ine) {
            // do nothing
            }
            result.setResultCode(ResultCodeEnum.SUCCESS);
            ReferralImpl refs = new ReferralImpl();
            refs.addLdapUrl("ldap://someserver.com");
            refs.addLdapUrl("ldap://apache.org");
            refs.addLdapUrl("ldap://another.net");
            result.setReferral(refs);
            return result;
        }

        public MessageTypeEnum getType() {
            return MessageTypeEnum.EXTENDED_RESPONSE;
        }

        public Map<String, Control> getControls() {
            return EMPTY_CONTROL_MAP;
        }

        public ExtendedResponse addControl(Control control) {
            return this;
        }

        public ExtendedResponse removeControl(Control control) {
            return this;
        }

        public int getMessageId() {
            return 45;
        }

        public Object get(Object a_key) {
            return null;
        }

        public Object put(Object a_key, Object a_value) {
            return null;
        }

        public ExtendedResponse addAllControls(Control[] controls) {
            return this;
        }

        public boolean hasControl(String oid) {
            return false;
        }

        public Control getControl(String oid) {
            return null;
        }

        public ExtendedResponse setMessageId(int messageId) {
            return this;
        }
    };
    assertTrue(resp0.equals(resp1));
    assertFalse(resp1.equals(resp0));
}
Also used : Dn(org.apache.directory.api.ldap.model.name.Dn) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) Test(org.junit.Test)

Example 69 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class ModifyDnRequestImplTest method getRequest.

/**
 * Constructs a ModifyDnrequest to test.
 *
 * @return the request
 */
private ModifyDnRequestImpl getRequest() {
    // Construct the ModifyDn request to test
    ModifyDnRequestImpl request = new ModifyDnRequestImpl();
    request.setMessageId(45);
    request.setDeleteOldRdn(true);
    try {
        request.setName(new Dn("dc=admins,dc=apache,dc=org"));
        request.setNewRdn(new Rdn("dc=administrators"));
        request.setNewSuperior(new Dn("dc=groups,dc=apache,dc=org"));
    } catch (LdapException ine) {
    // do nothing
    }
    return request;
}
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)

Example 70 with LdapException

use of org.apache.directory.api.ldap.model.exception.LdapException in project directory-ldap-api by apache.

the class ObjectClassHelper method buildSuperiors.

/**
 * Build the references to this ObjectClass SUPERIORS, checking that the type
 * hierarchy is correct.
 */
private static void buildSuperiors(ObjectClass objectClass, List<Throwable> errors, Registries registries) {
    ObjectClassRegistry ocRegistry = registries.getObjectClassRegistry();
    List<String> superiorOids = objectClass.getSuperiorOids();
    if (superiorOids != null) {
        objectClass.getSuperiors().clear();
        for (String superiorName : superiorOids) {
            try {
                ObjectClass superior = ocRegistry.lookup(ocRegistry.getOidByName(superiorName));
                // Before adding the superior, check that the ObjectClass type is consistent
                switch(objectClass.getType()) {
                    case ABSTRACT:
                        if (superior.getType() != ObjectClassTypeEnum.ABSTRACT) {
                            // An ABSTRACT OC can only inherit from ABSTRACT OCs
                            String msg = I18n.err(I18n.ERR_13766_ABSTRACT_OC_CANNOT_INHERIT_FROM_OC, objectClass.getOid(), superior.getObjectType(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_ABSTRACT_MUST_INHERIT_FROM_ABSTRACT_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    case AUXILIARY:
                        if (superior.getType() == ObjectClassTypeEnum.STRUCTURAL) {
                            // An AUXILIARY OC cannot inherit from STRUCTURAL OCs
                            String msg = I18n.err(I18n.ERR_13767_AUX_OC_CANNOT_INHERIT_FROM_STRUCT_OC, objectClass.getOid(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_AUXILIARY_CANNOT_INHERIT_FROM_STRUCTURAL_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    case STRUCTURAL:
                        if (superior.getType() == ObjectClassTypeEnum.AUXILIARY) {
                            // A STRUCTURAL OC cannot inherit from AUXILIARY OCs
                            String msg = I18n.err(I18n.ERR_13768_STRUCT_OC_CANNOT_INHERIT_FROM_AUX_OC, objectClass.getOid(), superior);
                            LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_STRUCTURAL_CANNOT_INHERIT_FROM_AUXILIARY_OC, msg);
                            ldapSchemaException.setSourceObject(objectClass);
                            errors.add(ldapSchemaException);
                            LOG.info(msg);
                            continue;
                        }
                        break;
                    default:
                        throw new IllegalArgumentException(I18n.err(I18n.ERR_13717_UNEXPECTED_OBJECT_CLASS_TYPE_ENUM, objectClass.getType()));
                }
                objectClass.getSuperiors().add(superior);
            } catch (LdapException ne) {
                // Cannot find the OC
                String msg = I18n.err(I18n.ERR_13769_CANNOT_REGISTER_SUPERIOR_MISSING, objectClass.getOid(), superiorName);
                LdapSchemaException ldapSchemaException = new LdapSchemaException(LdapSchemaExceptionCodes.OC_NONEXISTENT_SUPERIOR, msg, ne);
                ldapSchemaException.setSourceObject(objectClass);
                ldapSchemaException.setRelatedId(superiorName);
                errors.add(ldapSchemaException);
                LOG.info(msg);
                return;
            }
        }
    }
}
Also used : ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) ObjectClassRegistry(org.apache.directory.api.ldap.model.schema.registries.ObjectClassRegistry) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Aggregations

LdapException (org.apache.directory.api.ldap.model.exception.LdapException)361 LdapConnection (org.apache.directory.ldap.client.api.LdapConnection)161 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)111 ArrayList (java.util.ArrayList)94 FinderException (org.apache.directory.fortress.core.FinderException)73 Modification (org.apache.directory.api.ldap.model.entry.Modification)70 Entry (org.apache.directory.api.ldap.model.entry.Entry)68 IOException (java.io.IOException)57 DefaultModification (org.apache.directory.api.ldap.model.entry.DefaultModification)57 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)53 SearchCursor (org.apache.directory.api.ldap.model.cursor.SearchCursor)51 UpdateException (org.apache.directory.fortress.core.UpdateException)41 LdapInvalidDnException (org.apache.directory.api.ldap.model.exception.LdapInvalidDnException)35 Dn (org.apache.directory.api.ldap.model.name.Dn)34 SEPASecurityException (it.unibo.arces.wot.sepa.commons.exceptions.SEPASecurityException)29 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)25 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)25 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)23 DecoderException (org.apache.directory.api.asn1.DecoderException)22 LdapNoPermissionException (org.apache.directory.api.ldap.model.exception.LdapNoPermissionException)22