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 */
020package org.apache.directory.shared.ldap.model.constants;
021
022
023/**
024 * An enum to store all the security constants used in the server
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 */
028public enum LdapSecurityConstants
029{
030    /** The SHA encryption method */
031    HASH_METHOD_SHA("sha"),
032
033    /** The Salted SHA encryption method */
034    HASH_METHOD_SSHA("ssha"),
035
036    /** The MD5 encryption method */
037    HASH_METHOD_MD5("md5"),
038
039    /** The Salter MD5 encryption method */
040    HASH_METHOD_SMD5("smd5"),
041
042    /** The crypt encryption method */
043    HASH_METHOD_CRYPT("crypt"),
044
045    /** The SHA-256 encryption method */
046    HASH_METHOD_SHA256("sha-256"),
047
048    /** The salted SHA-256 encryption method */
049    HASH_METHOD_SSHA256("ssha-256"),
050
051    /** The SHA-384 encryption method */
052    HASH_METHOD_SHA384("sha-384"),
053
054    /** The salted SHA-384 encryption method */
055    HASH_METHOD_SSHA384("ssha-384"),
056
057    /** The SHA-512 encryption method */
058    HASH_METHOD_SHA512("sha-512"),
059
060    /** The salted SHA-512 encryption method */
061    HASH_METHOD_SSHA512("ssha-512");
062
063    /* These encryption types are not yet supported 
064    ** The AES encryption method *
065    ENC_METHOD_AES("aes"),
066    
067    ** The 3DES encryption method *
068    ENC_METHOD_3DES("3des"),
069    
070    ** The Blowfish encryption method *
071    ENC_METHOD_BLOWFISH("blowfish"),
072    
073    ** The RC4 encryption method *
074    ENC_METHOD_RC4("rc4");
075    */
076
077    /** The associated name */
078    private String name;
079
080
081    /**
082     * Creates a new instance of LdapSecurityConstants.
083     * 
084     * @param name the associated name
085     */
086    private LdapSecurityConstants( String name )
087    {
088        this.name = name;
089    }
090
091
092    /**
093     * @return the name associated with the constant.
094     */
095    public String getName()
096    {
097        return name;
098    }
099
100
101    /**
102     * Get the associated constant from a string
103     *
104     * @param name The algorithm's name
105     * @return The associated constant
106     */
107    public static LdapSecurityConstants getAlgorithm( String name )
108    {
109        String algorithm = "";
110
111        if ( name != null )
112        {
113            algorithm = name.toLowerCase();
114        }
115
116        if ( HASH_METHOD_SHA.getName().equalsIgnoreCase( algorithm ) )
117        {
118            return HASH_METHOD_SHA;
119        }
120
121        if ( HASH_METHOD_SSHA.getName().equalsIgnoreCase( algorithm ) )
122        {
123            return HASH_METHOD_SSHA;
124        }
125
126        if ( HASH_METHOD_MD5.getName().equalsIgnoreCase( algorithm ) )
127        {
128            return HASH_METHOD_MD5;
129        }
130
131        if ( HASH_METHOD_SMD5.getName().equalsIgnoreCase( algorithm ) )
132        {
133            return HASH_METHOD_SMD5;
134        }
135
136        if ( HASH_METHOD_CRYPT.getName().equalsIgnoreCase( algorithm ) )
137        {
138            return HASH_METHOD_CRYPT;
139        }
140
141        if ( HASH_METHOD_SHA256.getName().equalsIgnoreCase( algorithm ) )
142        {
143            return HASH_METHOD_SHA256;
144        }
145
146        if ( HASH_METHOD_SSHA256.getName().equalsIgnoreCase( algorithm ) )
147        {
148            return HASH_METHOD_SSHA256;
149        }
150
151        if ( HASH_METHOD_SHA384.getName().equalsIgnoreCase( algorithm ) )
152        {
153            return HASH_METHOD_SHA384;
154        }
155
156        if ( HASH_METHOD_SSHA384.getName().equalsIgnoreCase( algorithm ) )
157        {
158            return HASH_METHOD_SSHA384;
159        }
160
161        if ( HASH_METHOD_SHA512.getName().equalsIgnoreCase( algorithm ) )
162        {
163            return HASH_METHOD_SHA512;
164        }
165
166        if ( HASH_METHOD_SSHA512.getName().equalsIgnoreCase( algorithm ) )
167        {
168            return HASH_METHOD_SSHA512;
169        }
170
171        /*
172        if ( ENC_METHOD_AES.getName().equalsIgnoreCase( algorithm ) )
173        {
174            return ENC_METHOD_AES;
175        }
176
177        if ( ENC_METHOD_3DES.getName().equalsIgnoreCase( algorithm ) )
178        {
179            return ENC_METHOD_3DES;
180        }
181
182        if ( ENC_METHOD_BLOWFISH.getName().equalsIgnoreCase( algorithm ) )
183        {
184            return ENC_METHOD_BLOWFISH;
185        }
186
187        if ( ENC_METHOD_RC4.getName().equalsIgnoreCase( algorithm ) )
188        {
189            return ENC_METHOD_RC4;
190        }
191        */
192
193        return null;
194    }
195}