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.provider;
019
020import java.util.Objects;
021
022import org.apache.commons.lang3.builder.HashCodeBuilder;
023import org.apache.hadoop.hbase.HBaseInterfaceAudience;
024import org.apache.hadoop.security.UserGroupInformation.AuthenticationMethod;
025import org.apache.yetus.audience.InterfaceAudience;
026import org.apache.yetus.audience.InterfaceStability;
027
028/**
029 * Describes the way in which some {@link SaslClientAuthenticationProvider} authenticates over SASL.
030 */
031@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.AUTHENTICATION)
032@InterfaceStability.Evolving
033public class SaslAuthMethod {
034
035  private final String name;
036  private final byte code;
037  private final String saslMech;
038  private final AuthenticationMethod method;
039
040  public SaslAuthMethod(String name, byte code, String saslMech, AuthenticationMethod method) {
041    this.name = name;
042    this.code = code;
043    this.saslMech = saslMech;
044    this.method = method;
045  }
046
047  /**
048   * Returns the unique name to identify this authentication method among other HBase auth methods.
049   */
050  public String getName() {
051    return name;
052  }
053
054  /**
055   * Returns the unique value to identify this authentication method among other HBase auth methods.
056   */
057  public byte getCode() {
058    return code;
059  }
060
061  /**
062   * Returns the SASL mechanism used by this authentication method.
063   */
064  public String getSaslMechanism() {
065    return saslMech;
066  }
067
068  /**
069   * Returns the Hadoop {@link AuthenticationMethod} for this method.
070   */
071  public AuthenticationMethod getAuthMethod() {
072    return method;
073  }
074
075  @Override
076  public boolean equals(Object o) {
077    if (!(o instanceof SaslAuthMethod)) {
078      return false;
079    }
080    SaslAuthMethod other = (SaslAuthMethod) o;
081    return Objects.equals(name, other.name) &&
082        code == other.code &&
083        Objects.equals(saslMech, other.saslMech) &&
084        Objects.equals(method, other.method);
085  }
086
087  @Override
088  public int hashCode() {
089    return new HashCodeBuilder()
090        .append(name)
091        .append(code)
092        .append(saslMech)
093        .append(method)
094        .toHashCode();
095  }
096}