Java Code Examples for org.apache.directory.api.ldap.model.message.ResultCodeEnum#OBJECT_CLASS_VIOLATION

The following examples show how to use org.apache.directory.api.ldap.model.message.ResultCodeEnum#OBJECT_CLASS_VIOLATION . 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: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see the presence of all required attributes within an entry.
 */
private void assertRequiredAttributesPresent( Dn dn, Entry entry, Set<String> must ) throws LdapException
{
    for ( Attribute attribute : entry )
    {
        must.remove( attribute.getAttributeType().getOid() );
    }

    if ( must.size() != 0 )
    {
        // include AT names for better error reporting
        StringBuilder sb = new StringBuilder();
        sb.append( '[' );

        for ( String oid : must )
        {
            String name = schemaManager.getAttributeType( oid ).getName();
            sb.append( name )
                .append( '(' )
                .append( oid )
                .append( "), " );
        }

        int end = sb.length();
        sb.replace( end - 2, end, "" ); // remove the trailing ', '
        sb.append( ']' );

        throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_279,
            sb, dn.getName() ) );
    }
}
 
Example 4
Source File: SchemaInterceptor.java    From MyVirtualDirectory with Apache License 2.0 5 votes vote down vote up
/**
 * Checks to see the presence of all required attributes within an entry.
 */
private void assertRequiredAttributesPresent( Dn dn, Entry entry, Set<String> must ) throws LdapException
{
    for ( Attribute attribute : entry )
    {
        must.remove( attribute.getAttributeType().getOid() );
    }

    if ( must.size() != 0 )
    {
        // include AT names for better error reporting
        StringBuilder sb = new StringBuilder();
        sb.append( '[' );

        for ( String oid : must )
        {
            String name = schemaManager.getAttributeType( oid ).getName();
            sb.append( name )
                .append( '(' )
                .append( oid )
                .append( "), " );
        }

        int end = sb.length();
        sb.replace( end - 2, end, "" ); // remove the trailing ', '
        sb.append( ']' );

        throw new LdapSchemaViolationException( ResultCodeEnum.OBJECT_CLASS_VIOLATION, I18n.err( I18n.ERR_279,
            sb, dn.getName() ) );
    }
}