| 82 | |
| 83 | |
| 84 | Future<AuthenticationResult> BasicAuthenticatorProcess::authenticate( |
| 85 | const Request& request) |
| 86 | { |
| 87 | AuthenticationResult unauthorized; |
| 88 | unauthorized.unauthorized = |
| 89 | Unauthorized({"Basic realm=\"" + realm_ + "\""}); |
| 90 | |
| 91 | Option<string> credentials = request.headers.get("Authorization"); |
| 92 | |
| 93 | if (credentials.isNone()) { |
| 94 | return unauthorized; |
| 95 | } |
| 96 | |
| 97 | vector<string> components = strings::split(credentials.get(), " "); |
| 98 | |
| 99 | if (components.size() != 2 || components[0] != "Basic") { |
| 100 | return unauthorized; |
| 101 | } |
| 102 | |
| 103 | Try<string> decoded = base64::decode(components[1]); |
| 104 | |
| 105 | if (decoded.isError()) { |
| 106 | return unauthorized; |
| 107 | } |
| 108 | |
| 109 | vector<string> credential = strings::split(decoded.get(), ":"); |
| 110 | |
| 111 | if (credential.size() != 2 || |
| 112 | !credentials_.contains(credential[0]) || |
| 113 | credentials_.at(credential[0]) != credential[1]) { |
| 114 | return unauthorized; |
| 115 | } |
| 116 | |
| 117 | AuthenticationResult authenticated; |
| 118 | authenticated.principal = Principal(credential[0]); |
| 119 | return authenticated; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | BasicAuthenticator::BasicAuthenticator( |