(handler http.Handler, r *http.Request, w http.ResponseWriter)
| 98 | } |
| 99 | |
| 100 | func checkAuthorizationHeader(handler http.Handler, r *http.Request, w http.ResponseWriter) bool { |
| 101 | if config.BasicAuth == "" { |
| 102 | return false |
| 103 | } |
| 104 | |
| 105 | auth_header := r.Header.Get("Authorization") |
| 106 | if len(auth_header) < 6 { |
| 107 | return false |
| 108 | } |
| 109 | |
| 110 | if auth_header[0:6] == "Basic " { |
| 111 | b_creds, _ := base64.StdEncoding.DecodeString(auth_header[6:]) |
| 112 | creds := string(b_creds) |
| 113 | if creds == config.BasicAuth { |
| 114 | colon_idx := strings.Index(creds, ":") |
| 115 | if colon_idx == -1 { |
| 116 | return false |
| 117 | } |
| 118 | username := creds[0:colon_idx] |
| 119 | r.Header.Set(config.UsernameHeader, username) |
| 120 | r.Header.Del("Authorization") |
| 121 | handler.ServeHTTP(w, r) |
| 122 | return true |
| 123 | } else { |
| 124 | logger.Printf("rejected basic auth creds: authorization header: %s", auth_header) |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | return false |
| 129 | } |
| 130 | |
| 131 | func allowedByWhiteList(c *Config, p string) bool { |
| 132 | if c.Whitelist == "" && c.WhitelistPrefix == "" { |
no test coverage detected