代码拉取完成,页面将自动刷新
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", "testAndEnable")
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
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。