javax.naming.NoPermissionException#org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException源码实例Demo

下面列出了javax.naming.NoPermissionException#org.apache.directory.api.ldap.model.exception.LdapEntryAlreadyExistsException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: keycloak   文件: LDAPEmbeddedServer.java
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();
    }
}
 
源代码2 项目: MyVirtualDirectory   文件: ExceptionInterceptor.java
/**
 * 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 );
}
 
源代码3 项目: MyVirtualDirectory   文件: ExceptionInterceptor.java
/**
 * 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 );
}