org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor Java Examples

The following examples show how to use org.apache.directory.api.ldap.schema.extractor.SchemaLdifExtractor. 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: SchemaManagerLoadTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    workingDirectory = System.getProperty( "workingDirectory" );

    if ( workingDirectory == null )
    {
        String path = SchemaManagerLoadTest.class.getResource( "" ).getPath();
        int targetPos = path.indexOf( "target" );
        workingDirectory = path.substring( 0, targetPos + 6 );
    }

    // Make sure every test class has its own schema directory
    workingDirectory = new File( workingDirectory, "SchemaManagerLoadTest" ).getAbsolutePath();

    schemaRepository = new File( workingDirectory, "schema" );

    // Cleanup the target directory
    FileUtils.deleteDirectory( schemaRepository );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
    extractor.extractOrCopy();
}
 
Example #2
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    workingDirectory = System.getProperty( "workingDirectory" );

    if ( workingDirectory == null )
    {
        String path = SchemaManagerDelTest.class.getResource( "" ).getPath();
        int targetPos = path.indexOf( "target" );
        workingDirectory = path.substring( 0, targetPos + 6 );
    }

    // Make sure every test class has its own schema directory
    workingDirectory = new File( workingDirectory, "SchemaManagerDelTest" ).getAbsolutePath();

    schemaRepository = new File( workingDirectory, "schema" );

    // Cleanup the target directory
    FileUtils.deleteDirectory( schemaRepository );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
    extractor.extractOrCopy();
}
 
Example #3
Source File: MatchingRuleTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    tmpFolder = Files.createTempDirectory( MatchingRuleTest.class.getSimpleName() );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tmpFolder.toFile() );
    extractor.extractOrCopy();

    LdifSchemaLoader loader = new LdifSchemaLoader( new File( tmpFolder.toFile(), "schema" ) );
    schemaManager = new DefaultSchemaManager( loader );
    
    for ( Schema schema : loader.getAllSchemas() )
    {
        schema.enable();
    }
    
    schemaManager.loadAllEnabled();
}
 
Example #4
Source File: SchemaManagerLoadWithDepsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    workingDirectory = System.getProperty( "workingDirectory" );

    if ( workingDirectory == null )
    {
        String path = SchemaManagerLoadWithDepsTest.class.getResource( "" ).getPath();
        int targetPos = path.indexOf( "target" );
        workingDirectory = path.substring( 0, targetPos + 6 );
    }

    // Make sure every test class has its own schema directory
    workingDirectory = new File( workingDirectory, "SchemaManagerLoadWithDepsTest" ).getAbsolutePath();

    schemaRepository = new File( workingDirectory, "schema" );

    // Cleanup the target directory
    FileUtils.deleteDirectory( schemaRepository );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
    extractor.extractOrCopy();
}
 
Example #5
Source File: LdifSchemaLoaderTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testLoader() throws Exception
{
    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( tmpFolder.toFile() );
    extractor.extractOrCopy();

    LdifSchemaLoader loader = new LdifSchemaLoader( new File( tmpFolder.toFile(), "schema" ) );
    SchemaManager sm = new DefaultSchemaManager( loader );

    boolean loaded = sm.loadAllEnabled();

    if ( !loaded )
    {
        fail( "Schema load failed : " + Exceptions.printErrors( sm.getErrors() ) );
    }

    assertTrue( sm.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
}
 
Example #6
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    workingDirectory = System.getProperty( "workingDirectory" );

    if ( workingDirectory == null )
    {
        String path = SchemaManagerAddTest.class.getResource( "" ).getPath();
        int targetPos = path.indexOf( "target" );
        workingDirectory = path.substring( 0, targetPos + 6 );
    }

    // Make sure every test class has its own schema directory
    workingDirectory = new File( workingDirectory, "SchemaManagerAddTest" ).getAbsolutePath();

    schemaRepository = new File( workingDirectory, "schema" );

    // Cleanup the target directory
    FileUtils.deleteDirectory( schemaRepository );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
    extractor.extractOrCopy();
}
 
Example #7
Source File: SchemaManagerEnableDisableLoadTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@BeforeAll
public static void setup() throws Exception
{
    workingDirectory = System.getProperty( "workingDirectory" );

    if ( workingDirectory == null )
    {
        String path = SchemaManagerEnableDisableLoadTest.class.getResource( "" ).getPath();
        int targetPos = path.indexOf( "target" );
        workingDirectory = path.substring( 0, targetPos + 6 );
    }

    // Make sure every test class has its own schema directory
    workingDirectory = new File( workingDirectory, "SchemaManagerEnableDisableLoadTest" ).getAbsolutePath();

    schemaRepository = new File( workingDirectory, "schema" );

    // Cleanup the target directory
    FileUtils.deleteDirectory( schemaRepository );

    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( new File( workingDirectory ) );
    extractor.extractOrCopy();
}
 
Example #8
Source File: LdapTestEnvironment.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
/**
 * initialize the schema manager and add the schema partition to directory
 * service
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
protected void initSchemaPartition() throws Exception {
  InstanceLayout instanceLayout = service.getInstanceLayout();

  File schemaPartitionDirectory = new File(instanceLayout.getPartitionsDirectory(), "schema");

  // Extract the schema on disk (a brand new one) and load the registries
  if (schemaPartitionDirectory.exists()) {
    LOG.info("schema partition already exists, skipping schema extraction");
  } else {
    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory());
    extractor.extractOrCopy();
  }

  SchemaLoader loader = new LdifSchemaLoader(schemaPartitionDirectory);
  SchemaManager schemaManager = new DefaultSchemaManager(loader);

  // 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();

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

  if (!errors.isEmpty()) {
    throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
  }

  service.setSchemaManager(schemaManager);

  // Init the LdifPartition with schema
  LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, service.getDnFactory());
  schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());

  // The schema partition
  SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
  schemaPartition.setWrappedPartition(schemaLdifPartition);
  service.setSchemaPartition(schemaPartition);
}
 
Example #9
Source File: Server.java    From MyVirtualDirectory with Apache License 2.0 4 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 {
    InstanceLayout instanceLayout = directoryService.getInstanceLayout();

    File schemaPartitionDirectory = new File(instanceLayout.getPartitionsDirectory(), "schema");

    // Extract the schema on disk (a brand new one) and load the registries
    if (schemaPartitionDirectory.exists()) {
        System.out.println("schema partition already exists, skipping schema extraction");
    } else {
        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(instanceLayout.getPartitionsDirectory());
        extractor.extractOrCopy();
    }

    SchemaLoader loader = new LdifSchemaLoader(schemaPartitionDirectory);
    SchemaManager schemaManager = new DefaultSchemaManager(loader);

    // 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();

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

    if (errors.size() != 0) {
        throw new Exception(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }

    directoryService.setSchemaManager(schemaManager);

    if (this.dnFactory == null) {
        this.dnFactory = new DefaultDnFactory(schemaManager, new net.sf.ehcache.Cache(new CacheConfiguration("myvd-apacheds-dns", 10000)));
    }

    // Init the LdifPartition with schema
    LdifPartition schemaLdifPartition = new LdifPartition(schemaManager, this.dnFactory);
    schemaLdifPartition.setPartitionPath(schemaPartitionDirectory.toURI());

    // The schema partition
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(schemaLdifPartition);
    directoryService.setSchemaPartition(schemaPartition);
}
 
Example #10
Source File: ApacheDSStartStopListener.java    From syncope with Apache License 2.0 4 votes vote down vote up
/**
 * Initialize the schema manager and add the schema partition to directory service.
 *
 * @throws Exception if the schema LDIF files are not found on the classpath
 */
private void initSchemaPartition() throws Exception {
    File workingDirectory = service.getInstanceLayout().getPartitionsDirectory();

    // Extract the schema on disk (a brand new one) and load the registries
    File schemaRepository = new File(workingDirectory, "schema");
    SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor(workingDirectory);
    try {
        extractor.extractOrCopy();
    } catch (IOException ioe) {
        // The schema has already been extracted, bypass
    }

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

    // 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();

    // Tell all the normalizer comparators that they should not normalize anything
    ComparatorRegistry comparatorRegistry = schemaManager.getComparatorRegistry();
    for (LdapComparator<?> comparator : comparatorRegistry) {
        if (comparator instanceof NormalizingComparator) {
            ((NormalizingComparator) comparator).setOnServer();
        }
    }

    service.setSchemaManager(schemaManager);

    // Init the LdifPartition
    LdifPartition ldifPartition = new LdifPartition(schemaManager, service.getDnFactory());
    ldifPartition.setPartitionPath(new File(workingDirectory, "schema").toURI());
    SchemaPartition schemaPartition = new SchemaPartition(schemaManager);
    schemaPartition.setWrappedPartition(ldifPartition);
    service.setSchemaPartition(schemaPartition);

    List<Throwable> errors = schemaManager.getErrors();
    if (!errors.isEmpty()) {
        throw new IllegalStateException(I18n.err(I18n.ERR_317, Exceptions.printErrors(errors)));
    }
}