跳到主要内容

SSO集成

背景介绍

作为企业实践,在应用程序中应用单点登录 (SSO) 是很常见的,这样可以通过集中且安全的方式管理用户凭证。

基于 Streampark 使用 Apache Shiro 进行身份验证和授权的事实,我们将使用 Pac4j 框架来实现单点登录 (SSO) 支持功能。 Pac4j 是 Shiro 社区推荐的 SSO 集成解决方案,也被其他 Apache 项目应用,如 Knox、Durid、Zeppelin 等。

SSO 登录工作流

我们提出了三个主要用例,其工作流程如下所示:

a) SSO启用时,新用户登录


b) SSO启用时,现有用户登录


c) SSO未启用时,用户登录


如何启用SSO登录

  • 从配置文件application.yml启用SSO:
...
spring:
profiles:
active: mysql #[h2,pgsql,mysql]
include: sso
...
sso:
# If turn to true, please provide the sso properties the application-sso.yml
enable: true
  • 选择第三方方式,例如Github或谷歌登录,参数设置细节可参照pac4j配置指引, 并填写如下所示的application-sso.yml配置:
pac4j:
callbackUrl: http://localhost:10000/callback
# Put all parameters under `properties`
# Check supported sso config parameters for different authentication clients from the below link
# https://github.com/pac4j/pac4j/blob/master/documentation/docs/config-module.md
properties:
# principalNameAttribute:
# Optional, change by authentication client
# Please replace and fill in your client config below when enabled SSO
principalNameAttribute: email
oidc:
type: google
id: xxx
secret: xxx
useNonce: true
# github:
# id: xxx
# secret: xxx
  • 重启Streampark,检查是否会重定向至正确的第三方登录页,并成功完成登录过程:



注意事项

  • 新用户通过SSO登录后,其帐户将自动添加到streampark中。但管理员仍然需要手动将用户添加到适当的组下,否则新用户登录成功后仍然无法定向到登陆页面。

  • 目前我们仅支持OAuthOpenID Connect (OIDC)作为常规支持的登录方式,如果您需要支持SamlCAS,请转到streampark-console/streampark-console-service/pom.xml,将它们更为包含在依赖当中:

        <!-- Include pac4j-config/core/oauth/oidc-->
<dependency>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-springboot</artifactId>
<version>${pac4jVersion}</version>
<exclusions>
<exclusion>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
</exclusion>
<!-- cas & opensaml is not supported-->
<exclusion>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-cas</artifactId>
</exclusion>
<exclusion>
<groupId>org.pac4j</groupId>
<artifactId>pac4j-saml-opensamlv3</artifactId>
</exclusion>
</exclusions>
</dependency>