View Javadoc

1   /**
2    *
3    * Licensed to the Apache Software Foundation (ASF) under one
4    * or more contributor license agreements.  See the NOTICE file
5    * distributed with this work for additional information
6    * regarding copyright ownership.  The ASF licenses this file
7    * to you under the Apache License, Version 2.0 (the
8    * "License"); you may not use this file except in compliance
9    * with the License.  You may obtain a copy of the License at
10   *
11   *     http://www.apache.org/licenses/LICENSE-2.0
12   *
13   * Unless required by applicable law or agreed to in writing, software
14   * distributed under the License is distributed on an "AS IS" BASIS,
15   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16   * See the License for the specific language governing permissions and
17   * limitations under the License.
18   */
19  
20  package org.apache.hadoop.hbase.security;
21  
22  import java.io.DataInput;
23  import java.io.DataOutput;
24  import java.io.IOException;
25  
26  import org.apache.hadoop.hbase.classification.InterfaceAudience;
27  import org.apache.hadoop.security.UserGroupInformation;
28  
29  /** Authentication method */
30  @InterfaceAudience.Private
31  public enum AuthMethod {
32    SIMPLE((byte) 80, "", UserGroupInformation.AuthenticationMethod.SIMPLE),
33    KERBEROS((byte) 81, "GSSAPI", UserGroupInformation.AuthenticationMethod.KERBEROS),
34    DIGEST((byte) 82, "DIGEST-MD5", UserGroupInformation.AuthenticationMethod.TOKEN);
35  
36    /** The code for this method. */
37    public final byte code;
38    public final String mechanismName;
39    public final UserGroupInformation.AuthenticationMethod authenticationMethod;
40  
41    AuthMethod(byte code, String mechanismName,
42               UserGroupInformation.AuthenticationMethod authMethod) {
43      this.code = code;
44      this.mechanismName = mechanismName;
45      this.authenticationMethod = authMethod;
46    }
47  
48    private static final int FIRST_CODE = values()[0].code;
49  
50    /** Return the object represented by the code. */
51    public static AuthMethod valueOf(byte code) {
52      final int i = (code & 0xff) - FIRST_CODE;
53      return i < 0 || i >= values().length ? null : values()[i];
54    }
55  
56    /** Return the SASL mechanism name */
57    public String getMechanismName() {
58      return mechanismName;
59    }
60  
61    /** Read from in */
62    public static AuthMethod read(DataInput in) throws IOException {
63      return valueOf(in.readByte());
64    }
65  
66    /** Write to out */
67    public void write(DataOutput out) throws IOException {
68      out.write(code);
69    }
70  }