Java Code Examples for org.apache.directory.api.ldap.model.schema.AttributeType#getUsage()

The following examples show how to use org.apache.directory.api.ldap.model.schema.AttributeType#getUsage() . 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: 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 3
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attributeType The attributeType we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, AttributeType attributeType )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    if ( ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && allUserAttributes )
    {
        return true;
    }

    if ( ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) && allOperationalAttributes )
    {
        return true;
    }

    // Loop on the returningAttribute, as we have two conditions to check
    if ( returningAttributes == null )
    {
        return false;
    }

    for ( AttributeTypeOptions attributeTypeOptions : returningAttributes )
    {
        if ( attributeTypeOptions.getAttributeType().equals( attributeType ) ||
            attributeTypeOptions.getAttributeType().isAncestorOf( attributeType ) )
        {
            return true;
        }
    }

    return false;
}
 
Example 4
Source File: FilteringOperationContext.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Tells if an attribute is present in the list of attribute to return
 * 
 * @param attributeType The attributeType we are looking for
 * @return true if the attribute is present
 */
public boolean contains( SchemaManager schemaManager, AttributeType attributeType )
{
    if ( isNoAttributes() )
    {
        return false;
    }

    if ( ( attributeType.getUsage() == UsageEnum.USER_APPLICATIONS ) && allUserAttributes )
    {
        return true;
    }

    if ( ( attributeType.getUsage() != UsageEnum.USER_APPLICATIONS ) && allOperationalAttributes )
    {
        return true;
    }

    // Loop on the returningAttribute, as we have two conditions to check
    if ( returningAttributes == null )
    {
        return false;
    }

    for ( AttributeTypeOptions attributeTypeOptions : returningAttributes )
    {
        if ( attributeTypeOptions.getAttributeType().equals( attributeType ) ||
            attributeTypeOptions.getAttributeType().isAncestorOf( attributeType ) )
        {
            return true;
        }
    }

    return false;
}
 
Example 5
Source File: ParserDescriptionUtils.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Checks two schema attributeTypes for an exact match.
 *
 * @param at0 the first attributeType to compare
 * @param at1 the second attributeType to compare
 * @return true if both attributeTypes match exactly, false otherwise
 */
public static boolean attributeTypesMatch( AttributeType at0, AttributeType at1 )
{
    // compare all common description parameters
    if ( !descriptionsMatch( at0, at1 ) )
    {
        return false;
    }

    // check that the same super type is being used for both attributes
    if ( !at0.getSuperiorOid().equals( at1.getSuperiorOid() ) )
    {
        return false;
    }

    // check that the same matchingRule is used by both ATs for EQUALITY
    if ( !at0.getEqualityOid().equals( at1.getEqualityOid() ) )
    {
        return false;
    }

    // check that the same matchingRule is used by both ATs for SUBSTRING
    if ( !at0.getSubstringOid().equals( at1.getSubstringOid() ) )
    {
        return false;
    }

    // check that the same matchingRule is used by both ATs for ORDERING
    if ( !at0.getOrderingOid().equals( at1.getOrderingOid() ) )
    {
        return false;
    }

    // check that the same syntax is used by both ATs
    if ( !at0.getSyntaxOid().equals( at1.getSyntaxOid() ) )
    {
        return false;
    }

    // check that the syntax length constraint is the same for both
    if ( at0.getSyntaxLength() != at1.getSyntaxLength() )
    {
        return false;
    }

    // check that the ATs have the same single valued flag value
    if ( at0.isSingleValued() != at1.isSingleValued() )
    {
        return false;
    }

    // check that the ATs have the same collective flag value
    if ( at0.isCollective() != at1.isCollective() )
    {
        return false;
    }

    // check that the ATs have the same user modifiable flag value
    if ( at0.isUserModifiable() != at1.isUserModifiable() )
    {
        return false;
    }

    // check that the ATs have the same USAGE
    if ( at0.getUsage() != at1.getUsage() )
    {
        return false;
    }

    return true;
}