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.kerberos.codec.types;
021
022
023/**
024 * Type safe enumeration of Single-use Authentication Mechanism types
025 *
026 * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
027 */
028public enum SamType
029{
030    /*
031     * Enumeration elements are constructed once upon class loading.
032     * Order of appearance here determines the order of compareTo.
033     */
034
035    /** safe SAM type enum for Enigma Logic */
036    PA_SAM_TYPE_ENIGMA(1, "Enigma Logic"),
037
038    /** safe SAM type enum for Digital Pathways */
039    PA_SAM_TYPE_DIGI_PATH(2, "Digital Pathways"),
040
041    /** safe SAM type enum for S/key where KDC has key 0 */
042    PA_SAM_TYPE_SKEY_K0(3, "S/key where KDC has key 0"),
043
044    /** safe SAM type enum for Traditional S/Key */
045    PA_SAM_TYPE_SKEY(4, "Traditional S/Key"),
046
047    /** safe SAM type enum for Security Dynamics */
048    PA_SAM_TYPE_SECURID(5, "Security Dynamics"),
049
050    /** safe SAM type enum for CRYPTOCard */
051    PA_SAM_TYPE_CRYPTOCARD(6, "CRYPTOCard"),
052
053    /** safe SAM type enum for Apache Software Foundation */
054    PA_SAM_TYPE_APACHE(7, "Apache Software Foundation");
055
056    /** the name of the sam type */
057    private String name;
058
059    /** the value/code for the sam type */
060    private int ordinal;
061
062
063    /**
064     * Private constructor prevents construction outside of this class.
065     */
066    private SamType( int ordinal, String name )
067    {
068        this.ordinal = ordinal;
069        this.name = name;
070    }
071
072
073    /**
074     * Returns the name of the SamType.
075     *
076     * @return the name of the SAM type
077     */
078    @Override
079    public String toString()
080    {
081        return name;
082    }
083
084
085    /**
086     * Gets the ordinal by its ordinal value.
087     *
088     * @param ordinal the ordinal value of the ordinal
089     * @return the type corresponding to the ordinal value
090     */
091    public static SamType getTypeByOrdinal( int ordinal )
092    {
093        for ( SamType st : SamType.values() )
094        {
095            if ( ordinal == st.getOrdinal() )
096            {
097                return st;
098            }
099        }
100
101        return PA_SAM_TYPE_APACHE;
102    }
103
104
105    /**
106     * Gets the ordinal value associated with this SAM type.
107     *
108     * @return the ordinal value associated with this SAM type
109     */
110    public int getOrdinal()
111    {
112        return ordinal;
113    }
114}