001/**
002 *
003 * Licensed to the Apache Software Foundation (ASF) under one
004 * or more contributor license agreements.  See the NOTICE file
005 * distributed with this work for additional information
006 * regarding copyright ownership.  The ASF licenses this file
007 * to you under the Apache License, Version 2.0 (the
008 * "License"); you may not use this file except in compliance
009 * with the License.  You may obtain a copy of the License at
010 *
011 *     http://www.apache.org/licenses/LICENSE-2.0
012 *
013 * Unless required by applicable law or agreed to in writing, software
014 * distributed under the License is distributed on an "AS IS" BASIS,
015 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
016 * See the License for the specific language governing permissions and
017 * limitations under the License.
018 */
019
020package org.apache.hadoop.hbase.security;
021
022import java.io.DataInput;
023import java.io.DataOutput;
024import java.io.IOException;
025
026import org.apache.yetus.audience.InterfaceAudience;
027import org.apache.hadoop.security.UserGroupInformation;
028
029/** Authentication method */
030@InterfaceAudience.Private
031public enum AuthMethod {
032  SIMPLE((byte) 80, "", UserGroupInformation.AuthenticationMethod.SIMPLE),
033  KERBEROS((byte) 81, "GSSAPI", UserGroupInformation.AuthenticationMethod.KERBEROS),
034  DIGEST((byte) 82, "DIGEST-MD5", UserGroupInformation.AuthenticationMethod.TOKEN);
035
036  /** The code for this method. */
037  public final byte code;
038  public final String mechanismName;
039  public final UserGroupInformation.AuthenticationMethod authenticationMethod;
040
041  AuthMethod(byte code, String mechanismName,
042             UserGroupInformation.AuthenticationMethod authMethod) {
043    this.code = code;
044    this.mechanismName = mechanismName;
045    this.authenticationMethod = authMethod;
046  }
047
048  private static final int FIRST_CODE = values()[0].code;
049
050  /** Return the object represented by the code. */
051  public static AuthMethod valueOf(byte code) {
052    final int i = (code & 0xff) - FIRST_CODE;
053    return i < 0 || i >= values().length ? null : values()[i];
054  }
055
056  /** Return the SASL mechanism name */
057  public String getMechanismName() {
058    return mechanismName;
059  }
060
061  /** Read from in */
062  public static AuthMethod read(DataInput in) throws IOException {
063    return valueOf(in.readByte());
064  }
065
066  /** Write to out */
067  public void write(DataOutput out) throws IOException {
068    out.write(code);
069  }
070}