36 Star 415 Fork 76

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
filter.go 1.08 KB
一键复制 编辑 原始数据 按行查看 历史
package requests
import (
"context"
"fmt"
"net/http"
"github.com/rancher/rancher/pkg/auth/util"
"github.com/rancher/types/config"
"github.com/sirupsen/logrus"
)
func NewAuthenticationFilter(ctx context.Context, managementContext *config.ManagementContext, next http.Handler) (http.Handler, error) {
if managementContext == nil {
return nil, fmt.Errorf("Failed to build NewAuthenticationFilter, nil ManagementContext")
}
auth := NewAuthenticator(ctx, managementContext)
return &authHeaderHandler{
auth: auth,
next: next,
}, nil
}
type authHeaderHandler struct {
auth Authenticator
next http.Handler
}
func (h authHeaderHandler) ServeHTTP(rw http.ResponseWriter, req *http.Request) {
authed, user, groups, err := h.auth.Authenticate(req)
if err != nil || !authed {
util.ReturnHTTPError(rw, req, 401, err.Error())
return
}
logrus.Debugf("Impersonating user %v, groups %v", user, groups)
req.Header.Set("Impersonate-User", user)
req.Header.Del("Impersonate-Group")
for _, group := range groups {
req.Header.Add("Impersonate-Group", group)
}
h.next.ServeHTTP(rw, req)
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.0-alpha14

搜索帮助