AuthMiddleware returns a pre-handle middleware handler to perform user authentication.
(next http.Handler)
| 159 | |
| 160 | // AuthMiddleware returns a pre-handle middleware handler to perform user authentication. |
| 161 | func (o *ObjectNode) authMiddleware(next http.Handler) http.Handler { |
| 162 | return http.HandlerFunc( |
| 163 | func(w http.ResponseWriter, r *http.Request) { |
| 164 | // parse authentication |
| 165 | auth, err := NewAuth(r) |
| 166 | if err != nil && err == MissingSecurityElement { |
| 167 | // anonymous request will be authed in policy and acl check step |
| 168 | next.ServeHTTP(w, r) |
| 169 | return |
| 170 | } |
| 171 | if err != nil { |
| 172 | log.LogErrorf("authMiddleware: parse auth fail: requestID(%v) err(%v)", |
| 173 | GetRequestID(r), err) |
| 174 | o.errorResponse(w, r, err, nil) |
| 175 | return |
| 176 | } |
| 177 | // validate authentication information |
| 178 | if err = o.validateAuthInfo(r, auth); err != nil { |
| 179 | o.errorResponse(w, r, err, nil) |
| 180 | return |
| 181 | } |
| 182 | |
| 183 | next.ServeHTTP(w, r) |
| 184 | }) |
| 185 | } |
| 186 | |
| 187 | // PolicyCheckMiddleware returns a pre-handle middleware handler to process policy check. |
| 188 | func (o *ObjectNode) policyCheckMiddleware(next http.Handler) http.Handler { |
nothing calls this directly
no test coverage detected