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


Java AuthMethod类代码示例

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


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

示例1: getAuthorizedUgi

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private UserGroupInformation getAuthorizedUgi(String authorizedId)
    throws InvalidToken, AccessControlException {
  if (authMethod == AuthMethod.TOKEN) {
    TokenIdentifier tokenId = SaslRpcServer.getIdentifier(authorizedId,
        secretManager);
    UserGroupInformation ugi = tokenId.getUser();
    if (ugi == null) {
      throw new AccessControlException(
          "Can't retrieve username from tokenIdentifier.");
    }
    ugi.addTokenIdentifier(tokenId);
    return ugi;
  } else {
    return UserGroupInformation.createRemoteUser(authorizedId, authMethod);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:17,代码来源:Server.java

示例2: buildSaslNegotiateResponse

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
/**
 * Process the Sasl's Negotiate request, including the optimization of 
 * accelerating token negotiation.
 * @return the response to Negotiate request - the list of enabled 
 *         authMethods and challenge if the TOKENS are supported. 
 * @throws SaslException - if attempt to generate challenge fails.
 * @throws IOException - if it fails to create the SASL server for Tokens
 */
private RpcSaslProto buildSaslNegotiateResponse()
    throws InterruptedException, SaslException, IOException {
  RpcSaslProto negotiateMessage = negotiateResponse;
  // accelerate token negotiation by sending initial challenge
  // in the negotiation response
  if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
    saslServer = createSaslServer(AuthMethod.TOKEN);
    byte[] challenge = saslServer.evaluateResponse(new byte[0]);
    RpcSaslProto.Builder negotiateBuilder =
        RpcSaslProto.newBuilder(negotiateResponse);
    negotiateBuilder.getAuthsBuilder(0)  // TOKEN is always first
        .setChallenge(ByteString.copyFrom(challenge));
    negotiateMessage = negotiateBuilder.build();
  }
  sentNegotiate = true;
  return negotiateMessage;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:26,代码来源:Server.java

示例3: authorizeConnection

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
/**
 * Authorize proxy users to access this server
 * @throws WrappedRpcServerException - user is not allowed to proxy
 */
private void authorizeConnection() throws WrappedRpcServerException {
  try {
    // If auth method is TOKEN, the token was obtained by the
    // real user for the effective user, therefore not required to
    // authorize real user. doAs is allowed only for simple or kerberos
    // authentication
    if (user != null && user.getRealUser() != null
        && (authMethod != AuthMethod.TOKEN)) {
      ProxyUsers.authorize(user, this.getHostAddress());
    }
    authorize(user, protocolName, getHostInetAddress());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Successfully authorized " + connectionContext);
    }
    rpcMetrics.incrAuthorizationSuccesses();
  } catch (AuthorizationException ae) {
    LOG.info("Connection from " + this
        + " for protocol " + connectionContext.getProtocol()
        + " is unauthorized for user " + user);
    rpcMetrics.incrAuthorizationFailures();
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ae);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:29,代码来源:Server.java

示例4: buildNegotiateResponse

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的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

示例5: getAuthMethods

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private List<AuthMethod> getAuthMethods(SecretManager<?> secretManager,
                                           Configuration conf) {
  AuthenticationMethod confAuthenticationMethod =
      SecurityUtil.getAuthenticationMethod(conf);        
  List<AuthMethod> authMethods = new ArrayList<AuthMethod>();
  if (confAuthenticationMethod == AuthenticationMethod.TOKEN) {
    if (secretManager == null) {
      throw new IllegalArgumentException(AuthenticationMethod.TOKEN +
          " authentication requires a secret manager");
    } 
  } else if (secretManager != null) {
    LOG.debug(AuthenticationMethod.TOKEN +
        " authentication enabled for secret manager");
    // most preferred, go to the front of the line!
    authMethods.add(AuthenticationMethod.TOKEN.getAuthMethod());
  }
  authMethods.add(confAuthenticationMethod.getAuthMethod());        
  
  LOG.debug("Server accepts auth methods:" + authMethods);
  return authMethods;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:22,代码来源:Server.java

示例6: writeConnectionContext

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private void writeConnectionContext(ConnectionId remoteId,
                                    AuthMethod authMethod)
                                        throws IOException {
  // Write out the ConnectionHeader
  IpcConnectionContextProto message = ProtoUtil.makeIpcConnectionContext(
      RPC.getProtocolName(remoteId.getProtocol()),
      remoteId.getTicket(),
      authMethod);
  RpcRequestHeaderProto connectionContextHeader = ProtoUtil
      .makeRpcRequestHeader(RpcKind.RPC_PROTOCOL_BUFFER,
          OperationProto.RPC_FINAL_PACKET, CONNECTION_CONTEXT_CALL_ID,
          RpcConstants.INVALID_RETRY_COUNT, clientId);
  RpcRequestMessageWrapper request =
      new RpcRequestMessageWrapper(connectionContextHeader, message);
  
  // Write out the packet length
  out.writeInt(request.getLength());
  request.write(out);
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:20,代码来源:Client.java

示例7: doDigestRpc

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private void doDigestRpc(Server server, TestTokenSecretManager sm)
    throws Exception {
  final UserGroupInformation current = UserGroupInformation.getCurrentUser();
  addr = NetUtils.getConnectAddress(server);
  TestTokenIdentifier tokenId = new TestTokenIdentifier(new Text(current
      .getUserName()));
  Token<TestTokenIdentifier> token = new Token<TestTokenIdentifier>(tokenId, sm);
  SecurityUtil.setTokenService(token, addr);
  current.addToken(token);

  TestRpcService proxy = null;
  try {
    proxy = getClient(addr, conf);
    AuthMethod authMethod = convert(
        proxy.getAuthMethod(null, newEmptyRequest()));
    assertEquals(TOKEN, authMethod);
    //QOP must be auth
    assertEquals(expectedQop.saslQop,
                 RPC.getConnectionIdForProxy(proxy).getSaslQop());            
    proxy.ping(null, newEmptyRequest());
  } finally {
    stop(server, proxy);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:25,代码来源:TestSaslRPC.java

示例8: runNegotiation

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private void runNegotiation(CallbackHandler clientCbh,
                            CallbackHandler serverCbh)
                                throws SaslException {
  String mechanism = AuthMethod.PLAIN.getMechanismName();

  SaslClient saslClient = Sasl.createSaslClient(
      new String[]{ mechanism }, null, null, null, null, clientCbh);
  assertNotNull(saslClient);

  SaslServer saslServer = Sasl.createSaslServer(
      mechanism, null, "localhost", null, serverCbh);
  assertNotNull("failed to find PLAIN server", saslServer);
  
  byte[] response = saslClient.evaluateChallenge(new byte[0]);
  assertNotNull(response);
  assertTrue(saslClient.isComplete());

  response = saslServer.evaluateResponse(response);
  assertNull(response);
  assertTrue(saslServer.isComplete());
  assertNotNull(saslServer.getAuthorizationID());
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:23,代码来源:TestSaslRPC.java

示例9: getAuthMethod

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
@Override
public TestProtos.AuthMethodResponseProto getAuthMethod(
    RpcController controller, TestProtos.EmptyRequestProto request)
    throws ServiceException {
  AuthMethod authMethod = null;
  try {
    authMethod = UserGroupInformation.getCurrentUser()
        .getAuthenticationMethod().getAuthMethod();
  } catch (IOException e) {
    throw new ServiceException(e);
  }

  return TestProtos.AuthMethodResponseProto.newBuilder()
      .setCode(authMethod.code)
      .setMechanismName(authMethod.getMechanismName())
      .build();
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:18,代码来源:TestRpcBase.java

示例10: buildSaslNegotiateResponse

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private RpcSaslProto buildSaslNegotiateResponse()
    throws IOException, InterruptedException {
  RpcSaslProto negotiateMessage = negotiateResponse;
  // accelerate token negotiation by sending initial challenge
  // in the negotiation response
  if (enabledAuthMethods.contains(AuthMethod.TOKEN)) {
    saslServer = createSaslServer(AuthMethod.TOKEN);
    byte[] challenge = saslServer.evaluateResponse(new byte[0]);
    RpcSaslProto.Builder negotiateBuilder =
        RpcSaslProto.newBuilder(negotiateResponse);
    negotiateBuilder.getAuthsBuilder(0)  // TOKEN is always first
        .setChallenge(ByteString.copyFrom(challenge));
    negotiateMessage = negotiateBuilder.build();
  }
  sentNegotiate = true;
  return negotiateMessage;
}
 
开发者ID:naver,项目名称:hadoop,代码行数:18,代码来源:Server.java

示例11: getAuthorizedUgi

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
private UserGroupInformation getAuthorizedUgi(String authorizedId)
    throws InvalidToken, AccessControlException {
  if (authMethod == AuthMethod.TOKEN) {
    TokenIdentifier tokenId = SaslRpcServer.getIdentifier(authorizedId,
        secretManager);
    UserGroupInformation ugi = tokenId.getUser();
    if (ugi == null) {
      throw new AccessControlException(
          "Can't retrieve username from tokenIdentifier.");
    }
    ugi.addTokenIdentifier(tokenId);
    return ugi;
  } else {
    return UserGroupInformation.createRemoteUser(authorizedId);
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:17,代码来源:Server.java

示例12: authorizeConnection

import org.apache.hadoop.security.SaslRpcServer.AuthMethod; //导入依赖的package包/类
/**
 * Authorize proxy users to access this server
 * @throws WrappedRpcServerException - user is not allowed to proxy
 */
private void authorizeConnection() throws WrappedRpcServerException {
  try {
    // If auth method is TOKEN, the token was obtained by the
    // real user for the effective user, therefore not required to
    // authorize real user. doAs is allowed only for simple or kerberos
    // authentication
    if (user != null && user.getRealUser() != null
        && (authMethod != AuthMethod.TOKEN)) {
      ProxyUsers.authorize(user, this.getHostAddress(), conf);
    }
    authorize(user, protocolName, getHostInetAddress());
    if (LOG.isDebugEnabled()) {
      LOG.debug("Successfully authorized " + connectionContext);
    }
    rpcMetrics.incrAuthorizationSuccesses();
  } catch (AuthorizationException ae) {
    LOG.info("Connection from " + this
        + " for protocol " + connectionContext.getProtocol()
        + " is unauthorized for user " + user);
    rpcMetrics.incrAuthorizationFailures();
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ae);
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:29,代码来源:Server.java


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