专业的编程技术博客社区

网站首页 > 博客文章 正文

BI工具superset管理端的单点登录集成

baijin 2024-09-10 11:02:56 博客文章 11 ℃ 0 评论

基于superset的最新version 1.0.0版本实践

aimind_security.py

from superset.security.manager import SupersetSecurityManager
from flask_appbuilder.security.views import *
import logging
log = logging.getLogger(__name__)


class CustomAuthDBView(AuthDBView):
    login_template = 'appbuilder/general/security/login_db.html'

    @expose('/login/', methods=['GET', 'POST'])
    def login(self):
        log.info('here1')
        token = request.args.get('token')
        log.info('here2')
        if not token:
            token = request.cookies.get('access_token')
        if token is not None:
            jwt_payload = jwt.decode(token, 'secret', algorithms=['HS256'])
            user_name = jwt_payload.get("user_name")
            user = self.appbuilder.sm.find_user(username=user_name)
            if not user:
                role_admin = self.appbuilder.sm.find_role('Admin')
                user = self.appbuilder.sm.add_user(user_name, user_name, 'aimind', user_name + "@aimind.com",
                                                   role_admin, password="aimind" + user_name)
            if user:
                login_user(user, remember=False)
                redirect_url = request.args.get('redirect')
                if not redirect_url:
                    redirect_url = self.appbuilder.get_url_for_index
                return redirect(redirect_url)
            else:
                return super(CustomAuthDBView, self).login()
        else:
            flash('Unable to auto login', 'warning')
            return super(CustomAuthDBView, self).login()


class CustomSecurityManager(SupersetSecurityManager):
    authdbview = CustomAuthDBView


然后再config.py中增加两部分引用,中间行为引入部分

from superset.utils.logging_configurator import DefaultLoggingConfigurator
from .aimind_security import CustomSecurityManager

logger = logging.getLogger(__name__)

非注释部分为引入内容

# ----------------------------------------------------
# AUTHENTICATION CONFIG
# ----------------------------------------------------
# The authentication type
# AUTH_OID : Is for OpenID
# AUTH_DB : Is for database (username/password)
# AUTH_LDAP : Is for LDAP
# AUTH_REMOTE_USER : Is for using REMOTE_USER from web server
AUTH_TYPE = AUTH_DB
CUSTOM_SECURITY_MANAGER = CustomSecurityManager
# Uncomment to setup Full admin role name
# AUTH_ROLE_ADMIN = 'Admin'


关于最新版本汉化问题 注释掉最后的一行

# ---------------------------------------------------
# Babel config for translations
# ---------------------------------------------------
# Setup default language
BABEL_DEFAULT_LOCALE = "zh"
# Your application default translation path
BABEL_DEFAULT_FOLDER = "superset/translations"
# The allowed translation for you app
LANGUAGES = {
    "en": {"flag": "us", "name": "English"},
    "es": {"flag": "es", "name": "Spanish"},
    "it": {"flag": "it", "name": "Italian"},
    "fr": {"flag": "fr", "name": "French"},
    "zh": {"flag": "cn", "name": "Chinese"},
    "ja": {"flag": "jp", "name": "Japanese"},
    "de": {"flag": "de", "name": "German"},
    "pt": {"flag": "pt", "name": "Portuguese"},
    "pt_BR": {"flag": "br", "name": "Brazilian Portuguese"},
    "ru": {"flag": "ru", "name": "Russian"},
    "ko": {"flag": "kr", "name": "Korean"},
}
# Turning off i18n by default as translation in most languages are
# incomplete and not well maintained.
#LANGUAGES = {}


隐藏图标的方式 将width设置成0

# Uncomment to setup an App icon
APP_ICON = "/static/assets/images/superset-logo-horiz.png"
APP_ICON_WIDTH = 0

跨域访问部分的配置

# CORS Options
ENABLE_CORS = True
#CORS_OPTIONS: Dict[Any, Any] = {}
CORS_OPTIONS: Dict[Any, Any] = {"origins": "*"}

# Chrome allows up to 6 open connections per domain at a time. When there are more
# than 6 slices in dashboard, a lot of time fetch requests are queued up and wait for
# next available socket. PR #5039 is trying to allow domain sharding for Superset,
# and this feature will be enabled by configuration only (by default Superset
# doesn't allow cross-domain request).
SUPERSET_WEBSERVER_DOMAINS = []

效果如下


转载于https://www.cnblogs.com/xiaoqi/p/intergate-superset.html

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表