37 Star 404 Fork 74

GVPrancher/rancher

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
samlconfig.go 1.80 KB
一键复制 编辑 原始数据 按行查看 历史
carolyn 提交于 2018-08-14 13:01 . add keycloak as an auth provider
package samlconfig
import (
"fmt"
"github.com/mitchellh/mapstructure"
"github.com/rancher/rancher/pkg/auth/providers/saml"
"github.com/rancher/types/apis/management.cattle.io/v3"
"github.com/rancher/types/config"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
)
type authProvider struct {
authConfigs v3.AuthConfigInterface
}
func Register(apiContext *config.ScaledContext) {
a := newAuthProvider(apiContext)
apiContext.Management.AuthConfigs("").AddHandler("authConfigController", a.sync)
}
func newAuthProvider(apiContext *config.ScaledContext) *authProvider {
a := &authProvider{
authConfigs: apiContext.Management.AuthConfigs(""),
}
return a
}
func (a *authProvider) sync(key string, config *v3.AuthConfig) error {
samlConfig := &v3.SamlConfig{}
if key == "" || config == nil {
return nil
}
if config.Name != saml.PingName && config.Name != saml.ADFSName && config.Name != saml.KeyCloakName {
return nil
}
if !config.Enabled {
return nil
}
authConfigObj, err := a.authConfigs.ObjectClient().UnstructuredClient().Get(config.Name, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to retrieve SamlConfig, error: %v", err)
}
u, ok := authConfigObj.(runtime.Unstructured)
if !ok {
return fmt.Errorf("failed to retrieve SamlConfig, cannot read k8s Unstructured data")
}
storedSamlConfigMap := u.UnstructuredContent()
mapstructure.Decode(storedSamlConfigMap, samlConfig)
metadataMap, ok := storedSamlConfigMap["metadata"].(map[string]interface{})
if !ok {
return fmt.Errorf("failed to retrieve SamlConfig metadata, cannot read k8s Unstructured data")
}
typemeta := &metav1.ObjectMeta{}
mapstructure.Decode(metadataMap, typemeta)
samlConfig.ObjectMeta = *typemeta
return saml.InitializeSamlServiceProvider(samlConfig, config.Name)
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/rancher/rancher.git
git@gitee.com:rancher/rancher.git
rancher
rancher
rancher
v2.0.12-rc3

搜索帮助