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