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
021package org.apache.directory.server.kerberos.changepwd.exceptions;
022
023
024/**
025 * Type safe enumeration of Change Password error types
026 *
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public enum ChangePasswdErrorType
030{
031    // TODO Add i18n. Don't no if these error messages are also a response to the client.
032    // If so shall they really be i18n?
033
034    /**
035     * Constant for the "Request failed due to being malformed" error type.
036     */
037    KRB5_KPASSWD_MALFORMED(1, "Request failed due to being malformed."),
038
039    /**
040     * Constant for the "Request failed due to a hard error in processing the request" error type.
041     */
042    KRB5_KPASSWD_HARDERROR(2, "Request failed due to a hard error in processing the request."),
043
044    /**
045     * Constant for the "Request failed due to an error in authentication processing" error type.
046     */
047    KRB5_KPASSWD_AUTHERROR(3, "Request failed due to an error in authentication processing."),
048
049    /**
050     * Constant for the "Request failed due to a soft error in processing the request" error type.
051     */
052    KRB5_KPASSWD_SOFTERROR(4, "Request failed due to a soft error in processing the request."),
053
054    /**
055     * Constant for the "Requestor not authorized" error type.
056     */
057    KRB5_KPASSWD_ACCESSDENIED(5, "Requestor not authorized."),
058
059    /**
060     * Constant for the "Protocol version unsupported" error type.
061     */
062    KRB5_KPASSWD_BAD_VERSION(6, "Protocol version unsupported."),
063
064    /**
065     * Constant for the "Initial flag required" error type.
066     */
067    KRB5_KPASSWD_INITIAL_FLAG_NEEDED(7, "Initial flag required."),
068
069    /**
070     * Constant for the "Request failed for an unknown reason" error type.
071     */
072    KRB5_KPASSWD_UNKNOWN_ERROR(8, "Request failed for an unknown reason.");
073
074    /**
075     * The name of the error type.
076     */
077    private final String name;
078
079    /**
080     * The value/code for the error type.
081     */
082    private final int value;
083
084
085    /**
086     * Private constructor prevents construction outside of this class.
087     */
088    private ChangePasswdErrorType( int value, String name )
089    {
090        this.value = value;
091        this.name = name;
092    }
093
094
095    /**
096     * Returns the message for this Change Password error.
097     *
098     * @return the message for this Change Password error.
099     */
100    public String getMessage()
101    {
102        return name;
103    }
104
105
106    /**
107     * Returns the message for this Change Password error.
108     *
109     * @return the message for this Change Password error.
110     */
111    @Override
112    public String toString()
113    {
114        return name;
115    }
116
117
118    /**
119     * Gets the error type by its value.
120     *
121     * @param value the value of the error
122     * @return the type corresponding to the value
123     */
124    public static ChangePasswdErrorType getTypeByValue( int value )
125    {
126        for ( ChangePasswdErrorType et : ChangePasswdErrorType.values() )
127        {
128            if ( value == et.getValue() )
129            {
130                return et;
131            }
132        }
133
134        return KRB5_KPASSWD_UNKNOWN_ERROR;
135    }
136
137
138    /**
139     * Gets the value associated with this Change Password error.
140     *
141     * @return the value associated with this Change Password error
142     */
143    public int getValue()
144    {
145        return value;
146    }
147}