Search in sources :

Example 71 with Schema

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

the class SchemaEntityFactory method getMatchingRule.

/**
 * {@inheritDoc}
 * @throws LdapInvalidAttributeValueException If the MatchingRule does not exist
 * @throws LdapUnwillingToPerformException If the schema is not loaded
 */
@Override
public MatchingRule getMatchingRule(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapUnwillingToPerformException, LdapInvalidAttributeValueException {
    checkEntry(entry, SchemaConstants.MATCHING_RULE);
    // The MatchingRule OID
    String oid = getOid(entry, SchemaConstants.MATCHING_RULE, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested MatchingRule
        String msg = I18n.err(I18n.ERR_16028_CANNOT_ADD_MR, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16029_CANNOT_ADD_MR_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    MutableMatchingRule matchingRule = new MutableMatchingRule(oid);
    // The syntax field
    Attribute mSyntax = entry.get(MetaSchemaConstants.M_SYNTAX_AT);
    if (mSyntax != null) {
        matchingRule.setSyntaxOid(mSyntax.getString());
    }
    // The normalizer and comparator fields will be updated when we will
    // apply the registry
    // Common properties
    setSchemaObjectProperties(matchingRule, entry, schema);
    return matchingRule;
}
Also used : MutableMatchingRule(org.apache.directory.api.ldap.model.schema.MutableMatchingRule) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Example 72 with Schema

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

the class SchemaEntityFactory method getSyntaxChecker.

/**
 * {@inheritDoc}
 */
@Override
public SyntaxChecker getSyntaxChecker(SchemaManager schemaManager, Entry entry, Registries targetRegistries, String schemaName) throws LdapException {
    checkEntry(entry, SchemaConstants.SYNTAX_CHECKER);
    // The SyntaxChecker OID
    String oid = getOid(entry, SchemaConstants.SYNTAX_CHECKER, schemaManager.isStrict());
    // Get the schema
    if (!schemaManager.isSchemaLoaded(schemaName)) {
        // The schema is not loaded. We can't create the requested Normalizer
        String msg = I18n.err(I18n.ERR_16019_CANNOT_ADD_SC, entry.getDn().getName(), schemaName);
        LOG.warn(msg);
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, msg);
    }
    Schema schema = getSchema(schemaName, targetRegistries);
    if (schema == null) {
        // The schema is disabled. We still have to update the backend
        String msg = I18n.err(I18n.ERR_16020_CANNOT_ADD_SC_IN_REGISTRY, entry.getDn().getName(), schemaName);
        LOG.info(msg);
        schema = schemaManager.getLoadedSchema(schemaName);
    }
    // The FQCN
    String className = getFqcn(entry, SchemaConstants.SYNTAX_CHECKER);
    // The ByteCode
    Attribute byteCode = entry.get(MetaSchemaConstants.M_BYTECODE_AT);
    try {
        // Class load the syntaxChecker
        SyntaxChecker syntaxChecker = classLoadSyntaxChecker(schemaManager, oid, className, byteCode);
        // Update the common fields
        setSchemaObjectProperties(syntaxChecker, entry, schema);
        // return the resulting syntaxChecker
        return syntaxChecker;
    } catch (Exception e) {
        throw new LdapUnwillingToPerformException(ResultCodeEnum.UNWILLING_TO_PERFORM, e.getMessage(), e);
    }
}
Also used : SyntaxChecker(org.apache.directory.api.ldap.model.schema.SyntaxChecker) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) Attribute(org.apache.directory.api.ldap.model.entry.Attribute) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) LdapInvalidAttributeValueException(org.apache.directory.api.ldap.model.exception.LdapInvalidAttributeValueException) InvocationTargetException(java.lang.reflect.InvocationTargetException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 73 with Schema

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

the class SchemaManagerLoadWithDepsTest method testLoadWithDepsCoreInetOrgPersonAndNis.

/**
 * test loading the "InetOrgPerson", "core" and a disabled schema
 */
@Test
public void testLoadWithDepsCoreInetOrgPersonAndNis() throws Exception {
    LdifSchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    Schema system = loader.getSchema("system");
    Schema core = loader.getSchema("core");
    Schema empty = new DefaultSchema(loader, "empty");
    Schema cosine = loader.getSchema("cosine");
    Schema inetOrgPerson = loader.getSchema("InetOrgPerson");
    assertTrue(schemaManager.load(system, core, empty, cosine, inetOrgPerson));
    assertTrue(schemaManager.getErrors().isEmpty());
    assertEquals(142, schemaManager.getAttributeTypeRegistry().size());
    assertEquals(36, schemaManager.getComparatorRegistry().size());
    assertEquals(42, schemaManager.getMatchingRuleRegistry().size());
    assertEquals(35, schemaManager.getNormalizerRegistry().size());
    assertEquals(50, schemaManager.getObjectClassRegistry().size());
    assertEquals(59, schemaManager.getSyntaxCheckerRegistry().size());
    assertEquals(66, schemaManager.getLdapSyntaxRegistry().size());
    assertEquals(300, schemaManager.getGlobalOidRegistry().size());
    assertEquals(5, schemaManager.getRegistries().getLoadedSchemas().size());
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("system"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("core"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("cosine"));
    assertNotNull(schemaManager.getRegistries().getLoadedSchema("InetOrgPerson"));
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) SchemaManager(org.apache.directory.api.ldap.model.schema.SchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) DefaultSchemaManager(org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager) Test(org.junit.Test)

Example 74 with Schema

use of org.apache.directory.api.ldap.model.schema.registries.Schema in project cloudstack by apache.

the class EmbeddedLdapServer method addSchemaFromClasspath.

/**
 * Add additional schemas to the directory server. This uses
 * JarLdifSchemaLoader, which will search for the "ou=schema" directory
 * within "/schema" on the classpath. If packaging the schema as part of
 * a jar using Gradle or Maven, you'd probably want to put your
 * "ou=schema" directory in src/main/resources/schema.
 * <p/>
 * It's also required that a META-INF/apacheds-schema.index be present in
 * your classpath that lists each LDIF file in your schema directory.
 *
 * @param schemaName The name of the schema
 * @return true if the schemas have been loaded and the registries is
 * consistent
 */
public boolean addSchemaFromClasspath(String schemaName) throws LdapException, IOException {
    // To debug if your apacheds-schema.index isn't found:
    // Enumeration<URL> indexes = getClass().getClassLoader().getResources("META-INF/apacheds-schema.index");
    JarLdifSchemaLoader schemaLoader = new JarLdifSchemaLoader();
    Schema schema = schemaLoader.getSchema(schemaName);
    return schema != null && getDirectoryService().getSchemaManager().load(schema);
}
Also used : JarLdifSchemaLoader(org.apache.directory.api.ldap.schema.loader.JarLdifSchemaLoader) DefaultSchema(org.apache.directory.api.ldap.model.schema.registries.DefaultSchema) Schema(org.apache.directory.api.ldap.model.schema.registries.Schema)

Aggregations

Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)74 ArrayList (java.util.ArrayList)34 Entry (org.apache.directory.api.ldap.model.entry.Entry)34 DefaultSchema (org.apache.directory.api.ldap.model.schema.registries.DefaultSchema)28 LdifEntry (org.apache.directory.api.ldap.model.ldif.LdifEntry)26 LdifReader (org.apache.directory.api.ldap.model.ldif.LdifReader)25 File (java.io.File)13 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)13 SchemaObjectWrapper (org.apache.directory.api.ldap.model.schema.SchemaObjectWrapper)13 URL (java.net.URL)12 LdapUnwillingToPerformException (org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException)12 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)11 Attribute (org.apache.directory.api.ldap.model.entry.Attribute)9 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)9 Registries (org.apache.directory.api.ldap.model.schema.registries.Registries)9 AttributesFactory (org.apache.directory.api.ldap.model.schema.AttributesFactory)8 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)7 DefaultSchemaManager (org.apache.directory.api.ldap.schema.manager.impl.DefaultSchemaManager)7 Test (org.junit.Test)7 SchemaManager (org.apache.directory.api.ldap.model.schema.SchemaManager)6