| 1077 | } |
| 1078 | |
| 1079 | sq_callback_result_t Webserver::HandleSpnego(struct sq_connection* connection, |
| 1080 | struct sq_request_info* request_info, vector<string>* response_headers) { |
| 1081 | const char* authz_header = sq_get_header(connection, "Authorization"); |
| 1082 | string authn_princ; |
| 1083 | kudu::Status s = RunSpnegoStep(authz_header, response_headers, &authn_princ); |
| 1084 | if (s.IsIncomplete()) { |
| 1085 | SendResponse(connection, "401 Authentication Required", "text/plain", |
| 1086 | "Must authenticate with SPNEGO.", *response_headers); |
| 1087 | total_negotiate_auth_failure_->Increment(1); |
| 1088 | return SQ_HANDLED_OK; |
| 1089 | } |
| 1090 | if (s.ok() && authn_princ.empty()) { |
| 1091 | s = kudu::Status::RuntimeError("SPNEGO indicated complete, but got empty principal"); |
| 1092 | // Crash in debug builds, but fall through to treating as an error 500 in |
| 1093 | // release. |
| 1094 | LOG(DFATAL) << "Got no authenticated principal for SPNEGO-authenticated " |
| 1095 | << " connection from " |
| 1096 | << GetRemoteAddress(request_info).ToString() |
| 1097 | << ": " << s.ToString(); |
| 1098 | } |
| 1099 | if (!s.ok()) { |
| 1100 | LOG(WARNING) << "Failed to authenticate request from " |
| 1101 | << GetRemoteAddress(request_info).ToString() |
| 1102 | << " via SPNEGO: " << s.ToString(); |
| 1103 | const char* http_status = s.IsNotAuthorized() ? "401 Authentication Required" : |
| 1104 | "500 Internal Server Error"; |
| 1105 | |
| 1106 | SendResponse(connection, http_status, "text/plain", s.ToString(), *response_headers); |
| 1107 | total_negotiate_auth_failure_->Increment(1); |
| 1108 | return SQ_HANDLED_OK; |
| 1109 | } |
| 1110 | |
| 1111 | request_info->remote_user = strdup(authn_princ.c_str()); |
| 1112 | |
| 1113 | total_negotiate_auth_success_->Increment(1); |
| 1114 | return SQ_CONTINUE_HANDLING; |
| 1115 | } |
| 1116 | |
| 1117 | bool Webserver::GetUsernameFromAuthHeader(struct sq_connection* connection, |
| 1118 | struct sq_request_info* request_info, string& err_msg) { |
nothing calls this directly
no test coverage detected