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; 019 020import java.util.concurrent.ConcurrentHashMap; 021import java.util.concurrent.ConcurrentMap; 022 023import org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos.TokenIdentifier.Kind; 024import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos; 025import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos; 026import org.apache.hadoop.hbase.shaded.protobuf.generated.ClientProtos; 027import org.apache.hadoop.hbase.shaded.protobuf.generated.MasterProtos.MasterService; 028import org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos; 029import org.apache.yetus.audience.InterfaceAudience; 030 031/** 032 * Maps RPC protocol interfaces to required configuration 033 */ 034@InterfaceAudience.Private 035public class SecurityInfo { 036 /** Maps RPC service names to authentication information */ 037 private static ConcurrentMap<String,SecurityInfo> infos = new ConcurrentHashMap<>(); 038 // populate info for known services 039 static { 040 infos.put(AdminProtos.AdminService.getDescriptor().getName(), 041 new SecurityInfo(SecurityConstants.REGIONSERVER_KRB_PRINCIPAL, 042 Kind.HBASE_AUTH_TOKEN)); 043 infos.put(ClientProtos.ClientService.getDescriptor().getName(), 044 new SecurityInfo(SecurityConstants.REGIONSERVER_KRB_PRINCIPAL, 045 Kind.HBASE_AUTH_TOKEN)); 046 infos.put(MasterService.getDescriptor().getName(), 047 new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN)); 048 infos.put(RegionServerStatusProtos.RegionServerStatusService.getDescriptor().getName(), 049 new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN)); 050 infos.put(MasterProtos.HbckService.getDescriptor().getName(), 051 new SecurityInfo(SecurityConstants.MASTER_KRB_PRINCIPAL, Kind.HBASE_AUTH_TOKEN)); 052 // NOTE: IF ADDING A NEW SERVICE, BE SURE TO UPDATE HBasePolicyProvider ALSO ELSE 053 // new Service will not be found when all is Kerberized!!!! 054 } 055 056 /** 057 * Adds a security configuration for a new service name. Note that this will have no effect if 058 * the service name was already registered. 059 */ 060 public static void addInfo(String serviceName, SecurityInfo securityInfo) { 061 infos.putIfAbsent(serviceName, securityInfo); 062 } 063 064 /** 065 * Returns the security configuration associated with the given service name. 066 */ 067 public static SecurityInfo getInfo(String serviceName) { 068 return infos.get(serviceName); 069 } 070 071 private final String serverPrincipal; 072 private final Kind tokenKind; 073 074 public SecurityInfo(String serverPrincipal, Kind tokenKind) { 075 this.serverPrincipal = serverPrincipal; 076 this.tokenKind = tokenKind; 077 } 078 079 public String getServerPrincipal() { 080 return serverPrincipal; 081 } 082 083 public Kind getTokenKind() { 084 return tokenKind; 085 } 086}