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 org.apache.hadoop.security.UserGroupInformation;
23  
24  import java.io.DataInput;
25  import java.io.DataOutput;
26  import java.io.IOException;
27  
28  /** Authentication method */
29  public enum AuthMethod {
30    SIMPLE((byte) 80, "", UserGroupInformation.AuthenticationMethod.SIMPLE),
31    KERBEROS((byte) 81, "GSSAPI", UserGroupInformation.AuthenticationMethod.KERBEROS),
32    DIGEST((byte) 82, "DIGEST-MD5", UserGroupInformation.AuthenticationMethod.TOKEN);
33  
34    /** The code for this method. */
35    public final byte code;
36    public final String mechanismName;
37    public final UserGroupInformation.AuthenticationMethod authenticationMethod;
38  
39    AuthMethod(byte code, String mechanismName,
40               UserGroupInformation.AuthenticationMethod authMethod) {
41      this.code = code;
42      this.mechanismName = mechanismName;
43      this.authenticationMethod = authMethod;
44    }
45  
46    private static final int FIRST_CODE = values()[0].code;
47  
48    /** Return the object represented by the code. */
49    public static AuthMethod valueOf(byte code) {
50      final int i = (code & 0xff) - FIRST_CODE;
51      return i < 0 || i >= values().length ? null : values()[i];
52    }
53  
54    /** Return the SASL mechanism name */
55    public String getMechanismName() {
56      return mechanismName;
57    }
58  
59    /** Read from in */
60    public static AuthMethod read(DataInput in) throws IOException {
61      return valueOf(in.readByte());
62    }
63  
64    /** Write to out */
65    public void write(DataOutput out) throws IOException {
66      out.write(code);
67    }
68  }