Java Code Examples for org.apache.directory.api.ldap.model.schema.SchemaManager#getErrors()

The following examples show how to use org.apache.directory.api.ldap.model.schema.SchemaManager#getErrors() . 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: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistingComparator() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    LdapComparator<?> lc = new BooleanComparator( "0.0" );
    assertFalse( schemaManager.delete( lc ) );

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

    assertEquals( ctrSize, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 2
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject a new MatchingRule without a syntax
 */
@Test
public void testAddMatchingRuleNoSyntax() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    MatchingRule matchingRule = new MatchingRule( "1.1.0" );

    // It should fail (no syntax)
    assertFalse( schemaManager.add( matchingRule ) );

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

    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );
    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isMRPresent( schemaManager, "1.1.0" ) );

    assertEquals( mrrSize, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 3
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject a new valid Syntax, with no SC : the associated SC
 * will be the default OctetString SC
 */
@Test
public void testAddValidSyntax() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int sSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    LdapSyntax syntax = new LdapSyntax( "1.1.0" );

    // It should not fail
    assertTrue( schemaManager.add( syntax ) );

    LdapSyntax added = schemaManager.lookupLdapSyntaxRegistry( "1.1.0" );

    assertNotNull( added );
    assertEquals( OctetStringSyntaxChecker.class.getName(), added.getSyntaxChecker().getClass().getName() );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );

    assertTrue( isSyntaxPresent( schemaManager, "1.1.0" ) );
    assertEquals( sSize + 1, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 4
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistingSyntaxChecker() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    SyntaxChecker sc = BooleanSyntaxChecker.builder().setOid( "0.0" ).build();
    assertFalse( schemaManager.delete( sc ) );

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

    assertEquals( scrSize, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 5
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteExistingObjectClassUsedByAnotherObjectClass() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int ocSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass oc = new ObjectClass( "2.5.6.0" );

    // shouldn't delete the 'top' OC
    assertFalse( schemaManager.delete( oc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertFalse( errors.isEmpty() );
    assertTrue( errors.get( 0 ) instanceof LdapProtocolErrorException );

    assertEquals( ocSize, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 6
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddNewComparator() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ctrSize = schemaManager.getComparatorRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    LdapComparator<?> lc = new BooleanComparator( oid );

    assertTrue( schemaManager.add( lc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );

    assertEquals( ctrSize + 1, schemaManager.getComparatorRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    LdapComparator<?> added = schemaManager.lookupComparatorRegistry( oid );

    assertNotNull( added );
    assertEquals( lc.getClass().getName(), added.getFqcn() );
}
 
Example 7
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeleteNonExistingNormalizer() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    Normalizer nr = new BooleanNormalizer();
    nr.setOid( "0.0" );
    assertFalse( schemaManager.delete( nr ) );

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

    assertEquals( nrSize, schemaManager.getNormalizerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 8
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
@Test
public void testAddNewSyntaxChecker() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    SyntaxChecker syntaxChecker = RegexSyntaxChecker.builder().setOid( oid ).build();

    assertTrue( schemaManager.add( syntaxChecker ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );

    assertEquals( nrSize + 1, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    SyntaxChecker added = schemaManager.lookupSyntaxCheckerRegistry( oid );

    assertNotNull( added );
    assertEquals( syntaxChecker.getClass().getName(), added.getFqcn() );
}
 
Example 9
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType with itself as a superior
 */
@Test
public void testAddAttributeTypeSupWithOwnSup() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( null );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSuperiorOid( "1.1.0" );
    attributeType.setUsage( UsageEnum.DISTRIBUTED_OPERATION );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 10
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType with an already attributed name
 */
@Test
public void testAddAttributeTypeNameAlreadyExist() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.1.0" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setSubstringOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setNames( "Test", "cn" );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    // The AT must not be there
    assertFalse( isATPresent( schemaManager, "1.1.1.0" ) );

    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 11
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Test that we can't add two Normalizers with the same class code.
 */
@Test
public void testAddNormalizerWithWrongFQCN() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer( oid );

    // using java.sql.ResultSet cause it is very unlikely to get loaded
    // in ADS, as the FQCN is not the one expected
    normalizer.setFqcn( "java.sql.ResultSet" );

    assertFalse( schemaManager.add( normalizer ) );

    List<Throwable> errors = schemaManager.getErrors();
    errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );

    assertEquals( nrSize, schemaManager.getNormalizerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    try
    {
        schemaManager.lookupNormalizerRegistry( oid );
        fail();
    }
    catch ( Exception e )
    {
        // Expected
        assertTrue( true );
    }
}
 
Example 12
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
@Test
public void testAddAlreadyExistingNormalizer() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int nrSize = schemaManager.getNormalizerRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String oid = "0.0.0";
    Normalizer normalizer = new NoOpNormalizer( oid );

    assertTrue( schemaManager.add( normalizer ) );

    Normalizer added = schemaManager.lookupNormalizerRegistry( oid );

    assertNotNull( added );
    assertEquals( normalizer.getClass().getName(), added.getFqcn() );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 0, errors.size() );
    assertEquals( nrSize + 1, schemaManager.getNormalizerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    Normalizer normalizer2 = new NoOpNormalizer( oid );

    assertFalse( schemaManager.add( normalizer2 ) );

    errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );

    assertEquals( nrSize + 1, schemaManager.getNormalizerRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );

    added = schemaManager.lookupNormalizerRegistry( oid );

    assertNotNull( added );
    assertEquals( normalizer.getClass().getName(), added.getFqcn() );
}
 
Example 13
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType with an invalid SUBSTR MR
 */
@Test
public void testAddAttributeTypeNoSupInvalidSubstringMR() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( null );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( "0.0" );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setUsage( UsageEnum.USER_APPLICATIONS );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 14
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject a single valued AttributeType which is Collective
 */
@Test
public void testAddAttributeTypeCollectiveOperationalSigleValue() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( SchemaConstants.DISTINGUISHED_NAME_MATCH_MR_OID );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setUsage( UsageEnum.USER_APPLICATIONS );
    attributeType.setCollective( true );
    attributeType.setSingleValued( true );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 15
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 16
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to inject an AttributeType with an invalid EQUALITY MR
 */
@Test
public void testAddAttributeTypeNoSupInvalidEqualityMR() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setEqualityOid( "0.0" );
    attributeType.setOrderingOid( null );
    attributeType.setSubstringOid( null );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.26" );
    attributeType.setUsage( UsageEnum.USER_APPLICATIONS );

    // It should fail
    assertFalse( schemaManager.add( attributeType ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertEquals( 1, errors.size() );
    Throwable error = errors.get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 17
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Check that a Syntax which has been used by a deleted MatchingRule
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedMatchingRule() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int mrrSize = schemaManager.getMatchingRuleRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String MR_OID = "2.5.13.11";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.41";

    // Check that the MR and S are present
    assertTrue( isMatchingRulePresent( schemaManager, MR_OID ) );
    assertTrue( isSyntaxPresent( schemaManager, S_OID ) );

    // Now try to remove the S
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry( S_OID );

    // shouldn't be deleted cause there is a MR associated with it
    assertFalse( schemaManager.delete( syntax ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertFalse( errors.isEmpty() );
    assertTrue( errors.get( 0 ) instanceof LdapProtocolErrorException );

    // Now delete the using MR : it should be OK
    MatchingRule mr = new MatchingRule( MR_OID );
    assertTrue( schemaManager.delete( mr ) );

    assertEquals( mrrSize - 1, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );

    assertFalse( isMatchingRulePresent( schemaManager, MR_OID ) );

    // and try to delete the syntax again
    assertTrue( schemaManager.delete( syntax ) );

    assertFalse( isSyntaxPresent( schemaManager, S_OID ) );
    assertEquals( srSize - 1, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( goidSize - 2, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 18
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Check that a Syntax which has been used by a deleted AttributeType
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxUsedByRemovedAttributeType() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String AT_OID = "1.3.6.1.4.1.1466.101.120.16";
    String S_OID = "1.3.6.1.4.1.1466.115.121.1.54";

    // Check that the AT and S are present
    assertTrue( isAttributeTypePresent( schemaManager, AT_OID ) );
    assertTrue( isSyntaxPresent( schemaManager, S_OID ) );

    // Now try to remove the S
    LdapSyntax syntax = schemaManager.lookupLdapSyntaxRegistry( S_OID );

    // shouldn't be deleted cause there is a AT associated with it
    assertFalse( schemaManager.delete( syntax ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertFalse( errors.isEmpty() );
    assertTrue( errors.get( 0 ) instanceof LdapProtocolErrorException );

    // Now delete the using AT : it should be OK
    AttributeType at = new AttributeType( AT_OID );
    assertTrue( schemaManager.delete( at ) );

    assertEquals( atrSize - 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );

    assertFalse( isAttributeTypePresent( schemaManager, AT_OID ) );

    // and try to delete the syntax again
    assertTrue( schemaManager.delete( syntax ) );

    assertFalse( isSyntaxPresent( schemaManager, S_OID ) );
    assertEquals( srSize - 1, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( goidSize - 2, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 19
Source File: SchemaManagerDelTest.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Check that a SyntaxChecker which has been used by a deleted Syntax
 * can be removed
 */
@Test
public void testDeleteExistingSyntaxCheckerUsedByRemovedSyntax() throws Exception
{
    SchemaManager schemaManager = loadSchema( "system" );
    int scrSize = schemaManager.getSyntaxCheckerRegistry().size();
    int srSize = schemaManager.getLdapSyntaxRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    String OID = "1.3.6.1.4.1.1466.115.121.1.33";

    // Check that the S and SC are present
    assertTrue( isSyntaxCheckerPresent( schemaManager, OID ) );
    assertTrue( isSyntaxPresent( schemaManager, OID ) );

    // Now try to remove the SC
    SyntaxChecker sc = schemaManager.lookupSyntaxCheckerRegistry( OID );

    // shouldn't be deleted cause there is a S associated with it
    assertFalse( schemaManager.delete( sc ) );

    List<Throwable> errors = schemaManager.getErrors();
    assertFalse( errors.isEmpty() );
    assertTrue( errors.get( 0 ) instanceof LdapProtocolErrorException );

    // Now delete the using S : it should be OK
    LdapSyntax syntax = new LdapSyntax( OID );
    assertTrue( schemaManager.delete( syntax ) );

    assertEquals( srSize - 1, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );

    assertFalse( isSyntaxPresent( schemaManager, OID ) );

    // and try to delete the SC again
    assertTrue( schemaManager.delete( sc ) );

    assertFalse( isSyntaxCheckerPresent( schemaManager, OID ) );
    assertEquals( scrSize - 1, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( goidSize - 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example 20
Source File: Runner.java    From aws-iam-ldap-bridge 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 = 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() )
    {
        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 ) ) );
    }

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