org.apache.directory.api.ldap.model.schema.SchemaManager Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.schema.SchemaManager. 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
/**
 * test loading the "InetOrgPerson" and "core" schema, which depends on "system" and "cosine"
 */
@Test
public void testLoadCoreAndInetOrgPerson() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    assertTrue( schemaManager.load( "system" ) );
    assertTrue( schemaManager.load( "core", "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( 4, 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 #2
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 #3
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new instance of DefaultEntry, with a
 * Dn and a list of IDs.
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 * @param elements The list of attributes to create.
 * @throws LdapException If the provided Dn or Elements are invalid
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn, Object... elements ) throws LdapException
{
    DefaultEntry entry = ( DefaultEntry ) createEntry( schemaManager, elements );

    this.dn = dn;
    this.attributes = entry.attributes;
    this.schemaManager = schemaManager;

    if ( schemaManager != null )
    {
        if ( !dn.isSchemaAware() )
        {
            this.dn = new Dn( schemaManager, dn );
        }

        initObjectClassAT();
    }
}
 
Example #4
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The String Dn for this serverEntry. Can be null.
 * @throws LdapInvalidDnException If the Dn is invalid
 */
public DefaultEntry( SchemaManager schemaManager, String dn ) throws LdapInvalidDnException
{
    this.schemaManager = schemaManager;

    if ( Strings.isEmpty( dn ) )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = new Dn( dn );
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example #5
Source File: DefaultEntry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn )
{
    this.schemaManager = schemaManager;

    if ( dn == null )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = normalizeDn( dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example #6
Source File: SchemaManagerLoadWithDepsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test loading the "java" schema, which depends on "system" and "core"
 */
@Test
public void testLoadJava() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    schemaManager.loadWithDeps( "Java" );

    assertTrue( schemaManager.getErrors().isEmpty() );
    assertEquals( 99, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( 36, schemaManager.getComparatorRegistry().size() );
    assertEquals( 42, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
    assertEquals( 41, schemaManager.getObjectClassRegistry().size() );
    assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( 66, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( 248, schemaManager.getGlobalOidRegistry().size() );

    assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "Java" ) );
}
 
Example #7
Source File: MyVDBaseCursor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Creates a new entry filtering Cursor over an existing Cursor using a
 * list of filters initially: more can be added later after creation.
 * 
 * @param wrapped the underlying wrapped Cursor whose entries are filtered
 * @param operationContext the operation context that created this Cursor
 * @param invocation the search operation invocation creating this Cursor
 * @param filters a list of filters to be used
 */
public MyVDBaseCursor( Cursor<Entry> wrapped,
    SearchOperationContext operationContext,
    SchemaManager schemaManager,
    List<EntryFilter> filters )
{
    if ( IS_DEBUG )
    {
        LOG_CURSOR.debug( "Creating MyVDBaseCursor {}", this );
    }

    this.wrapped = wrapped;
    this.operationContext = operationContext;
    this.filters = new ArrayList<EntryFilter>();
    this.filters.addAll( filters );
    this.schemaManager = schemaManager;
}
 
Example #8
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject an AttributeType which is a NO-USER-MODIFICATION and is operational
 */
@Test
public void testAddAttributeTypeNoSupNoUserModificationOpAttr() 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.DISTRIBUTED_OPERATION );
    attributeType.setUserModifiable( false );

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

    assertTrue( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #9
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Addition of an STRUCTURAL OC with some AUXILIARY superior
 */
@Test
public void testAddObjectClassSuperiorsStructuralWithAuxiliaryInSup() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );
    objectClass.setNames( "Test" );
    objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
    objectClass.addSuperiorOids( "extensibleObject" );

    assertFalse( schemaManager.add( objectClass ) );

    assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaException );

    assertFalse( isOCPresent( schemaManager, "1.1.1" ) );

    assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #10
Source File: ApacheDSUtil.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
public static AttributeType addBinaryAttributeToSchema(Attribute attribute,SchemaManager schemaManager) throws LdapException {
	String newOID = generateRandomOID(schemaManager);
	MutableAttributeType at = new MutableAttributeType(newOID);
	
	// base new attributes on javaSerializedData
	AttributeType uidAT = schemaManager.getAttributeType("1.3.6.1.4.1.42.2.27.4.1.8");
	at.setNames(attribute.getId());
	at.setSyntax(uidAT.getSyntax());
	at.setSingleValued(false);
	
	at.setSchemaName(uidAT.getSchemaName());
	at.setSpecification(uidAT.getSpecification());
	at.setUsage(uidAT.getUsage());
	
	LOG.warn("Creating dynamic schema entry : '{}' {}", at.getName(), at.getOid());
	
	schemaManager.add(at);
	return at;
}
 
Example #11
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attribute The attribute we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, String attribute )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( attribute );

        return contains( schemaManager, attributeType );
    }
    catch ( LdapException le )
    {
        return false;
    }
}
 
Example #12
Source File: SchemaManagerLoadWithDepsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test loading the "cosine" schema, which depends on "system" and "core"
 */
@Test
public void testLoadCosine() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader.getAllSchemas() );

    schemaManager.loadWithDeps( "cosine" );

    assertTrue( schemaManager.getErrors().isEmpty() );
    assertEquals( 133, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( 36, schemaManager.getComparatorRegistry().size() );
    assertEquals( 42, schemaManager.getMatchingRuleRegistry().size() );
    assertEquals( 35, schemaManager.getNormalizerRegistry().size() );
    assertEquals( 49, schemaManager.getObjectClassRegistry().size() );
    assertEquals( 59, schemaManager.getSyntaxCheckerRegistry().size() );
    assertEquals( 66, schemaManager.getLdapSyntaxRegistry().size() );
    assertEquals( 290, schemaManager.getGlobalOidRegistry().size() );

    assertEquals( 3, schemaManager.getRegistries().getLoadedSchemas().size() );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "system" ) );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "core" ) );
    assertNotNull( schemaManager.getRegistries().getLoadedSchema( "cosine" ) );
}
 
Example #13
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Addition of an OC with an AT present more than once in MAY
 */
@Test
public void testAddObjectClassNoSuperiorATMoreThanOnceInMay() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );
    objectClass.addMayAttributeTypeOids( "cn", "ref", "commonName" );

    assertFalse( schemaManager.add( objectClass ) );

    assertEquals( 1, schemaManager.getErrors().size() );
    assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaException );

    assertFalse( isOCPresent( schemaManager, "1.1.1" ) );

    assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #14
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 #15
Source File: SchemaManagerLoadWithDepsTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * test loading the "InetOrgPerson" and "core" schema, which depends on "system" and "cosine"
 */
@Test
public void testLoadCoreAndInetOrgPerson() throws Exception
{
    LdifSchemaLoader loader = new LdifSchemaLoader( schemaRepository );
    SchemaManager schemaManager = new DefaultSchemaManager( loader );

    schemaManager.loadWithDeps( "core", "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( 4, 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 #16
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * <p>
 * Creates a new instance of DefaultEntry, schema aware.
 * </p>
 * <p>
 * No attributes will be created.
 * </p>
 *
 * @param schemaManager The reference to the schemaManager
 * @param dn The Dn for this serverEntry. Can be null.
 */
public DefaultEntry( SchemaManager schemaManager, Dn dn )
{
    this.schemaManager = schemaManager;

    if ( dn == null )
    {
        this.dn = Dn.EMPTY_DN;
    }
    else
    {
        this.dn = dn;
        normalizeDN( this.dn );
    }

    // Initialize the ObjectClass object
    initObjectClassAT();
}
 
Example #17
Source File: ApacheDSUtil.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
public static AttributeType addAttributeToSchema(Attribute attribute,SchemaManager schemaManager) throws LdapException {
	String newOID = generateRandomOID(schemaManager);
	MutableAttributeType at = new MutableAttributeType(newOID);
	
	// base new attributes on uid
	AttributeType uidAT = schemaManager.getAttributeType("0.9.2342.19200300.100.1.1");
	at.setNames(attribute.getId());
	at.setSyntax(uidAT.getSyntax());
	at.setSingleValued(false);
	at.setEquality(uidAT.getEquality());
	
	at.setSubstring(uidAT.getSubstring());
	at.setSchemaName(uidAT.getSchemaName());
	at.setSpecification(uidAT.getSpecification());
	at.setUsage(uidAT.getUsage());
	
	LOG.warn("Creating dynamic schema entry : '{}' {}", at.getName(), at.getOid());
	
	schemaManager.add(at);
	return at;
}
 
Example #18
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 #19
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Addition of a valid OC
 */
@Test
public void testAddObjectClassNoSuperiorValid() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );

    assertTrue( schemaManager.add( objectClass ) );

    assertEquals( 0, schemaManager.getErrors().size() );

    ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );

    assertNotNull( added );

    assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #20
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Try to inject an AttributeType without EQUALITY MR
 */
@Test
public void testAddAttributeTypeNoEqualityMR() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int atrSize = schemaManager.getAttributeTypeRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    AttributeType attributeType = new AttributeType( "1.1.0" );
    attributeType.setSyntaxOid( "1.3.6.1.4.1.1466.115.121.1.8 " );
    attributeType.setUsage( UsageEnum.USER_APPLICATIONS );

    // It should be OK
    assertTrue( schemaManager.add( attributeType ) );

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

    assertTrue( isATPresent( schemaManager, "1.1.0" ) );
    assertEquals( atrSize + 1, schemaManager.getAttributeTypeRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #21
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Addition of an ABSTRACT OC with some AUXILIARY superior
 */
@Test
public void testAddObjectClassSuperiorsAbstractWithAuxiliaryInSup() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );
    objectClass.setNames( "Test" );
    objectClass.setType( ObjectClassTypeEnum.ABSTRACT );
    objectClass.addSuperiorOids( "extensibleObject" );

    assertFalse( schemaManager.add( objectClass ) );

    assertTrue( schemaManager.getErrors().get( 0 ) instanceof LdapSchemaException );

    assertFalse( isOCPresent( schemaManager, "1.1.1" ) );

    assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #22
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Addition of an OC with not existing AT in MAY
 */
@Test
public void testAddObjectClassNoSuperiorNonExistingAtInMay() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );
    objectClass.addMayAttributeTypeOids( "cn", "none", "userPassword" );

    assertFalse( schemaManager.add( objectClass ) );

    assertEquals( 1, schemaManager.getErrors().size() );
    Throwable error = schemaManager.getErrors().get( 0 );

    assertTrue( error instanceof LdapSchemaException );

    assertFalse( isOCPresent( schemaManager, "1.1.1" ) );

    assertEquals( ocrSize, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #23
Source File: LDAPEmbeddedServer.java    From keycloak with Apache License 2.0 6 votes vote down vote up
private void importLdif() throws Exception {
    Map<String, String> map = new HashMap<String, String>();
    map.put("hostname", this.bindHost);
    if (this.ldapSaslPrincipal != null) {
        map.put("ldapSaslPrincipal", this.ldapSaslPrincipal);
    }

    // Find LDIF file on filesystem or classpath ( if it's like classpath:ldap/users.ldif )
    InputStream is = FindFile.findFile(ldifFile);
    if (is == null) {
        throw new IllegalStateException("LDIF file not found on classpath or on file system. Location was: " + ldifFile);
    }

    final String ldifContent = StrSubstitutor.replace(StreamUtil.readString(is), map);
    log.info("Content of LDIF: " + ldifContent);
    final SchemaManager schemaManager = directoryService.getSchemaManager();

    importLdifContent(directoryService, ldifContent);
}
 
Example #24
Source File: Ava.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Construct a schema aware Ava. The AttributeType and value will be checked accordingly
 * to the SchemaManager.
 * <p>
 * Note that the upValue should <b>not</b> be null or empty, or resolve
 * to an empty string after having trimmed it.
 *
 * @param schemaManager The SchemaManager instance
 * @param upType The User Provided type
 * @param value The value
 */
private void createAva( SchemaManager schemaManager, String upType, Value value )
{
    StringBuilder sb = new StringBuilder();

    normType = attributeType.getOid();
    this.upType = upType;
    this.value = value;
    
    sb.append( upType );
    sb.append( '=' );
    
    if ( value != null )
    {
        sb.append( Rdn.escapeValue( value.getString() ) );
    }
    
    upName = sb.toString();

    hashCode();
}
 
Example #25
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 #26
Source File: OutboundLdapConnectionTestCase.java    From wildfly-core with GNU Lesser General Public License v2.1 6 votes vote down vote up
@BeforeClass
@CreateDS(
    name = "WildFlyDS",
    factory = InMemoryDirectoryServiceFactory.class,
    partitions = @CreatePartition(name = "wildfly", suffix = "dc=wildfly,dc=org"),
    allowAnonAccess = true
)
@CreateLdapServer(
    transports = @CreateTransport(protocol = "LDAP", address = "localhost", port = 10389),
    allowAnonymousAccess = true
)
public static void setUpLdap() throws Exception {
    directoryService = DSAnnotationProcessor.getDirectoryService();
    final SchemaManager schemaManager = directoryService.getSchemaManager();
    final InputStream ldif = OutboundLdapConnectionTestCase.class
            .getResourceAsStream("/" + OutboundLdapConnectionTestCase.class.getSimpleName() + ".ldif");
    for (LdifEntry ldifEntry : new LdifReader(ldif)) {
        directoryService.getAdminSession().add(new DefaultEntry(schemaManager, ldifEntry.getEntry()));
    }
    ldapServer = ServerAnnotationProcessor.getLdapServer(directoryService);
}
 
Example #27
Source File: SchemaManagerAddTest.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Addition of an OC with some AT present in MUST and in MAY in one of its
 * superior
 */
@Test
public void testAddObjectClassSuperiorsATInMustPresentInSuperiorsMay() throws Exception
{
    SchemaManager schemaManager = loadSystem();
    int ocrSize = schemaManager.getObjectClassRegistry().size();
    int goidSize = schemaManager.getGlobalOidRegistry().size();

    ObjectClass objectClass = new ObjectClass( "1.1.1" );
    objectClass.setNames( "Test" );
    objectClass.setType( ObjectClassTypeEnum.STRUCTURAL );
    objectClass.addSuperiorOids( "alias", "OpenLDAProotDSE" );
    objectClass.addMustAttributeTypeOids( "aliasedObjectName", "cn" );

    assertTrue( schemaManager.add( objectClass ) );

    assertEquals( 0, schemaManager.getErrors().size() );

    ObjectClass added = schemaManager.lookupObjectClassRegistry( "1.1.1" );

    assertNotNull( added );
    assertTrue( added.getNames().contains( "Test" ) );
    assertNotNull( added.getSuperiors() );
    assertEquals( 2, added.getSuperiors().size() );

    Set<String> expectedSups = new HashSet<String>();
    expectedSups.add( "alias" );
    expectedSups.add( "OpenLDAProotDSE" );

    for ( ObjectClass addedOC : added.getSuperiors() )
    {
        assertTrue( expectedSups.contains( addedOC.getName() ) );
        expectedSups.remove( addedOC.getName() );
    }

    assertEquals( ocrSize + 1, schemaManager.getObjectClassRegistry().size() );
    assertEquals( goidSize + 1, schemaManager.getGlobalOidRegistry().size() );
}
 
Example #28
Source File: Rdn.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 *
 * Creates a new schema aware instance of Rdn.
 *
 * @param schemaManager the schema manager
 */
public Rdn( SchemaManager schemaManager )
{
    // Don't waste space... This is not so often we have multiple
    // name-components in a Rdn... So we won't initialize the Map and the
    // treeSet.
    this.schemaManager = schemaManager;
    upName = "";
    normName = "";
    normalized = schemaManager != null;
    h = 0;
}
 
Example #29
Source File: SubtreeSpecificationChecker.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a normalizing subtree specification parser.
 * 
 * @param schemaManager The SchemaManager
 */
public SubtreeSpecificationChecker( SchemaManager schemaManager )
{
    // place holder for the first input
    StringReader in = new StringReader( "" );
    this.lexer = new ReusableAntlrSubtreeSpecificationCheckerLexer( in );
    this.parser = new ReusableAntlrSubtreeSpecificationChecker( lexer );

    // this method MUST be called while we cannot do
    // constructor overloading for antlr generated parser
    this.parser.init( schemaManager );
}
 
Example #30
Source File: MyVDBaseCursor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new entry filtering Cursor over an existing Cursor using a
 * no filter initially: more can be added later after creation.
 * 
 * @param wrapped the underlying wrapped Cursor whose entries are filtered
 * @param searchControls the controls of search that created this Cursor
 * @param invocation the search operation invocation creating this Cursor
 * @param filter a single filter to be used
 */
public MyVDBaseCursor( Cursor<Entry> wrapped, SearchOperationContext operationContext,
    SchemaManager schemaManager )
{
    if ( IS_DEBUG )
    {
        LOG_CURSOR.debug( "Creating MyVDBaseCursor {}", this );
    }

    this.wrapped = wrapped;
    this.operationContext = operationContext;
    this.filters = new ArrayList<EntryFilter>();
    this.schemaManager = schemaManager;
}