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.io.IOException; 021import java.net.InetAddress; 022import java.util.Map; 023 024import javax.security.sasl.SaslClient; 025 026import org.apache.hadoop.conf.Configuration; 027import org.apache.hadoop.hbase.HBaseInterfaceAudience; 028import org.apache.hadoop.hbase.security.SecurityInfo; 029import org.apache.hadoop.hbase.security.User; 030import org.apache.hadoop.security.UserGroupInformation; 031import org.apache.hadoop.security.token.Token; 032import org.apache.hadoop.security.token.TokenIdentifier; 033import org.apache.yetus.audience.InterfaceAudience; 034import org.apache.yetus.audience.InterfaceStability; 035 036import org.apache.hadoop.hbase.shaded.protobuf.generated.RPCProtos.UserInformation; 037 038/** 039 * Encapsulation of client-side logic to authenticate to HBase via some means over SASL. 040 * Implementations should not directly implement this interface, but instead extend 041 * {@link AbstractSaslClientAuthenticationProvider}. 042 * 043 * Implementations of this interface must make an implementation of {@code hashCode()} 044 * which returns the same value across multiple instances of the provider implementation. 045 */ 046@InterfaceAudience.LimitedPrivate(HBaseInterfaceAudience.AUTHENTICATION) 047@InterfaceStability.Evolving 048public interface SaslClientAuthenticationProvider extends SaslAuthenticationProvider { 049 050 /** 051 * Creates the SASL client instance for this auth'n method. 052 */ 053 SaslClient createClient(Configuration conf, InetAddress serverAddr, SecurityInfo securityInfo, 054 Token<? extends TokenIdentifier> token, boolean fallbackAllowed, 055 Map<String, String> saslProps) throws IOException; 056 057 /** 058 * Constructs a {@link UserInformation} from the given {@link UserGroupInformation} 059 */ 060 UserInformation getUserInfo(User user); 061 062 /** 063 * Returns the "real" user, the user who has the credentials being authenticated by the 064 * remote service, in the form of an {@link UserGroupInformation} object. 065 * 066 * It is common in the Hadoop "world" to have distinct notions of a "real" user and a "proxy" 067 * user. A "real" user is the user which actually has the credentials (often, a Kerberos ticket), 068 * but some code may be running as some other user who has no credentials. This method gives 069 * the authentication provider a chance to acknowledge this is happening and ensure that any 070 * RPCs are executed with the real user's credentials, because executing them as the proxy user 071 * would result in failure because no credentials exist to authenticate the RPC. 072 * 073 * Not all implementations will need to implement this method. By default, the provided User's 074 * UGI is returned directly. 075 */ 076 default UserGroupInformation getRealUser(User ugi) { 077 return ugi.getUGI(); 078 } 079 080 /** 081 * Returns true if the implementation is capable of performing some action which may allow a 082 * failed authentication to become a successful authentication. Otherwise, returns false 083 */ 084 default boolean canRetry() { 085 return false; 086 } 087 088 /** 089 * Executes any necessary logic to re-login the client. Not all implementations will have 090 * any logic that needs to be executed. 091 */ 092 default void relogin() throws IOException {} 093}