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


Java RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER属性代码示例

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


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

示例1: saslReadAndProcess

private void saslReadAndProcess(DataInputStream dis) throws
WrappedRpcServerException, IOException, InterruptedException {
  final RpcSaslProto saslMessage =
      decodeProtobufFromStream(RpcSaslProto.newBuilder(), dis);
  switch (saslMessage.getState()) {
    case WRAP: {
      if (!saslContextEstablished || !useWrap) {
        throw new WrappedRpcServerException(
            RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
            new SaslException("Server is not wrapping data"));
      }
      // loops over decoded data and calls processOneRpc
      unwrapPacketAndProcessRpcs(saslMessage.getToken().toByteArray());
      break;
    }
    default:
      saslProcess(saslMessage);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:19,代码来源:Server.java

示例2: saslReadAndProcess

private void saslReadAndProcess(RpcWritable.Buffer buffer) throws
    RpcServerException, IOException, InterruptedException {
  final RpcSaslProto saslMessage =
      getMessage(RpcSaslProto.getDefaultInstance(), buffer);
  switch (saslMessage.getState()) {
    case WRAP: {
      if (!saslContextEstablished || !useWrap) {
        throw new FatalRpcServerException(
            RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
            new SaslException("Server is not wrapping data"));
      }
      // loops over decoded data and calls processOneRpc
      unwrapPacketAndProcessRpcs(saslMessage.getToken().toByteArray());
      break;
    }
    default:
      saslProcess(saslMessage);
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:19,代码来源:Server.java

示例3: processOneRpc

/**
 * Process one RPC Request from buffer read from socket stream 
 *  - decode rpc in a rpc-Call
 *  - handle out-of-band RPC requests such as the initial connectionContext
 *  - A successfully decoded RpcCall will be deposited in RPC-Q and
 *    its response will be sent later when the request is processed.
 * 
 * Prior to this call the connectionHeader ("hrpc...") has been handled and
 * if SASL then SASL has been established and the buf we are passed
 * has been unwrapped from SASL.
 * 
 * @param buf - contains the RPC request header and the rpc request
 * @throws IOException - internal error that should not be returned to
 *         client, typically failure to respond to client
 * @throws WrappedRpcServerException - an exception that is sent back to the
 *         client in this method and does not require verbose logging by the
 *         Listener thread
 * @throws InterruptedException
 */    
private void processOneRpc(byte[] buf)
    throws IOException, WrappedRpcServerException, InterruptedException {
  int callId = -1;
  int retry = RpcConstants.INVALID_RETRY_COUNT;
  try {
    final DataInputStream dis =
        new DataInputStream(new ByteArrayInputStream(buf));
    final RpcRequestHeaderProto header =
        decodeProtobufFromStream(RpcRequestHeaderProto.newBuilder(), dis);
    callId = header.getCallId();
    retry = header.getRetryCount();
    if (LOG.isDebugEnabled()) {
      LOG.debug(" got #" + callId);
    }
    checkRpcHeaders(header);
    
    if (callId < 0) { // callIds typically used during connection setup
      processRpcOutOfBandRequest(header, dis);
    } else if (!connectionContextRead) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection context not established");
    } else {
      processRpcRequest(header, dis);
    }
  } catch (WrappedRpcServerException wrse) { // inform client of error
    Throwable ioe = wrse.getCause();
    final Call call = new Call(callId, retry, null, this);
    setupResponse(authFailedResponse, call,
        RpcStatusProto.FATAL, wrse.getRpcErrorCodeProto(), null,
        ioe.getClass().getName(), ioe.getMessage());
    call.sendResponse();
    throw wrse;
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:54,代码来源:Server.java

示例4: processRpcOutOfBandRequest

/**
 * Establish RPC connection setup by negotiating SASL if required, then
 * reading and authorizing the connection header
 * @param header - RPC header
 * @param dis - stream to request payload
 * @throws WrappedRpcServerException - setup failed due to SASL
 *         negotiation failure, premature or invalid connection context,
 *         or other state errors. This exception needs to be sent to the 
 *         client.
 * @throws IOException - failed to send a response back to the client
 * @throws InterruptedException
 */
private void processRpcOutOfBandRequest(RpcRequestHeaderProto header,
    DataInputStream dis) throws WrappedRpcServerException, IOException,
    InterruptedException {
  final int callId = header.getCallId();
  if (callId == CONNECTION_CONTEXT_CALL_ID) {
    // SASL must be established prior to connection context
    if (authProtocol == AuthProtocol.SASL && !saslContextEstablished) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection header sent during SASL negotiation");
    }
    // read and authorize the user
    processConnectionContext(dis);
  } else if (callId == AuthProtocol.SASL.callId) {
    // if client was switched to simple, ignore first SASL message
    if (authProtocol != AuthProtocol.SASL) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "SASL protocol not requested by client");
    }
    saslReadAndProcess(dis);
  } else if (callId == PING_CALL_ID) {
    LOG.debug("Received ping message");
  } else {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        "Unknown out of band call #" + callId);
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:41,代码来源:Server.java

示例5: processOneRpc

/**
 * Process an RPC Request - handle connection setup and decoding of
 * request into a Call
 * @param buf - contains the RPC request header and the rpc request
 * @throws IOException - internal error that should not be returned to
 *         client, typically failure to respond to client
 * @throws WrappedRpcServerException - an exception to be sent back to
 *         the client that does not require verbose logging by the
 *         Listener thread
 * @throws InterruptedException
 */    
private void processOneRpc(byte[] buf)
    throws IOException, WrappedRpcServerException, InterruptedException {
  int callId = -1;
  int retry = RpcConstants.INVALID_RETRY_COUNT;
  try {
    final DataInputStream dis =
        new DataInputStream(new ByteArrayInputStream(buf));
    final RpcRequestHeaderProto header =
        decodeProtobufFromStream(RpcRequestHeaderProto.newBuilder(), dis);
    callId = header.getCallId();
    retry = header.getRetryCount();
    if (LOG.isDebugEnabled()) {
      LOG.debug(" got #" + callId);
    }
    checkRpcHeaders(header);
    
    if (callId < 0) { // callIds typically used during connection setup
      processRpcOutOfBandRequest(header, dis);
    } else if (!connectionContextRead) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection context not established");
    } else {
      processRpcRequest(header, dis);
    }
  } catch (WrappedRpcServerException wrse) { // inform client of error
    Throwable ioe = wrse.getCause();
    final Call call = new Call(callId, retry, null, this);
    setupResponse(authFailedResponse, call,
        RpcStatusProto.FATAL, wrse.getRpcErrorCodeProto(), null,
        ioe.getClass().getName(), ioe.getMessage());
    responder.doRespond(call);
    throw wrse;
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:46,代码来源:Server.java

示例6: processRpcOutOfBandRequest

/**
 * Establish RPC connection setup by negotiating SASL if required, then
 * reading and authorizing the connection header
 * @param header - RPC header
 * @param dis - stream to request payload
 * @throws WrappedRpcServerException - setup failed due to SASL
 *         negotiation failure, premature or invalid connection context,
 *         or other state errors 
 * @throws IOException - failed to send a response back to the client
 * @throws InterruptedException
 */
private void processRpcOutOfBandRequest(RpcRequestHeaderProto header,
    DataInputStream dis) throws WrappedRpcServerException, IOException,
    InterruptedException {
  final int callId = header.getCallId();
  if (callId == CONNECTION_CONTEXT_CALL_ID) {
    // SASL must be established prior to connection context
    if (authProtocol == AuthProtocol.SASL && !saslContextEstablished) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection header sent during SASL negotiation");
    }
    // read and authorize the user
    processConnectionContext(dis);
  } else if (callId == AuthProtocol.SASL.callId) {
    // if client was switched to simple, ignore first SASL message
    if (authProtocol != AuthProtocol.SASL) {
      throw new WrappedRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "SASL protocol not requested by client");
    }
    saslReadAndProcess(dis);
  } else if (callId == PING_CALL_ID) {
    LOG.debug("Received ping message");
  } else {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        "Unknown out of band call #" + callId);
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:40,代码来源:Server.java

示例7: processRpcOutOfBandRequest

/**
 * Establish RPC connection setup by negotiating SASL if required, then
 * reading and authorizing the connection header
 * @param header - RPC header
 * @param buffer - stream to request payload
 * @throws RpcServerException - setup failed due to SASL
 *         negotiation failure, premature or invalid connection context,
 *         or other state errors 
 * @throws IOException - failed to send a response back to the client
 * @throws InterruptedException
 */
private void processRpcOutOfBandRequest(RpcRequestHeaderProto header,
    RpcWritable.Buffer buffer) throws RpcServerException,
        IOException, InterruptedException {
  final int callId = header.getCallId();
  if (callId == CONNECTION_CONTEXT_CALL_ID) {
    // SASL must be established prior to connection context
    if (authProtocol == AuthProtocol.SASL && !saslContextEstablished) {
      throw new FatalRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection header sent during SASL negotiation");
    }
    // read and authorize the user
    processConnectionContext(buffer);
  } else if (callId == AuthProtocol.SASL.callId) {
    // if client was switched to simple, ignore first SASL message
    if (authProtocol != AuthProtocol.SASL) {
      throw new FatalRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "SASL protocol not requested by client");
    }
    saslReadAndProcess(buffer);
  } else if (callId == PING_CALL_ID) {
    LOG.debug("Received ping message");
  } else {
    throw new FatalRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        "Unknown out of band call #" + callId);
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:40,代码来源:Server.java

示例8: saslProcess

/**
 * Process saslMessage and send saslResponse back
 * @param saslMessage received SASL message
 * @throws WrappedRpcServerException setup failed due to SASL negotiation 
 *         failure, premature or invalid connection context, or other state 
 *         errors. This exception needs to be sent to the client. This 
 *         exception will wrap {@link RetriableException}, 
 *         {@link InvalidToken}, {@link StandbyException} or 
 *         {@link SaslException}.
 * @throws IOException if sending reply fails
 * @throws InterruptedException
 */
private void saslProcess(RpcSaslProto saslMessage)
    throws WrappedRpcServerException, IOException, InterruptedException {
  if (saslContextEstablished) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        new SaslException("Negotiation is already complete"));
  }
  RpcSaslProto saslResponse = null;
  try {
    try {
      saslResponse = processSaslMessage(saslMessage);
    } catch (IOException e) {
      rpcMetrics.incrAuthenticationFailures();
      if (LOG.isDebugEnabled()) {
        LOG.debug(StringUtils.stringifyException(e));
      }
      // attempting user could be null
      IOException tce = (IOException) getTrueCause(e);
      AUDITLOG.warn(AUTH_FAILED_FOR + this.toString() + ":"
          + attemptingUser + " (" + e.getLocalizedMessage()
          + ") with true cause: (" + tce.getLocalizedMessage() + ")");
      throw tce;
    }
    
    if (saslServer != null && saslServer.isComplete()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server context established. Negotiated QoP is "
            + saslServer.getNegotiatedProperty(Sasl.QOP));
      }
      user = getAuthorizedUgi(saslServer.getAuthorizationID());
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server successfully authenticated client: " + user);
      }
      rpcMetrics.incrAuthenticationSuccesses();
      AUDITLOG.info(AUTH_SUCCESSFUL_FOR + user);
      saslContextEstablished = true;
    }
  } catch (WrappedRpcServerException wrse) { // don't re-wrap
    throw wrse;
  } catch (IOException ioe) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ioe);
  }
  // send back response if any, may throw IOException
  if (saslResponse != null) {
    doSaslReply(saslResponse);
  }
  // do NOT enable wrapping until the last auth response is sent
  if (saslContextEstablished) {
    String qop = (String) saslServer.getNegotiatedProperty(Sasl.QOP);
    // SASL wrapping is only used if the connection has a QOP, and
    // the value is not auth.  ex. auth-int & auth-priv
    useWrap = (qop != null && !"auth".equalsIgnoreCase(qop));        
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:67,代码来源:Server.java

示例9: processConnectionContext

/** Reads the connection context following the connection header
 * @param dis - DataInputStream from which to read the header 
 * @throws WrappedRpcServerException - if the header cannot be
 *         deserialized, or the user is not authorized
 */ 
private void processConnectionContext(DataInputStream dis)
    throws WrappedRpcServerException {
  // allow only one connection context during a session
  if (connectionContextRead) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        "Connection context already processed");
  }
  connectionContext = decodeProtobufFromStream(
      IpcConnectionContextProto.newBuilder(), dis);
  protocolName = connectionContext.hasProtocol() ? connectionContext
      .getProtocol() : null;

  UserGroupInformation protocolUser = ProtoUtil.getUgi(connectionContext);
  if (saslServer == null) {
    user = protocolUser;
  } else {
    // user is authenticated
    user.setAuthenticationMethod(authMethod);
    //Now we check if this is a proxy user case. If the protocol user is
    //different from the 'user', it is a proxy user scenario. However, 
    //this is not allowed if user authenticated with DIGEST.
    if ((protocolUser != null)
        && (!protocolUser.getUserName().equals(user.getUserName()))) {
      if (authMethod == AuthMethod.TOKEN) {
        // Not allowed to doAs if token authentication is used
        throw new WrappedRpcServerException(
            RpcErrorCodeProto.FATAL_UNAUTHORIZED,
            new AccessControlException("Authenticated user (" + user
                + ") doesn't match what the client claims to be ("
                + protocolUser + ")"));
      } else {
        // Effective user can be different from authenticated user
        // for simple auth or kerberos auth
        // The user is the real user. Now we create a proxy user
        UserGroupInformation realUser = user;
        user = UserGroupInformation.createProxyUser(protocolUser
            .getUserName(), realUser);
      }
    }
  }
  authorizeConnection();
  // don't set until after authz because connection isn't established
  connectionContextRead = true;
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:50,代码来源:Server.java

示例10: saslProcess

private void saslProcess(RpcSaslProto saslMessage)
    throws WrappedRpcServerException, IOException, InterruptedException {
  if (saslContextEstablished) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        new SaslException("Negotiation is already complete"));
  }
  RpcSaslProto saslResponse = null;
  try {
    try {
      saslResponse = processSaslMessage(saslMessage);
    } catch (IOException e) {
      rpcMetrics.incrAuthenticationFailures();
      // attempting user could be null
      AUDITLOG.warn(AUTH_FAILED_FOR + this.toString() + ":"
          + attemptingUser + " (" + e.getLocalizedMessage() + ")");
      throw (IOException) getCauseForInvalidToken(e);
    }
    
    if (saslServer != null && saslServer.isComplete()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server context established. Negotiated QoP is "
            + saslServer.getNegotiatedProperty(Sasl.QOP));
      }
      user = getAuthorizedUgi(saslServer.getAuthorizationID());
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server successfully authenticated client: " + user);
      }
      rpcMetrics.incrAuthenticationSuccesses();
      AUDITLOG.info(AUTH_SUCCESSFUL_FOR + user);
      saslContextEstablished = true;
    }
  } catch (WrappedRpcServerException wrse) { // don't re-wrap
    throw wrse;
  } catch (IOException ioe) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ioe);
  }
  // send back response if any, may throw IOException
  if (saslResponse != null) {
    doSaslReply(saslResponse);
  }
  // do NOT enable wrapping until the last auth response is sent
  if (saslContextEstablished) {
    String qop = (String) saslServer.getNegotiatedProperty(Sasl.QOP);
    // SASL wrapping is only used if the connection has a QOP, and
    // the value is not auth.  ex. auth-int & auth-priv
    useWrap = (qop != null && !"auth".equalsIgnoreCase(qop));        
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:50,代码来源:Server.java

示例11: saslProcess

private void saslProcess(RpcSaslProto saslMessage)
    throws WrappedRpcServerException, IOException, InterruptedException {
  if (saslContextEstablished) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        new SaslException("Negotiation is already complete"));
  }
  RpcSaslProto saslResponse = null;
  try {
    try {
      saslResponse = processSaslMessage(saslMessage);
    } catch (IOException e) {
      rpcMetrics.incrAuthenticationFailures();
      if (LOG.isDebugEnabled()) {
        LOG.debug(StringUtils.stringifyException(e));
      }
      // attempting user could be null
      IOException tce = (IOException) getCauseForInvalidToken(e);
      AUDITLOG.warn(AUTH_FAILED_FOR + this.toString() + ":"
          + attemptingUser + " (" + e.getLocalizedMessage()
          + ") with true cause: (" + tce.getLocalizedMessage() + ")");
      throw tce;
    }
    
    if (saslServer != null && saslServer.isComplete()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server context established. Negotiated QoP is "
            + saslServer.getNegotiatedProperty(Sasl.QOP));
      }
      user = getAuthorizedUgi(saslServer.getAuthorizationID());
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server successfully authenticated client: " + user);
      }
      rpcMetrics.incrAuthenticationSuccesses();
      AUDITLOG.info(AUTH_SUCCESSFUL_FOR + user);
      saslContextEstablished = true;
    }
  } catch (WrappedRpcServerException wrse) { // don't re-wrap
    throw wrse;
  } catch (IOException ioe) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ioe);
  }
  // send back response if any, may throw IOException
  if (saslResponse != null) {
    doSaslReply(saslResponse);
  }
  // do NOT enable wrapping until the last auth response is sent
  if (saslContextEstablished) {
    String qop = (String) saslServer.getNegotiatedProperty(Sasl.QOP);
    // SASL wrapping is only used if the connection has a QOP, and
    // the value is not auth.  ex. auth-int & auth-priv
    useWrap = (qop != null && !"auth".equalsIgnoreCase(qop));        
  }
}
 
开发者ID:Nextzero,项目名称:hadoop-2.6.0-cdh5.4.3,代码行数:55,代码来源:Server.java

示例12: saslProcess

private void saslProcess(RpcSaslProto saslMessage)
    throws WrappedRpcServerException, IOException, InterruptedException {
  if (saslContextEstablished) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        new SaslException("Negotiation is already complete"));
  }
  RpcSaslProto saslResponse = null;
  try {
    try {
      saslResponse = processSaslMessage(saslMessage);
    } catch (IOException e) {
      IOException sendToClient = e;
      Throwable cause = e;
      while (cause != null) {
        if (cause instanceof InvalidToken) {
          sendToClient = (InvalidToken) cause;
          break;
        }
        cause = cause.getCause();
      }
      rpcMetrics.incrAuthenticationFailures();
      String clientIP = this.toString();
      // attempting user could be null
      AUDITLOG.warn(AUTH_FAILED_FOR + clientIP + ":" + attemptingUser +
        " (" + e.getLocalizedMessage() + ")");
      throw sendToClient;
    }
    
    if (saslServer != null && saslServer.isComplete()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server context established. Negotiated QoP is "
            + saslServer.getNegotiatedProperty(Sasl.QOP));
      }
      user = getAuthorizedUgi(saslServer.getAuthorizationID());
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server successfully authenticated client: " + user);
      }
      rpcMetrics.incrAuthenticationSuccesses();
      AUDITLOG.info(AUTH_SUCCESSFUL_FOR + user);
      saslContextEstablished = true;
    }
  } catch (WrappedRpcServerException wrse) { // don't re-wrap
    throw wrse;
  } catch (IOException ioe) {
    throw new WrappedRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ioe);
  }
  // send back response if any, may throw IOException
  if (saslResponse != null) {
    doSaslReply(saslResponse);
  }
  // do NOT enable wrapping until the last auth response is sent
  if (saslContextEstablished) {
    String qop = (String) saslServer.getNegotiatedProperty(Sasl.QOP);
    // SASL wrapping is only used if the connection has a QOP, and
    // the value is not auth.  ex. auth-int & auth-priv
    useWrap = (qop != null && !"auth".equalsIgnoreCase(qop));        
  }
}
 
开发者ID:ict-carch,项目名称:hadoop-plus,代码行数:60,代码来源:Server.java

示例13: saslProcess

private void saslProcess(RpcSaslProto saslMessage)
    throws RpcServerException, IOException, InterruptedException {
  if (saslContextEstablished) {
    throw new FatalRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        new SaslException("Negotiation is already complete"));
  }
  RpcSaslProto saslResponse = null;
  try {
    try {
      saslResponse = processSaslMessage(saslMessage);
    } catch (IOException e) {
      rpcMetrics.incrAuthenticationFailures();
      if (LOG.isDebugEnabled()) {
        LOG.debug(StringUtils.stringifyException(e));
      }
      // attempting user could be null
      IOException tce = (IOException) getCauseForInvalidToken(e);
      AUDITLOG.warn(AUTH_FAILED_FOR + this.toString() + ":"
          + attemptingUser + " (" + e.getLocalizedMessage()
          + ") with true cause: (" + tce.getLocalizedMessage() + ")");
      throw tce;
    }
    
    if (saslServer != null && saslServer.isComplete()) {
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server context established. Negotiated QoP is "
            + saslServer.getNegotiatedProperty(Sasl.QOP));
      }
      user = getAuthorizedUgi(saslServer.getAuthorizationID());
      if (LOG.isDebugEnabled()) {
        LOG.debug("SASL server successfully authenticated client: " + user);
      }
      rpcMetrics.incrAuthenticationSuccesses();
      AUDITLOG.info(AUTH_SUCCESSFUL_FOR + user);
      saslContextEstablished = true;
    }
  } catch (RpcServerException rse) { // don't re-wrap
    throw rse;
  } catch (IOException ioe) {
    throw new FatalRpcServerException(
        RpcErrorCodeProto.FATAL_UNAUTHORIZED, ioe);
  }
  // send back response if any, may throw IOException
  if (saslResponse != null) {
    doSaslReply(saslResponse);
  }
  // do NOT enable wrapping until the last auth response is sent
  if (saslContextEstablished) {
    String qop = (String) saslServer.getNegotiatedProperty(Sasl.QOP);
    // SASL wrapping is only used if the connection has a QOP, and
    // the value is not auth.  ex. auth-int & auth-priv
    useWrap = (qop != null && !"auth".equalsIgnoreCase(qop));
    if (!useWrap) {
      disposeSasl();
    }
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:58,代码来源:Server.java

示例14: processConnectionContext

/** Reads the connection context following the connection header
 * @param buffer - DataInputStream from which to read the header
 * @throws RpcServerException - if the header cannot be
 *         deserialized, or the user is not authorized
 */ 
private void processConnectionContext(RpcWritable.Buffer buffer)
    throws RpcServerException {
  // allow only one connection context during a session
  if (connectionContextRead) {
    throw new FatalRpcServerException(
        RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
        "Connection context already processed");
  }
  connectionContext = getMessage(IpcConnectionContextProto.getDefaultInstance(), buffer);
  protocolName = connectionContext.hasProtocol() ? connectionContext
      .getProtocol() : null;

  UserGroupInformation protocolUser = ProtoUtil.getUgi(connectionContext);
  if (authProtocol == AuthProtocol.NONE) {
    user = protocolUser;
    authenticateSSLConnection(protocolUser);
  } else {
    // user is authenticated
    user.setAuthenticationMethod(authMethod);
    //Now we check if this is a proxy user case. If the protocol user is
    //different from the 'user', it is a proxy user scenario. However, 
    //this is not allowed if user authenticated with DIGEST.
    if ((protocolUser != null)
        && (!protocolUser.getUserName().equals(user.getUserName()))) {
      if (authMethod == AuthMethod.TOKEN) {
        // Not allowed to doAs if token authentication is used
        throw new FatalRpcServerException(
            RpcErrorCodeProto.FATAL_UNAUTHORIZED,
            new AccessControlException("Authenticated user (" + user
                + ") doesn't match what the client claims to be ("
                + protocolUser + ")"));
      } else {
        // Effective user can be different from authenticated user
        // for simple auth or kerberos auth
        // The user is the real user. Now we create a proxy user
        UserGroupInformation realUser = user;
        user = UserGroupInformation.createProxyUser(protocolUser
            .getUserName(), realUser);
      }
    }
  }
  authorizeConnection();
  // don't set until after authz because connection isn't established
  connectionContextRead = true;
  if (user != null) {
    connectionManager.incrUserConnections(user.getShortUserName());
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:53,代码来源:Server.java

示例15: processOneRpc

/**
 * Process one RPC Request from buffer read from socket stream 
 *  - decode rpc in a rpc-Call
 *  - handle out-of-band RPC requests such as the initial connectionContext
 *  - A successfully decoded RpcCall will be deposited in RPC-Q and
 *    its response will be sent later when the request is processed.
 * 
 * Prior to this call the connectionHeader ("hrpc...") has been handled and
 * if SASL then SASL has been established and the buf we are passed
 * has been unwrapped from SASL.
 * 
 * @param bb - contains the RPC request header and the rpc request
 * @throws IOException - internal error that should not be returned to
 *         client, typically failure to respond to client
 * @throws InterruptedException
 */
private void processOneRpc(ByteBuffer bb)
    throws IOException, InterruptedException {
  // exceptions that escape this method are fatal to the connection.
  // setupResponse will use the rpc status to determine if the connection
  // should be closed.
  int callId = -1;
  int retry = RpcConstants.INVALID_RETRY_COUNT;
  try {
    final RpcWritable.Buffer buffer = RpcWritable.Buffer.wrap(bb);
    final RpcRequestHeaderProto header =
        getMessage(RpcRequestHeaderProto.getDefaultInstance(), buffer);
    callId = header.getCallId();
    retry = header.getRetryCount();
    if (LOG.isDebugEnabled()) {
      LOG.debug(" got #" + callId);
    }
    checkRpcHeaders(header);

    if (callId < 0) { // callIds typically used during connection setup
      processRpcOutOfBandRequest(header, buffer);
    } else if (!connectionContextRead) {
      throw new FatalRpcServerException(
          RpcErrorCodeProto.FATAL_INVALID_RPC_HEADER,
          "Connection context not established");
    } else {
      processRpcRequest(header, buffer);
    }
  } catch (RpcServerException rse) {
    // inform client of error, but do not rethrow else non-fatal
    // exceptions will close connection!
    if (LOG.isDebugEnabled()) {
      LOG.debug(Thread.currentThread().getName() +
          ": processOneRpc from client " + this +
          " threw exception [" + rse + "]");
    }
    // use the wrapped exception if there is one.
    Throwable t = (rse.getCause() != null) ? rse.getCause() : rse;
    final RpcCall call = new RpcCall(this, callId, retry);
    setupResponse(call,
        rse.getRpcStatusProto(), rse.getRpcErrorCodeProto(), null,
        t.getClass().getName(), t.getMessage());
    sendResponse(call);
  }
}
 
开发者ID:hopshadoop,项目名称:hops,代码行数:60,代码来源:Server.java


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