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

The following examples show how to use org.apache.directory.api.ldap.model.schema.AttributeType#getSyntax() . 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: LdifAnonymizer.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Add an attributeType that has to be anonymized
 *
 * @param attributeType the AttributeType that has to be anonymized
 * @throws LdapException If the attributeType cannot be added
 */
public void addAnonAttributeType( AttributeType attributeType ) throws LdapException
{
    schemaManager.add( attributeType );
    LdapSyntax syntax = attributeType.getSyntax();
    
    if ( syntax.isHumanReadable() )
    {
        if ( syntax.getOid().equals( SchemaConstants.INTEGER_SYNTAX ) )
        {
            attributeAnonymizers.put( attributeType.getOid(), new IntegerAnonymizer() );
        }
        else if ( syntax.getOid().equals( SchemaConstants.DIRECTORY_STRING_SYNTAX ) )
        {
            attributeAnonymizers.put( attributeType.getOid(), new StringAnonymizer() );
        }
        else if ( syntax.getOid().equals( SchemaConstants.TELEPHONE_NUMBER_SYNTAX ) )
        {
            attributeAnonymizers.put( attributeType.getOid(), new TelephoneNumberAnonymizer() );
        }
    }
    else
    {
        attributeAnonymizers.put( attributeType.getOid(), new BinaryAnonymizer() );
    }
}
 
Example 2
Source File: Value.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
private void init( AttributeType attributeType )
{
    if ( attributeType != null )
    {
        if ( attributeType.getSyntax() == null )
        {
            // Some broken LDAP servers do not have proper syntax definitions, default to HR
            // Log this on trace level only. Otherwise we get logs full of errors when working
            // with AD and similar not-really-LDAP-compliant servers.
            if ( LOG.isTraceEnabled() )
            {
                LOG.trace( I18n.err( I18n.ERR_13225_NO_SYNTAX ) );
            }
            
            isHR = true;
        }
        else
        {
            isHR = attributeType.getSyntax().isHumanReadable();
        }
    }
    else
    {
        if ( LOG.isWarnEnabled() )
        {
            LOG.warn( I18n.msg( I18n.MSG_13202_AT_IS_NULL ) );
        }
    }
    
    this.attributeType = attributeType;
}
 
Example 3
Source File: Registries.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Add the SchemaObjectReferences. This method does nothing, it's just
 * a catch all. The other methods will be called for each specific
 * schemaObject
 *
public void addCrossReferences( SchemaObject schemaObject )
{
    // Do nothing : it's a catch all method.
}


/**
 * Delete the AT references (using and usedBy) :
 * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
 * AT -> S
 * AT -> AT
 * 
 * @param attributeType The AttributeType to remove
 */
public void delCrossReferences( AttributeType attributeType )
{
    if ( attributeType.getEquality() != null )
    {
        delReference( attributeType, attributeType.getEquality() );
    }

    if ( attributeType.getOrdering() != null )
    {
        delReference( attributeType, attributeType.getOrdering() );
    }

    if ( attributeType.getSubstring() != null )
    {
        delReference( attributeType, attributeType.getSubstring() );
    }

    if ( attributeType.getSyntax() != null )
    {
        delReference( attributeType, attributeType.getSyntax() );
    }

    if ( attributeType.getSuperior() != null )
    {
        delReference( attributeType, attributeType.getSuperior() );
    }
}
 
Example 4
Source File: SchemaBinaryAttributeDetector.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isBinary( String attributeId )
{
    String attrId = Strings.toLowerCaseAscii( attributeId );

    if ( attrId.endsWith( ";binary" ) )
    {
        return true;
    }

    if ( schemaManager != null )
    {
        AttributeType attributeType =  schemaManager.getAttributeType( attrId );
        
        if ( attributeType == null )
        {
            return false;
        }
        
        LdapSyntax ldapSyntax = attributeType.getSyntax();
        
        return ( ldapSyntax != null ) && !ldapSyntax.isHumanReadable();
    }

    return false;
}
 
Example 5
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean isValid( AttributeType attributeType ) throws LdapInvalidAttributeValueException
{
    LdapSyntax syntax = attributeType.getSyntax();

    if ( syntax == null )
    {
        return false;
    }

    SyntaxChecker syntaxChecker = syntax.getSyntaxChecker();

    if ( syntaxChecker == null )
    {
        return false;
    }

    // Check that we can have no value for this attributeType
    if ( values.isEmpty() )
    {
        return syntaxChecker.isValidSyntax( null );
    }

    // Check that we can't have more than one value if the AT is single-value
    if ( ( attributeType.isSingleValued() ) && ( values.size() > 1 ) )
    {
        return false;
    }

    // Now check the values
    for ( Value value : values )
    {
        try
        {
            if ( !value.isValid( syntaxChecker ) )
            {
                return false;
            }
        }
        catch ( LdapException le )
        {
            return false;
        }
    }

    return true;
}
 
Example 6
Source File: Value.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Creates a schema aware StringValue with an initial user provided String value.
 *
 * @param attributeType the schema type associated with this StringValue
 * @param upValue the value to wrap
 * @throws LdapInvalidAttributeValueException If the added value is invalid accordingly
 * to the schema
 */
public Value( AttributeType attributeType, String upValue ) throws LdapInvalidAttributeValueException
{
    init( attributeType );
    this.upValue = upValue;
    
    if ( upValue != null )
    {
        bytes = Strings.getBytesUtf8( upValue );
    }
    else
    {
        bytes = null;
    }
    
    try
    {
        computeNormValue();
    }
    catch ( LdapException le )
    {
        LOG.error( le.getMessage() );
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13247_INVALID_VALUE_CANT_NORMALIZE, upValue ) );
    }
    
    if ( !attributeType.isRelaxed() )
    {
        // Check the value
        LdapSyntax syntax = attributeType.getSyntax();
        
        if ( ( syntax != null ) && ( syntax.getSyntaxChecker() != null ) ) 
        {
            if ( !attributeType.getSyntax().getSyntaxChecker().isValidSyntax( upValue ) )
            {
                throw new LdapInvalidAttributeValueException( ResultCodeEnum.INVALID_ATTRIBUTE_SYNTAX, 
                    I18n.err( I18n.ERR_13246_INVALID_VALUE_PER_SYNTAX ) );
            }
        }
        else
        {
            // We should always have a SyntaxChecker
            throw new IllegalArgumentException( I18n.err( I18n.ERR_13219_NULL_SYNTAX_CHECKER, normValue ) );
        }
    }
    
    hashCode();
}
 
Example 7
Source File: AttributeTypeHelper.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Inject the AttributeType into the Registries, updating the references to
 * other SchemaObject
 *
 * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
 * an exception is thrown.
 * 
 * @param attributeType The AttributeType to add to the Registries
 * @param errorHandler Error handler
 * @param registries The Registries
 * @throws LdapException If the AttributeType is not valid
 */
public static void addToRegistries( AttributeType attributeType, SchemaErrorHandler errorHandler, Registries registries ) throws LdapException
{
    if ( registries != null )
    {
        try
        {
            attributeType.unlock();
            AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();

            // The superior
            if ( !buildSuperior( attributeType, errorHandler, registries ) )
            {
                // We have had errors, let's stop here as we need a correct superior to continue
                return;
            }

            // The Syntax
            buildSyntax( attributeType, errorHandler, registries );

            // The EQUALITY matching rule
            buildEquality( attributeType, errorHandler, registries );

            // The ORDERING matching rule
            buildOrdering( attributeType, errorHandler, registries );

            // The SUBSTR matching rule
            buildSubstring( attributeType, errorHandler, registries );

            // Check the USAGE
            checkUsage( attributeType, errorHandler );

            // Check the COLLECTIVE element
            checkCollective( attributeType, errorHandler );

            // Inject the attributeType into the oid/normalizer map
            attributeTypeRegistry.addMappingFor( attributeType );

            // Register this AttributeType into the Descendant map
            attributeTypeRegistry.registerDescendants( attributeType, attributeType.getSuperior() );

            /**
             * Add the AT references (using and usedBy) :
             * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
             * AT -> S
             * AT -> AT
             */
            if ( attributeType.getEquality() != null )
            {
                registries.addReference( attributeType, attributeType.getEquality() );
            }

            if ( attributeType.getOrdering() != null )
            {
                registries.addReference( attributeType, attributeType.getOrdering() );
            }

            if ( attributeType.getSubstring() != null )
            {
                registries.addReference( attributeType, attributeType.getSubstring() );
            }

            if ( attributeType.getSyntax() != null )
            {
                registries.addReference( attributeType, attributeType.getSyntax() );
            }

            if ( attributeType.getSuperior() != null )
            {
                registries.addReference( attributeType, attributeType.getSuperior() );
            }
        }
        finally
        {
            attributeType.lock();
        }
    }
}
 
Example 8
Source File: AttributeTypeHelper.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Remove the AttributeType from the registries, updating the references to
 * other SchemaObject.
 *
 * If one of the referenced SchemaObject does not exist (SUP, EQUALITY, ORDERING, SUBSTR, SYNTAX),
 * an exception is thrown.
 * 
 * @param attributeType The AttributeType to remove from the Registries
 * @param errorHandler Error handler
 * @param registries The Registries
 * @throws LdapException If the AttributeType is not valid
 */
public static void removeFromRegistries( AttributeType attributeType, SchemaErrorHandler errorHandler, Registries registries ) throws LdapException
{
    if ( registries != null )
    {
        AttributeTypeRegistry attributeTypeRegistry = registries.getAttributeTypeRegistry();

        // Remove the attributeType from the oid/normalizer map
        attributeTypeRegistry.removeMappingFor( attributeType );

        // Unregister this AttributeType into the Descendant map
        attributeTypeRegistry.unregisterDescendants( attributeType, attributeType.getSuperior() );

        /**
         * Remove the AT references (using and usedBy) :
         * AT -> MR (for EQUALITY, ORDERING and SUBSTR)
         * AT -> S
         * AT -> AT
         */
        if ( attributeType.getEquality() != null )
        {
            registries.delReference( attributeType, attributeType.getEquality() );
        }

        if ( attributeType.getOrdering() != null )
        {
            registries.delReference( attributeType, attributeType.getOrdering() );
        }

        if ( attributeType.getSubstring() != null )
        {
            registries.delReference( attributeType, attributeType.getSubstring() );
        }

        if ( attributeType.getSyntax() != null )
        {
            registries.delReference( attributeType, attributeType.getSyntax() );
        }

        if ( attributeType.getSuperior() != null )
        {
            registries.delReference( attributeType, attributeType.getSuperior() );
        }
    }
}