001    /*
002     *  Licensed to the Apache Software Foundation (ASF) under one
003     *  or more contributor license agreements.  See the NOTICE file
004     *  distributed with this work for additional information
005     *  regarding copyright ownership.  The ASF licenses this file
006     *  to you under the Apache License, Version 2.0 (the
007     *  "License"); you may not use this file except in compliance
008     *  with the License.  You may obtain a copy of the License at
009     *  
010     *    http://www.apache.org/licenses/LICENSE-2.0
011     *  
012     *  Unless required by applicable law or agreed to in writing,
013     *  software distributed under the License is distributed on an
014     *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015     *  KIND, either express or implied.  See the License for the
016     *  specific language governing permissions and limitations
017     *  under the License. 
018     *  
019     */
020    package org.apache.directory.shared.ldap.constants;
021    
022    /**
023     * An enum to store all the security constants used in the server
024     *
025     * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
026     * @version $Rev:$
027     */
028    public enum LdapSecurityConstants
029    {
030        HASH_METHOD_SHA( "sha" ),
031    
032        HASH_METHOD_SSHA( "ssha" ),
033    
034        HASH_METHOD_MD5( "md5" ),
035    
036        HASH_METHOD_SMD5( "smd5" ),
037    
038        HASH_METHOD_CRYPT( "crypt" );
039        
040        private String name;
041        
042        /**
043         * Creates a new instance of LdapSecurityConstants.
044         */
045        private LdapSecurityConstants( String name )
046        {
047            this.name = name;
048        }
049    
050        /**
051         * Return the name associated with the constant.
052         */
053        public String getName()
054        {
055            return name;
056        }
057        
058        
059        /**
060         * Get the associated constant from a string
061         *
062         * @param name The algorithm's name
063         * @return The associated constant
064         */
065        public static LdapSecurityConstants getAlgorithm( String name )
066        {
067            String algorithm = ( name == null ? "" : name.toLowerCase() );
068            
069            if ( HASH_METHOD_SHA.getName().equalsIgnoreCase( algorithm ) )
070            {
071                return HASH_METHOD_SHA;
072            }
073    
074            if ( HASH_METHOD_SSHA.getName().equalsIgnoreCase( algorithm ) )
075            {
076                return HASH_METHOD_SSHA;
077            }
078    
079            if ( HASH_METHOD_MD5.getName().equalsIgnoreCase( algorithm ) )
080            {
081                return HASH_METHOD_MD5;
082            }
083    
084            if ( HASH_METHOD_SMD5.getName().equalsIgnoreCase( algorithm ) )
085            {
086                return HASH_METHOD_SMD5;
087            }
088            
089            if ( HASH_METHOD_CRYPT.getName().equalsIgnoreCase( algorithm ) )
090            {
091                return HASH_METHOD_CRYPT;
092            }
093            
094            return null;
095        }
096    }