org.apache.directory.api.ldap.model.schema.registries.Schema Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.schema.registries.Schema. 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: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Schema> getDisabled()
{
    List<Schema> disabled = new ArrayList<>();

    for ( Schema schema : registries.getLoadedSchemas().values() )
    {
        if ( schema.isDisabled() )
        {
            disabled.add( schema );
        }
    }

    return disabled;
}
 
Example #2
Source File: SchemaEntityFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Process the common attributes to all SchemaObjects :
 *  - obsolete
 *  - description
 *  - names
 *  - schemaName
 *  - specification (if any)
 *  - extensions
 *  - isEnabled
 *  
 *  @param schemaObject The SchemaObject to set
 *  @param description The SchemaObjetc description
 *  @param schema  the updated Schema 
 */
private void setSchemaObjectProperties( SchemaObject schemaObject, SchemaObject description, Schema schema )
{
    // The isObsolete field
    schemaObject.setObsolete( description.isObsolete() );

    // The description field
    schemaObject.setDescription( description.getDescription() );

    // The names field
    schemaObject.setNames( description.getNames() );

    // The isEnabled field. Has the description does not hold a
    // Disable field, we will inherit from the schema enable field
    schemaObject.setEnabled( schema.isEnabled() );

    // The specification field
    schemaObject.setSpecification( description.getSpecification() );

    // The schemaName field
    schemaObject.setSchemaName( schema.getSchemaName() );

    // The extensions field
    schemaObject.setExtensions( description.getExtensions() );
}
 
Example #3
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean loadAllEnabledRelaxed() throws LdapException
{
    Schema[] enabledSchemas = new Schema[schemaMap.size()];
    int i = 0;
    
    for ( Schema schema : schemaMap.values() )
    {
        if ( schema.isEnabled() )
        {
            enabledSchemas[i++] = schema;
        }
    }
    
    return loadWithDepsRelaxed( enabledSchemas );
}
 
Example #4
Source File: SingleLdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
private List<Entry> loadSchemaObjects( String schemaObjectType, Schema... schemas )
{
    Map<String, List<Entry>> m = scObjEntryMap.get( schemaObjectType );
    List<Entry> atList = new ArrayList<>();

    for ( Schema s : schemas )
    {
        List<Entry> preLoaded = m.get( s.getSchemaName() );
        
        if ( preLoaded != null )
        {
            atList.addAll( preLoaded );
        }
    }

    return atList;
}
 
Example #5
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Delete all the schemaObjects for a given schema from the registries
 * 
 * @param schema The schema from which we want teh SchemaObjects to be deleted
 * @param registries The Registries to process
 * @throws LdapException If the SchemaObjects cannot be deleted
 */
private void deleteSchemaObjects( Schema schema, Registries registries ) throws LdapException
{
    Map<String, Set<SchemaObjectWrapper>> schemaObjects = registries.getObjectBySchemaName();
    Set<SchemaObjectWrapper> content = schemaObjects.get( Strings.toLowerCaseAscii( schema.getSchemaName() ) );

    List<SchemaObject> toBeDeleted = new ArrayList<>();

    if ( content != null )
    {
        // Build an intermediate list to avoid concurrent modifications
        for ( SchemaObjectWrapper schemaObjectWrapper : content )
        {
            toBeDeleted.add( schemaObjectWrapper.get() );
        }

        for ( SchemaObject schemaObject : toBeDeleted )
        {
            registries.delete( schemaObject );
        }
    }
}
 
Example #6
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 #7
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Schema> getEnabled()
{
    List<Schema> enabled = new ArrayList<>();

    for ( Schema schema : registries.getLoadedSchemas().values() )
    {
        if ( schema.isEnabled() )
        {
            enabled.add( schema );
        }
    }

    return enabled;
}
 
Example #8
Source File: SchemaManagerLoadTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test that we can't load a new schema with bad dependencies
 */
@Test
public void loadNewSchemaBadDependencies() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    Schema dummy = new DefaultSchema( loader, "dummy" );
    dummy.addDependencies( "bad" );

    assertFalse( schemaManager.load( dummy ) );

    assertFalse( schemaManager.getErrors().isEmpty() );
    assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( 0, schemaManager.getComparatorRegistry().size() );
    assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
    assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
    assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( 0, schemaManager.getGlobalOidRegistry().size() );

    assertEquals( 0, schemaManager.getRegistries().getLoadedSchemas().size() );
    assertNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
}
 
Example #9
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
protected void addSchemaObjects( Schema schema, Registries registries ) throws LdapException
{
    // Create a content container for this schema
    registries.addSchema( schema.getSchemaName() );
    schemaMap.put( schema.getSchemaName(), schema );

    // And inject any existing SchemaObject into the registries
    try
    {
        addComparators( schema, registries );
        addNormalizers( schema, registries );
        addSyntaxCheckers( schema, registries );
        addSyntaxes( schema, registries );
        addMatchingRules( schema, registries );
        addAttributeTypes( schema, registries );
        addObjectClasses( schema, registries );
        //addMatchingRuleUses( schema, registries );
        //addDitContentRules( schema, registries );
        //addNameForms( schema, registries );
        //addDitStructureRules( schema, registries );
    }
    catch ( IOException ioe )
    {
        throw new LdapOtherException( ioe.getMessage(), ioe );
    }
}
 
Example #10
Source File: SchemaManagerLoadTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Test that we can load a new schema
 */
@Test
public void loadNewSchema() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    Schema dummy = new DefaultSchema( loader, "dummy" );

    assertTrue( schemaManager.load( dummy ) );

    assertTrue( schemaManager.getErrors().isEmpty() );
    assertEquals( 0, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( 0, schemaManager.getComparatorRegistry().size() );
    assertEquals( 0, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( 0, schemaManager.getNormalizerRegistry().size() );
    assertEquals( 0, schemaManager.getObjectClassRegistry().size() );
    assertEquals( 0, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( 0, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( 0, schemaManager.getGlobalOidRegistry().size() );

    assertEquals( 1, schemaManager.getRegistries().getLoadedSchemas().size() );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "dummy" ) );
}
 
Example #11
Source File: SchemaEntityFactory.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Get the schema from its name. Return the Other reference if there
 * is no schema name. Throws a NPE if the schema is not loaded.
 * 
 * @param schemaName The schema name to fetch
 * @param registries The registries where we get the schema from
 * @return the found Schema
 */
private Schema getSchema( String schemaName, Registries registries )
{
    if ( Strings.isEmpty( schemaName ) )
    {
        schemaName = MetaSchemaConstants.SCHEMA_OTHER;
    }

    Schema schema = registries.getLoadedSchema( schemaName );

    if ( schema == null )
    {
        String msg = I18n.err( I18n.ERR_16015_NON_EXISTENT_SCHEMA, schemaName );
        LOG.error( msg );
    }

    return schema;
}
 
Example #12
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of DefaultSchemaManager with the default schema schemaLoader
 *
 * @param relaxed If the schema  manager should be relaxed or not
 * @param schemas The list of schema to load
 */
public DefaultSchemaManager( boolean relaxed, Collection<Schema> schemas )
{
    // Default to the the root (one schemaManager for all the entries
    namingContext = Dn.ROOT_DSE;

    for ( Schema schema : schemas )
    {
        schemaMap.put( schema.getSchemaName(), schema );
    }
    
    registries = new Registries();
    factory = new SchemaEntityFactory();
    isRelaxed = relaxed;
    setErrorHandler( new LoggingSchemaErrorHandler() );
}
 
Example #13
Source File: SchemaEntityFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Normalizer getNormalizer( SchemaManager schemaManager, NormalizerDescription normalizerDescription,
    Registries targetRegistries, String schemaName ) throws LdapException
{
    checkDescription( normalizerDescription, SchemaConstants.NORMALIZER );

    // The Comparator OID
    String oid = getOid( normalizerDescription, SchemaConstants.NORMALIZER );

    // Get the schema
    Schema schema = getSchema( schemaName, targetRegistries );

    if ( schema == null )
    {
        // The schema is not loaded. We can't create the requested Normalizer
        String msg = I18n.err( I18n.ERR_16024_CANNOT_ADD_NORMALIZER, normalizerDescription.getName(), schemaName );
        
        if ( LOG.isWarnEnabled() )
        {
            LOG.warn( msg );
        }
        
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, msg );
    }

    // The FQCN
    String fqcn = getFqcn( normalizerDescription, SchemaConstants.NORMALIZER );

    // get the byteCode
    Attribute byteCode = getByteCode( normalizerDescription, SchemaConstants.NORMALIZER );

    // Class load the normalizer
    Normalizer normalizer = classLoadNormalizer( schemaManager, oid, fqcn, byteCode );

    // Update the common fields
    setSchemaObjectProperties( normalizer, normalizerDescription, schema );

    return normalizer;
}
 
Example #14
Source File: JarLdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> matchingRuleUseList = new ArrayList<>();

    if ( schemas == null )
    {
        return matchingRuleUseList;
    }

    for ( Schema schema : schemas )
    {
        String start = getSchemaDirectoryString( schema )
            + SchemaConstants.MATCHING_RULE_USE_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;

        for ( String resourcePath : RESOURCE_MAP.keySet() )
        {
            if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
            {
                URL resource = getResource( resourcePath, "matchingRuleUse LDIF file" );
                LdifReader reader = new LdifReader( resource.openStream() );
                LdifEntry entry = reader.next();
                reader.close();

                matchingRuleUseList.add( entry.getEntry() );
            }
        }
    }

    return matchingRuleUseList;
}
 
Example #15
Source File: AttributesFactory.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Get a SchemaObject as an Entry
 *
 * @param obj The schema oobject to convert
 * @param schema The schema which this object belongs to
 * @param schemaManager The SchemaManager
 * @return The converted schema object as an Entry
 * @throws LdapException If we can't convert teh schema object
 */
public Entry getAttributes( SchemaObject obj, Schema schema, SchemaManager schemaManager ) throws LdapException
{
    if ( obj instanceof LdapSyntax )
    {
        return convert( ( LdapSyntax ) obj, schema, schemaManager );
    }
    else if ( obj instanceof MatchingRule )
    {
        return convert( ( MatchingRule ) obj, schema, schemaManager );
    }
    else if ( obj instanceof AttributeType )
    {
        return convert( ( AttributeType ) obj, schema, schemaManager );
    }
    else if ( obj instanceof ObjectClass )
    {
        return convert( ( ObjectClass ) obj, schema, schemaManager );
    }
    else if ( obj instanceof MatchingRuleUse )
    {
        return convert( ( MatchingRuleUse ) obj, schema, schemaManager );
    }
    else if ( obj instanceof DitStructureRule )
    {
        return convert( ( DitStructureRule ) obj, schema, schemaManager );
    }
    else if ( obj instanceof DitContentRule )
    {
        return convert( ( DitContentRule ) obj, schema, schemaManager );
    }
    else if ( obj instanceof NameForm )
    {
        return convert( ( NameForm ) obj, schema, schemaManager );
    }

    throw new IllegalArgumentException( I18n.err( I18n.ERR_13712_UNKNOWN_SCHEMA_OBJECT_TYPE, obj.getClass() ) );
}
 
Example #16
Source File: LdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> ditContentRuleList = new ArrayList<>();

    if ( schemas == null )
    {
        return ditContentRuleList;
    }

    for ( Schema schema : schemas )
    {
        File ditContentRulesDirectory = new File( getSchemaDirectory( schema ),
            SchemaConstants.DIT_CONTENT_RULES_PATH );

        if ( !ditContentRulesDirectory.exists() )
        {
            return ditContentRuleList;
        }

        File[] ditContentRuleFiles = ditContentRulesDirectory.listFiles( ldifFilter );

        if ( ditContentRuleFiles != null )
        {
            for ( File ldifFile : ditContentRuleFiles )
            {
                LdifReader reader = new LdifReader( ldifFile );
                LdifEntry entry = reader.next();
                reader.close();

                ditContentRuleList.add( entry.getEntry() );
            }
        }
    }

    return ditContentRuleList;
}
 
Example #17
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Add all the Schema's comparators
 * 
 * @param schema The schema in which the Comparators will be added
 * @param registries The Registries to process
 * @throws LdapException If the Comparators cannot be added
 * @throws IOException If the Comparators cannot be loaded
 */
private void addComparators( Schema schema, Registries registries ) throws LdapException, IOException
{
    if ( schema.getSchemaLoader() == null )
    {
        return;
    }
    
    for ( Entry entry : schema.getSchemaLoader().loadComparators( schema ) )
    {
        LdapComparator<?> comparator = factory.getLdapComparator( this, entry, registries, schema.getSchemaName() );

        addSchemaObject( registries, comparator, schema );
    }
}
 
Example #18
Source File: SchemaManagerLoadTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * test loading the "InetOrgPerson", "core" and an empty schema. The empty schema
 * should be present in the registries, as it's a vaid schema
 */
@Test
public void testLoadSchemasWithDepsCoreInetOrgPersonAndBad() 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" ) );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "empty" ) );
}
 
Example #19
Source File: JarLdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadDitContentRules( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> ditContentRulesList = new ArrayList<>();

    if ( schemas == null )
    {
        return ditContentRulesList;
    }

    for ( Schema schema : schemas )
    {
        String start = getSchemaDirectoryString( schema )
            + SchemaConstants.DIT_CONTENT_RULES_PATH + "/" + "m-oid=";
        String end = "." + LDIF_EXT;

        for ( String resourcePath : RESOURCE_MAP.keySet() )
        {
            if ( resourcePath.startsWith( start ) && resourcePath.endsWith( end ) )
            {
                URL resource = getResource( resourcePath, "ditContentRule LDIF file" );
                LdifReader reader = new LdifReader( resource.openStream() );
                LdifEntry entry = reader.next();
                reader.close();

                ditContentRulesList.add( entry.getEntry() );
            }
        }
    }

    return ditContentRulesList;
}
 
Example #20
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isDisabled( String schemaName )
{
    Schema schema = registries.getLoadedSchema( schemaName );

    return ( schema != null ) && schema.isDisabled();
}
 
Example #21
Source File: JarLdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Scans for LDIF files just describing the various schema contained in
 * the schema repository.
 *
 * @throws LdapException If the schema can't be initialized
 * @throws IOException If the file cannot be read
 */
private void initializeSchemas() throws IOException, LdapException
{
    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_16006_INITIALIZING_SCHEMA ) );
    }

    Pattern pat = Pattern.compile( "schema" + SEPARATOR_PATTERN + "ou=schema"
        + SEPARATOR_PATTERN + "cn=[a-z0-9-_]*\\." + LDIF_EXT );

    for ( String file : RESOURCE_MAP.keySet() )
    {
        if ( pat.matcher( file ).matches() )
        {
            URL resource = getResource( file, "schema LDIF file" );

            try ( InputStream in = resource.openStream() )
            {
                try ( LdifReader reader = new LdifReader( in ) )
                {
                    LdifEntry entry = reader.next();
                    Schema schema = getSchema( entry.getEntry() );
                    schemaMap.put( schema.getSchemaName(), schema );

                    if ( LOG.isDebugEnabled() )
                    {
                        LOG.debug( I18n.msg( I18n.MSG_16007_SCHEMA_INITIALIZED, schema ) );
                    }
                }
            }
            catch ( LdapException le )
            {
                LOG.error( I18n.err( I18n.ERR_16009_LDIF_LOAD_FAIL, file ), le );
                throw le;
            }
        }
    }
}
 
Example #22
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isSchemaLoaded( String schemaName )
{
    try
    {
        Schema schema = schemaMap.get( schemaName );
        
        return schema != null;
    }
    catch ( Exception e )
    {
        return false;
    }
}
 
Example #23
Source File: SchemaManagerLoadWithDepsTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * 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" ) );
}
 
Example #24
Source File: LdifSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadMatchingRuleUses( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> matchingRuleUseList = new ArrayList<>();

    if ( schemas == null )
    {
        return matchingRuleUseList;
    }

    for ( Schema schema : schemas )
    {
        File matchingRuleUsesDirectory = new File( getSchemaDirectory( schema ),
            SchemaConstants.MATCHING_RULE_USE_PATH );

        if ( !matchingRuleUsesDirectory.exists() )
        {
            return matchingRuleUseList;
        }

        File[] matchingRuleUseFiles = matchingRuleUsesDirectory.listFiles( ldifFilter );

        if ( matchingRuleUseFiles != null )
        {
            for ( File ldifFile : matchingRuleUseFiles )
            {
                LdifReader reader = new LdifReader( ldifFile );
                LdifEntry entry = reader.next();
                reader.close();

                matchingRuleUseList.add( entry.getEntry() );
            }
        }
    }

    return matchingRuleUseList;
}
 
Example #25
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Add all the Schema's Syntaxes
 * 
 * @param schema The schema in which the Syntaxes will be added
 * @param registries The Registries to process
 * @throws LdapException If the Syntaxes cannot be added
 * @throws IOException If the Syntaxes cannot be loaded
 */
private void addSyntaxes( Schema schema, Registries registries ) throws LdapException, IOException
{
    if ( schema.getSchemaLoader() == null )
    {
        return;
    }

    for ( Entry entry : schema.getSchemaLoader().loadSyntaxes( schema ) )
    {
        LdapSyntax syntax = factory.getSyntax( this, entry, registries, schema.getSchemaName() );

        addSchemaObject( registries, syntax, schema );
    }
}
 
Example #26
Source File: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean loadDisabled( String... schemaNames ) throws LdapException
{
    Schema[] schemas = toArray( schemaNames );

    return loadDisabled( schemas );
}
 
Example #27
Source File: DefaultSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadObjectClasses( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> objectClassEntries = new ArrayList<>();

    if ( schemas == null )
    {
        return objectClassEntries;
    }

    AttributesFactory factory = new AttributesFactory();

    for ( Schema schema : schemas )
    {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();

        for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
        {
            SchemaObject schemaObject = schemaObjectWrapper.get();

            if ( schemaObject instanceof ObjectClass )
            {
                ObjectClass objectClass = ( ObjectClass ) schemaObject;

                Entry objectClassEntry = factory.convert( objectClass, schema, null );

                objectClassEntries.add( objectClassEntry );
            }
        }
    }

    return objectClassEntries;
}
 
Example #28
Source File: QuirkySchemaTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Try to load a quirky schema. This schema has a lot of issues that violate the
 * standards. Therefore load the schema in relaxed mode. We should be able to work
 * with this schema anyway. E.g. the loader and schema manager should not die on
 * null pointer or similar trivial error.
 */
@Test
public void testLoadQuirkySchema() throws Exception
{
    LdapConnection connection = createFakeConnection( "src/test/resources/schema-quirky.ldif" );
    DefaultSchemaLoader loader = new DefaultSchemaLoader( connection, true );
    Collection<Schema> allEnabled = loader.getAllEnabled();
    assertEquals( 1, allEnabled.size() );
    Schema schema = allEnabled.iterator().next();
    assertNotNull( schema );

    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    boolean loaded = schemaManager.loadAllEnabledRelaxed();
    
    if ( !loaded )
    {
        fail( "Schema load failed : " + Exceptions.printErrors( schemaManager.getErrors() ) );
    }
    
    assertTrue ( schemaManager.getErrors().size() > 0, "Surprisingly no errors after load" );

    assertTrue( schemaManager.getRegistries().getAttributeTypeRegistry().contains( "cn" ) );
    ObjectClass person = schemaManager.getRegistries().getObjectClassRegistry().lookup( "person" );
    assertNotNull( person );
    assertEquals( 2, person.getMustAttributeTypes().size() );
    assertEquals( 5, person.getMayAttributeTypes().size() );
}
 
Example #29
Source File: DefaultSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadSyntaxCheckers( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> syntaxCheckerEntries = new ArrayList<>();

    if ( schemas == null )
    {
        return syntaxCheckerEntries;
    }

    for ( Schema schema : schemas )
    {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();

        for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
        {
            SchemaObject schemaObject = schemaObjectWrapper.get();

            if ( schemaObject instanceof SyntaxCheckerDescription )
            {
                SyntaxCheckerDescription syntaxCheckerDescription = ( SyntaxCheckerDescription ) schemaObject;
                Entry syntaxCheckerEntry = getEntry( syntaxCheckerDescription );

                syntaxCheckerEntries.add( syntaxCheckerEntry );
            }
        }
    }

    return syntaxCheckerEntries;
}
 
Example #30
Source File: DefaultSchemaLoader.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public List<Entry> loadSyntaxes( Schema... schemas ) throws LdapException, IOException
{
    List<Entry> syntaxEntries = new ArrayList<>();

    if ( schemas == null )
    {
        return syntaxEntries;
    }

    AttributesFactory factory = new AttributesFactory();

    for ( Schema schema : schemas )
    {
        Set<SchemaObjectWrapper> schemaObjectWrappers = schema.getContent();

        for ( SchemaObjectWrapper schemaObjectWrapper : schemaObjectWrappers )
        {
            SchemaObject schemaObject = schemaObjectWrapper.get();

            if ( schemaObject instanceof LdapSyntax )
            {
                LdapSyntax ldapSyntax = ( LdapSyntax ) schemaObject;

                Entry ldapSyntaxEntry = factory.convert( ldapSyntax, schema, null );

                syntaxEntries.add( ldapSyntaxEntry );
            }
        }
    }

    return syntaxEntries;
}