当前位置: 首页>>代码示例>>Java>>正文


Java TokenSelector.selectToken方法代码示例

本文整理汇总了Java中org.apache.hadoop.security.token.TokenSelector.selectToken方法的典型用法代码示例。如果您正苦于以下问题:Java TokenSelector.selectToken方法的具体用法?Java TokenSelector.selectToken怎么用?Java TokenSelector.selectToken使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.hadoop.security.token.TokenSelector的用法示例。


在下文中一共展示了TokenSelector.selectToken方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getServerToken

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
/**
 * Try to locate the required token for the server.
 * 
 * @param authType of the SASL client
 * @return Token for server, or null if no token available
 * @throws IOException - token selector cannot be instantiated
 */
private Token<?> getServerToken(SaslAuth authType) throws IOException {
  TokenInfo tokenInfo = SecurityUtil.getTokenInfo(protocol, conf);
  LOG.debug("Get token info proto:" + protocol + " info:" + tokenInfo);
  if (tokenInfo == null) { // protocol has no support for tokens
    return null;
  }
  TokenSelector<?> tokenSelector = null;
  try {
    tokenSelector = tokenInfo.value().newInstance();
  } catch (InstantiationException | IllegalAccessException e) {
    throw new IOException(e.toString(), e);
  }
  return tokenSelector.selectToken(
      SecurityUtil.buildTokenService(serverAddr), ugi.getTokens());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:SaslRpcClient.java

示例2: Connection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
Connection(ConnectionId remoteId, final Codec codec, final CompressionCodec compressor)
throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName());
  }
  this.server = remoteId.getAddress();
  this.codec = codec;
  this.compressor = compressor;

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  SecurityInfo securityInfo = SecurityInfo.getInfo(remoteId.getServiceName());
  this.useSasl = userProvider.isHBaseSecurityEnabled();
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException(
          "Can't obtain server Kerberos config key from SecurityInfo");
    }
    serverPrincipal = SecurityUtil.getServerPrincipal(
        conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service="
          + remoteId.getServiceName() + " is " + serverPrincipal);
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Use " + authMethod + " authentication for service " + remoteId.serviceName +
      ", sasl=" + useSasl);
  }
  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;

  ConnectionHeader.Builder builder = ConnectionHeader.newBuilder();
  builder.setServiceName(remoteId.getServiceName());
  UserInformation userInfoPB = getUserInfo(ticket);
  if (userInfoPB != null) {
    builder.setUserInfo(userInfoPB);
  }
  if (this.codec != null) {
    builder.setCellBlockCodecClass(this.codec.getClass().getCanonicalName());
  }
  if (this.compressor != null) {
    builder.setCellBlockCompressorClass(this.compressor.getClass().getCanonicalName());
  }
  builder.setVersionInfo(ProtobufUtil.getVersionInfo());
  this.header = builder.build();

  this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
    remoteId.getAddress().toString() +
    ((ticket==null)?" from an unknown user": (" from "
    + ticket.getUserName())));
  this.setDaemon(true);

  if (conf.getBoolean(SPECIFIC_WRITE_THREAD, false)) {
    callSender = new CallSender(getName(), conf);
    callSender.start();
  } else {
    callSender = null;
  }
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:81,代码来源:RpcClientImpl.java

示例3: setupAuthorization

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
/**
 * Set up server authorization
 *
 * @throws java.io.IOException if auth setup failed
 */
private void setupAuthorization() throws IOException {
  SecurityInfo securityInfo = SecurityInfo.getInfo(serviceName);
  this.useSasl = client.userProvider.isHBaseSecurityEnabled();

  this.token = null;
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector = tokenHandlers.get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector
            .selectToken(new Text(client.clusterId), ticket.getUGI().getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type " + tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException("Can't obtain server Kerberos config key from SecurityInfo");
    }
    this.serverPrincipal = SecurityUtil.getServerPrincipal(client.conf.get(serverKey),
        address.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service=" + serviceName + " is "
          + serverPrincipal);
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Use " + authMethod + " authentication for service " + serviceName +
        ", sasl=" + useSasl);
  }
  reloginMaxBackoff = client.conf.getInt("hbase.security.relogin.maxbackoff", 5000);
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:48,代码来源:AsyncRpcChannel.java

示例4: Connection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
Connection(ConnectionId remoteId, final Codec codec, final CompressionCodec compressor)
throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName());
  }
  this.server = remoteId.getAddress();
  this.codec = codec;
  this.compressor = compressor;

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  SecurityInfo securityInfo = SecurityInfo.getInfo(remoteId.getServiceName());
  this.useSasl = userProvider.isHBaseSecurityEnabled();
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException(
          "Can't obtain server Kerberos config key from SecurityInfo");
    }
    serverPrincipal = SecurityUtil.getServerPrincipal(
        conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service="
          + remoteId.getServiceName() + " is " + serverPrincipal);
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Use " + authMethod + " authentication for service " + remoteId.serviceName +
      ", sasl=" + useSasl);
  }
  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;

  ConnectionHeader.Builder builder = ConnectionHeader.newBuilder();
  builder.setServiceName(remoteId.getServiceName());
  UserInformation userInfoPB = getUserInfo(ticket);
  if (userInfoPB != null) {
    builder.setUserInfo(userInfoPB);
  }
  if (this.codec != null) {
    builder.setCellBlockCodecClass(this.codec.getClass().getCanonicalName());
  }
  if (this.compressor != null) {
    builder.setCellBlockCompressorClass(this.compressor.getClass().getCanonicalName());
  }
  this.header = builder.build();

  this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
    remoteId.getAddress().toString() +
    ((ticket==null)?" from an unknown user": (" from "
    + ticket.getUserName())));
  this.setDaemon(true);

  if (conf.getBoolean(SPECIFIC_WRITE_THREAD, false)) {
    callSender = new CallSender(getName(), conf);
    callSender.start();
  } else {
    callSender = null;
  }
}
 
开发者ID:grokcoder,项目名称:pbase,代码行数:80,代码来源:RpcClientImpl.java

示例5: Connection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
Connection(ConnectionId remoteId, final Codec codec, final CompressionCodec compressor)
throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName());
  }
  this.server = remoteId.getAddress();
  this.codec = codec;
  this.compressor = compressor;

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  SecurityInfo securityInfo = SecurityInfo.getInfo(remoteId.getServiceName());
  this.useSasl = userProvider.isHBaseSecurityEnabled();
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException(
          "Can't obtain server Kerberos config key from SecurityInfo");
    }
    serverPrincipal = SecurityUtil.getServerPrincipal(
        conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service="
          + remoteId.getServiceName() + " is " + serverPrincipal);
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Use " + authMethod + " authentication for service " + remoteId.serviceName +
      ", sasl=" + useSasl);
  }
  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;

  ConnectionHeader.Builder builder = ConnectionHeader.newBuilder();
  builder.setServiceName(remoteId.getServiceName());
  UserInformation userInfoPB;
  if ((userInfoPB = getUserInfo(ticket)) != null) {
    builder.setUserInfo(userInfoPB);
  }
  if (this.codec != null) {
    builder.setCellBlockCodecClass(this.codec.getClass().getCanonicalName());
  }
  if (this.compressor != null) {
    builder.setCellBlockCompressorClass(this.compressor.getClass().getCanonicalName());
  }
  this.header = builder.build();

  this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
    remoteId.getAddress().toString() +
    ((ticket==null)?" from an unknown user": (" from "
    + ticket.getUserName())));
  this.setDaemon(true);
}
 
开发者ID:tenggyut,项目名称:HIndex,代码行数:73,代码来源:RpcClient.java

示例6: SecureConnection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
public SecureConnection(ConnectionId remoteId) throws IOException {
  super(remoteId);
  this.server = remoteId.getAddress();

  User ticket = remoteId.getTicket();
  Class<?> protocol = remoteId.getProtocol();
  this.useSasl = userProvider.isHBaseSecurityEnabled();
  if (useSasl && protocol != null) {
    TokenInfo tokenInfo = protocol.getAnnotation(TokenInfo.class);
    if (tokenInfo != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenInfo.value());
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getUGI().getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenInfo.value());
      }
    }
    KerberosInfo krbInfo = protocol.getAnnotation(KerberosInfo.class);
    if (krbInfo != null) {
      String serverKey = krbInfo.serverPrincipal();
      if (serverKey == null) {
        throw new IOException(
            "Can't obtain server Kerberos config key from KerberosInfo");
      }
      serverPrincipal = SecurityUtil.getServerPrincipal(
          conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  header = new SecureConnectionHeader(
      protocol == null ? null : protocol.getName(), ticket, authMethod);

  if (LOG.isDebugEnabled())
    LOG.debug("Use " + authMethod + " authentication for protocol "
        + protocol.getSimpleName());

  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
}
 
开发者ID:wanhao,项目名称:IRIndex,代码行数:53,代码来源:SecureClient.java

示例7: RpcConnection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
protected RpcConnection(Configuration conf, HashedWheelTimer timeoutTimer, ConnectionId remoteId,
    String clusterId, boolean isSecurityEnabled, Codec codec, CompressionCodec compressor)
    throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName());
  }
  this.timeoutTimer = timeoutTimer;
  this.codec = codec;
  this.compressor = compressor;
  this.conf = conf;

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  SecurityInfo securityInfo = SecurityInfo.getInfo(remoteId.getServiceName());
  this.useSasl = isSecurityEnabled;
  Token<? extends TokenIdentifier> token = null;
  String serverPrincipal = null;
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector = AbstractRpcClient.TOKEN_HANDLERS
          .get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId), ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type " + tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException("Can't obtain server Kerberos config key from SecurityInfo");
    }
    serverPrincipal = SecurityUtil.getServerPrincipal(conf.get(serverKey),
      remoteId.address.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service=" + remoteId.getServiceName()
          + " is " + serverPrincipal);
    }
  }
  this.token = token;
  this.serverPrincipal = serverPrincipal;
  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  // Log if debug AND non-default auth, else if trace enabled.
  // No point logging obvious.
  if ((LOG.isDebugEnabled() && !authMethod.equals(AuthMethod.SIMPLE)) ||
      LOG.isTraceEnabled()) {
    // Only log if not default auth.
    LOG.debug("Use " + authMethod + " authentication for service " + remoteId.serviceName
        + ", sasl=" + useSasl);
  }
  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;
}
 
开发者ID:apache,项目名称:hbase,代码行数:60,代码来源:RpcConnection.java

示例8: Connection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
Connection(ConnectionId remoteId, final Codec codec, final CompressionCodec compressor)
throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " + remoteId.getAddress().getHostName());
  }
  this.server = remoteId.getAddress();
  this.codec = codec;
  this.compressor = compressor;

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  SecurityInfo securityInfo = SecurityInfo.getInfo(remoteId.getServiceName());
  this.useSasl = userProvider.isHBaseSecurityEnabled();
  if (useSasl && securityInfo != null) {
    AuthenticationProtos.TokenIdentifier.Kind tokenKind = securityInfo.getTokenKind();
    if (tokenKind != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenKind);
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenKind);
      }
    }
    String serverKey = securityInfo.getServerPrincipal();
    if (serverKey == null) {
      throw new IOException(
          "Can't obtain server Kerberos config key from SecurityInfo");
    }
    serverPrincipal = SecurityUtil.getServerPrincipal(
        conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
    if (LOG.isDebugEnabled()) {
      LOG.debug("RPC Server Kerberos principal name for service="
          + remoteId.getServiceName() + " is " + serverPrincipal);
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled()) {
    LOG.debug("Use " + authMethod + " authentication for service " + remoteId.serviceName +
      ", sasl=" + useSasl);
  }
  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;

  ConnectionHeader.Builder builder = ConnectionHeader.newBuilder();
  builder.setServiceName(remoteId.getServiceName());
  UserInformation userInfoPB;
  if ((userInfoPB = getUserInfo(ticket)) != null) {
    builder.setUserInfo(userInfoPB);
  }
  if (this.codec != null) {
    builder.setCellBlockCodecClass(this.codec.getClass().getCanonicalName());
  }
  if (this.compressor != null) {
    builder.setCellBlockCompressorClass(this.compressor.getClass().getCanonicalName());
  }
  this.header = builder.build();

  this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
    remoteId.getAddress().toString() +
    ((ticket==null)?" from an unknown user": (" from "
    + ticket.getUserName())));
  this.setDaemon(true);

  if (conf.getBoolean(ALLOWS_INTERRUPTS, false)) {
    callSender = new CallSender(getName(), conf);
    callSender.start();
  } else {
    callSender = null;
  }
}
 
开发者ID:shenli-uiuc,项目名称:PyroDB,代码行数:80,代码来源:RpcClient.java

示例9: SecureConnection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
public SecureConnection(ConnectionId remoteId) throws IOException {
  super(remoteId);
  this.server = remoteId.getAddress();

  User ticket = remoteId.getTicket();
  Class<?> protocol = remoteId.getProtocol();
  this.useSasl = User.isHBaseSecurityEnabled(conf);
  if (useSasl && protocol != null) {
    TokenInfo tokenInfo = protocol.getAnnotation(TokenInfo.class);
    if (tokenInfo != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenInfo.value());
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getUGI().getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenInfo.value());
      }
    }
    KerberosInfo krbInfo = protocol.getAnnotation(KerberosInfo.class);
    if (krbInfo != null) {
      String serverKey = krbInfo.serverPrincipal();
      if (serverKey == null) {
        throw new IOException(
            "Can't obtain server Kerberos config key from KerberosInfo");
      }
      serverPrincipal = SecurityUtil.getServerPrincipal(
          conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  header = new SecureConnectionHeader(
      protocol == null ? null : protocol.getName(), ticket, authMethod);

  if (LOG.isDebugEnabled())
    LOG.debug("Use " + authMethod + " authentication for protocol "
        + protocol.getSimpleName());

  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
}
 
开发者ID:zwqjsj0404,项目名称:HBase-Research,代码行数:53,代码来源:SecureClient.java

示例10: Connection

import org.apache.hadoop.security.token.TokenSelector; //导入方法依赖的package包/类
Connection(ConnectionId remoteId) throws IOException {
  if (remoteId.getAddress().isUnresolved()) {
    throw new UnknownHostException("unknown host: " +
                                   remoteId.getAddress().getHostName());
  }
  this.server = remoteId.getAddress();

  UserGroupInformation ticket = remoteId.getTicket().getUGI();
  Class<?> protocol = remoteId.getProtocol();
  this.useSasl = User.isHBaseSecurityEnabled(conf);
  if (useSasl && protocol != null) {
    TokenInfo tokenInfo = protocol.getAnnotation(TokenInfo.class);
    if (tokenInfo != null) {
      TokenSelector<? extends TokenIdentifier> tokenSelector =
          tokenHandlers.get(tokenInfo.value());
      if (tokenSelector != null) {
        token = tokenSelector.selectToken(new Text(clusterId),
            ticket.getTokens());
      } else if (LOG.isDebugEnabled()) {
        LOG.debug("No token selector found for type "+tokenInfo.value());
      }
    }
    KerberosInfo krbInfo = protocol.getAnnotation(KerberosInfo.class);
    if (krbInfo != null) {
      String serverKey = krbInfo.serverPrincipal();
      if (serverKey == null) {
        throw new IOException(
            "Can't obtain server Kerberos config key from KerberosInfo");
      }
      serverPrincipal = SecurityUtil.getServerPrincipal(
          conf.get(serverKey), server.getAddress().getCanonicalHostName().toLowerCase());
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
    }
  }

  if (!useSasl) {
    authMethod = AuthMethod.SIMPLE;
  } else if (token != null) {
    authMethod = AuthMethod.DIGEST;
  } else {
    authMethod = AuthMethod.KERBEROS;
  }

  if (LOG.isDebugEnabled())
    LOG.debug("Use " + authMethod + " authentication for protocol "
        + protocol.getSimpleName());

  reloginMaxBackoff = conf.getInt("hbase.security.relogin.maxbackoff", 5000);
  this.remoteId = remoteId;

  ConnectionHeader.Builder builder = ConnectionHeader.newBuilder();
  builder.setProtocol(protocol == null ? "" : protocol.getName());
  UserInformation userInfoPB;
  if ((userInfoPB = getUserInfoPB(ticket)) != null) {
    builder.setUserInfo(userInfoPB);
  }
  this.header = builder.build();

  this.setName("IPC Client (" + socketFactory.hashCode() +") connection to " +
    remoteId.getAddress().toString() +
    ((ticket==null)?" from an unknown user": (" from " 
    + ticket.getUserName())));
  this.setDaemon(true);
}
 
开发者ID:daidong,项目名称:DominoHBase,代码行数:68,代码来源:HBaseClient.java


注:本文中的org.apache.hadoop.security.token.TokenSelector.selectToken方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。