org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException Java Examples

The following examples show how to use org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException. 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: LDAPEmbeddedServer.java    From keycloak with Apache License 2.0 5 votes vote down vote up
private static void importLdifContent(DirectoryService directoryService, String ldifContent) throws Exception {
    LdifReader ldifReader = new LdifReader(IOUtils.toInputStream(ldifContent));

    try {
        for (LdifEntry ldifEntry : ldifReader) {
            try {
                directoryService.getAdminSession().add(new DefaultEntry(directoryService.getSchemaManager(), ldifEntry.getEntry()));
            } catch (LdapEntryAlreadyExistsException ignore) {
                log.info("Entry " + ldifEntry.getDn() + " already exists. Ignoring.");
            }
        }
    } finally {
        ldifReader.close();
    }
}
 
Example #2
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 #3
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 );
}