org.apache.directory.shared.ldap.schema.registries.SchemaLoader Java Examples

The following examples show how to use org.apache.directory.shared.ldap.schema.registries.SchemaLoader. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: CarbonDirectoryServiceFactory.java    From carbon-identity with Apache License 2.0 5 votes vote down vote up
/**
 * Inits the schema and schema partition.
 *
 * @throws Exception If unable to extract schema files.
 */
private void initSchema()
        throws Exception {
    SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();

    // Init the LdifPartition
    LdifPartition ldifPartition = new LdifPartition();
    String workingDirectory = directoryService.getWorkingDirectory().getPath();
    ldifPartition.setWorkingDirectory(workingDirectory + File.separator + "schema");

    // Extract the schema on disk (a brand new one) and load the registries
    File schemaRepository = new File(workingDirectory, "schema");
    if (!schemaRepository.exists()) {
        SchemaLdifExtractor extractor =
                new CarbonSchemaLdifExtractor(new File(workingDirectory),
                        new File(this.schemaZipStore));
        extractor.extractOrCopy();
    }

    schemaPartition.setWrappedPartition(ldifPartition);

    SchemaLoader loader = new LdifSchemaLoader(schemaRepository);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);
    directoryService.setSchemaManager(schemaManager);

    // We have to load the schema now, otherwise we won't be able
    // to initialize the Partitions, as we won't be able to parse
    // and normalize their suffix DN
    schemaManager.loadAllEnabled();

    schemaPartition.setSchemaManager(schemaManager);

    List<Throwable> errors = schemaManager.getErrors();

    if (!errors.isEmpty()) {
        throw new DirectoryServerException(I18n.err(I18n.ERR_317, ExceptionUtils.printErrors(errors)));
    }
}
 
Example #2
Source File: EmbeddedADS.java    From vertx-auth with Apache License 2.0 5 votes vote down vote up
/**
 * initialize the schema manager and add the schema partition to diectory service
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
private void initSchemaPartition() throws Exception {
  SchemaPartition schemaPartition = service.getSchemaService().getSchemaPartition();

  // Init the LdifPartition
  LdifPartition ldifPartition = new LdifPartition();
  String workingDirectory = service.getWorkingDirectory().getPath();
  ldifPartition.setWorkingDirectory(workingDirectory + "/schema");

  // Extract the schema on disk (a brand new one) and load the registries
  File schemaRepository = new File(workingDirectory, "schema");
  SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(new File(workingDirectory));
  extractor.extractOrCopy(true);

  schemaPartition.setWrappedPartition(ldifPartition);

  SchemaLoader loader = new LdifSchemaLoader(schemaRepository);
  SchemaManager schemaManager = new DefaultSchemaManager(loader);
  service.setSchemaManager(schemaManager);

  // We have to load the schema now, otherwise we won't be able
  // to initialize the Partitions, as we won't be able to parse
  // and normalize their suffix DN
  schemaManager.loadAllEnabled();

  schemaPartition.setSchemaManager(schemaManager);

  List<Throwable> errors = schemaManager.getErrors();

  if (errors.size() != 0) {
    throw new Exception("Schema load failed : " + errors);
  }
}