Search in sources :

Example 1 with Registries

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

the class DefaultSchemaManager method enable.

/**
 * {@inheritDoc}
 */
@Override
public boolean enable(Schema... schemas) throws LdapException {
    boolean enabled = false;
    // Reset the errors if not null
    if (errors != null) {
        errors.clear();
    }
    // Work on a cloned and relaxed registries
    Registries clonedRegistries = cloneRegistries();
    clonedRegistries.setRelaxed();
    Set<Schema> disabledSchemas = new HashSet<>();
    for (Schema schema : schemas) {
        if (schema.getDependencies() != null) {
            for (String dependency : schema.getDependencies()) {
                Schema dependencySchema = schemaMap.get(dependency);
                if (dependencySchema.isDisabled()) {
                    disabledSchemas.add(dependencySchema);
                }
            }
        }
        schema.enable();
        load(clonedRegistries, schema);
    }
    // Revert back the disabled schema to disabled
    for (Schema disabledSchema : disabledSchemas) {
        if (disabledSchema.isEnabled()) {
            disabledSchema.disable();
        }
    }
    // Build the cross references
    errors = clonedRegistries.buildReferences();
    // Destroy the clonedRegistry
    clonedRegistries.clear();
    if (errors.isEmpty()) {
        // Ok no errors. Check the registries now
        errors = clonedRegistries.checkRefInteg();
        if (errors.isEmpty()) {
            // We are golden : let's apply the schemas in the real registries
            for (Schema schema : schemas) {
                schema.enable();
                load(registries, schema);
            }
            // Build the cross references
            errors = registries.buildReferences();
            registries.setStrict();
            enabled = true;
        }
    }
    // clear the cloned registries
    clonedRegistries.clear();
    return enabled;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) HashSet(java.util.HashSet)

Example 2 with Registries

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

the class DefaultSchemaManager method verify.

/**
 * {@inheritDoc}
 */
@Override
public boolean verify(Schema... schemas) throws LdapException {
    // Work on a cloned registries
    Registries clonedRegistries = cloneRegistries();
    // Loop on all the schemas
    for (Schema schema : schemas) {
        try {
            // Inject the schema
            boolean loaded = load(clonedRegistries, schema);
            if (!loaded) {
                // We got an error : exit
                clonedRegistries.clear();
                return false;
            }
            // Now, check the registries
            List<Throwable> errorList = clonedRegistries.checkRefInteg();
            if (!errorList.isEmpty()) {
                // We got an error : exit
                clonedRegistries.clear();
                return false;
            }
        } catch (Exception e) {
            // We got an error : exit
            clonedRegistries.clear();
            return false;
        }
    }
    // We can now delete the cloned registries before exiting
    clonedRegistries.clear();
    return true;
}
Also used : Schema(org.apache.directory.api.ldap.model.schema.registries.Schema) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapProtocolErrorException(org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException) LdapUnwillingToPerformException(org.apache.directory.api.ldap.model.exception.LdapUnwillingToPerformException) IOException(java.io.IOException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) LdapSchemaException(org.apache.directory.api.ldap.model.exception.LdapSchemaException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 3 with Registries

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

the class LdapNetworkConnection method addSchema.

/**
 * parses the given schema file present in OpenLDAP schema format
 * and adds all the SchemaObjects present in it to the SchemaManager
 *
 * @param schemaFile the schema file in OpenLDAP schema format
 * @throws LdapException in case of any errors while parsing
 */
public void addSchema(File schemaFile) throws LdapException {
    try {
        if (schemaManager == null) {
            loadSchema();
        }
        if (schemaManager == null) {
            throw new LdapException("Cannot load the schema");
        }
        OpenLdapSchemaParser olsp = new OpenLdapSchemaParser();
        olsp.setQuirksMode(true);
        olsp.parse(schemaFile);
        Registries registries = schemaManager.getRegistries();
        List<Throwable> errors = new ArrayList<>();
        for (AttributeType atType : olsp.getAttributeTypes()) {
            registries.buildReference(errors, atType);
            registries.getAttributeTypeRegistry().register(atType);
        }
        for (ObjectClass oc : olsp.getObjectClassTypes()) {
            registries.buildReference(errors, oc);
            registries.getObjectClassRegistry().register(oc);
        }
        LOG.info("successfully loaded the schema from file {}", schemaFile.getAbsolutePath());
    } catch (Exception e) {
        LOG.error(I18n.err(I18n.ERR_03206_FAIL_LOAD_SCHEMA_FILE, schemaFile.getAbsolutePath()));
        throw new LdapException(e);
    }
}
Also used : OpenLdapSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.OpenLdapSchemaParser) ObjectClass(org.apache.directory.api.ldap.model.schema.ObjectClass) AttributeType(org.apache.directory.api.ldap.model.schema.AttributeType) ArrayList(java.util.ArrayList) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) UnresolvedAddressException(java.nio.channels.UnresolvedAddressException) ConnectException(java.net.ConnectException) IOException(java.io.IOException) LdapInvalidDnException(org.apache.directory.api.ldap.model.exception.LdapInvalidDnException) InvalidConnectionException(org.apache.directory.ldap.client.api.exception.InvalidConnectionException) LdapOperationException(org.apache.directory.api.ldap.model.exception.LdapOperationException) LdapAuthenticationException(org.apache.directory.api.ldap.model.exception.LdapAuthenticationException) MessageEncoderException(org.apache.directory.api.ldap.codec.api.MessageEncoderException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) DecoderException(org.apache.directory.api.asn1.DecoderException) LdapNoPermissionException(org.apache.directory.api.ldap.model.exception.LdapNoPermissionException) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException) ProtocolEncoderException(org.apache.mina.filter.codec.ProtocolEncoderException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException)

Example 4 with Registries

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

the class ApiLdapModelOsgiTest method useBundleClasses.

@Override
protected void useBundleClasses() throws Exception {
    // uses FastDnParser
    new Dn("dc=example,dc=com");
    // uses ComplexDnparser (antlr based)
    new Dn("cn=a+sn=b,dc=example,dc=com");
    new Value("foo");
    new DefaultAttribute("cn");
    new DefaultEntry();
    AttributeUtils.toJndiAttribute(new DefaultAttribute("cn"));
    new BindRequestImpl();
    new EqualityNode<String>("cn", "foo");
    new LdapUrl("ldap://ldap.example.com:10389/dc=example,dc=com?objectclass");
    new ObjectClassDescriptionSchemaParser().parse("( 2.5.6.0 NAME 'top' DESC 'top of the superclass chain' ABSTRACT MUST objectClass )");
    SchemaObject schemaObject = new LdapSyntax("1.2.3");
    new Registries().getGlobalOidRegistry().register(schemaObject);
    new Registries().getLoadedSchemas();
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) SchemaObject(org.apache.directory.api.ldap.model.schema.SchemaObject) ObjectClassDescriptionSchemaParser(org.apache.directory.api.ldap.model.schema.parsers.ObjectClassDescriptionSchemaParser) Value(org.apache.directory.api.ldap.model.entry.Value) DefaultEntry(org.apache.directory.api.ldap.model.entry.DefaultEntry) LdapSyntax(org.apache.directory.api.ldap.model.schema.LdapSyntax) Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) Dn(org.apache.directory.api.ldap.model.name.Dn) DefaultAttribute(org.apache.directory.api.ldap.model.entry.DefaultAttribute) EqualityNode(org.apache.directory.api.ldap.model.filter.EqualityNode) BindRequestImpl(org.apache.directory.api.ldap.model.message.BindRequestImpl)

Example 5 with Registries

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

the class DefaultSchemaManager method cloneRegistries.

// -----------------------------------------------------------------------
// Helper methods
// -----------------------------------------------------------------------
/**
 * Clone the registries before doing any modification on it. Relax it
 * too so that we can update it.
 */
private Registries cloneRegistries() throws LdapException {
    try {
        // Relax the controls at first
        errors = new ArrayList<>();
        // Clone the Registries
        Registries clonedRegistries = registries.clone();
        // And update references. We may have errors, that may be fixed
        // by the new loaded schemas.
        errors = clonedRegistries.checkRefInteg();
        // Now, relax the cloned Registries if there is no error
        clonedRegistries.setRelaxed();
        return clonedRegistries;
    } catch (CloneNotSupportedException cnse) {
        throw new LdapOtherException(cnse.getMessage(), cnse);
    }
}
Also used : Registries(org.apache.directory.api.ldap.model.schema.registries.Registries) LdapOtherException(org.apache.directory.api.ldap.model.exception.LdapOtherException)

Aggregations

Registries (org.apache.directory.api.ldap.model.schema.registries.Registries)12 Schema (org.apache.directory.api.ldap.model.schema.registries.Schema)9 LdapOtherException (org.apache.directory.api.ldap.model.exception.LdapOtherException)5 LdapProtocolErrorException (org.apache.directory.api.ldap.model.exception.LdapProtocolErrorException)3 SchemaObject (org.apache.directory.api.ldap.model.schema.SchemaObject)3 IOException (java.io.IOException)2 LdapException (org.apache.directory.api.ldap.model.exception.LdapException)2 LdapSchemaException (org.apache.directory.api.ldap.model.exception.LdapSchemaException)2 LoadableSchemaObject (org.apache.directory.api.ldap.model.schema.LoadableSchemaObject)2 ConnectException (java.net.ConnectException)1 UnresolvedAddressException (java.nio.channels.UnresolvedAddressException)1 ArrayList (java.util.ArrayList)1 HashSet (java.util.HashSet)1 DecoderException (org.apache.directory.api.asn1.DecoderException)1 MessageEncoderException (org.apache.directory.api.ldap.codec.api.MessageEncoderException)1 CursorException (org.apache.directory.api.ldap.model.cursor.CursorException)1 DefaultAttribute (org.apache.directory.api.ldap.model.entry.DefaultAttribute)1 DefaultEntry (org.apache.directory.api.ldap.model.entry.DefaultEntry)1 Value (org.apache.directory.api.ldap.model.entry.Value)1 LdapAuthenticationException (org.apache.directory.api.ldap.model.exception.LdapAuthenticationException)1