Superset单点登录调整源码

///修改config.py 

from flask_appbuilder.security.manager import AUTH_REMOTE_USER

AUTH_TYPE=AUTH_REMOTE_USER

from custom_sso_security_manager import CustomSsoSecurityManager
CUSTOM_SECURITY_MANAGER = CustomSsoSecurityManager
AUTH_USER_REGISTRATION = True   #允许用户注册
AUTH_USER_REGISTRATION_ROLE = "Gamma"  #设置默认添加用户角色

/superset根目录添加custom_sso_security_manager.py
from superset.security import SupersetSecurityManager
import logging
from flask_appbuilder.security.views import AuthRemoteUserView, expose
from flask_appbuilder.const import LOGMSG_WAR_SEC_LOGIN_FAILED
from flask import request,g, redirect
from flask_login import login_user, logout_user
import requests
import json

logger = logging.getLogger(__name__)


CAS_LOGIN_SERVER_URL = 'http://xxxxx/api/login/casLogin'
CAS_CHECK_SERVER_URL = 'http://xxxxx/api/login/currentUser'
CAS_LOGINOUT_SERVER_URL = 'http://xxxxx/api/login/out'

class MyAuthRemoteUserView(AuthRemoteUserView):
    # this front-end template should be put under the folder `superset/templates/appbuilder/general/security`
    # so that superset could find this templates to render
    login_template = 'appbuilder/general/security/login_my.html'
    title = "My Login"

    # this method is going to overwrite 
    # https://github.com/dpgaspar/Flask-AppBuilder/blob/master/flask_appbuilder/security/views.py#L556
    @expose('/login/', methods=['GET', 'POST'])
    def login(self):
        print("My special login...")
        if not g.user or not g.user.get_id():
            return redirect(CAS_LOGIN_SERVER_URL+"?redirect="+request.host_url+"logincas")

        print("loginSSO")
        print(request.host_url)

    @expose('/logincas/', methods=['GET', 'POST'])
    def logincas(self):
        token=request.args.get('token')
        print("logincas"+token)
        manager=self.appbuilder.sm

        result = requests.get(CAS_CHECK_SERVER_URL + '?token=' + token)
        userCAS = json.loads(result.content)
        username=userCAS["loginName"]
        user = manager.find_user(username=username)
        print(user)

        # User does not exist, create one if auto user registration.
        if user is None and manager.auth_user_registration:
            user = manager.add_user(
            # All we have is REMOTE_USER, so we set
            # the other fields to blank.
                username=username,
                first_name=username.split('@')[0],
                last_name='-',
                email=username,
                role=manager.find_role(manager.auth_user_registration_role))

        # If user does not exist on the DB and not auto user registration,
        # or user is inactive, go away.
        elif user is None or (not user.is_active):
            logger.info(LOGMSG_WAR_SEC_LOGIN_FAILED.format(username))
            return None
            
        manager.update_user_auth_stat(user)
        print(user)
        login_user(user, remember=False)
        return redirect(self.appbuilder.get_url_for_index)

    @expose("/logout/")
    def logout(self):
        logout_user()
        print("loginout")
        return redirect(CAS_LOGINOUT_SERVER_URL+'?redirect='+request.host_url)
       

class CustomSsoSecurityManager(SupersetSecurityManager):
    authremoteuserview=MyAuthRemoteUserView
    
Gamma角色添加权限
默认Gamma角色不能访问库,需设置角色,添加all database access on all_database_access权限(全部数据库)。

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/416799.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

webpack-dev-server 搭建本地服务以及浏览器实时刷新

一、概述开发项目中为了保证上线,开发项目是都需要使用localhost进行开发,以前的做法就是本地搭建Apache或者Tomcat服务器。有的前端开发人员 对服务器的搭建和配置并不熟悉,这个时候需要后台开发人员进行帮忙,有的时候后台开发人…

java调用kafka

pom.xml <dependency> <groupId>org.apache.kafka</groupId> <artifactId>kafka-clients</artifactId> <version>2.3.1</version> </dependency> 注意调试通过后要添加…

[Noi2015]软件包管理器

来自FallDream的博客&#xff0c;未经允许&#xff0c;请勿转载&#xff0c;谢谢。 Linux用户和OSX用户一定对软件包管理器不会陌生。通过软件包管理器&#xff0c;你可以通过一行命令安装某一个软件包&#xff0c;然后软件包管理器会帮助你从软件源下载软件包&#xff0c;同时…

ELK+Kafka部署

目录 1.背景 2.ELK的配置 2.1.下载 2.2.关闭防火墙 2.3.安装elasticsearch 2.4.安装Logstash 2.5.安装Kibana 2.6.Java日志输出到Logstash 2.7.OSS版本 3.Kafka的配置 3.1.zookeeper搭建 3.2.kafka搭建 4.整合 1.背景 高日志压力情况下&#xff0c;为了避免Logsta…

Allegro改动shape网络节点

使用Allegro时改动shape的网络节点方法&#xff1a; ①选择shape->Select Shape or Void/Cavity ②选择要改动的shape ③点击&#xff08;...&#xff09;改动网络节点的名字 ④改动完毕 转载于:https://www.cnblogs.com/claireyuancy/p/6804046.html

ELK套件FileBeat部署

目录 1.简介 2.下载 3.直接输出到ElasticSearch 4.输出到Logstash 5.更改nginx日志路径 6.logstash负载均衡 7.日志文件直接作为输入 1.简介 FileBeat用于文件数据采集并输出到ElasticSearch或Logstash中。 ELK搭建过程参见&#xff1a; ELK搭建及Java程序接入 2.下载…

python基础之数据类型

python基础之数据类型 字符串(string) 用引号括起的都是字符串,其中的引号可以是单引号, 也可以是双引号1.使用方法修改字符串的大小写 例&#xff1a; >>> name "ada lovelace" >>> print name.title() Ada Lovelace >>> print(name.up…

MetricBeat(win/linux)部署 系统CPU内存等资源情况监控

目录 1.下载 2.linux系统监控 ​3.启用模块 4.windows系统监控 1.下载 下载MetricBeat的linux和windows版本 https://artifacts.elastic.co/downloads/beats/metricbeat/metricbeat-oss-7.2.1-linux-x86_64.tar.gz https://artifacts.elastic.co/downloads/beats/metricbea…

android CoordinatorLayout使用

一、CoordinatorLayout有什么作用 CoordinatorLayout作为“super-powered FrameLayout”基本实现两个功能&#xff1a; 1、作为顶层布局 2、调度协调子布局 CoordinatorLayout使用新的思路通过协调调度子布局的形式实现触摸影响布局的形式产生动画效果。CoordinatorLayout通过…

deepin15.11系统体验

目录 1.下载 2.安装 3.装好后的体验 4.命令情况 5.windows共享 6.总结 听说华为笔记本都预装deepin&#xff0c;下载下来体验下 vmware创建linux系统&#xff0c;版本选择Other Linux 4.x or later kernel 64-bit 1.下载 官网 https://www.deepin.org/ 从官网下载iso真心…

带视觉差的轮播图

最终结果&#xff1a; 代码&#xff1a; <!DOCTYPE html> <html> <head lang"en"><meta charset"UTF-8"><title></title><style>html {box-sizing: border-box;font-family: Open Sans, sans-serif;}*, *:befor…

深度终端:ubuntu等linux下好用的远程终端软件

终端好不好用&#xff0c;直接上图&#xff0c;有图有真相—— 这终端不错啊&#xff0c;可以添加远程链接信息&#xff0c;像xshell似的&#xff0c;比ubuntu那些的终端强多了&#xff0c;每次都得一步步连。 怎么装&#xff1f; sudo apt install -y deepin-terminal PS&…

大数据产品的备份及恢复

Hbase Distcp方式整体下载上传方式CopyTable备份Export工具elasticsearch 建立备份快照数据挂载点建立快照仓储repository建立snapshot快照备份恢复snapshot快照数据 原集群恢复新集群恢复HDFSHbase的备份恢复 hbase数据备份策略有两类&#xff1a; 离线备份&#xff08;关闭Hb…

centos7 greenplum6.1开源版本编译

greenplum开源版本 https://greenplum.org/ 其官方手册 https://greenplum.org/documentation/ 其下载介质地址 https://github.com/greenplum-db/gpdb/releases 本次下载src-full https://github.com/greenplum-db/gpdb/releases/download/6.1.0/6.1.0-src-full.zip 编译参…

Centos7 Greenplum6.1开源版本集群部署

目录 1.前言 1.1参照文档 1.2部署包 1.3服务器环境 2 准备工作 2.1 Linux用户 2.2 主机名和hosts配置 2.3 防火墙 2.4 系统资源配置 2.5 暂时启用gpadmin sudo 2.6 复制配置文件到所有节点上 3 安装Greenplum DB 3.1 在Master节点上安装Greenplum DB 3.2 在Master…

转 C#对多个集合和数组的操作(合并,去重,判断)

在开发过程中.数组和集合的处理是最让我们担心.一般会用for or foreach 来处理一些操作.这里介绍一些常用的集合跟数组的操作函数. 首先举例2个集合A,B. List<int> listA new List<int> {1,2,3,5,7,9}; List<int> listB new List<int> {13,4,17,29…

centos7 postgresql9和postgis2.1插件编译部署

目录 依赖安装 下载编译libgeos 下载编译proj4 编译Postgresql9 编译PostGIS2 启动postgresql服务 开通外部网络访问 数据库开启PostGIS扩展 查看PostGIS版本 升级PostGIS版本 依赖安装 这个命令里面安装的包可能会多&#xff0c;由于是编译GreenPlum用的&#xff0…

三国人物共现网络

三国部分人物共现图 转载于:https://www.cnblogs.com/jzssuanfa/p/6814865.html