(w http.ResponseWriter, r *http.Request)
| 143 | } |
| 144 | |
| 145 | func (m *basicAuthAndSessionMiddleware) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
| 146 | if hasValidAPIKeyHeader(r, m.guiCfg) { |
| 147 | m.next.ServeHTTP(w, r) |
| 148 | return |
| 149 | } |
| 150 | |
| 151 | if m.tokenCookieManager.hasValidSession(r) { |
| 152 | m.next.ServeHTTP(w, r) |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | // Fall back to Basic auth if provided |
| 157 | if username, ok := attemptBasicAuth(r, m.guiCfg, m.ldapCfg, m.evLogger); ok { |
| 158 | m.tokenCookieManager.createSession(username, false, w, r) |
| 159 | m.next.ServeHTTP(w, r) |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | // Exception for static assets and REST calls that don't require authentication. |
| 164 | if isNoAuthPath(r.URL.Path, m.guiCfg.MetricsWithoutAuth) { |
| 165 | m.next.ServeHTTP(w, r) |
| 166 | return |
| 167 | } |
| 168 | |
| 169 | // Some browsers don't send the Authorization request header unless prompted by a 401 response. |
| 170 | // This enables https://user:pass@localhost style URLs to keep working. |
| 171 | if m.guiCfg.SendBasicAuthPrompt { |
| 172 | unauthorized(w, m.tokenCookieManager.shortID) |
| 173 | return |
| 174 | } |
| 175 | |
| 176 | forbidden(w) |
| 177 | } |
| 178 | |
| 179 | func (m *basicAuthAndSessionMiddleware) passwordAuthHandler(w http.ResponseWriter, r *http.Request) { |
| 180 | var req struct { |
nothing calls this directly
no test coverage detected