Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(120)

Side by Side Diff: scheduler/appengine/ui/common.go

Issue 2830443003: auth: Refactor how authentication methods are passed to server/auth library. (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 // Copyright 2015 The LUCI Authors. All rights reserved. 1 // Copyright 2015 The LUCI Authors. All rights reserved.
2 // Use of this source code is governed under the Apache License, Version 2.0 2 // Use of this source code is governed under the Apache License, Version 2.0
3 // that can be found in the LICENSE file. 3 // that can be found in the LICENSE file.
4 4
5 // Package ui implements request handlers that serve user facing HTML pages. 5 // Package ui implements request handlers that serve user facing HTML pages.
6 package ui 6 package ui
7 7
8 import ( 8 import (
9 "strings" 9 "strings"
10 10
11 "golang.org/x/net/context" 11 "golang.org/x/net/context"
12 12
13 "github.com/luci/gae/service/info" 13 "github.com/luci/gae/service/info"
14 14
15 "github.com/luci/luci-go/appengine/gaeauth/server"
15 "github.com/luci/luci-go/server/auth" 16 "github.com/luci/luci-go/server/auth"
16 "github.com/luci/luci-go/server/auth/xsrf" 17 "github.com/luci/luci-go/server/auth/xsrf"
17 "github.com/luci/luci-go/server/router" 18 "github.com/luci/luci-go/server/router"
18 "github.com/luci/luci-go/server/templates" 19 "github.com/luci/luci-go/server/templates"
19 20
20 "github.com/luci/luci-go/scheduler/appengine/catalog" 21 "github.com/luci/luci-go/scheduler/appengine/catalog"
21 "github.com/luci/luci-go/scheduler/appengine/engine" 22 "github.com/luci/luci-go/scheduler/appengine/engine"
22 ) 23 )
23 24
24 // Config is global configuration of UI handlers. 25 // Config is global configuration of UI handlers.
25 type Config struct { 26 type Config struct {
26 Engine engine.Engine 27 Engine engine.Engine
27 Catalog catalog.Catalog 28 Catalog catalog.Catalog
28 TemplatesPath string // path to templates directory deployed to GAE 29 TemplatesPath string // path to templates directory deployed to GAE
29 } 30 }
30 31
31 // InstallHandlers adds HTTP handlers that render HTML pages. 32 // InstallHandlers adds HTTP handlers that render HTML pages.
32 func InstallHandlers(r *router.Router, base router.MiddlewareChain, cfg Config) { 33 func InstallHandlers(r *router.Router, base router.MiddlewareChain, cfg Config) {
33 tmpl := prepareTemplates(cfg.TemplatesPath) 34 tmpl := prepareTemplates(cfg.TemplatesPath)
34 35
35 m := base.Extend(func(c *router.Context, next router.Handler) { 36 m := base.Extend(func(c *router.Context, next router.Handler) {
36 c.Context = context.WithValue(c.Context, configContextKey(0), &c fg) 37 c.Context = context.WithValue(c.Context, configContextKey(0), &c fg)
37 next(c) 38 next(c)
38 » }, templates.WithTemplates(tmpl), auth.Authenticate) 39 » })
40 » m = m.Extend(
41 » » templates.WithTemplates(tmpl),
42 » » auth.Authenticate(&auth.Authenticator{
43 » » » Methods: []auth.Method{server.CookieAuth},
44 » » }),
45 » )
39 46
40 r.GET("/", m, indexPage) 47 r.GET("/", m, indexPage)
41 r.GET("/jobs/:ProjectID", m, projectPage) 48 r.GET("/jobs/:ProjectID", m, projectPage)
42 r.GET("/jobs/:ProjectID/:JobID", m, jobPage) 49 r.GET("/jobs/:ProjectID/:JobID", m, jobPage)
43 r.GET("/jobs/:ProjectID/:JobID/:InvID", m, invocationPage) 50 r.GET("/jobs/:ProjectID/:JobID/:InvID", m, invocationPage)
44 51
45 // All POST forms must be protected with XSRF token. 52 // All POST forms must be protected with XSRF token.
46 mxsrf := m.Extend(xsrf.WithTokenCheck) 53 mxsrf := m.Extend(xsrf.WithTokenCheck)
47 r.POST("/actions/runJob/:ProjectID/:JobID", mxsrf, runJobAction) 54 r.POST("/actions/runJob/:ProjectID/:JobID", mxsrf, runJobAction)
48 r.POST("/actions/pauseJob/:ProjectID/:JobID", mxsrf, pauseJobAction) 55 r.POST("/actions/pauseJob/:ProjectID/:JobID", mxsrf, pauseJobAction)
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
87 "AppVersion": strings.Split(info.VersionID(c), ".")[0], 94 "AppVersion": strings.Split(info.VersionID(c), ".")[0],
88 "IsAnonymous": auth.CurrentIdentity(c) == "anony mous:anonymous", 95 "IsAnonymous": auth.CurrentIdentity(c) == "anony mous:anonymous",
89 "User": auth.CurrentUser(c), 96 "User": auth.CurrentUser(c),
90 "LoginURL": loginURL, 97 "LoginURL": loginURL,
91 "LogoutURL": logoutURL, 98 "LogoutURL": logoutURL,
92 "XsrfToken": token, 99 "XsrfToken": token,
93 }, nil 100 }, nil
94 }, 101 },
95 } 102 }
96 } 103 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698