Skip to content

Commit

Permalink
[Feature-14802][api] Use Casdoor SSO to log in, add admin user config…
Browse files Browse the repository at this point in the history
…uration (#14814)

* [Feature-14802][feat] Use Casdoor SSO to log in, add admin user configuration

    Use Casdoor SSO to log in, add admin user configuration

This closes #14802

* [Feature-14802][feat] Use Casdoor SSO to log in, add admin user configuration

    Use Casdoor SSO to log in, add admin user configuration

This closes #14802

* update doc

* [Feature-14802][feat] Use Casdoor SSO to log in, add admin user configuration

    Use Casdoor SSO to log in, add admin user configuration

This closes #14802

---------

Co-authored-by: Eric Gao <ericgao.apache@gmail.com>
Co-authored-by: 旺阳 <qingwli@cisco.com>
  • Loading branch information
3 people authored Sep 4, 2023
1 parent 46c0eb4 commit adf49fd
Show file tree
Hide file tree
Showing 9 changed files with 94 additions and 3 deletions.
8 changes: 8 additions & 0 deletions docs/docs/en/architecture/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,14 @@ Location: `api-server/conf/application.yaml`
|security.authentication.ldap.ssl.enable|false|LDAP switch|
|security.authentication.ldap.ssl.trust-store|ldapkeystore.jks|LDAP jks file absolute path|
|security.authentication.ldap.ssl.trust-store-password|password|LDAP jks password|
|security.authentication.casdoor.user.admin||admin user account when you log-in with Casdoor|
|casdoor.endpoint||Casdoor server url|
|casdoor.client-id||id in Casdoor|
|casdoor.client-secret||secret in Casdoor|
|casdoor.certificate||certificate in Casdoor|
|casdoor.organization-name||organization name in Casdoor|
|casdoor.application-name||application name in Casdoor|
|casdoor.redirect-url||doplhinscheduler login url|
|api.traffic.control.global.switch|false|traffic control global switch|
|api.traffic.control.max-global-qps-rate|300|global max request number per second|
|api.traffic.control.tenant-switch|false|traffic control tenant switch|
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/en/guide/security/authentication-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ security:
# jks file absolute path && password
trust-store: "/ldapkeystore.jks"
trust-store-password: "password"
casdoor:
user:
admin: ""
oauth2:
enable: false
provider:
Expand All @@ -53,6 +56,19 @@ security:
callbackUrl: ""
iconUri: ""
provider: google
casdoor:
# Your Casdoor server url
endpoint: ""
client-id: ""
client-secret: ""
# The certificate may be multi-line, you can use `|-` for ease
certificate: ""
# Your organization name added in Casdoor
organization-name: ""
# Your application name added in Casdoor
application-name: ""
# Doplhinscheduler login url
redirect-url: ""
```
For detailed explanation of specific fields, please see: [Api-server related configuration](../../architecture/configuration.md)
Expand Down
8 changes: 8 additions & 0 deletions docs/docs/zh/architecture/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,14 @@ common.properties配置文件目前主要是配置hadoop/s3/yarn/applicationId
|security.authentication.ldap.ssl.enable|false|LDAP ssl开关|
|security.authentication.ldap.ssl.trust-store|ldapkeystore.jks|LDAP jks文件绝对路径|
|security.authentication.ldap.ssl.trust-store-password|password|LDAP jks密码|
|security.authentication.casdoor.user.admin||Casdoor登陆时,系统管理员账号|
|casdoor.endpoint||Casdoor服务器URL|
|casdoor.client-id||Casdoor中的ID|
|casdoor.client-secret||Casdoor中的密钥|
|casdoor.certificate||Casdoor中的证书|
|casdoor.organization-name||Casdoor中的组织名称|
|casdoor.application-name||Casdoor中的应用名称|
|casdoor.redirect-url||dolphinscheduler登录URL|
|api.traffic.control.global.switch|false|流量控制全局开关|
|api.traffic.control.max-global-qps-rate|300|全局最大请求数/秒|
|api.traffic.control.tenant-switch|false|流量控制租户开关|
Expand Down
16 changes: 16 additions & 0 deletions docs/docs/zh/guide/security/authentication-type.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ security:
# jks file absolute path && password
trust-store: "/ldapkeystore.jks"
trust-store-password: "password"
casdoor:
user:
admin: ""
oauth2:
enable: false
provider:
Expand All @@ -53,6 +56,19 @@ security:
callbackUrl: ""
iconUri: ""
provider: google
casdoor:
# Your Casdoor server url
endpoint: ""
client-id: ""
client-secret: ""
# The certificate may be multi-line, you can use `|-` for ease
certificate: ""
# Your organization name added in Casdoor
organization-name: ""
# Your application name added in Casdoor
application-name: ""
# Doplhinscheduler login url
redirect-url: ""
```
具体字段解释详见:[Api-server相关配置](../../architecture/configuration.md)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ public class CasdoorAuthenticator extends AbstractSsoAuthenticator {
private CasdoorAuthService casdoorAuthService;
@Value("${casdoor.redirect-url}")
private String redirectUrl;
@Value("${security.authentication.casdoor.user.admin:#{null}}")
private String adminUserName;

@Override
public User login(String state, String code, String extra) {
Expand All @@ -66,12 +68,17 @@ public User login(String state, String code, String extra) {
// check if user exist
user = usersService.getUserByUserName(casdoorUser.getName());
if (user == null) {
user = usersService.createUser(UserType.GENERAL_USER, casdoorUser.getName(), casdoorUser.getEmail());
user = usersService.createUser(getUserType(casdoorUser.getName()), casdoorUser.getName(),
casdoorUser.getEmail());
}
}
return user;
}

public UserType getUserType(String userName) {
return adminUserName.equalsIgnoreCase(userName) ? UserType.ADMIN_USER : UserType.GENERAL_USER;
}

@Override
public String getSignInUrl(String state) {
return casdoorAuthService.getSigninUrl(redirectUrl, state);
Expand Down
17 changes: 17 additions & 0 deletions dolphinscheduler-api/src/main/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ security:
# jks file absolute path && password
trust-store: "/ldapkeystore.jks"
trust-store-password: "password"
casdoor:
user:
admin: ""
oauth2:
enable: false
provider:
Expand All @@ -204,6 +207,20 @@ security:
callbackUrl: ""
iconUri: ""
provider: google
casdoor:
# Your Casdoor server url
endpoint: ""
client-id: ""
client-secret: ""
# The certificate may be multi-line, you can use `|-` for ease
certificate: ""
# Your organization name added in Casdoor
organization-name: ""
# Your application name added in Casdoor
application-name: ""
# Doplhinscheduler login url
redirect-url: ""


# Override by profile

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@
"casdoor.certificate=public-key",
"casdoor.organization-name=built-in",
"casdoor.application-name=app-built-in",
"casdoor.redirect-url=http://localhost:8888/view/login/index.html"
"casdoor.redirect-url=http://localhost:8888/view/login/index.html",
"security.authentication.casdoor.user.admin=admin"
})
public class CasdoorAuthenticatorTest extends AbstractControllerTest {

Expand Down
3 changes: 3 additions & 0 deletions dolphinscheduler-api/src/test/resources/application.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,9 @@ security:
# jks file absolute path && password
trust-store: "/ldapkeystore.jks"
trust-store-password: "password"
casdoor:
user:
admin: ""
oauth2:
enable: true
provider:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,9 @@ security:
# jks file absolute path && password
trust-store: "/ldapkeystore.jks"
trust-store-password: ""
casdoor:
user:
admin: admin
oauth2:
enable: false
provider:
Expand All @@ -135,7 +138,19 @@ security:
iconUri: ""
provider: gitee


casdoor:
# Your Casdoor server url
endpoint: http://localhost:8000
client-id: ""
client-secret: ""
# The certificate may be multi-line, you can use `|-` for ease
certificate: ""
# Your organization name added in Casdoor
organization-name: built-in
# Your application name added in Casdoor
application-name: dolphinscheduler
# Doplhinscheduler login url
redirect-url: http://localhost:5173/login



Expand Down

0 comments on commit adf49fd

Please sign in to comment.