| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2016 The LUCI Authors. All rights reserved. |
| 2 // Use of this source code is governed under the Apache License, Version 2.0 |
| 3 // that can be found in the LICENSE file. |
| 4 |
| 5 package gaemiddleware |
| 6 |
| 7 import ( |
| 8 "fmt" |
| 9 "net/http" |
| 10 |
| 11 "github.com/luci/luci-go/common/logging" |
| 12 "github.com/luci/luci-go/server/auth" |
| 13 "github.com/luci/luci-go/server/router" |
| 14 ) |
| 15 |
| 16 // RequireSuperuser ensures that the request is from an authenticated AppEngine |
| 17 // super user, as defined by the AppEngine instance. |
| 18 // |
| 19 // It is recommended that auth.Autologin be installed prior to calling this so |
| 20 // that anonymous users have an opportunity to log in. |
| 21 func RequireSuperuser(c *router.Context, next router.Handler) { |
| 22 cu := auth.CurrentUser(c.Context) |
| 23 if !cu.Superuser { |
| 24 c.Writer.WriteHeader(http.StatusForbidden) |
| 25 logging.Fields{ |
| 26 "user": cu.Identity, |
| 27 }.Errorf(c.Context, "request not made by super user") |
| 28 fmt.Fprint(c.Writer, "error: only available to super user") |
| 29 return |
| 30 } |
| 31 |
| 32 next(c) |
| 33 } |
| OLD | NEW |