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, software
013 * distributed under the License is distributed on an "AS IS" BASIS,
014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015 * See the License for the specific language governing permissions and
016 * limitations under the License.
017 */
018package org.apache.hadoop.hbase.security;
019
020import java.io.DataInput;
021import java.io.DataOutput;
022import java.io.IOException;
023import org.apache.hadoop.security.UserGroupInformation;
024import org.apache.yetus.audience.InterfaceAudience;
025
026/** Authentication method */
027@InterfaceAudience.Private
028public enum AuthMethod {
029  SIMPLE((byte) 80, "", UserGroupInformation.AuthenticationMethod.SIMPLE),
030  KERBEROS((byte) 81, "GSSAPI", UserGroupInformation.AuthenticationMethod.KERBEROS),
031  DIGEST((byte) 82, "DIGEST-MD5", UserGroupInformation.AuthenticationMethod.TOKEN);
032
033  /** The code for this method. */
034  public final byte code;
035  public final String mechanismName;
036  public final UserGroupInformation.AuthenticationMethod authenticationMethod;
037
038  AuthMethod(byte code, String mechanismName,
039    UserGroupInformation.AuthenticationMethod authMethod) {
040    this.code = code;
041    this.mechanismName = mechanismName;
042    this.authenticationMethod = authMethod;
043  }
044
045  private static final int FIRST_CODE = values()[0].code;
046
047  /** Return the object represented by the code. */
048  public static AuthMethod valueOf(byte code) {
049    final int i = (code & 0xff) - FIRST_CODE;
050    return i < 0 || i >= values().length ? null : values()[i];
051  }
052
053  /** Return the SASL mechanism name */
054  public String getMechanismName() {
055    return mechanismName;
056  }
057
058  /** Read from in */
059  public static AuthMethod read(DataInput in) throws IOException {
060    return valueOf(in.readByte());
061  }
062
063  /** Write to out */
064  public void write(DataOutput out) throws IOException {
065    out.write(code);
066  }
067}