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;
}
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);
}
}
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"));
}
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);
}
Aggregations