org.apache.directory.server.core.api.interceptor.context.AddOperationContext Java Examples

The following examples show how to use org.apache.directory.server.core.api.interceptor.context.AddOperationContext. 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: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddRequest addRequest, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, addRequest );

    addContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();
    try
    {
        operationManager.add( addContext );
    }
    catch ( LdapException e )
    {
        addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
        throw e;
    }
    addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
}
 
Example #2
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn addDn = addContext.getDn();
    
    if ( !addDn.isSchemaAware() )
    {
        addContext.setDn( new Dn( schemaManager, addDn ) );
    }
    
    Dn entryDn = addContext.getEntry().getDn();
    
    if ( !entryDn.isSchemaAware() )
    {
        addContext.getEntry().setDn( new Dn( schemaManager, entryDn ) );
    }
    
    addRdnAttributesToEntry( addContext.getDn(), addContext.getEntry() );
    
    next( addContext );
}
 
Example #3
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddRequest addRequest, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, addRequest );

    addContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();
    try
    {
        operationManager.add( addContext );
    }
    catch ( LdapException e )
    {
        addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
        throw e;
    }
    addRequest.getResultResponse().addAllControls( addContext.getResponseControls() );
}
 
Example #4
Source File: InMemorySchemaPartition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws Exception {
    if (initialized)
        return;

    LOG.debugf("Initializing schema partition %s", getId());
    suffixDn.apply(schemaManager);
    super.doInit();

    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();

            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
 
Example #5
Source File: InMemorySchemaPartition.java    From bouncr with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws InvalidNameException, Exception {
    if (initialized)
        return;

    LOG.debug("Initializing schema partition " + getId());
    suffixDn.apply(schemaManager);
    super.doInit();

    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();

            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
 
Example #6
Source File: InMemorySchemaPartition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws Exception {
    if (initialized)
        return;

    LOG.debug("Initializing schema partition " + getId());
    suffixDn.apply(schemaManager);
    super.doInit();

    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();

            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
 
Example #7
Source File: InMemorySchemaPartition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws Exception {
    if (initialized)
        return;

    LOG.debug("Initializing schema partition " + getId());
    suffixDn.apply(schemaManager);
    super.doInit();

    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();

            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
 
Example #8
Source File: InMemorySchemaPartition.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws Exception {
    if (initialized)
        return;

    LOG.debug("Initializing schema partition " + getId());
    suffixDn.apply(schemaManager);
    super.doInit();

    // load schema
    final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
    for (String resourcePath : new TreeSet<String>(resMap.keySet())) {
        if (resourcePath.endsWith(".ldif")) {
            URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
            LdifReader reader = new LdifReader(resource.openStream());
            LdifEntry ldifEntry = reader.next();
            reader.close();

            Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
            // add mandatory attributes
            if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
                entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
            }
            if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
                entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
            }
            AddOperationContext addContext = new AddOperationContext(null, entry);
            super.add(addContext);
        }
    }
}
 
Example #9
Source File: InMemorySchemaPartition.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Partition initialization - loads schema entries from the files on classpath.
 *
 * @see org.apache.directory.server.core.partition.impl.avl.AvlPartition#doInit()
 */
@Override
protected void doInit() throws InvalidNameException, Exception {
   if (initialized) {
      return;
   }

   LOG.debug("Initializing schema partition " + getId());
   suffixDn.apply(schemaManager);
   super.doInit();

   // load schema
   final Map<String, Boolean> resMap = ResourceMap.getResources(Pattern.compile("schema[/\\Q\\\\E]ou=schema.*"));
   for (String resourcePath : new TreeSet<>(resMap.keySet())) {
      if (resourcePath.endsWith(".ldif")) {
         URL resource = DefaultSchemaLdifExtractor.getUniqueResource(resourcePath, "Schema LDIF file");
         LdifEntry ldifEntry;
         try (LdifReader reader = new LdifReader(resource.openStream())) {
            ldifEntry = reader.next();
         }

         Entry entry = new DefaultEntry(schemaManager, ldifEntry.getEntry());
         // add mandatory attributes
         if (entry.get(SchemaConstants.ENTRY_CSN_AT) == null) {
            entry.add(SchemaConstants.ENTRY_CSN_AT, defaultCSNFactory.newInstance().toString());
         }
         if (entry.get(SchemaConstants.ENTRY_UUID_AT) == null) {
            entry.add(SchemaConstants.ENTRY_UUID_AT, UUID.randomUUID().toString());
         }
         AddOperationContext addContext = new AddOperationContext(null, entry);
         super.add(addContext);
      }
   }
}
 
Example #10
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( Entry entry, boolean ignoreReferral, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, entry );

    addContext.setLogChange( log );
    setReferralHandling( addContext, ignoreReferral );

    OperationManager operationManager = directoryService.getOperationManager();
    operationManager.add( addContext );
}
 
Example #11
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( Entry entry, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, entry );

    addContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();
    operationManager.add( addContext );
}
 
Example #12
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Partition partition = getPartition( addContext.getDn() );
    partition.add( addContext );

    
    // MyVD doesn't care about csn
    // Attribute at = addContext.getEntry().get( SchemaConstants.ENTRY_CSN_AT );
    // directoryService.setContextCsn( at.getString() );
}
 
Example #13
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( Entry entry, boolean ignoreReferral, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, entry );

    addContext.setLogChange( log );
    setReferralHandling( addContext, ignoreReferral );

    OperationManager operationManager = directoryService.getOperationManager();
    operationManager.add( addContext );
}
 
Example #14
Source File: DefaultCoreSession.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( Entry entry, LogChange log ) throws LdapException
{
    AddOperationContext addContext = new AddOperationContext( this, entry );

    addContext.setLogChange( log );

    OperationManager operationManager = directoryService.getOperationManager();
    operationManager.add( addContext );
}
 
Example #15
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Partition partition = getPartition( addContext.getDn() );
    partition.add( addContext );
}
 
Example #16
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * In the pre-invocation state this interceptor method checks to see if the entry to be added already exists.  If it
 * does an exception is raised.
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();

    if ( subschemSubentryDn.equals( name ) )
    {
        throw new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_249 ) );
    }

    Dn suffix = nexus.getSuffixDn( name );

    // we're adding the suffix entry so just ignore stuff to mess with the parent
    if ( suffix.equals( name ) )
    {
        next( addContext );
        return;
    }

    Dn parentDn = name.getParent();

    // check if we're trying to add to a parent that is an alias
    boolean notAnAlias;

    synchronized ( notAliasCache )
    {
        notAnAlias = notAliasCache.containsKey( parentDn.getNormName() );
    }

    /*if ( !notAnAlias )
    {
        // We don't know if the parent is an alias or not, so we will launch a
        // lookup, and update the cache if it's not an alias
        Entry attrs;

        try
        {
            CoreSession session = addContext.getSession();
            LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );

            attrs = directoryService.getPartitionNexus().lookup( lookupContext );
        }
        catch ( Exception e )
        {
            LdapNoSuchObjectException e2 = new LdapNoSuchObjectException(
                I18n.err( I18n.ERR_251_PARENT_NOT_FOUND, parentDn.getName() ) );
            throw e2;
        }

        Attribute objectClass = ( ( ClonedServerEntry ) attrs ).getOriginalEntry().get(
            OBJECT_CLASS_AT );

        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
        {
            String msg = I18n.err( I18n.ERR_252_ALIAS_WITH_CHILD_NOT_ALLOWED, name.getName(), parentDn.getName() );
            LdapAliasException e = new LdapAliasException( msg );
            //e.setResolvedName( DNFactory.create( parentDn.getName() ) );
            throw e;
        }
        else
        {
            synchronized ( notAliasCache )
            {
                notAliasCache.put( parentDn.getNormName(), parentDn );
            }
        }
    }*/

    next( addContext );
}
 
Example #17
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();
    Entry entry = addContext.getEntry();

    // Not the responsibility of MyVD to verify schema
    //check( name, entry );

    // Special checks for the MetaSchema branch
    if ( name.isDescendantOf( schemaBaseDn ) )
    {
        // get the schema name
        String schemaName = getSchemaName( name );

        if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_SCHEMA_OC ) )
        {
            next( addContext );

            if ( schemaManager.isSchemaLoaded( schemaName ) )
            {
                // Update the OC superiors for each added ObjectClass
                computeSuperiors();
            }
        }
        else if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_OBJECT_CLASS_OC ) )
        {
            // This is an ObjectClass addition
            checkOcSuperior( addContext.getEntry() );

            next( addContext );

            // Update the structures now that the schema element has been added
            Schema schema = schemaManager.getLoadedSchema( schemaName );

            if ( ( schema != null ) && schema.isEnabled() )
            {
                Attribute oidAT = entry.get( MetaSchemaConstants.M_OID_AT );
                String ocOid = oidAT.getString();

                ObjectClass addedOC = schemaManager.lookupObjectClassRegistry( ocOid );
                computeSuperior( addedOC );
            }
        }
        else if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_ATTRIBUTE_TYPE_OC ) )
        {
            // This is an AttributeType addition
            next( addContext );
        }
        else
        {
            next( addContext );
        }

    }
    else
    {
        next( addContext );
    }
}
 
Example #18
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();
    Entry entry = addContext.getEntry();

    // Not the responsibility of MyVD to verify schema
    //check( name, entry );

    // Special checks for the MetaSchema branch
    if ( name.isDescendantOf( schemaBaseDn ) )
    {
        // get the schema name
        String schemaName = getSchemaName( name );

        if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_SCHEMA_OC ) )
        {
            next( addContext );

            if ( schemaManager.isSchemaLoaded( schemaName ) )
            {
                // Update the OC superiors for each added ObjectClass
                computeSuperiors();
            }
        }
        else if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_OBJECT_CLASS_OC ) )
        {
            // This is an ObjectClass addition
            checkOcSuperior( addContext.getEntry() );

            next( addContext );

            // Update the structures now that the schema element has been added
            Schema schema = schemaManager.getLoadedSchema( schemaName );

            if ( ( schema != null ) && schema.isEnabled() )
            {
                Attribute oidAT = entry.get( MetaSchemaConstants.M_OID_AT );
                String ocOid = oidAT.getString();

                ObjectClass addedOC = schemaManager.lookupObjectClassRegistry( ocOid );
                computeSuperior( addedOC );
            }
        }
        else if ( entry.contains( OBJECT_CLASS_AT, SchemaConstants.META_ATTRIBUTE_TYPE_OC ) )
        {
            // This is an AttributeType addition
            next( addContext );
        }
        else
        {
            next( addContext );
        }

    }
    else
    {
        next( addContext );
    }
}
 
Example #19
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * In the pre-invocation state this interceptor method checks to see if the entry to be added already exists.  If it
 * does an exception is raised.
 */
public void add( AddOperationContext addContext ) throws LdapException
{
    Dn name = addContext.getDn();

    if ( subschemSubentryDn.equals( name ) )
    {
        throw new LdapEntryAlreadyExistsException( I18n.err( I18n.ERR_249 ) );
    }

    Dn suffix = nexus.getSuffixDn( name );

    // we're adding the suffix entry so just ignore stuff to mess with the parent
    if ( suffix.equals( name ) )
    {
        next( addContext );
        return;
    }

    Dn parentDn = name.getParent();

    // check if we're trying to add to a parent that is an alias
    boolean notAnAlias;

    synchronized ( notAliasCache )
    {
        notAnAlias = notAliasCache.containsKey( parentDn.getNormName() );
    }

    /*if ( !notAnAlias )
    {
        // We don't know if the parent is an alias or not, so we will launch a
        // lookup, and update the cache if it's not an alias
        Entry attrs;

        try
        {
            CoreSession session = addContext.getSession();
            LookupOperationContext lookupContext = new LookupOperationContext( session, parentDn, SchemaConstants.ALL_ATTRIBUTES_ARRAY );

            attrs = directoryService.getPartitionNexus().lookup( lookupContext );
        }
        catch ( Exception e )
        {
            LdapNoSuchObjectException e2 = new LdapNoSuchObjectException(
                I18n.err( I18n.ERR_251_PARENT_NOT_FOUND, parentDn.getName() ) );
            throw e2;
        }

        Attribute objectClass = ( ( ClonedServerEntry ) attrs ).getOriginalEntry().get(
            OBJECT_CLASS_AT );

        if ( objectClass.contains( SchemaConstants.ALIAS_OC ) )
        {
            String msg = I18n.err( I18n.ERR_252_ALIAS_WITH_CHILD_NOT_ALLOWED, name.getName(), parentDn.getName() );
            LdapAliasException e = new LdapAliasException( msg );
            //e.setResolvedName( DNFactory.create( parentDn.getName() ) );
            throw e;
        }
        else
        {
            synchronized ( notAliasCache )
            {
                notAliasCache.put( parentDn.getNormName(), parentDn );
            }
        }
    }*/

    next( addContext );
}