-
Notifications
You must be signed in to change notification settings - Fork 1.3k
[Feature] Sso Backend support #3366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
yangzehan
wants to merge
23
commits into
DataLinkDC:dev
Choose a base branch
from
yangzehan:sso
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 17 commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
b721d8e
Add sso support for github oauth
yangzehan ddc20d7
Add sso support for github oauth
yangzehan e5bbc74
Add sso support for github oauth
yangzehan 2b84285
mvn -T 4C spotless:apply
yangzehan db9cbb7
Delete redundant files, fix the SSO client, specify the client name, …
yangzehan 43e685d
mvn spotless:apply
yangzehan 59a1cef
rollback
yangzehan 4aeb724
Remove basic connection information
yangzehan afc9277
Improve logic and add front-end code
yangzehan e3d179d
mvn -T 4C spotless:apply
yangzehan 396a884
Add registration ID
yangzehan ee042a0
Fix user_type
yangzehan 6972025
Add sso automatic assembly and Remove redundant sso dependencies
yangzehan 01720f3
Remove redundant code
yangzehan c9456d9
Optimize the logout logic and fix the inability to access SSO related…
yangzehan de2f460
mvn -T 4C spotless:apply
yangzehan 5896c5d
delete console.log(location.hash)
yangzehan f2f132e
Merge remote-tracking branch 'refs/remotes/origin/dev' into sso
yangzehan d068481
perf(sso): Remove redundant code
yangzehan e2eade9
perf(sso): Delete redundant configuration information
yangzehan ed026f4
op code
Zzzz-zmy 765e3c1
Merge branch 'dev' into sso
Zzzz-zmy f075ada
Update AppConfig.java
Zzzz-zmy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
dinky-admin/src/main/java/org/dinky/configure/Pac4jConfigAutoConfiguration.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.dinky.configure; | ||
|
|
||
| import org.dinky.configure.propertie.Pac4jConfigurationProperties; | ||
|
|
||
| import org.pac4j.config.client.PropertiesConfigFactory; | ||
| import org.pac4j.core.config.Config; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
| import org.springframework.boot.context.properties.EnableConfigurationProperties; | ||
| import org.springframework.context.annotation.Bean; | ||
| import org.springframework.context.annotation.Configuration; | ||
|
|
||
| /** | ||
| * The Pac4jConfigAutoConfiguration class for Spring. | ||
| * | ||
| * @author yangzehan | ||
| * | ||
| */ | ||
| @Configuration(value = "Pac4jConfigAutoConfiguration", proxyBeanMethods = false) | ||
| @EnableConfigurationProperties(org.dinky.configure.propertie.Pac4jConfigurationProperties.class) | ||
| public class Pac4jConfigAutoConfiguration { | ||
|
|
||
| @Autowired | ||
| private Pac4jConfigurationProperties pac4j; | ||
|
|
||
| @Bean | ||
| @ConditionalOnMissingBean | ||
| public Config config() { | ||
| final PropertiesConfigFactory factory = | ||
| new PropertiesConfigFactory(pac4j.getCallbackUrl(), pac4j.getProperties()); | ||
| return factory.build(); | ||
| } | ||
| } |
45 changes: 45 additions & 0 deletions
45
dinky-admin/src/main/java/org/dinky/configure/propertie/Pac4jConfigurationProperties.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.dinky.configure.propertie; | ||
|
|
||
| import java.util.LinkedHashMap; | ||
| import java.util.Map; | ||
|
|
||
| import org.springframework.boot.context.properties.ConfigurationProperties; | ||
|
|
||
| import lombok.Getter; | ||
| import lombok.Setter; | ||
|
|
||
| /** | ||
| * The pac4j configuration and callback URL. | ||
| * | ||
| * @author yangzehan | ||
| * | ||
| */ | ||
| @ConfigurationProperties(prefix = "pac4j", ignoreUnknownFields = false) | ||
| @Getter | ||
| @Setter | ||
| public class Pac4jConfigurationProperties { | ||
| private Map<String, String> properties = new LinkedHashMap<>(); | ||
| private Map<String, String> callback = new LinkedHashMap<>(); | ||
| private Map<String, String> centralLogout = new LinkedHashMap<>(); | ||
| private Map<String, String> logout = new LinkedHashMap<>(); | ||
| private String callbackUrl; | ||
| } |
131 changes: 131 additions & 0 deletions
131
dinky-admin/src/main/java/org/dinky/controller/SsoCpntroller.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| /* | ||
| * | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| * | ||
| */ | ||
|
|
||
| package org.dinky.controller; | ||
|
|
||
| import org.dinky.data.dto.LoginDTO; | ||
| import org.dinky.data.dto.UserDTO; | ||
| import org.dinky.data.enums.Status; | ||
| import org.dinky.data.exception.AuthException; | ||
| import org.dinky.data.result.Result; | ||
| import org.dinky.service.UserService; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| import javax.annotation.PostConstruct; | ||
|
|
||
| import org.pac4j.core.config.Config; | ||
| import org.pac4j.core.context.JEEContext; | ||
| import org.pac4j.core.profile.CommonProfile; | ||
| import org.pac4j.core.profile.ProfileManager; | ||
| import org.pac4j.springframework.web.LogoutController; | ||
| import org.springframework.beans.factory.annotation.Autowired; | ||
| import org.springframework.beans.factory.annotation.Value; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import org.springframework.web.servlet.ModelAndView; | ||
| import org.springframework.web.servlet.view.RedirectView; | ||
|
|
||
| import cn.dev33.satoken.annotation.SaIgnore; | ||
| import io.swagger.annotations.ApiOperation; | ||
| import lombok.NoArgsConstructor; | ||
|
|
||
| /** | ||
| * @author 杨泽翰 | ||
| */ | ||
| @RestController | ||
| @NoArgsConstructor | ||
| @RequestMapping("/api/sso") | ||
| public class SsoCpntroller { | ||
| @Value("${sso.redirect}") | ||
| private String redirect; | ||
|
|
||
| @Value("${sso.enabled:false}") | ||
| private Boolean ssoEnabled; | ||
|
|
||
| @Value("${pac4j.centralLogout.defaultUrl:#{null}}") | ||
| private String defaultUrl; | ||
|
|
||
| @Value("${pac4j.centralLogout.logoutUrlPattern:#{null}}") | ||
| private String logoutUrlPattern; | ||
|
|
||
| @Value("${pac4j.properties.principalNameAttribute:#{null}}") | ||
| private String principalNameAttribute; | ||
|
|
||
| @Autowired | ||
| private Config config; | ||
|
|
||
| @Autowired | ||
| private JEEContext webContext; | ||
|
|
||
| @Autowired | ||
| private ProfileManager profileManager; | ||
|
|
||
| private LogoutController logoutController; | ||
|
|
||
| @Autowired | ||
| private UserService userService; | ||
|
|
||
| @PostConstruct | ||
| protected void afterPropertiesSet() { | ||
| logoutController = new LogoutController(); | ||
| logoutController.setDefaultUrl(defaultUrl); | ||
| logoutController.setLogoutUrlPattern(logoutUrlPattern); | ||
| logoutController.setLocalLogout(true); | ||
| logoutController.setCentralLogout(true); | ||
| logoutController.setConfig(config); | ||
| logoutController.setDestroySession(true); | ||
| } | ||
|
|
||
| @GetMapping("/token") | ||
| public Result<UserDTO> ssoToken() throws AuthException { | ||
| if (!ssoEnabled) { | ||
| return Result.failed(Status.SINGLE_LOGIN_DISABLED); | ||
| } | ||
| List<CommonProfile> all = profileManager.getAll(true); | ||
| String username = all.get(0).getAttribute(principalNameAttribute).toString(); | ||
| if (username == null) { | ||
| throw new AuthException(Status.NOT_MATCHED_PRINCIPAL_NAME_ATTRIBUTE); | ||
| } | ||
| LoginDTO loginDTO = new LoginDTO(); | ||
| loginDTO.setUsername(username); | ||
| loginDTO.setSsoLogin(true); | ||
| return userService.loginUser(loginDTO); | ||
| } | ||
|
|
||
| @GetMapping("/login") | ||
| public ModelAndView ssoLogin() { | ||
| RedirectView redirectView = new RedirectView(redirect); | ||
| return new ModelAndView(redirectView); | ||
| } | ||
|
|
||
| @GetMapping("/logout") | ||
| public void ssoLogout() { | ||
|
|
||
| logoutController.logout(webContext.getNativeRequest(), webContext.getNativeResponse()); | ||
| } | ||
|
|
||
| @GetMapping("/ssoEnableStatus") | ||
| @SaIgnore | ||
| @ApiOperation("Get SSO enable status") | ||
| public Result<Boolean> ssoStatus() { | ||
| return Result.succeed(ssoEnabled); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.