36 Star 392 Fork 70

GVPrancher / rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
saml_actions.go 2.09 KB
AI 代码解读
一键复制 编辑 原始数据 按行查看 历史
package saml
import (
"encoding/json"
"fmt"
"net/http"
"github.com/rancher/norman/httperror"
"github.com/rancher/norman/types"
"github.com/rancher/rancher/pkg/auth/providers/common"
"github.com/rancher/types/apis/management.cattle.io/v3"
)
func (s *Provider) formatter(apiContext *types.APIContext, resource *types.RawResource) {
common.AddCommonActions(apiContext, resource)
resource.AddAction(apiContext, "testAndEnable")
}
func (s *Provider) actionHandler(actionName string, action *types.Action, request *types.APIContext) error {
handled, err := common.HandleCommonAction(actionName, action, request, s.name, s.authConfigs)
if err != nil {
return err
}
if handled {
return nil
}
if actionName == "testAndEnable" {
return s.testAndEnable(actionName, action, request)
}
return httperror.NewAPIError(httperror.ActionNotAvailable, "")
}
func (s *Provider) testAndEnable(actionName string, action *types.Action, request *types.APIContext) error {
// get Final redirect URL from request body
samlLogin := &v3.SamlConfigTestInput{}
if err := json.NewDecoder(request.Request.Body).Decode(samlLogin); err != nil {
return httperror.NewAPIError(httperror.InvalidBodyContent,
fmt.Sprintf("SAML: Failed to parse body: %v", err))
}
samlConfig, err := s.getSamlConfig()
if err != nil {
return err
}
err = InitializeSamlServiceProvider(samlConfig, s.name)
if err != nil {
return err
}
provider := SamlProviders[s.name]
finalRedirectURL := samlLogin.FinalRedirectURL
provider.clientState.SetState(request.Response, request.Request, "Rancher_UserID", provider.userMGR.GetUser(request))
provider.clientState.SetState(request.Response, request.Request, "Rancher_FinalRedirectURL", finalRedirectURL)
provider.clientState.SetState(request.Response, request.Request, "Rancher_Action", testAndEnableAction)
idpRedirectURL, err := provider.HandleSamlLogin(request.Response, request.Request)
if err != nil {
return err
}
data := map[string]interface{}{
"idpRedirectUrl": idpRedirectURL,
"type": "samlConfigTestOutput",
}
request.WriteResponse(http.StatusOK, data)
return nil
}
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.2.0-rc6

搜索帮助