日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Superset单点登录调整源码

發布時間:2023/12/10 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 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单点登录调整源码的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。