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 HASH_METHOD_SHA256( "sha-256" );
041
042 private String name;
043
044 /**
045 * Creates a new instance of LdapSecurityConstants.
046 */
047 private LdapSecurityConstants( String name )
048 {
049 this.name = name;
050 }
051
052 /**
053 * Return the name associated with the constant.
054 */
055 public String getName()
056 {
057 return name;
058 }
059
060
061 /**
062 * Get the associated constant from a string
063 *
064 * @param name The algorithm's name
065 * @return The associated constant
066 */
067 public static LdapSecurityConstants getAlgorithm( String name )
068 {
069 String algorithm = ( name == null ? "" : name.toLowerCase() );
070
071 if ( HASH_METHOD_SHA.getName().equalsIgnoreCase( algorithm ) )
072 {
073 return HASH_METHOD_SHA;
074 }
075
076 if ( HASH_METHOD_SSHA.getName().equalsIgnoreCase( algorithm ) )
077 {
078 return HASH_METHOD_SSHA;
079 }
080
081 if ( HASH_METHOD_MD5.getName().equalsIgnoreCase( algorithm ) )
082 {
083 return HASH_METHOD_MD5;
084 }
085
086 if ( HASH_METHOD_SMD5.getName().equalsIgnoreCase( algorithm ) )
087 {
088 return HASH_METHOD_SMD5;
089 }
090
091 if ( HASH_METHOD_CRYPT.getName().equalsIgnoreCase( algorithm ) )
092 {
093 return HASH_METHOD_CRYPT;
094 }
095
096 if ( HASH_METHOD_SHA256.getName().equalsIgnoreCase( algorithm ) )
097 {
098 return HASH_METHOD_SHA256;
099 }
100
101 return null;
102 }
103 }