Java Code Examples for org.apache.directory.api.util.Strings#toLowerCaseAscii()

The following examples show how to use org.apache.directory.api.util.Strings#toLowerCaseAscii() . 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: DefaultSchemaManager.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieve the schema name for a specific SchemaObject, or return "other" if none is found.
 * 
 * @param schemaObject The schemaObject to read
 * @return The schema name
 */
private String getSchemaName( SchemaObject schemaObject )
{
    String schemaName = Strings.toLowerCaseAscii( schemaObject.getSchemaName() );

    if ( Strings.isEmpty( schemaName ) )
    {
        return MetaSchemaConstants.SCHEMA_OTHER;
    }

    if ( schemaMap.get( schemaName ) == null )
    {
        return null;
    }
    else
    {
        return schemaName;
    }
}
 
Example 2
Source File: SchemaObjectSorter.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
private SchemaObjectIterator( List<T> schemaObjects, ReferenceCallback<T> callback )
{
    this.schemaObjects = schemaObjects;
    this.callback = callback;

    this.oid2numericOid = new HashMap<>();
    this.numericOid2schemaObject = new TreeMap<>();
    this.loopCount = 0;

    for ( T schemaObject : schemaObjects )
    {
        String oid = Strings.toLowerCaseAscii( schemaObject.getOid() );
        oid2numericOid.put( oid, oid );
        
        for ( String name : schemaObject.getNames() )
        {
            oid2numericOid.put( Strings.toLowerCaseAscii( name ), oid );
        }
        
        numericOid2schemaObject.put( oid, schemaObject );
    }
}
 
Example 3
Source File: DefaultSchemaObjectRegistry.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
     * {@inheritDoc}
     */
    @Override
public String getOidByName( String name ) throws LdapException
    {
        T schemaObject = byName.get( name );

        if ( schemaObject == null )
        {
            // last resort before giving up check with lower cased version
            String lowerCased = Strings.toLowerCaseAscii( name );

            schemaObject = byName.get( lowerCased );

            // ok this name is not for a schema object in the registry
            if ( schemaObject == null )
            {
                throw new LdapException( I18n.err( I18n.ERR_13740_CANNOT_FIND_OID_FROM_NAME, name ) );
            }
        }

        // we found the schema object by key on the first lookup attempt
        return schemaObject.getOid();
    }
 
Example 4
Source File: AbstractGrammar.java    From directory-ldap-api with Apache License 2.0 6 votes vote down vote up
/**
 * Processes the task required in the grammar to the given tag type
 *
 * @param container the DSML container
 * @param tagType the tag type
 * @throws XmlPullParserException when an error occurs during the parsing
 */
private void processTag( Dsmlv2Container container, int tagType ) throws XmlPullParserException
{
    XmlPullParser xpp = container.getParser();

    String tagName = Strings.toLowerCaseAscii( xpp.getName() );

    GrammarTransition transition = getTransition( container.getState(), new Tag( tagName, tagType ) );

    if ( transition != null )
    {
        container.setState( transition.getNextState() );

        if ( transition.hasAction() )
        {
            GrammarAction action = transition.getAction();
            action.action( container );
        }
    }
    else
    {
        throw new XmlPullParserException( I18n.err( I18n.ERR_03036_MISSING_TAG, new Tag( tagName, tagType ) ), xpp, null );
    }
}
 
Example 5
Source File: DefaultAttribute.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void setUpId( String upId, AttributeType attributeType )
{
    String trimmed = Strings.trim( upId );

    if ( Strings.isEmpty( trimmed ) && ( attributeType == null ) )
    {
        throw new IllegalArgumentException( I18n.err( I18n.ERR_13235_NULL_ID_WITH_NULL_AT_NOT_ALLOWED ) );
    }

    String newId = Strings.toLowerCaseAscii( trimmed );

    setUpIdInternal( upId, newId, attributeType );
}
 
Example 6
Source File: ProxiedAuthzImpl.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * The authzId syntax is given by the RFC 2829 :
 * 
 * <pre>
 * authzId    = dnAuthzId / uAuthzId / &lt;empty&gt;
 * dnAuthzId  = "dn:" dn
 * dn         = utf8string
 * uAuthzId   = "u:" userid
 * userid     = utf8string
 * </pre>
 * @param authzId the authzId to set
 */
@Override
public void setAuthzId( String authzId )
{
    // We should have a valid authzId
    if ( authzId == null )
    {
        throw new RuntimeException( I18n.err( I18n.ERR_13511_INVALID_PROXIED_AUTHZ_NULL ) );
    }

    if ( !Strings.isEmpty( authzId ) )
    {
        String lowercaseAuthzId = Strings.toLowerCaseAscii( authzId );

        if ( lowercaseAuthzId.startsWith( "dn:" ) )
        {
            String dn = authzId.substring( 3 );

            if ( !Dn.isValid( dn ) )
            {
                throw new RuntimeException( I18n.err( I18n.ERR_13512_INVALID_PROXIED_AUTHZ_BAD_DN ) );
            }
        }
        else if ( !lowercaseAuthzId.startsWith( "u:" ) )
        {
            throw new RuntimeException( I18n.err( I18n.ERR_13513_INVALID_PROXIED_AUTHZ_NO_DN_OR_U ) );
        }
    }

    this.authzId = authzId;
}
 
Example 7
Source File: DefaultConfigurableBinaryAttributeDetector.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void removeBinaryAttribute( String... binaryAttributes )
{
    if ( binaryAttributes != null )
    {
        for ( String binaryAttribute : binaryAttributes )
        {
            String attrId = Strings.toLowerCaseAscii( binaryAttribute );
            this.binaryAttributes.remove( attrId );
        }
    }
}
 
Example 8
Source File: DefaultConfigurableBinaryAttributeDetector.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void addBinaryAttribute( String... binaryAttributes )
{
    if ( binaryAttributes != null )
    {
        for ( String binaryAttribute : binaryAttributes )
        {
            String attrId = Strings.toLowerCaseAscii( binaryAttribute );
            this.binaryAttributes.add( attrId );
        }
    }
}
 
Example 9
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 10
Source File: Registries.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * Retrieve the schema name for a specific SchemaObject, or return "other" if none is found.
 * 
 * @param schemaObject The SchemaObject
 * @return The associated Schema
 */
private String getSchemaName( SchemaObject schemaObject )
{
    String schemaName = Strings.toLowerCaseAscii( schemaObject.getSchemaName() );

    if ( loadedSchemas.containsKey( schemaName ) )
    {
        return schemaName;
    }
    else
    {
        return MetaSchemaConstants.SCHEMA_OTHER;
    }
}
 
Example 11
Source File: LowerCaseKeyMap.java    From directory-ldap-api with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void putAll( Map<? extends String, ? extends Schema> map )
{
    for ( Map.Entry<? extends String, ? extends Schema> e : map.entrySet() )
    {
        super.put( Strings.toLowerCaseAscii( e.getKey() ), e.getValue() );
    }
}
 
Example 12
Source File: LowerCaseKeyMap.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Schema remove( Object key )
{
    return super.remove( Strings.toLowerCaseAscii( ( String ) key ) );
}
 
Example 13
Source File: LowerCaseKeyMap.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Schema put( String key, Schema value )
{
    return super.put( Strings.toLowerCaseAscii( key ), value );
}
 
Example 14
Source File: LowerCaseKeyMap.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public boolean containsKey( Object key )
{
    return super.containsKey( Strings.toLowerCaseAscii( ( String ) key ) );
}
 
Example 15
Source File: LowerCaseKeyMap.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public Schema get( Object key )
{
    return super.get( Strings.toLowerCaseAscii( ( String ) key ) );
}
 
Example 16
Source File: PasswordUtil.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Get the algorithm from the stored password. 
 * It can be found on the beginning of the stored password, between 
 * curly brackets.
 * @param credentials the credentials of the user
 * @return the name of the algorithm to use
 */
public static LdapSecurityConstants findAlgorithm( byte[] credentials )
{
    if ( ( credentials == null ) || ( credentials.length == 0 ) )
    {
        return null;
    }

    if ( credentials[0] == '{' )
    {
        // get the algorithm
        int pos = 1;

        while ( pos < credentials.length )
        {
            if ( credentials[pos] == '}' )
            {
                break;
            }

            pos++;
        }

        if ( pos < credentials.length )
        {
            if ( pos == 1 )
            {
                // We don't have an algorithm : return the credentials as is
                return null;
            }

            String algorithm = Strings.toLowerCaseAscii( Strings.utf8ToString( credentials, 1, pos - 1 ) );

            // support for crypt additional encryption algorithms (e.g. {crypt}$1$salt$ez2vlPGdaLYkJam5pWs/Y1)
            if ( credentials.length > pos + 3 && credentials[pos + 1] == '$'
                && Character.isDigit( credentials[pos + 2] ) )
            {
                if ( credentials[pos + 3] == '$' )
                {
                    algorithm += Strings.utf8ToString( credentials, pos + 1, 3 );
                }
                else if ( credentials.length > pos + 4 && credentials[pos + 4] == '$' )
                {
                    algorithm += Strings.utf8ToString( credentials, pos + 1, 4 );
                }
            }

            return LdapSecurityConstants.getAlgorithm( algorithm );
        }
        else
        {
            // We don't have an algorithm
            return null;
        }
    }
    else
    {
        // No '{algo}' part
        return null;
    }
}
 
Example 17
Source File: LdifReader.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Parse the Dn of an entry
 *
 * @param line The line to parse
 * @return A Dn
 * @throws LdapLdifException If the Dn is invalid
 */
protected String parseDn( String line ) throws LdapLdifException
{
    String dn;

    String lowerLine = Strings.toLowerCaseAscii( line );

    if ( lowerLine.startsWith( "dn:" ) || lowerLine.startsWith( "Dn:" ) )
    {
        // Ok, we have a Dn. Is it base 64 encoded ?
        int length = line.length();

        if ( length == 3 )
        {
            // The Dn is empty : it's a rootDSE
            dn = "";
        }
        else if ( line.charAt( 3 ) == ':' )
        {
            if ( length > 4 )
            {
                // This is a base 64 encoded Dn.
                String trimmedLine = line.substring( 4 ).trim();

                dn = Strings.utf8ToString( Base64.decode( trimmedLine.toCharArray() ) );
            }
            else
            {
                // The Dn is empty : error
                LOG.error( I18n.err( I18n.ERR_13404_EMPTY_DN_NOT_ALLOWED, lineNumber ) );
                throw new LdapLdifException( I18n.err( I18n.ERR_13445_NO_DN ) );
            }
        }
        else
        {
            dn = line.substring( 3 ).trim();
        }
    }
    else
    {
        LOG.error( I18n.err( I18n.ERR_13405_DN_EXPECTED, lineNumber ) );
        throw new LdapLdifException( I18n.err( I18n.ERR_13445_NO_DN ) );
    }

    // Check that the Dn is valid. If not, an exception will be thrown
    if ( validateDn && !Dn.isValid( dn ) )
    {
        String message = I18n.err( I18n.ERR_13446_INVALID_DN, dn, lineNumber );
        LOG.error( message );
        throw new LdapLdifException( message );
    }

    return dn;
}
 
Example 18
Source File: LdifAttributesReader.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a ldif file. The following rules are processed :
 *
 * <pre>
 * &lt;ldif-file&gt; ::= &lt;ldif-attrval-record&gt; &lt;ldif-attrval-records&gt; |
 * &lt;ldif-change-record&gt; &lt;ldif-change-records&gt; &lt;ldif-attrval-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;attrval-spec&gt; &lt;attrval-specs&gt; &lt;ldif-change-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt; &lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
 * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
 * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
 * </pre>
 * 
 * @return The read entry
 * @throws LdapLdifException If the entry can't be read or is invalid
 */
private Attributes parseAttributes() throws LdapLdifException
{
    if ( ( lines == null ) || lines.isEmpty() )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) );
        }

        return null;
    }

    Attributes attributes = new BasicAttributes( true );

    // Now, let's iterate through the other lines
    for ( String line : lines )
    {
        // Each line could start either with an OID, an attribute type, with
        // "control:" or with "changetype:"
        String lowerLine = Strings.toLowerCaseAscii( line );

        // We have three cases :
        // 1) The first line after the Dn is a "control:" -> this is an error
        // 2) The first line after the Dn is a "changeType:" -> this is an error
        // 3) The first line after the Dn is anything else
        if ( lowerLine.startsWith( "control:" ) )
        {
            LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) );
        }
        else if ( lowerLine.startsWith( "changetype:" ) )
        {
            LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) );
        }
        else if ( line.indexOf( ':' ) > 0 )
        {
            parseAttribute( attributes, line, lowerLine );
        }
        else
        {
            // Invalid attribute Value
            LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, attributes ) );
    }

    return attributes;
}
 
Example 19
Source File: LdifAttributesReader.java    From directory-ldap-api with Apache License 2.0 4 votes vote down vote up
/**
 * Parse a ldif file. The following rules are processed :
 *
 * &lt;ldif-file&gt; ::= &lt;ldif-attrval-record&gt; &lt;ldif-attrval-records&gt; |
 * &lt;ldif-change-record&gt; &lt;ldif-change-records&gt; &lt;ldif-attrval-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;attrval-spec&gt; &lt;attrval-specs&gt; &lt;ldif-change-record&gt; ::=
 * &lt;dn-spec&gt; &lt;sep&gt; &lt;controls-e&gt; &lt;changerecord&gt; &lt;dn-spec&gt; ::= "dn:" &lt;fill&gt;
 * &lt;distinguishedName&gt; | "dn::" &lt;fill&gt; &lt;base64-distinguishedName&gt;
 * &lt;changerecord&gt; ::= "changetype:" &lt;fill&gt; &lt;change-op&gt;
 *
 * @param schemaManager The SchemaManager
 * @return The read entry
 * @throws LdapLdifException If the entry can't be read or is invalid
 */
private Entry parseEntry( SchemaManager schemaManager ) throws LdapLdifException
{
    if ( ( lines == null ) || lines.isEmpty() )
    {
        if ( LOG.isDebugEnabled() )
        {
            LOG.debug( I18n.msg( I18n.MSG_13408_END_OF_LDIF ) );
        }
        
        return null;
    }

    Entry entry = new DefaultEntry( schemaManager );

    // Now, let's iterate through the other lines
    for ( String line : lines )
    {
        // Each line could start either with an OID, an attribute type, with
        // "control:" or with "changetype:"
        String lowerLine = Strings.toLowerCaseAscii( line );

        // We have three cases :
        // 1) The first line after the Dn is a "control:" -> this is an error
        // 2) The first line after the Dn is a "changeType:" -> this is an error
        // 3) The first line after the Dn is anything else
        if ( lowerLine.startsWith( "control:" ) )
        {
            LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) );
        }
        else if ( lowerLine.startsWith( "changetype:" ) )
        {
            LOG.error( I18n.err( I18n.ERR_13401_CHANGE_NOT_ALLOWED ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13440_NO_CHANGE ) );
        }
        else if ( line.indexOf( ':' ) > 0 )
        {
            parseEntryAttribute( schemaManager, entry, line, lowerLine );
        }
        else
        {
            // Invalid attribute Value
            LOG.error( I18n.err( I18n.ERR_13402_EXPECTING_ATTRIBUTE_TYPE ) );
            throw new LdapLdifException( I18n.err( I18n.ERR_13441_BAD_ATTRIBUTE ) );
        }
    }

    if ( LOG.isDebugEnabled() )
    {
        LOG.debug( I18n.msg( I18n.MSG_13405_READ_ATTR, entry ) );
    }

    return entry;
}
 
Example 20
Source File: Tag.java    From directory-ldap-api with Apache License 2.0 2 votes vote down vote up
/**
 * Sets the name of the tag
 *
 * @param name the name to set
 */
public void setName( String name )
{
    this.name = Strings.toLowerCaseAscii( name );
}