-
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
Open
Changes from all 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
111 changes: 111 additions & 0 deletions
dinky-admin/src/main/java/org/dinky/controller/SsoController.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,111 @@ | ||
/* | ||
* | ||
* 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.profile.CommonProfile; | ||
import org.pac4j.core.profile.ProfileManager; | ||
import org.pac4j.springframework.web.CallbackController; | ||
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 SsoController { | ||
@Value("${sso.redirect}") | ||
private String redirect; | ||
|
||
@Value("${sso.enabled:false}") | ||
private Boolean ssoEnabled; | ||
|
||
@Value("${pac4j.properties.principalNameAttribute:#{null}}") | ||
private String principalNameAttribute; | ||
|
||
@Autowired | ||
private Config config; | ||
|
||
@Autowired | ||
CallbackController callbackController; | ||
|
||
@Autowired | ||
private ProfileManager profileManager; | ||
|
||
@Autowired | ||
private UserService userService; | ||
|
||
@PostConstruct | ||
protected void afterPropertiesSet() { | ||
callbackController.setDefaultUrl(redirect); | ||
callbackController.setConfig(config); | ||
} | ||
|
||
@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("/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
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
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.
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.