• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java SaslAuth类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Java中org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth的典型用法代码示例。如果您正苦于以下问题:Java SaslAuth类的具体用法?Java SaslAuth怎么用?Java SaslAuth使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



SaslAuth类属于org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto包,在下文中一共展示了SaslAuth类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。

示例1: getServerToken

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的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: buildNegotiateResponse

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
private RpcSaslProto buildNegotiateResponse(List<AuthMethod> authMethods)
    throws IOException {
  RpcSaslProto.Builder negotiateBuilder = RpcSaslProto.newBuilder();
  if (authMethods.contains(AuthMethod.SIMPLE) && authMethods.size() == 1) {
    // SIMPLE-only servers return success in response to negotiate
    negotiateBuilder.setState(SaslState.SUCCESS);
  } else {
    negotiateBuilder.setState(SaslState.NEGOTIATE);
    for (AuthMethod authMethod : authMethods) {
      SaslRpcServer saslRpcServer = new SaslRpcServer(authMethod);      
      SaslAuth.Builder builder = negotiateBuilder.addAuthsBuilder()
          .setMethod(authMethod.toString())
          .setMechanism(saslRpcServer.mechanism);
      if (saslRpcServer.protocol != null) {
        builder.setProtocol(saslRpcServer.protocol);
      }
      if (saslRpcServer.serverId != null) {
        builder.setServerId(saslRpcServer.serverId);
      }
    }
  }
  return negotiateBuilder.build();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:24,代码来源:Server.java


示例3: isValidAuthType

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
private boolean isValidAuthType(SaslAuth authType) {
  AuthMethod authMethod;
  try {
    authMethod = AuthMethod.valueOf(authType.getMethod());
  } catch (IllegalArgumentException iae) { // unknown auth
    authMethod = null;
  }
  // do we know what it is?  is it using our mechanism?
  return authMethod != null &&
         authMethod.getMechanismName().equals(authType.getMechanism());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:12,代码来源:SaslRpcClient.java


示例4: createSaslClient

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
/**
 * Try to create a SaslClient for an authentication type.  May return
 * null if the type isn't supported or the client lacks the required
 * credentials.
 * 
 * @param authType - the requested authentication method
 * @return SaslClient for the authType or null
 * @throws SaslException - error instantiating client
 * @throws IOException - misc errors
 */
private SaslClient createSaslClient(SaslAuth authType)
    throws SaslException, IOException {
  String saslUser = null;
  // SASL requires the client and server to use the same proto and serverId
  // if necessary, auth types below will verify they are valid
  final String saslProtocol = authType.getProtocol();
  final String saslServerName = authType.getServerId();
  Map<String, String> saslProperties =
    saslPropsResolver.getClientProperties(serverAddr.getAddress());  
  CallbackHandler saslCallback = null;
  
  final AuthMethod method = AuthMethod.valueOf(authType.getMethod());
  switch (method) {
    case TOKEN: {
      Token<?> token = getServerToken(authType);
      if (token == null) {
        LOG.debug("tokens aren't supported for this protocol" +
            " or user doesn't have one");
        return null;
      }
      saslCallback = new SaslClientCallbackHandler(token);
      break;
    }
    case KERBEROS: {
      if (ugi.getRealAuthenticationMethod().getAuthMethod() !=
          AuthMethod.KERBEROS) {
        LOG.debug("client isn't using kerberos");
        return null;
      }
      String serverPrincipal = getServerPrincipal(authType);
      if (serverPrincipal == null) {
        LOG.debug("protocol doesn't use kerberos");
        return null;
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server's Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
      break;
    }
    default:
      throw new IOException("Unknown authentication method " + method);
  }

  String mechanism = method.getMechanismName();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating SASL " + mechanism + "(" + method + ") "
        + " client to authenticate to service at " + saslServerName);
  }
  return Sasl.createSaslClient(
      new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
      saslProperties, saslCallback);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:64,代码来源:SaslRpcClient.java


示例5: processSaslMessage

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
/**
 * Process a saslMessge.
 * @param saslMessage received SASL message
 * @return the sasl response to send back to client
 * @throws SaslException if authentication or generating response fails, 
 *                       or SASL protocol mixup
 * @throws IOException if a SaslServer cannot be created
 * @throws AccessControlException if the requested authentication type 
 *         is not supported or trying to re-attempt negotiation.
 * @throws InterruptedException
 */
private RpcSaslProto processSaslMessage(RpcSaslProto saslMessage)
    throws SaslException, IOException, AccessControlException,
    InterruptedException {
  final RpcSaslProto saslResponse;
  final SaslState state = saslMessage.getState(); // required      
  switch (state) {
    case NEGOTIATE: {
      if (sentNegotiate) {
        // FIXME shouldn't this be SaslException?
        throw new AccessControlException(
            "Client already attempted negotiation");
      }
      saslResponse = buildSaslNegotiateResponse();
      // simple-only server negotiate response is success which client
      // interprets as switch to simple
      if (saslResponse.getState() == SaslState.SUCCESS) {
        switchToSimple();
      }
      break;
    }
    case INITIATE: {
      if (saslMessage.getAuthsCount() != 1) {
        throw new SaslException("Client mechanism is malformed");
      }
      // verify the client requested an advertised authType
      SaslAuth clientSaslAuth = saslMessage.getAuths(0);
      if (!negotiateResponse.getAuthsList().contains(clientSaslAuth)) {
        if (sentNegotiate) {
          throw new AccessControlException(
              clientSaslAuth.getMethod() + " authentication is not enabled."
                  + "  Available:" + enabledAuthMethods);
        }
        saslResponse = buildSaslNegotiateResponse();
        break;
      }
      authMethod = AuthMethod.valueOf(clientSaslAuth.getMethod());
      // abort SASL for SIMPLE auth, server has already ensured that
      // SIMPLE is a legit option above.  we will send no response
      if (authMethod == AuthMethod.SIMPLE) {
        switchToSimple();
        saslResponse = null;
        break;
      }
      // sasl server for tokens may already be instantiated
      if (saslServer == null || authMethod != AuthMethod.TOKEN) {
        saslServer = createSaslServer(authMethod);
      }
      saslResponse = processSaslToken(saslMessage);
      break;
    }
    case RESPONSE: {
      saslResponse = processSaslToken(saslMessage);
      break;
    }
    default:
      throw new SaslException("Client sent unsupported state " + state);
  }
  return saslResponse;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:71,代码来源:Server.java


示例6: createSaslClient

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
/**
 * Try to create a SaslClient for an authentication type.  May return
 * null if the type isn't supported or the client lacks the required
 * credentials.
 * 
 * @param authType - the requested authentication method
 * @return SaslClient for the authType or null
 * @throws SaslException - error instantiating client
 * @throws IOException - misc errors
 */
private SaslClient createSaslClient(SaslAuth authType)
    throws SaslException, IOException {
  String saslUser = null;
  // SASL requires the client and server to use the same proto and serverId
  // if necessary, auth types below will verify they are valid
  final String saslProtocol = authType.getProtocol();
  final String saslServerName = authType.getServerId();
  Map<String, String> saslProperties =
    saslPropsResolver.getClientProperties(serverAddr.getAddress());  
  CallbackHandler saslCallback = null;
  
  final AuthMethod method = AuthMethod.valueOf(authType.getMethod());
  switch (method) {
    case TOKEN: {
      Token<?> token = getServerToken(authType);
      if (token == null) {
        return null; // tokens aren't supported or user doesn't have one
      }
      saslCallback = new SaslClientCallbackHandler(token);
      break;
    }
    case KERBEROS: {
      if (ugi.getRealAuthenticationMethod().getAuthMethod() !=
          AuthMethod.KERBEROS) {
        return null; // client isn't using kerberos
      }
      String serverPrincipal = getServerPrincipal(authType);
      if (serverPrincipal == null) {
        return null; // protocol doesn't use kerberos
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server's Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
      break;
    }
    default:
      throw new IOException("Unknown authentication method " + method);
  }
  
  String mechanism = method.getMechanismName();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating SASL " + mechanism + "(" + method + ") "
        + " client to authenticate to service at " + saslServerName);
  }
  return Sasl.createSaslClient(
      new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
      saslProperties, saslCallback);
}
 
开发者ID:naver,项目名称:hadoop,代码行数:60,代码来源:SaslRpcClient.java


示例7: processSaslMessage

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
private RpcSaslProto processSaslMessage(RpcSaslProto saslMessage)
    throws IOException, InterruptedException {
  final RpcSaslProto saslResponse;
  final SaslState state = saslMessage.getState(); // required      
  switch (state) {
    case NEGOTIATE: {
      if (sentNegotiate) {
        throw new AccessControlException(
            "Client already attempted negotiation");
      }
      saslResponse = buildSaslNegotiateResponse();
      // simple-only server negotiate response is success which client
      // interprets as switch to simple
      if (saslResponse.getState() == SaslState.SUCCESS) {
        switchToSimple();
      }
      break;
    }
    case INITIATE: {
      if (saslMessage.getAuthsCount() != 1) {
        throw new SaslException("Client mechanism is malformed");
      }
      // verify the client requested an advertised authType
      SaslAuth clientSaslAuth = saslMessage.getAuths(0);
      if (!negotiateResponse.getAuthsList().contains(clientSaslAuth)) {
        if (sentNegotiate) {
          throw new AccessControlException(
              clientSaslAuth.getMethod() + " authentication is not enabled."
                  + "  Available:" + enabledAuthMethods);
        }
        saslResponse = buildSaslNegotiateResponse();
        break;
      }
      authMethod = AuthMethod.valueOf(clientSaslAuth.getMethod());
      // abort SASL for SIMPLE auth, server has already ensured that
      // SIMPLE is a legit option above.  we will send no response
      if (authMethod == AuthMethod.SIMPLE) {
        switchToSimple();
        saslResponse = null;
        break;
      }
      // sasl server for tokens may already be instantiated
      if (saslServer == null || authMethod != AuthMethod.TOKEN) {
        saslServer = createSaslServer(authMethod);
      }
      saslResponse = processSaslToken(saslMessage);
      break;
    }
    case RESPONSE: {
      saslResponse = processSaslToken(saslMessage);
      break;
    }
    default:
      throw new SaslException("Client sent unsupported state " + state);
  }
  return saslResponse;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:58,代码来源:Server.java


示例8: createSaslClient

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
/**
 * Try to create a SaslClient for an authentication type.  May return
 * null if the type isn't supported or the client lacks the required
 * credentials.
 * 
 * @param authType - the requested authentication method
 * @return SaslClient for the authType or null
 * @throws SaslException - error instantiating client
 * @throws IOException - misc errors
 */
private SaslClient createSaslClient(SaslAuth authType)
    throws SaslException, IOException {
  String saslUser = null;
  // SASL requires the client and server to use the same proto and serverId
  // if necessary, auth types below will verify they are valid
  final String saslProtocol = authType.getProtocol();
  final String saslServerName = authType.getServerId();
  Map<String, String> saslProperties = SaslRpcServer.SASL_PROPS;
  CallbackHandler saslCallback = null;
  
  final AuthMethod method = AuthMethod.valueOf(authType.getMethod());
  switch (method) {
    case TOKEN: {
      Token<?> token = getServerToken(authType);
      if (token == null) {
        return null; // tokens aren't supported or user doesn't have one
      }
      saslCallback = new SaslClientCallbackHandler(token);
      break;
    }
    case KERBEROS: {
      if (ugi.getRealAuthenticationMethod().getAuthMethod() !=
          AuthMethod.KERBEROS) {
        return null; // client isn't using kerberos
      }
      String serverPrincipal = getServerPrincipal(authType);
      if (serverPrincipal == null) {
        return null; // protocol doesn't use kerberos
      }
      if (LOG.isDebugEnabled()) {
        LOG.debug("RPC Server's Kerberos principal name for protocol="
            + protocol.getCanonicalName() + " is " + serverPrincipal);
      }
      break;
    }
    default:
      throw new IOException("Unknown authentication method " + method);
  }
  
  String mechanism = method.getMechanismName();
  if (LOG.isDebugEnabled()) {
    LOG.debug("Creating SASL " + mechanism + "(" + method + ") "
        + " client to authenticate to service at " + saslServerName);
  }
  return Sasl.createSaslClient(
      new String[] { mechanism }, saslUser, saslProtocol, saslServerName,
      saslProperties, saslCallback);
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:59,代码来源:SaslRpcClient.java


示例9: processSaslMessage

import org.apache.hadoop.ipc.protobuf.RpcHeaderProtos.RpcSaslProto.SaslAuth; //导入依赖的package包/类
private RpcSaslProto processSaslMessage(RpcSaslProto saslMessage)
    throws IOException, InterruptedException {
  RpcSaslProto saslResponse = null;
  final SaslState state = saslMessage.getState(); // required      
  switch (state) {
    case NEGOTIATE: {
      if (sentNegotiate) {
        throw new AccessControlException(
            "Client already attempted negotiation");
      }
      saslResponse = buildSaslNegotiateResponse();
      // simple-only server negotiate response is success which client
      // interprets as switch to simple
      if (saslResponse.getState() == SaslState.SUCCESS) {
        switchToSimple();
      }
      break;
    }
    case INITIATE: {
      if (saslMessage.getAuthsCount() != 1) {
        throw new SaslException("Client mechanism is malformed");
      }
      // verify the client requested an advertised authType
      SaslAuth clientSaslAuth = saslMessage.getAuths(0);
      if (!negotiateResponse.getAuthsList().contains(clientSaslAuth)) {
        if (sentNegotiate) {
          throw new AccessControlException(
              clientSaslAuth.getMethod() + " authentication is not enabled."
                  + "  Available:" + enabledAuthMethods);
        }
        saslResponse = buildSaslNegotiateResponse();
        break;
      }
      authMethod = AuthMethod.valueOf(clientSaslAuth.getMethod());
      // abort SASL for SIMPLE auth, server has already ensured that
      // SIMPLE is a legit option above.  we will send no response
      if (authMethod == AuthMethod.SIMPLE) {
        switchToSimple();
        break;
      }
      // sasl server for tokens may already be instantiated
      if (saslServer == null || authMethod != AuthMethod.TOKEN) {
        saslServer = createSaslServer(authMethod);
      }
      // fallthru to process sasl token
    }
    case RESPONSE: {
      if (!saslMessage.hasToken()) {
        throw new SaslException("Client did not send a token");
      }
      byte[] saslToken = saslMessage.getToken().toByteArray();
      if (LOG.isDebugEnabled()) {
        LOG.debug("Have read input token of size " + saslToken.length
            + " for processing by saslServer.evaluateResponse()");
      }
      saslToken = saslServer.evaluateResponse(saslToken);
      saslResponse = buildSaslResponse(
          saslServer.isComplete() ? SaslState.SUCCESS : SaslState.CHALLENGE,
          saslToken);
      break;
    }
    default:
      throw new SaslException("Client sent unsupported state " + state);
  }
  return saslResponse;
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:67,代码来源:Server.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java Result类代码示例发布时间:2022-05-22
下一篇:
Java PhysType类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap