| 1218 | } |
| 1219 | |
| 1220 | Status Webserver::HandleBasic(struct sq_connection* connection, |
| 1221 | struct sq_request_info* request_info, vector<string>* response_headers) { |
| 1222 | const char* authz_header = sq_get_header(connection, "Authorization"); |
| 1223 | if (!authz_header) { |
| 1224 | return Status::Expected("No Authorization header provided."); |
| 1225 | } |
| 1226 | |
| 1227 | string base64; |
| 1228 | if (!TryStripPrefixString(authz_header, "Basic ", &base64)) { |
| 1229 | return Status::Expected("No Basic authentication provided."); |
| 1230 | } |
| 1231 | string username, password; |
| 1232 | Status status = BasicAuthExtractCredentials(base64, username, password); |
| 1233 | if (!status.ok()) { |
| 1234 | LOG(ERROR) << "Error parsing basic authentication token from: " |
| 1235 | << GetRemoteAddress(request_info).ToString() << " Error: " << status; |
| 1236 | return status; |
| 1237 | } |
| 1238 | if (ldap_->LdapCheckPass(username.c_str(), password.c_str(), password.length()) |
| 1239 | && ldap_->LdapCheckFilters(username)) { |
| 1240 | request_info->remote_user = strdup(username.c_str()); |
| 1241 | return Status::OK(); |
| 1242 | } |
| 1243 | |
| 1244 | return Status::Expected("Failed to authenticate to LDAP."); |
| 1245 | } |
| 1246 | |
| 1247 | void Webserver::AddCookie(const char* user, vector<string>* response_headers, |
| 1248 | const string& authMech, string* cookie_rand_value) { |
nothing calls this directly
no test coverage detected