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.yetus.audience.InterfaceAudience;
024import org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos;
025import org.apache.hadoop.hbase.protobuf.generated.AuthenticationProtos.TokenIdentifier.Kind;
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;
029
030/**
031 * Maps RPC protocol interfaces to required configuration
032 */
033@InterfaceAudience.Private
034public class SecurityInfo {
035  /** Maps RPC service names to authentication information */
036  private static ConcurrentMap<String,SecurityInfo> infos = new ConcurrentHashMap<>();
037  // populate info for known services
038  static {
039    infos.put(AdminProtos.AdminService.getDescriptor().getName(),
040        new SecurityInfo("hbase.regionserver.kerberos.principal", Kind.HBASE_AUTH_TOKEN));
041    infos.put(ClientProtos.ClientService.getDescriptor().getName(),
042        new SecurityInfo("hbase.regionserver.kerberos.principal", Kind.HBASE_AUTH_TOKEN));
043    infos.put(MasterService.getDescriptor().getName(),
044        new SecurityInfo("hbase.master.kerberos.principal", Kind.HBASE_AUTH_TOKEN));
045    infos.put(RegionServerStatusProtos.RegionServerStatusService.getDescriptor().getName(),
046        new SecurityInfo("hbase.master.kerberos.principal", Kind.HBASE_AUTH_TOKEN));
047  }
048
049  /**
050   * Adds a security configuration for a new service name.  Note that this will have no effect if
051   * the service name was already registered.
052   */
053  public static void addInfo(String serviceName, SecurityInfo securityInfo) {
054    infos.putIfAbsent(serviceName, securityInfo);
055  }
056
057  /**
058   * Returns the security configuration associated with the given service name.
059   */
060  public static SecurityInfo getInfo(String serviceName) {
061    return infos.get(serviceName);
062  }
063
064  private final String serverPrincipal;
065  private final Kind tokenKind;
066
067  public SecurityInfo(String serverPrincipal, Kind tokenKind) {
068    this.serverPrincipal = serverPrincipal;
069    this.tokenKind = tokenKind;
070  }
071
072  public String getServerPrincipal() {
073    return serverPrincipal;
074  }
075
076  public Kind getTokenKind() {
077    return tokenKind;
078  }
079}