github.com/hustcat/docker@v1.3.3-0.20160314103604-901c67a8eeab/api/server/middleware/authorization.go (about) 1 package middleware 2 3 import ( 4 "net/http" 5 6 "github.com/Sirupsen/logrus" 7 "github.com/docker/docker/api/server/httputils" 8 "github.com/docker/docker/pkg/authorization" 9 "golang.org/x/net/context" 10 ) 11 12 // NewAuthorizationMiddleware creates a new Authorization middleware. 13 func NewAuthorizationMiddleware(plugins []authorization.Plugin) Middleware { 14 return func(handler httputils.APIFunc) httputils.APIFunc { 15 return func(ctx context.Context, w http.ResponseWriter, r *http.Request, vars map[string]string) error { 16 // FIXME: fill when authN gets in 17 // User and UserAuthNMethod are taken from AuthN plugins 18 // Currently tracked in https://github.com/docker/docker/pull/13994 19 user := "" 20 userAuthNMethod := "" 21 authCtx := authorization.NewCtx(plugins, user, userAuthNMethod, r.Method, r.RequestURI) 22 23 if err := authCtx.AuthZRequest(w, r); err != nil { 24 logrus.Errorf("AuthZRequest for %s %s returned error: %s", r.Method, r.RequestURI, err) 25 return err 26 } 27 28 rw := authorization.NewResponseModifier(w) 29 30 if err := handler(ctx, rw, r, vars); err != nil { 31 logrus.Errorf("Handler for %s %s returned error: %s", r.Method, r.RequestURI, err) 32 return err 33 } 34 35 if err := authCtx.AuthZResponse(rw, r); err != nil { 36 logrus.Errorf("AuthZResponse for %s %s returned error: %s", r.Method, r.RequestURI, err) 37 return err 38 } 39 return nil 40 } 41 } 42 }