private boolean isRelated()

in interceptors/authz/src/main/java/org/apache/directory/server/core/authz/support/RelatedProtectedItemFilter.java [101:295]


    private boolean isRelated( ACITuple tuple, OperationScope scope, Dn userName, Dn entryName,
        AttributeType attributeType, Value attrValue, Entry entry ) throws LdapException, InternalError
    {
        String oid = null;

        if ( attributeType != null )
        {
            oid = attributeType.getOid();
        }

        for ( ProtectedItem item : tuple.getProtectedItems() )
        {
            if ( item == ProtectedItem.ENTRY )
            {
                if ( scope != OperationScope.ENTRY )
                {
                    continue;
                }

                return true;
            }
            else if ( ( item == ProtectedItem.ALL_USER_ATTRIBUTE_TYPES ) 
                    || ( item == ProtectedItem.ALL_USER_ATTRIBUTE_TYPES_AND_VALUES ) )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE && scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE )
                {
                    continue;
                }

                return true;
            }
            else if ( item instanceof AllAttributeValuesItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE )
                {
                    continue;
                }

                AllAttributeValuesItem aav = ( AllAttributeValuesItem ) item;

                for ( Iterator<AttributeType> iterator = aav.iterator(); iterator.hasNext(); )
                {
                    AttributeType attr = iterator.next();

                    if ( oid.equals( attr.getOid() ) )
                    {
                        return true;
                    }
                }
            }
            else if ( item instanceof AttributeTypeItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE )
                {
                    continue;
                }

                AttributeTypeItem at = ( AttributeTypeItem ) item;

                for ( Iterator<AttributeType> iterator = at.iterator(); iterator.hasNext(); )
                {
                    AttributeType attr = iterator.next();

                    if ( oid.equals( attr.getOid() ) )
                    {
                        return true;
                    }
                }
            }
            else if ( item instanceof AttributeValueItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE )
                {
                    continue;
                }

                AttributeValueItem av = ( AttributeValueItem ) item;

                for ( Iterator<Attribute> j = av.iterator(); j.hasNext(); )
                {
                    Attribute entryAttribute = j.next();

                    AttributeType attr = entryAttribute.getAttributeType();
                    String attrOid;

                    if ( attr != null )
                    {
                        attrOid = entryAttribute.getAttributeType().getOid();
                    }
                    else
                    {
                        attr = schemaManager.lookupAttributeTypeRegistry( entryAttribute.getId() );
                        attrOid = attr.getOid();
                        entryAttribute.apply( attr );
                    }

                    if ( oid.equals( attrOid ) && entryAttribute.contains( attrValue ) )
                    {
                        return true;
                    }
                }
            }
            else if ( item instanceof ClassesItem )
            {
                ClassesItem refinement = ( ClassesItem ) item;

                if ( refinementEvaluator
                    .evaluate( refinement.getClasses(), entry.get( SchemaConstants.OBJECT_CLASS_AT ) ) )
                {
                    return true;
                }
            }
            else if ( item instanceof MaxImmSubItem )
            {
                return true;
            }
            else if ( item instanceof MaxValueCountItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE )
                {
                    continue;
                }

                MaxValueCountItem mvc = ( MaxValueCountItem ) item;

                for ( Iterator<MaxValueCountElem> j = mvc.iterator(); j.hasNext(); )
                {
                    MaxValueCountElem mvcItem = j.next();

                    if ( oid.equals( mvcItem.getAttributeType().getOid() ) )
                    {
                        return true;
                    }
                }
            }
            else if ( item instanceof RangeOfValuesItem )
            {
                RangeOfValuesItem rov = ( RangeOfValuesItem ) item;

                if ( entryEvaluator.evaluate( rov.getRefinement(), entryName, entry ) )
                {
                    return true;
                }
            }
            else if ( item instanceof RestrictedByItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE )
                {
                    continue;
                }

                RestrictedByItem rb = ( RestrictedByItem ) item;

                for ( Iterator<RestrictedByElem> j = rb.iterator(); j.hasNext(); )
                {
                    RestrictedByElem rbItem = j.next();

                    if ( oid.equals( rbItem.getAttributeType().getOid() ) )
                    {
                        return true;
                    }
                }
            }
            else if ( item instanceof SelfValueItem )
            {
                if ( scope != OperationScope.ATTRIBUTE_TYPE_AND_VALUE && scope != OperationScope.ATTRIBUTE_TYPE )
                {
                    continue;
                }

                SelfValueItem sv = ( SelfValueItem ) item;

                for ( Iterator<AttributeType> iterator = sv.iterator(); iterator.hasNext(); )
                {
                    AttributeType attr = iterator.next();

                    if ( oid.equals( attr.getOid() ) )
                    {
                        Attribute entryAttribute = entry.get( oid );

                        if ( ( entryAttribute != null ) && entryAttribute.contains( userName.getNormName() ) )
                        {
                            return true;
                        }
                    }
                }
            }
            else
            {
                throw new InternalError( I18n.err( I18n.ERR_232, item.getClass().getName() ) );
            }
        }

        return false;
    }