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权限(全部数据库)。
Superset单点登录调整源码相关推荐
- [精华][推荐]CAS SSO实现单点登录实例源码
1.因为是本地模拟sso环境,而sso的环境测试需要域名,所以需要虚拟几个域名出来,步骤如下: 2.进入目录C:\Windows\System32\drivers\etc 3.修改hosts文件 12 ...
- [精华][推荐]CAS SSO 实现单点登录实例源码
1.修改server.xml文件,如下: 注意: 这里使用的是https的认证方式,需要将这个配置放开,并做如下修改: <Connector port="8443" prot ...
- 通用权限管理系统组件 (GPM - General Permissions Manager) 中集成多系统的统一登录(数据库源码级)附源码...
眼前有20万行以上的代码时很多人都会眼花缭乱,不知道从哪里开始下手了,甚至不会去研究几下就直接放弃了.其实大多时候没有想象的那么复杂,代码里一大部分都是有重复的,有本质上差别的部分还是很少的. 春节期 ...
- android与html注册登录,Android登录注册源码
Android登录注册源码 资源下载此资源下载价格为2D币,请先登录 资源文件列表 andoird96pk/.classpath , 348 andoird96pk/.project , 847 an ...
- PHP游戏扫码登录器源码 支持一百多种热门游戏登录
介绍: PHP游戏扫码登录器源码 支持一百多种热门游戏登录 里面支持一百多种热门游戏登录,比如王者荣耀,英雄联盟手游,手游CF等等! ! ! 不管是用来运营吸引人气还是后续广告都是不错的程序,另外该源 ...
- 易语言网易云音乐登录post源码
易语言网易云音乐登录post源码 以下是部分源码: .版本 2 .支持库 dp1 data = 文本_替换 (#常量2, , , , "账号", 账号, "密码" ...
- 各种风格登录页响应式html5模板 Admin后台管理系统模板手机wap登录页html模板html会员登录页面模板源码70多套高大尚响应式网站模板html5网页静态模板Bootstrap扁平化网站源码
各种风格登录页响应式html5模板 Admin后台管理系统模板手机wap登录页html模板html会员登录页面模板源码70多套高大尚响应式网站模板html5网页静态模板Bootstrap扁平化网站源码 ...
- JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库
JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库 JAVA毕业设计Vue网上书籍购买商城登录计算机源码+lw文档+系统+调试部署+数据库 本源码技术栈: 项目架构 ...
- 计算机毕业设计JAVA钢材销售平台登录mybatis+源码+调试部署+系统+数据库+lw
计算机毕业设计JAVA钢材销售平台登录mybatis+源码+调试部署+系统+数据库+lw 计算机毕业设计JAVA钢材销售平台登录mybatis+源码+调试部署+系统+数据库+lw 本源码技术栈: 项目 ...
最新文章
- 开发者说:基于 Nacos 的网关灰度路由和服务权重灰度
- TensorFlow基于cifar10数据集实现进阶的卷积网络
- java citymap_Java实现Map集合二级联动
- batch批处理程序easyadd——追加单行文本到指定txt文件末尾
- 为Android安装BusyBox
- easyui前端实现多选框_在实际案例中学习前端开发(第二期)
- MinGW-w64离线安装包,环境配置(Windows)
- 智能优化算法:自私羊群优化算法-附代码
- css字竖排垂直居中显示,CSS--字体|垂直居中|background
- (ECPC 16) (6/11)
- LINUX网卡地址配置
- linux删除arp绑定失败,我用这个命令后总是说“ARP项目删除失败:请求的操作需要提升...
- Python MySQL 数据库技术 part 3
- PHP时间戳和日期相互转换
- wrong ELF class: ELFCLASS32
- 【Unity3D插件】Glow插件分享《边缘发光插件》
- matlab里open命令,告诉你Ununtu下在Matlab中读写OpenEXR格式的图片的方法及命令
- 想买个kindle保护套!
- bash命令补全工具bash-completion
- 双三次插值法(Bicubic interpolation)