Search in sources :

Example 1 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class DefaultSchemaLoader method loadNameForms.

private void loadNameForms(Attribute nameForms) throws LdapException {
    if (nameForms == null) {
        return;
    }
    for (Value value : nameForms) {
        String desc = value.getValue();
        try {
            NameForm nameForm = NF_DESCR_SCHEMA_PARSER.parseNameFormDescription(desc);
            updateSchemas(nameForm);
        } catch (ParseException pe) {
            throw new LdapException(pe);
        }
    }
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Value(org.apache.directory.api.ldap.model.entry.Value) ParseException(java.text.ParseException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 2 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class DefaultSchemaLoader method loadNameForms.

/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadNameForms(Schema... schemas) throws LdapException, IOException {
    List<Entry> nameFormEntries = new ArrayList<>();
    if (schemas == null) {
        return nameFormEntries;
    }
    AttributesFactory factory = new AttributesFactory();
    for (Schema schema : schemas) {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();
        for (SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers) {
            SchemaObject schemaObject = schemaObjectWrapper.get();
            if (schemaObject instanceof NameForm) {
                NameForm nameForm = (NameForm) schemaObject;
                Entry nameFormEntry = factory.convert(nameForm, schema, null);
                nameFormEntries.add(nameFormEntry);
            }
        }
    }
    return nameFormEntries;
}
Also used : SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) Entry(org.apache.directory.api.ldap.model.entry.Entry) AttributesFactory(org.apache.directory.api.ldap.model.schema.AttributesFactory) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) ArrayList(java.util.ArrayList) SchemaObjectWrapper(org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)

Example 3 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class Registries method unregister.

/**
 * Unregister a SchemaObject from the registries
 *
 * @param schemaObject The SchemaObject we want to deregister
 * @throws LdapException If the removal failed
 */
private SchemaObject unregister(List<Throwable> errors, SchemaObject schemaObject) throws LdapException {
    LOG.debug("Unregistering {}:{}", schemaObject.getObjectType(), schemaObject.getOid());
    // Check that the SchemaObject is present in the registries
    if (!(schemaObject instanceof LoadableSchemaObject) && !globalOidRegistry.contains(schemaObject.getOid())) {
        String msg = I18n.err(I18n.ERR_13751_UNREGISTERING_FAILED_NOT_PRESENT, schemaObject.getObjectType(), schemaObject.getOid());
        LOG.error(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    SchemaObject unregistered;
    // First call the specific registry's register method
    switch(schemaObject.getObjectType()) {
        case ATTRIBUTE_TYPE:
            unregistered = attributeTypeRegistry.unregister((AttributeType) schemaObject);
            break;
        case COMPARATOR:
            unregistered = comparatorRegistry.unregister((LdapComparator<?>) schemaObject);
            break;
        case DIT_CONTENT_RULE:
            unregistered = ditContentRuleRegistry.unregister((DitContentRule) schemaObject);
            break;
        case DIT_STRUCTURE_RULE:
            unregistered = ditStructureRuleRegistry.unregister((DitStructureRule) schemaObject);
            break;
        case LDAP_SYNTAX:
            unregistered = ldapSyntaxRegistry.unregister((LdapSyntax) schemaObject);
            break;
        case MATCHING_RULE:
            unregistered = matchingRuleRegistry.unregister((MatchingRule) schemaObject);
            break;
        case MATCHING_RULE_USE:
            unregistered = matchingRuleUseRegistry.unregister((MatchingRuleUse) schemaObject);
            break;
        case NAME_FORM:
            unregistered = nameFormRegistry.unregister((NameForm) schemaObject);
            break;
        case NORMALIZER:
            unregistered = normalizerRegistry.unregister((Normalizer) schemaObject);
            break;
        case OBJECT_CLASS:
            unregistered = objectClassRegistry.unregister((ObjectClass) schemaObject);
            break;
        case SYNTAX_CHECKER:
            unregistered = syntaxCheckerRegistry.unregister((SyntaxChecker) schemaObject);
            break;
        default:
            throw new IllegalArgumentException(I18n.err(I18n.ERR_13718_UNEXPECTED_SCHEMA_OBJECT_TYPE, schemaObject.getObjectType()));
    }
    return unregistered;
}
Also used : LdapComparator(org.apache.directory.api.ldap.model.schema.LdapComparator) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) MatchingRuleUse(org.apache.directory.api.ldap.model.schema.MatchingRuleUse) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) NameForm(org.apache.directory.api.ldap.model.schema.NameForm) Normalizer(org.apache.directory.api.ldap.model.schema.Normalizer) LoadableSchemaObject(org.apache.directory.api.ldap.model.schema.LoadableSchemaObject) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) MutableAttributeType(org.apache.directory.api.ldap.model.schema.MutableAttributeType) DitStructureRule(org.apache.directory.api.ldap.model.schema.DitStructureRule) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) DitContentRule(org.apache.directory.api.ldap.model.schema.DitContentRule) MatchingRule(org.apache.directory.api.ldap.model.schema.MatchingRule) MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule)

Example 4 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class NameFormDescriptionSchemaParserTest method testMay.

/**
 * Test MAY and its values.
 *
 * @throws ParseException
 */
@Test
public void testMay() throws ParseException, LdapException {
    String value = null;
    NameForm nf = null;
    // no MAY
    value = "( 1.1 OC o MUST m )";
    nf = parser.parseNameFormDescription(value);
    assertEquals(0, nf.getMayAttributeTypeOids().size());
    // MAY simple numericoid
    value = "( 1.1 OC o MUST m MAY 1.2.3 )";
    nf = parser.parseNameFormDescription(value);
    assertEquals(1, nf.getMayAttributeTypeOids().size());
    assertEquals("1.2.3", nf.getMayAttributeTypeOids().get(0));
    // MAY mulitple
    value = "(1.1 OC o MUST m MAY (cn$sn       $11.22.33.44.55         $  objectClass   ))";
    nf = parser.parseNameFormDescription(value);
    assertEquals(4, nf.getMayAttributeTypeOids().size());
    assertEquals("cn", nf.getMayAttributeTypeOids().get(0));
    assertEquals("sn", nf.getMayAttributeTypeOids().get(1));
    assertEquals("11.22.33.44.55", nf.getMayAttributeTypeOids().get(2));
    assertEquals("objectClass", nf.getMayAttributeTypeOids().get(3));
    // MAY must only appear once
    value = "( 1.1 OC o MUST m MAY test1 MAY test2 )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, MAY appears twice");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // invalid value
        value = "( 1.1 OC o MUST m MAY ( c_n ) )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, invalid value c_n");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 5 with NameForm

use of org.apache.directory.api.ldap.model.schema.NameForm in project directory-ldap-api by apache.

the class NameFormDescriptionSchemaParserTest method testOc.

/**
 * Test OC and its value.
 *
 * @throws ParseException
 */
@Test
public void testOc() throws ParseException, LdapException {
    String value = null;
    NameForm nf = null;
    // numeric oid
    value = "( 1.1 MUST m OC 1.2.3.4.5.6.7.8.9.0 )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", nf.getStructuralObjectClassOid());
    // numeric oid
    value = "(   1.1 MUST m   OC    123.4567.890    )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("123.4567.890", nf.getStructuralObjectClassOid());
    // descr
    value = "( 1.1 MUST m OC abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789 )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("abcdefghijklmnopqrstuvwxyz-ABCDEFGHIJKLMNOPQRSTUVWXYZ-0123456789", nf.getStructuralObjectClassOid());
    // quoted value
    value = "( 1.1 MUST m OC '1.2.3.4.5.6.7.8.9.0' )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("1.2.3.4.5.6.7.8.9.0", nf.getStructuralObjectClassOid());
    // quoted value
    value = "( 1.1 MUST m OC 'test' )";
    nf = parser.parseNameFormDescription(value);
    assertEquals("test", nf.getStructuralObjectClassOid());
    // invalid character
    value = "( 1.1 MUST m OC 1.2.3.4.A )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, invalid OC 1.2.3.4.A (invalid character)");
    } catch (ParseException pe) {
    // expected
    }
    // no multi value allowed
    value = "( 1.1 MUST m OC ( test1 test2 ) )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, OC must be single valued");
    } catch (ParseException pe) {
    // expected
    }
    // OC must only appear once
    value = "( 1.1 MUST m OC test1 OC test2 )";
    try {
        nf = parser.parseNameFormDescription(value);
        fail("Exception expected, OC appears twice");
    } catch (ParseException pe) {
    // expected
    }
    if (!parser.isQuirksMode()) {
        // OC is required
        value = "( 1.1 MUST m )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, OC is required");
        } catch (ParseException pe) {
        // expected
        }
        // invalid start
        value = "( 1.1 MUST m OC -test ) )";
        try {
            nf = parser.parseNameFormDescription(value);
            fail("Exception expected, invalid OC '-test' (starts with hypen)");
        } catch (ParseException pe) {
        // expected
        }
    }
}
Also used : NameForm(org.apache.directory.api.ldap.model.schema.NameForm) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

NameForm (org.apache.directory.api.ldap.model.schema.NameForm)9 ParseException (java.text.ParseException)5 Test (org.junit.Test)5 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 AttributeType (org.apache.directory.api.ldap.model.schema.AttributeType)2 DitContentRule (org.apache.directory.api.ldap.model.schema.DitContentRule)2 DitStructureRule (org.apache.directory.api.ldap.model.schema.DitStructureRule)2 LdapSyntax (org.apache.directory.api.ldap.model.schema.LdapSyntax)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 MatchingRule (org.apache.directory.api.ldap.model.schema.MatchingRule)2 MatchingRuleUse (org.apache.directory.api.ldap.model.schema.MatchingRuleUse)2 MutableAttributeType (org.apache.directory.api.ldap.model.schema.MutableAttributeType)2 MutableMatchingRule (org.apache.directory.api.ldap.model.schema.MutableMatchingRule)2 ObjectClass (org.apache.directory.api.ldap.model.schema.ObjectClass)2 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)2 ArrayList (java.util.ArrayList)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1