org.apache.directory.server.i18n.I18n Java Examples

The following examples show how to use org.apache.directory.server.i18n.I18n. 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: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 7 votes vote down vote up
/**
 * Checks to see if an attribute is required by as determined from an entry's
 * set of objectClass attribute values.
 *
 * @return true if the objectClass values require the attribute, false otherwise
 * @throws Exception if the attribute is not recognized
 */
private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException
{
    // Never check the attributes if the extensibleObject objectClass is
    // declared for this entry
    Attribute objectClass = entry.get( OBJECT_CLASS_AT );

    if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) )
    {
        return;
    }

    for ( Attribute attribute : entry )
    {
        String attrOid = attribute.getAttributeType().getOid();

        AttributeType attributeType = attribute.getAttributeType();

        if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
            && !allowed.contains( attrOid ) )
        {
            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277,
                attribute.getUpId(), dn.getName() ) );
        }
    }
}
 
Example #2
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate
 * LdapException.
 */
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Dn dn = deleteContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253,
            subschemSubentryDn ) );
    }

    next( deleteContext );

    // Update the alias cache
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( dn.getNormName() ) )
        {
            notAliasCache.remove( dn.getNormName() );
        }
    }
}
 
Example #3
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    if ( IS_DEBUG )
    {
        LOG.debug( "Operation Context: {}", compareContext );
    }

    // Check that the requested AT exists
    // complain if we do not recognize the attribute being compared
    if ( !schemaManager.getAttributeTypeRegistry().contains( compareContext.getOid() ) )
    {
        throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
    }

    boolean result = next( compareContext );

    return result;
}
 
Example #4
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    if ( IS_DEBUG )
    {
        LOG.debug( "Operation Context: {}", compareContext );
    }

    // Check that the requested AT exists
    // complain if we do not recognize the attribute being compared
    if ( !schemaManager.getAttributeTypeRegistry().contains( compareContext.getOid() ) )
    {
        throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
    }

    boolean result = next( compareContext );

    return result;
}
 
Example #5
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Dn oldDn = moveAndRenameContext.getDn();

    // Don't allow M&R in the SSSE
    if ( oldDn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oldDn.getNormName() ) )
        {
            notAliasCache.remove( oldDn.getNormName() );
        }
    }

    next( moveAndRenameContext );
}
 
Example #6
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    Dn oriChildName = moveContext.getDn();

    if ( oriChildName.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    next( moveContext );

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
        {
            notAliasCache.remove( oriChildName.getNormName() );
        }
    }
}
 
Example #7
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to make sure the entry being deleted exists, and has no children, otherwise throws the appropriate
 * LdapException.
 */
public void delete( DeleteOperationContext deleteContext ) throws LdapException
{
    Dn dn = deleteContext.getDn();

    if ( dn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_253,
            subschemSubentryDn ) );
    }

    next( deleteContext );

    // Update the alias cache
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( dn.getNormName() ) )
        {
            notAliasCache.remove( dn.getNormName() );
        }
    }
}
 
Example #8
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Checks to see if an attribute is required by as determined from an entry's
 * set of objectClass attribute values.
 *
 * @return true if the objectClass values require the attribute, false otherwise
 * @throws Exception if the attribute is not recognized
 */
private void assertAllAttributesAllowed( Dn dn, Entry entry, Set<String> allowed ) throws LdapException
{
    // Never check the attributes if the extensibleObject objectClass is
    // declared for this entry
    Attribute objectClass = entry.get( OBJECT_CLASS_AT );

    if ( objectClass.contains( SchemaConstants.EXTENSIBLE_OBJECT_OC ) )
    {
        return;
    }

    for ( Attribute attribute : entry )
    {
        String attrOid = attribute.getAttributeType().getOid();

        AttributeType attributeType = attribute.getAttributeType();

        if ( !attributeType.isCollective() && ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS )
            && !allowed.contains( attrOid ) )
        {
            throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_277,
                attribute.getUpId(), dn.getName() ) );
        }
    }
}
 
Example #9
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
private Entry getOriginalEntry( OperationContext opContext ) throws LdapException
{
    // We have to use the admin session here, otherwise we may have
    // trouble reading the entry due to insufficient access rights
    CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();

    Entry foundEntry = adminSession.lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES,
        SchemaConstants.ALL_USER_ATTRIBUTES );

    if ( foundEntry != null )
    {
        return foundEntry;
    }
    else
    {
        // This is an error : we *must* have an entry if we want to be able to rename.
        LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
            opContext.getDn() ) );

        throw ldnfe;
    }
}
 
Example #10
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void moveAndRename( MoveAndRenameOperationContext moveAndRenameContext ) throws LdapException
{
    Dn oldDn = moveAndRenameContext.getDn();

    // Don't allow M&R in the SSSE
    if ( oldDn.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oldDn.getNormName() ) )
        {
            notAliasCache.remove( oldDn.getNormName() );
        }
    }

    next( moveAndRenameContext );
}
 
Example #11
Source File: ExceptionInterceptor.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
public void move( MoveOperationContext moveContext ) throws LdapException
{
    Dn oriChildName = moveContext.getDn();

    if ( oriChildName.equals( subschemSubentryDn ) )
    {
        throw new LdapUnwillingToPerformException( ResultCodeEnum.UNWILLING_TO_PERFORM, I18n.err( I18n.ERR_258,
            subschemSubentryDn, subschemSubentryDn ) );
    }

    next( moveContext );

    // Remove the original entry from the NotAlias cache, if needed
    synchronized ( notAliasCache )
    {
        if ( notAliasCache.containsKey( oriChildName.getNormName() ) )
        {
            notAliasCache.remove( oriChildName.getNormName() );
        }
    }
}
 
Example #12
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with 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 #13
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
private Entry getOriginalEntry( OperationContext opContext ) throws LdapException
{
    // We have to use the admin session here, otherwise we may have
    // trouble reading the entry due to insufficient access rights
    CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();

    Entry foundEntry = adminSession.lookup( opContext.getDn(), SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES,
        SchemaConstants.ALL_USER_ATTRIBUTES );

    if ( foundEntry != null )
    {
        return foundEntry;
    }
    else
    {
        // This is an error : we *must* have an entry if we want to be able to rename.
        LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
            opContext.getDn() ) );

        throw ldnfe;
    }
}
 
Example #14
Source File: LdapsInitializer.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
public static IoFilterChainBuilder init( LdapServer server ) throws LdapException
{
    SSLContext sslCtx;
    try
    {
    	sslCtx = server.getSSLContext();
    	
    }
    catch ( Exception e )
    {
        throw new LdapException( I18n.err( I18n.ERR_683 ), e );
    }

    DefaultIoFilterChainBuilder chain = new DefaultIoFilterChainBuilder();
    SslFilter sslFilter = new SslFilter( sslCtx );

    List<String> cipherSuites = server.getEnabledCipherSuites();
    if( ( cipherSuites != null ) && !cipherSuites.isEmpty() )
    {
        sslFilter.setEnabledCipherSuites( cipherSuites.toArray( new String[cipherSuites.size()] ) );
    }
    
    sslFilter.setWantClientAuth( true );
    chain.addLast( "sslFilter", sslFilter );
    return chain;
}
 
Example #15
Source File: BindRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Deal with a received BindRequest
 * 
 * @param ldapSession The current session
 * @param bindRequest The received BindRequest
 * @throws Exception If the authentication cannot be handled
 */
public void handle( LdapSession ldapSession, BindRequest bindRequest ) throws Exception
{
    LOG.debug( "Received: {}", bindRequest );

    // Guard clause:  LDAP version 3
    if ( !bindRequest.getVersion3() )
    {
        LOG.error( I18n.err( I18n.ERR_162 ) );
        LdapResult bindResult = bindRequest.getResultResponse().getLdapResult();
        bindResult.setResultCode( ResultCodeEnum.PROTOCOL_ERROR );
        bindResult.setDiagnosticMessage( I18n.err( I18n.ERR_163 ) );
        ldapSession.getIoSession().write( bindRequest.getResultResponse() );
        return;
    }

    // Deal with the two kinds of authentication : Simple and SASL
    if ( bindRequest.isSimple() )
    {
        handleSimpleAuth( ldapSession, bindRequest );
    }
    else
    {
        handleSaslAuth( ldapSession, bindRequest );
    }
}
 
Example #16
Source File: BindRequestHandler.java    From MyVirtualDirectory with Apache License 2.0 6 votes vote down vote up
/**
 * Deal with a received BindRequest
 *
 * @param ldapSession The current session
 * @param bindRequest The received BindRequest
 * @throws Exception If the authentication cannot be handled
 */
public void handle(LdapSession ldapSession, BindRequest bindRequest) throws Exception {
    LOG.debug("Received: {}", bindRequest);

    // Guard clause:  LDAP version 3
    if (!bindRequest.getVersion3()) {
        LOG.error(I18n.err(I18n.ERR_162));
        LdapResult bindResult = bindRequest.getResultResponse().getLdapResult();
        bindResult.setResultCode(ResultCodeEnum.PROTOCOL_ERROR);
        bindResult.setDiagnosticMessage(I18n.err(I18n.ERR_163));
        ldapSession.getIoSession().write(bindRequest.getResultResponse());
        return;
    }

    // Deal with the two kinds of authentication : Simple and SASL
    if (bindRequest.isSimple()) {
        handleSimpleAuth(ldapSession, bindRequest);
    } else {
        handleSaslAuth(ldapSession, bindRequest);
    }
}
 
Example #17
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with 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 #18
Source File: ApimanLdapServer.java    From apiman with Apache License 2.0 5 votes vote down vote up
private static void injectEntry(LdifEntry entry) throws Exception {
    if (entry.isChangeAdd()) {
        service.getAdminSession().add(
                new DefaultServerEntry(service.getSchemaManager(), entry.getEntry()));
    } else if (entry.isChangeModify()) {
        service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
    } else {
        String message = I18n.err(I18n.ERR_117, entry.getChangeType());
        throw new NamingException(message);
    }
}
 
Example #19
Source File: KDCServerAnnotationProcessor.java    From wildfly-core with GNU Lesser General Public License v2.1 5 votes vote down vote up
private static Transport createTransport( CreateTransport transportBuilder, int startPort ) {
    String protocol = transportBuilder.protocol();
    int port = transportBuilder.port();
    int nbThreads = transportBuilder.nbThreads();
    int backlog = transportBuilder.backlog();
    String address = transportBuilder.address();

    if ( port == -1 )
    {
        port = AvailablePortFinder.getNextAvailable( startPort );
        startPort = port + 1;
    }

    if ( protocol.equalsIgnoreCase( "TCP" ) )
    {
        Transport tcp = new TcpTransport( address, port, nbThreads, backlog );
        return tcp;
    }
    else if ( protocol.equalsIgnoreCase( "UDP" ) )
    {
        UdpTransport udp = new UdpTransport( address, port );
        return udp;
    }
    else
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_689, protocol ) );
    }
}
 
Example #20
Source File: LdapTestParent.java    From apiman with Apache License 2.0 5 votes vote down vote up
private static void injectEntry(LdifEntry entry) throws Exception {
    if (entry.isChangeAdd()) {
        service.getAdminSession().add(
                new DefaultServerEntry(service.getSchemaManager(), entry.getEntry()));
    } else if (entry.isChangeModify()) {
        service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
    } else {
        String message = I18n.err(I18n.ERR_117, entry.getChangeType());
        throw new NamingException(message);
    }
}
 
Example #21
Source File: BasicAuthLDAPTest.java    From apiman with Apache License 2.0 5 votes vote down vote up
private static void injectEntry(LdifEntry entry) throws Exception {
    if (entry.isChangeAdd()) {
        service.getAdminSession().add(
                new DefaultServerEntry(service.getSchemaManager(), entry.getEntry()));
    } else if (entry.isChangeModify()) {
        service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
    } else {
        String message = I18n.err(I18n.ERR_117, entry.getChangeType());
        throw new NamingException(message);
    }
}
 
Example #22
Source File: BasicAuthLDAPSTest.java    From apiman with Apache License 2.0 5 votes vote down vote up
private static void injectEntry(LdifEntry entry) throws Exception {
    if (entry.isChangeAdd()) {
        service.getAdminSession().add(
                new DefaultServerEntry(service.getSchemaManager(), entry.getEntry()));
    } else if (entry.isChangeModify()) {
        service.getAdminSession().modify(entry.getDn(), entry.getModificationItems());
    } else {
        String message = I18n.err(I18n.ERR_117, entry.getChangeType());
        throw new NamingException(message);
    }
}
 
Example #23
Source File: NormalizationInterceptor.java    From syncope with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    Dn dn = compareContext.getDn();
    
    if ( !dn.isSchemaAware() )
    {
        compareContext.setDn( new Dn( schemaManager, dn ) );
    }

    // Get the attributeType from the OID
    try
    {
        AttributeType attributeType = schemaManager.lookupAttributeTypeRegistry( compareContext.getOid() );

        // Translate the value from binary to String if the AT is HR
        if ( attributeType.getSyntax().isHumanReadable() && ( !compareContext.getValue().isHumanReadable() ) )
        {
            compareContext.setValue( compareContext.getValue() );
        }

        compareContext.setAttributeType( attributeType );
    }
    catch ( LdapException le )
    {
        throw new LdapInvalidAttributeTypeException( I18n.err( I18n.ERR_266, compareContext.getOid() ) );
    }

    return next( compareContext );
}
 
Example #24
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with 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 #25
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private Value<?> convert( AttributeType attributeType, Value<?> value ) throws LdapException
{
    if ( attributeType.getSyntax().isHumanReadable() )
    {
        if ( value instanceof BinaryValue )
        {
            try
            {
                return new StringValue( attributeType, new String( ( ( BinaryValue ) value ).getBytes(), "UTF-8" ) );
            }
            catch ( UnsupportedEncodingException uee )
            {
                String message = I18n.err( I18n.ERR_47 );
                LOG.error( message );
                throw new LdapException( message );
            }
        }
    }
    else
    {
        if ( value instanceof StringValue )
        {
            return new BinaryValue( attributeType, ( ( StringValue ) value ).getBytes() );
        }
    }

    return null;
}
 
Example #26
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private void ensureStarted() throws LdapServiceUnavailableException
{
    if ( !directoryService.isStarted() )
    {
        throw new LdapServiceUnavailableException( ResultCodeEnum.UNAVAILABLE, I18n.err( I18n.ERR_316 ) );
    }
}
 
Example #27
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
private LdapPartialResultException buildLdapPartialResultException( Dn childDn )
{
    LdapPartialResultException lpre = new LdapPartialResultException( I18n.err( I18n.ERR_315 ) );

    lpre.setRemainingDn( childDn );
    lpre.setResolvedDn( Dn.EMPTY_DN );

    return lpre;
}
 
Example #28
Source File: DefaultOperationManager.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Eagerly populates fields of operation contexts so multiple Interceptors
 * in the processing pathway can reuse this value without performing a
 * redundant lookup operation.
 *
 * @param opContext the operation context to populate with cached fields
 */
private void eagerlyPopulateFields( OperationContext opContext ) throws LdapException
{
    // If the entry field is not set for ops other than add for example
    // then we set the entry but don't freak if we fail to do so since it
    // may not exist in the first place

    if ( opContext.getEntry() == null )
    {
        // We have to use the admin session here, otherwise we may have
        // trouble reading the entry due to insufficient access rights
        CoreSession adminSession = opContext.getSession().getDirectoryService().getAdminSession();

        LookupOperationContext lookupContext = new LookupOperationContext( adminSession, opContext.getDn(),
            SchemaConstants.ALL_ATTRIBUTES_ARRAY );
        Entry foundEntry = opContext.getSession().getDirectoryService().getPartitionNexus().lookup( lookupContext );

        if ( foundEntry != null )
        {
            opContext.setEntry( foundEntry );
        }
        else
        {
            // This is an error : we *must* have an entry if we want to be able to rename.
            LdapNoSuchObjectException ldnfe = new LdapNoSuchObjectException( I18n.err( I18n.ERR_256_NO_SUCH_OBJECT,
                opContext.getDn() ) );

            throw ldnfe;
        }
    }
}
 
Example #29
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a new attribute which contains the values representing the union
 * of two attributes. If one attribute is null then the resultant attribute
 * returned is a copy of the non-null attribute. If both are null then we
 * cannot determine the attribute ID and an {@link IllegalArgumentException}
 * is raised.
 * 
 * @param attr0 the first attribute
 * @param attr1 the second attribute
 * @return a new attribute with the union of values from both attribute
 *         arguments
 * @throws LdapException if there are problems accessing attribute values
 */
public static Attribute getUnion( Attribute attr0, Attribute attr1 ) throws LdapException
{
    if ( attr0 == null && attr1 == null )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_465 ) );
    }
    else if ( attr0 == null )
    {
        return attr1.clone();
    }
    else if ( attr1 == null )
    {
        return attr0.clone();
    }
    else if ( !attr0.getAttributeType().equals( attr1.getAttributeType() ) )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_466 ) );
    }

    Attribute attr = attr0.clone();

    for ( Value<?> value : attr1 )
    {
        attr.add( value );
    }

    return attr;
}
 
Example #30
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Creates the root nexus singleton of the entire system.  The root DSE has
 * several attributes that are injected into it besides those that may
 * already exist.  As partitions are added to the system more namingContexts
 * attributes are added to the rootDSE.
 *
 * @see <a href="http://www.faqs.org/rfcs/rfc3045.html">Vendor Information</a>
 * @param rootDse the root entry for the DSA
 * @throws javax.naming.Exception on failure to initialize
 */
public DefaultPartitionNexus( Entry rootDse ) throws Exception
{
    id = ID;
    suffixDn = null;

    // setup that root DSE
    this.rootDse = rootDse;

    // Add the basic informations
    rootDse.put( SchemaConstants.SUBSCHEMA_SUBENTRY_AT, ServerDNConstants.CN_SCHEMA_DN );
    rootDse.put( SchemaConstants.SUPPORTED_LDAP_VERSION_AT, "3" );
    rootDse.put( SchemaConstants.SUPPORTED_FEATURES_AT, SchemaConstants.FEATURE_ALL_OPERATIONAL_ATTRIBUTES );
    rootDse.put( SchemaConstants.SUPPORTED_EXTENSION_AT, NoticeOfDisconnect.EXTENSION_OID );

    // Add the objectClasses
    rootDse.put( SchemaConstants.OBJECT_CLASS_AT, SchemaConstants.TOP_OC, SchemaConstants.EXTENSIBLE_OBJECT_OC );

    // Add the 'vendor' name and version infos
    rootDse.put( SchemaConstants.VENDOR_NAME_AT, ASF );

    Properties props = new Properties();

    try
    {
        props.load( getClass().getResourceAsStream( "version.properties" ) );
    }
    catch ( IOException e )
    {
        LOG.error( I18n.err( I18n.ERR_33 ) );
    }

    rootDse.put( SchemaConstants.VENDOR_VERSION_AT, props.getProperty( "apacheds.version", "UNKNOWN" ) );

    // The rootDSE uuid has been randomly created
    rootDse.put( SchemaConstants.ENTRY_UUID_AT, "f290425c-8272-4e62-8a67-92b06f38dbf5" );
}