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.kerberos.client;
022
023
024/**
025 * The result codes returned by the change password server as defined in the <a href="http://www.ietf.org/rfc/rfc3244.txt">rfc3244</a>
026 * 
027 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
028 */
029public enum ChangePasswordResultCode
030{
031
032    /** request succeeds (This value is not allowed in a KRB-ERROR message) */
033    KRB5_KPASSWD_SUCCESS(0),
034
035    /** request fails due to being malformed */
036    KRB5_KPASSWD_MALFORMED(1),
037
038    /** 
039     * request fails due to "hard" error in processing the request 
040     * (for example, there is a resource or other problem causing 
041     * the request to fail) 
042     */
043    KRB5_KPASSWD_HARDERROR(2),
044
045    /** request fails due to an error in authentication processing */
046    KRB5_KPASSWD_AUTHERROR(3),
047
048    /** request fails due to a "soft" error in processing the request */
049    KRB5_KPASSWD_SOFTERROR(4),
050
051    /** requestor not authorized */
052    KRB5_KPASSWD_ACCESSDENIED(5),
053
054    /** protocol version unsupported */
055    KRB5_KPASSWD_BAD_VERSION(6),
056
057    /** initial flag required */
058    KRB5_KPASSWD_INITIAL_FLAG_NEEDED(7),
059
060    /** 0xFFFF(65535) is returned if the request fails for some other reason */
061    OTHER(0xFFFF);
062
063    private int val;
064
065
066    private ChangePasswordResultCode( int val )
067    {
068        this.val = val;
069    }
070
071
072    public int getVal()
073    {
074        return val;
075    }
076
077
078    public static ChangePasswordResultCode getByValue( int code )
079    {
080        switch ( code )
081        {
082            case 0:
083                return KRB5_KPASSWD_SUCCESS;
084
085            case 1:
086                return KRB5_KPASSWD_MALFORMED;
087
088            case 2:
089                return KRB5_KPASSWD_HARDERROR;
090
091            case 3:
092                return KRB5_KPASSWD_AUTHERROR;
093
094            case 4:
095                return KRB5_KPASSWD_SOFTERROR;
096
097            case 5:
098                return KRB5_KPASSWD_ACCESSDENIED;
099
100            case 6:
101                return KRB5_KPASSWD_BAD_VERSION;
102
103            case 7:
104                return KRB5_KPASSWD_INITIAL_FLAG_NEEDED;
105
106            case 0xFFFF:
107                return OTHER;
108
109            default:
110                throw new IllegalArgumentException( "Unknown result code " + code );
111        }
112    }
113
114
115    @Override
116    public String toString()
117    {
118        return super.toString() + "(" + getVal() + ")";
119    }
120
121}