Java Code Examples for org.apache.directory.server.core.api.partition.Partition

The following examples show how to use org.apache.directory.server.core.api.partition.Partition. These examples are extracted from open source projects. 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 Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Partition partition = getPartition( deleteContext.getDn() );
    Entry deletedEntry = partition.delete( deleteContext );

    Entry entry = deleteContext.getEntry();
    
    
    // MyVD doesn't care about csn
    // Attribute csn = entry.get( ENTRY_CSN_AT );
    // can be null while doing subentry deletion
    // //TODO verify if this gets in the way of replication
    // if ( csn != null )
    // {
    //     directoryService.setContextCsn( csn.getString() );
    // }

    return deletedEntry;
}
 
Example 2
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();

    if ( IS_DEBUG )
    {
        LOG.debug( "Check if Dn '" + dn + "' exists." );
    }

    if ( dn.isRootDse() )
    {
        return true;
    }

    Partition partition = getPartition( dn );

    return partition.hasEntry( hasEntryContext );
}
 
Example 3
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    // Special case : if we don't have any modification to apply, just return
    if ( modifyContext.getModItems().size() == 0 )
    {
        return;
    }

    Partition partition = getPartition( modifyContext.getDn() );

    partition.modify( modifyContext );

    if ( modifyContext.isPushToEvtInterceptor() )
    {
        directoryService.getInterceptor( InterceptorEnum.EVENT_INTERCEPTOR.getName() ).modify( modifyContext );
    }

    Entry alteredEntry = modifyContext.getAlteredEntry();

    if ( alteredEntry != null )
    {
        // MyVD doesn't care about csn
    	// directoryService.setContextCsn( alteredEntry.get( ENTRY_CSN_AT ).getString() );
    }
}
 
Example 4
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
    Dn base = searchContext.getDn();

    // TODO since we're handling the *, and + in the EntryFilteringCursor
    // we may not need this code: we need see if this is actually the
    // case and remove this code.
    if ( base.size() == 0 )
    {
        return searchFromRoot( searchContext );
    }

    // Not sure we need this code...
    base.apply( schemaManager );

    // Normal case : do a search on the specific partition
    Partition backend = getPartition( base );

    return backend.search( searchContext );
}
 
Example 5
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Partition getPartition( Dn dn ) throws LdapException
{
    Partition parent = null;

    synchronized ( partitionLookupTree )
    {
        parent = partitionLookupTree.getElement( dn );
    }

    if ( parent == null )
    {
        throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_268, dn ) );
    }
    else
    {
        return parent;
    }
}
 
Example 6
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean hasEntry( HasEntryOperationContext hasEntryContext ) throws LdapException
{
    Dn dn = hasEntryContext.getDn();

    if ( IS_DEBUG )
    {
        LOG.debug( "Check if Dn '" + dn + "' exists." );
    }

    if ( dn.isRootDse() )
    {
        return true;
    }

    Partition partition = getPartition( dn );

    return partition.hasEntry( hasEntryContext );
}
 
Example 7
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void modify( ModifyOperationContext modifyContext ) throws LdapException
{
    // Special case : if we don't have any modification to apply, just return
    if ( modifyContext.getModItems().size() == 0 )
    {
        return;
    }

    Partition partition = getPartition( modifyContext.getDn() );

    partition.modify( modifyContext );

    if ( modifyContext.isPushToEvtInterceptor() )
    {
        directoryService.getInterceptor( InterceptorEnum.EVENT_INTERCEPTOR.getName() ).modify( modifyContext );
    }
}
 
Example 8
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public EntryFilteringCursor search( SearchOperationContext searchContext ) throws LdapException
{
    Dn base = searchContext.getDn();

    // TODO since we're handling the *, and + in the EntryFilteringCursor
    // we may not need this code: we need see if this is actually the
    // case and remove this code.
    if ( base.size() == 0 )
    {
        return searchFromRoot( searchContext );
    }

    // Not sure we need this code...
    base.apply( schemaManager );

    // Normal case : do a search on the specific partition
    Partition backend = getPartition( base );

    return backend.search( searchContext );
}
 
Example 9
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Partition getPartition( Dn dn ) throws LdapException
{
    Partition parent = null;

    if ( !dn.isSchemaAware() )
    {
        dn.apply( schemaManager );
    }

    synchronized ( partitionLookupTree )
    {
        parent = partitionLookupTree.getElement( dn );
    }

    if ( parent == null )
    {
        throw new LdapNoSuchObjectException( I18n.err( I18n.ERR_268, dn ) );
    }
    else
    {
        return parent;
    }
}
 
Example 10
Source Project: syncope   Source File: ApacheDSStartStopListener.java    License: Apache License 2.0 6 votes vote down vote up
private void initSystemPartition() throws Exception {
    JdbmPartitionFactory partitionFactory = new JdbmPartitionFactory();

    Partition systemPartition = partitionFactory.createPartition(
            service.getSchemaManager(),
            service.getDnFactory(),
            "system",
            ServerDNConstants.SYSTEM_DN,
            500,
            new File(service.getInstanceLayout().getPartitionsDirectory(), "system"));
    systemPartition.setSchemaManager(service.getSchemaManager());

    partitionFactory.addIndex(systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100);

    service.setSystemPartition(systemPartition);
}
 
Example 11
/**
 * Add a new partition to the directory server.
 *
 * @param partitionName - The name of the partition.
 * @param indexes - The attributes to index.
 * @return This Builder for subsequent changes.
 */
public Builder addPartition(final String id, final String partitionName, final int indexSize, final String ... indexes) throws Exception {
    assertNotStarted();
    if (directoryService == null) {
        throw new IllegalStateException("The Directory service has not been created.");
    }

    SchemaManager schemaManager = directoryService.getSchemaManager();
    PartitionFactory partitionFactory = directoryServiceFactory.getPartitionFactory();
    Partition partition = partitionFactory.createPartition(schemaManager, directoryService.getDnFactory(), id, partitionName, 1000, workingDir);
    for (String current : indexes) {
        partitionFactory.addIndex(partition, current, indexSize);
    }
    partition.setCacheService(directoryService.getCacheService());
    partition.initialize();
    directoryService.addPartition(partition);

    return this;
}
 
Example 12
Source Project: aws-iam-ldap-bridge   Source File: Runner.java    License: Apache License 2.0 6 votes vote down vote up
public void createStructure() throws Exception {
    String rootDN = AWSIAMAuthenticator.getConfig().rootDN;
    Dn dnIAM = service.getDnFactory().create(rootDN);
    if (!utils.exists(dnIAM)) {
        IAM_LOG.info("Creating partition " + rootDN);
        Partition iamPartition = utils.addPartition("iam", rootDN, service.getDnFactory());

        // Index some attributes on the apache partition
        utils.addIndex(iamPartition, "objectClass", "ou", "uid", "gidNumber", "uidNumber", "cn");

        if (!utils.exists(dnIAM)) {
            IAM_LOG.info("Creating root node " + rootDN);
            Rdn rdn = dnIAM.getRdn(0);
            Entry entryIAM = new DefaultEntry(service.getSchemaManager(), dnIAM, "objectClass: top", "objectClass: domain",
                    "entryCsn: " + service.getCSN(), SchemaConstants.ENTRY_UUID_AT + ": " + UUID.randomUUID().toString(),
                    rdn.getType() + ": " + rdn.getValue());
            service.getAdminSession().add(entryIAM);
            checkErrors();
        }
    }
    service.sync();
}
 
Example 13
Source Project: quarkus-http   Source File: KerberosKDCUtil.java    License: Apache License 2.0 5 votes vote down vote up
private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id,
        final String suffix) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir.toFile());
    pf.addIndex(p, "krb5PrincipalName", 10);
    p.initialize();
    directoryService.addPartition(p);
}
 
Example 14
Source Project: light-oauth2   Source File: ApacheDirectoryServer.java    License: Apache License 2.0 5 votes vote down vote up
private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id,
                                    final String suffix) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir.toFile());
    pf.addIndex(p, "krb5PrincipalName", 10);
    p.initialize();
    directoryService.addPartition(p);
}
 
Example 15
Source Project: light-oauth2   Source File: ApacheDirectoryServer.java    License: Apache License 2.0 5 votes vote down vote up
private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id,
                                    final String suffix) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir.toFile());
    pf.addIndex(p, "krb5PrincipalName", 10);
    p.initialize();
    directoryService.addPartition(p);
}
 
Example 16
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: 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 17
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
    Dn dn = lookupContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        return new ClonedServerEntry( rootDse.clone() );
    }

    // This is for the case we do a lookup on the rootDSE
    if ( dn.isRootDse() )
    {
        Entry retval = new ClonedServerEntry( rootDse );

        return retval;
    }

    Partition partition = getPartition( dn );
    Entry entry = partition.lookup( lookupContext );

    if ( entry == null )
    {
        LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: "
            + dn.getName() );

        throw e;
    }

    return entry;
}
 
Example 18
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    // Get the current partition
    Partition partition = getPartition( moveContext.getDn() );

    partition.move( moveContext );

    Entry entry = moveContext.getModifiedEntry();
    
    // MyVD doesn't care about csn
    // directoryService.setContextCsn( entry.get( ENTRY_CSN_AT ).getString() );
}
 
Example 19
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Partition partition = getPartition( moveAndRenameContext.getDn() );
    partition.moveAndRename( moveAndRenameContext );

    Entry entry = moveAndRenameContext.getModifiedEntry();
    
    // MyVD doesn't care about csn
    // directoryService.setContextCsn( entry.get( ENTRY_CSN_AT ).getString() );
}
 
Example 20
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void rename( RenameOperationContext renameContext ) throws LdapException
{
    Partition partition = getPartition( renameContext.getDn() );
    partition.rename( renameContext );

    Entry entry = renameContext.getModifiedEntry();
    
    // MyVD doesn't care about csn
    // directoryService.setContextCsn( entry.get( ENTRY_CSN_AT ).getString() );
}
 
Example 21
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void unbind( UnbindOperationContext unbindContext ) throws LdapException
{
    Dn unbindContextDn = unbindContext.getDn();

    if ( !Dn.isNullOrEmpty( unbindContextDn ) )
    {
        Partition partition = getPartition( unbindContext.getDn() );
        partition.unbind( unbindContext );
    }
}
 
Example 22
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Dn getSuffixDn( Dn dn ) throws LdapException
{
    Partition partition = getPartition( dn );

    return partition.getSuffixDn();
}
 
Example 23
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
public void sync() throws Exception
{
    MultiException error = null;

    for ( Partition partition : this.partitions.values() )
    {
        try
        {
            partition.saveContextCsn();
            partition.sync();
        }
        catch ( Exception e )
        {
            LOG.warn( "Failed to flush partition data out.", e );
            if ( error == null )
            {
                //noinspection ThrowableInstanceNeverThrown
                error = new MultiException( I18n.err( I18n.ERR_265 ) );
            }

            // @todo really need to send this info to a monitor
            error.addThrowable( e );
        }
    }

    if ( error != null )
    {
        throw error;
    }
}
 
Example 24
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Partition partition = getPartition( deleteContext.getDn() );
    Entry deletedEntry = partition.delete( deleteContext );

    return deletedEntry;
}
 
Example 25
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Entry lookup( LookupOperationContext lookupContext ) throws LdapException
{
    Dn dn = lookupContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        return new ClonedServerEntry( rootDse.clone() );
    }

    // This is for the case we do a lookup on the rootDSE
    if ( dn.isRootDse() )
    {
        Entry retval = new ClonedServerEntry( rootDse );

        return retval;
    }

    Partition partition = getPartition( dn );
    Entry entry = partition.lookup( lookupContext );

    if ( entry == null )
    {
        LdapNoSuchObjectException e = new LdapNoSuchObjectException( "Attempt to lookup non-existant entry: "
            + dn.getName() );

        throw e;
    }

    return entry;
}
 
Example 26
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    // Get the current partition
    Partition partition = getPartition( moveContext.getDn() );

    partition.move( moveContext );
}
 
Example 27
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void unbind( UnbindOperationContext unbindContext ) throws LdapException
{
    Dn unbindContextDn = unbindContext.getDn();

    if ( !Dn.isNullOrEmpty( unbindContextDn ) )
    {
        Partition partition = getPartition( unbindContext.getDn() );
        partition.unbind( unbindContext );
    }
}
 
Example 28
Source Project: MyVirtualDirectory   Source File: DefaultPartitionNexus.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public Dn getSuffixDn( Dn dn ) throws LdapException
{
    Partition partition = getPartition( dn );

    return partition.getSuffixDn();
}
 
Example 29
private static void createPartition(final DirectoryServiceFactory dsf, final SchemaManager schemaManager, final String id,
        final String suffix, final DirectoryService directoryService, final File workingDir) throws Exception {
    PartitionFactory pf = dsf.getPartitionFactory();
    Partition p = pf.createPartition(schemaManager, id, suffix, 1000, workingDir);
    pf.addIndex(p, "uid", 10);
    pf.addIndex(p, "departmentNumber", 10);
    pf.addIndex(p, "member", 10);
    pf.addIndex(p, "memberOf", 10);
    p.initialize();
    directoryService.addPartition(p);
}
 
Example 30
Source Project: aws-iam-ldap-bridge   Source File: Runner.java    License: Apache License 2.0 5 votes vote down vote up
public Partition getPartition(DirectoryService directory, String id) throws LdapException {
    Set<? extends Partition> partitions = directory.getPartitions();
    for (Partition part : partitions) {
        if (part.getId().equalsIgnoreCase(id)) return part;
    }
    throw new LdapException("No partition with the ID " + id);
}