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

The following examples show how to use org.apache.directory.api.ldap.model.exception.LdapNoSuchAttributeException. 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: DefaultObjectClassRegistry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public ObjectClass unregister( String numericOid ) throws LdapException
{
    try
    {
        ObjectClass removed = super.unregister( numericOid );

        // Deleting an ObjectClass which might be used as a superior means we have
        // to recursively update the descendant map. We also have to remove
        // the at.oid -> descendant relation
        oidToDescendants.remove( numericOid );

        // Now recurse if needed
        unregisterDescendants( removed, removed.getSuperiors() );

        return removed;
    }
    catch ( LdapException ne )
    {
        throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
    }
}
 
Example #2
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributeType unregister( String numericOid ) throws LdapException
{
    try
    {
        AttributeType removed = super.unregister( numericOid );

        removeMappingFor( removed );

        // Deleting an AT which might be used as a superior means we have
        // to recursively update the descendant map. We also have to remove
        // the at.oid -> descendant relation
        oidToDescendantSet.remove( numericOid );

        // Now recurse if needed
        unregisterDescendants( removed, removed.getSuperior() );

        return removed;
    }
    catch ( LdapException ne )
    {
        throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
    }
}
 
Example #3
Source File: DefaultObjectClassRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasDescendants( String ancestorId ) throws LdapException
{
    try
    {
        String oid = getOidByName( ancestorId );
        Set<ObjectClass> descendants = oidToDescendants.get( oid );
        return ( descendants != null ) && !descendants.isEmpty();
    }
    catch ( LdapException ne )
    {
        throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
    }
}
 
Example #4
Source File: DefaultObjectClassRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void registerDescendants( ObjectClass objectClass, List<ObjectClass> ancestors )
    throws LdapException
{
    // add this attribute to descendant list of other attributes in superior chain
    if ( ( ancestors == null ) || ancestors.isEmpty() )
    {
        return;
    }

    for ( ObjectClass ancestor : ancestors )
    {
        // Get the ancestor's descendant, if any
        Set<ObjectClass> descendants = oidToDescendants.get( ancestor.getOid() );

        // Initialize the descendant Set to store the descendants for the attributeType
        if ( descendants == null )
        {
            descendants = new HashSet<>( 1 );
            oidToDescendants.put( ancestor.getOid(), descendants );
        }

        // Add the current ObjectClass as a descendant
        descendants.add( objectClass );

        try
        {
            // And recurse until we reach the top of the hierarchy
            registerDescendants( objectClass, ancestor.getSuperiors() );
        }
        catch ( LdapException ne )
        {
            throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
        }
    }
}
 
Example #5
Source File: DefaultObjectClassRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void unregisterDescendants( ObjectClass attributeType, List<ObjectClass> ancestors )
    throws LdapException
{
    // add this attribute to descendant list of other attributes in superior chain
    if ( ( ancestors == null ) || ancestors.isEmpty() )
    {
        return;
    }

    for ( ObjectClass ancestor : ancestors )
    {
        // Get the ancestor's descendant, if any
        Set<ObjectClass> descendants = oidToDescendants.get( ancestor.getOid() );

        if ( descendants != null )
        {
            descendants.remove( attributeType );

            if ( descendants.isEmpty() )
            {
                oidToDescendants.remove( ancestor.getOid() );
            }
        }

        try
        {
            // And recurse until we reach the top of the hierarchy
            unregisterDescendants( attributeType, ancestor.getSuperiors() );
        }
        catch ( LdapException ne )
        {
            throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
        }
    }
}
 
Example #6
Source File: ImmutableAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public String getOidByName( String name ) throws LdapException
{
    try
    {
        return immutableAttributeTypeRegistry.getOidByName( name );
    }
    catch ( LdapException le )
    {
        throw new LdapNoSuchAttributeException( le.getMessage(), le );
    }
}
 
Example #7
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean hasDescendants( String ancestorId ) throws LdapException
{
    try
    {
        String oid = getOidByName( ancestorId );
        Set<AttributeType> descendants = oidToDescendantSet.get( oid );
        return ( descendants != null ) && !descendants.isEmpty();
    }
    catch ( LdapException ne )
    {
        throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
    }
}
 
Example #8
Source File: DefaultAttributeTypeRegistry.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public AttributeType lookup( String oid ) throws LdapException
{
    try
    {
        return super.lookup( oid );
    }
    catch ( LdapException ne )
    {
        throw new LdapNoSuchAttributeException( ne.getMessage(), ne );
    }
}
 
Example #9
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    Attribute attr = compareContext.getOriginalEntry().get( compareContext.getAttributeType() );

    // complain if the attribute being compared does not exist in the entry
    if ( attr == null )
    {
        throw new LdapNoSuchAttributeException();
    }

    // see first if simple match without normalization succeeds
    if ( attr.contains( compareContext.getValue() ) )
    {
        return true;
    }

    // now must apply normalization to all values (attr and in request) to compare

    /*
     * Get ahold of the normalizer for the attribute and normalize the request
     * assertion value for comparisons with normalized attribute values.  Loop
     * through all values looking for a match.
     */
    Normalizer normalizer = compareContext.getAttributeType().getEquality().getNormalizer();
    Value<?> reqVal = normalizer.normalize( compareContext.getValue() );

    for ( Value<?> value : attr )
    {
        Value<?> attrValObj = normalizer.normalize( value );

        if ( attrValObj.equals( reqVal ) )
        {
            return true;
        }
    }

    return false;
}
 
Example #10
Source File: DefaultPartitionNexus.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
public boolean compare( CompareOperationContext compareContext ) throws LdapException
{
    Attribute attr = compareContext.getOriginalEntry().get( compareContext.getAttributeType() );

    // complain if the attribute being compared does not exist in the entry
    if ( attr == null )
    {
        throw new LdapNoSuchAttributeException();
    }

    // see first if simple match without normalization succeeds
    if ( attr.contains( compareContext.getValue() ) )
    {
        return true;
    }

    // now must apply normalization to all values (attr and in request) to compare

    /*
     * Get ahold of the normalizer for the attribute and normalize the request
     * assertion value for comparisons with normalized attribute values.  Loop
     * through all values looking for a match.
     */
    Normalizer normalizer = compareContext.getAttributeType().getEquality().getNormalizer();
    Value<?> reqVal = normalizer.normalize( compareContext.getValue() );

    for ( Value<?> value : attr )
    {
        Value<?> attrValObj = normalizer.normalize( value );

        if ( attrValObj.equals( reqVal ) )
        {
            return true;
        }
    }

    return false;
}
 
Example #11
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @param schemaManager
 * @param entry
 * @throws LdapException
 */
public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
{
    this.schemaManager = schemaManager;

    // Initialize the ObjectClass object
    initObjectClassAT();

    // We will clone the existing entry, because it may be normalized
    if ( entry.getDn() != null )
    {
        dn = entry.getDn();
        normalizeDN( dn );
    }
    else
    {
        dn = Dn.EMPTY_DN;
    }

    // Init the attributes map
    attributes = new HashMap<String, Attribute>( entry.size() );

    // and copy all the attributes
    for ( Attribute attribute : entry )
    {
        try
        {
            // First get the AttributeType
            AttributeType attributeType = attribute.getAttributeType();

            if ( attributeType == null )
            {
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(attribute, schemaManager);
                }
            }

            // Create a new ServerAttribute.
            Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );

            // And store it
            add( serverAttribute );
        }
        catch ( LdapException ne )
        {
            // Just log a warning
            LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
            throw ne;
        }
    }
}
 
Example #12
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example #13
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
private Set<AttributeTypeOptions> collectAttributeTypes( String... attributesIds )
{
    Set<AttributeTypeOptions> collectedAttributes = new HashSet<AttributeTypeOptions>();

    if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
    {
        for ( String returnAttribute : attributesIds )
        {
            if ( returnAttribute == null )
            {
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
            {
                noAttributes = true;
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
            {
                allOperationalAttributes = true;
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
            {
                allUserAttributes = true;
                continue;
            }

            try
            {
                String id = SchemaUtils.stripOptions( returnAttribute );
                Set<String> options = SchemaUtils.getOptions( returnAttribute );

                AttributeType attributeType = session.getDirectoryService()
                    .getSchemaManager().lookupAttributeTypeRegistry( id );
                AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );

                collectedAttributes.add( attrOptions );
            }
            catch ( LdapNoSuchAttributeException nsae )
            {
                LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored",
                    returnAttribute );
                // Unknown attributes should be silently ignored, as RFC 2251 states
            }
            catch ( LdapException le )
            {
                LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored",
                    returnAttribute );
                // Unknown attributes should be silently ignored, as RFC 2251 states
            }
        }
    }

    return collectedAttributes;
}
 
Example #14
Source File: DefaultEntry.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
/**
 * @param schemaManager
 * @param entry
 * @throws LdapException
 */
public DefaultEntry( SchemaManager schemaManager, Entry entry ) throws LdapException
{
    this.schemaManager = schemaManager;

    // Initialize the ObjectClass object
    initObjectClassAT();

    // We will clone the existing entry, because it may be normalized
    if ( entry.getDn() != null )
    {
        dn = entry.getDn();
        normalizeDN( dn );
    }
    else
    {
        dn = Dn.EMPTY_DN;
    }

    // Init the attributes map
    attributes = new HashMap<String, Attribute>( entry.size() );

    // and copy all the attributes
    for ( Attribute attribute : entry )
    {
        try
        {
            // First get the AttributeType
            AttributeType attributeType = attribute.getAttributeType();

            if ( attributeType == null )
            {
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( attribute.getId() );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(attribute, schemaManager);
                }
            }

            // Create a new ServerAttribute.
            Attribute serverAttribute = new DefaultAttribute( attributeType, attribute );

            // And store it
            add( serverAttribute );
        }
        catch ( LdapException ne )
        {
            // Just log a warning
            LOG.warn( "The attribute '" + attribute.getId() + "' cannot be stored" );
            throw ne;
        }
    }
}
 
Example #15
Source File: ServerEntryUtils.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
public static List<Modification> toServerModification( Modification[] modifications,
    SchemaManager schemaManager ) throws LdapException
{
    if ( modifications != null )
    {
        List<Modification> modificationsList = new ArrayList<Modification>();

        for ( Modification modification : modifications )
        {
            String attributeId = modification.getAttribute().getUpId();
            String id = stripOptions( attributeId );
            modification.getAttribute().setUpId( id );
            Set<String> options = getOptions( attributeId );

            // -------------------------------------------------------------------
            // DIRSERVER-646 Fix: Replacing an unknown attribute with no values 
            // (deletion) causes an error
            // -------------------------------------------------------------------
            if ( !schemaManager.getAttributeTypeRegistry().contains( id )
                && modification.getAttribute().size() == 0
                && modification.getOperation() == ModificationOperation.REPLACE_ATTRIBUTE )
            {
                // The attributeType does not exist in the schema.
                // It's an error
                String message = I18n.err( I18n.ERR_467, id );
                throw new LdapInvalidAttributeTypeException( message );
            }
            else
            {
                // TODO : handle options
                AttributeType attributeType = null;
                try {
                	attributeType = schemaManager.lookupAttributeTypeRegistry( id );
                } catch (LdapNoSuchAttributeException e) {
                	attributeType = ApacheDSUtil.addAttributeToSchema(modification.getAttribute(), schemaManager);
                }
                modificationsList.add( toServerModification( modification, attributeType ) );
            }
        }

        return modificationsList;
    }
    else
    {
        return null;
    }
}
 
Example #16
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 4 votes vote down vote up
private Set<AttributeTypeOptions> collectAttributeTypes( String... attributesIds )
{
    Set<AttributeTypeOptions> collectedAttributes = new HashSet<AttributeTypeOptions>();

    if ( ( attributesIds != null ) && ( attributesIds.length != 0 ) )
    {
        for ( String returnAttribute : attributesIds )
        {
            if ( returnAttribute == null )
            {
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.NO_ATTRIBUTE ) )
            {
                noAttributes = true;
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.ALL_OPERATIONAL_ATTRIBUTES ) )
            {
                allOperationalAttributes = true;
                continue;
            }

            if ( returnAttribute.equals( SchemaConstants.ALL_USER_ATTRIBUTES ) )
            {
                allUserAttributes = true;
                continue;
            }

            try
            {
                String id = SchemaUtils.stripOptions( returnAttribute );
                Set<String> options = SchemaUtils.getOptions( returnAttribute );

                AttributeType attributeType = session.getDirectoryService()
                    .getSchemaManager().lookupAttributeTypeRegistry( id );
                AttributeTypeOptions attrOptions = new AttributeTypeOptions( attributeType, options );

                collectedAttributes.add( attrOptions );
            }
            catch ( LdapNoSuchAttributeException nsae )
            {
                LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored",
                    returnAttribute );
                // Unknown attributes should be silently ignored, as RFC 2251 states
            }
            catch ( LdapException le )
            {
                LOG.warn( "Requested attribute {} does not exist in the schema, it will be ignored",
                    returnAttribute );
                // Unknown attributes should be silently ignored, as RFC 2251 states
            }
        }
    }

    return collectedAttributes;
}