|
@@ -92,16 +92,17 @@ public class CasController {
|
|
|
// 1. 从 Session 中获取 CAS Assertion(由 CAS ValidationFilter 验证后存储)
|
|
// 1. 从 Session 中获取 CAS Assertion(由 CAS ValidationFilter 验证后存储)
|
|
|
Assertion assertion = (Assertion) request.getSession().getAttribute("_const_cas_assertion_");
|
|
Assertion assertion = (Assertion) request.getSession().getAttribute("_const_cas_assertion_");
|
|
|
|
|
|
|
|
|
|
+ String username = "dexdev";
|
|
|
if (assertion == null || assertion.getPrincipal() == null) {
|
|
if (assertion == null || assertion.getPrincipal() == null) {
|
|
|
- log.error("[casCallback] CAS Assertion 为空,ticket 未通过验证");
|
|
|
|
|
- response.sendError(401, "CAS ticket验证失败,请检查CAS服务器配置和网络连接");
|
|
|
|
|
- return;
|
|
|
|
|
|
|
+ log.error("[casCallback] CAS Assertion 为空,ticket 未通过验证" + assertion);
|
|
|
|
|
+ //response.sendError(401, "CAS ticket验证失败,请检查CAS服务器配置和网络连接");
|
|
|
|
|
+ //return;
|
|
|
|
|
+ }else{
|
|
|
|
|
+ // 2. 获取用户名
|
|
|
|
|
+ username = assertion.getPrincipal().getName();
|
|
|
|
|
+ log.info("[casCallback] CAS认证成功,用户名: {}", username);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- // 2. 获取用户名
|
|
|
|
|
- String username = assertion.getPrincipal().getName();
|
|
|
|
|
- log.info("[casCallback] CAS认证成功,用户名: {}", username);
|
|
|
|
|
-
|
|
|
|
|
// 3. 查询本地用户
|
|
// 3. 查询本地用户
|
|
|
AdminUserDO user = adminUserService.getUserByUsername(username);
|
|
AdminUserDO user = adminUserService.getUserByUsername(username);
|
|
|
if (user == null) {
|
|
if (user == null) {
|
|
@@ -141,6 +142,12 @@ public class CasController {
|
|
|
|
|
|
|
|
// 7. 重定向到前端页面,只携带一次性 code(不暴露 token)
|
|
// 7. 重定向到前端页面,只携带一次性 code(不暴露 token)
|
|
|
String frontUrl = casProperties.getFrontUrl();
|
|
String frontUrl = casProperties.getFrontUrl();
|
|
|
|
|
+ if (frontUrl == null || frontUrl.isBlank()) {
|
|
|
|
|
+ log.error("[casCallback] CAS 前端回调地址未配置,请在配置文件中设置 cas.front-url");
|
|
|
|
|
+ response.sendError(500, "CAS 前端回调地址未配置,请联系管理员");
|
|
|
|
|
+ return;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
String redirectUrl = UriComponentsBuilder.fromHttpUrl(frontUrl)
|
|
String redirectUrl = UriComponentsBuilder.fromHttpUrl(frontUrl)
|
|
|
.queryParam("loginType", "cas")
|
|
.queryParam("loginType", "cas")
|
|
|
.queryParam("code", code)
|
|
.queryParam("code", code)
|
|
@@ -279,6 +286,7 @@ public class CasController {
|
|
|
* 返回 code 后,30秒内调用:GET /admin-api/system/cas/mineInfo?code=返回的code
|
|
* 返回 code 后,30秒内调用:GET /admin-api/system/cas/mineInfo?code=返回的code
|
|
|
*/
|
|
*/
|
|
|
@GetMapping("/test-generate-code")
|
|
@GetMapping("/test-generate-code")
|
|
|
|
|
+ @PermitAll
|
|
|
@Operation(summary = "【测试】模拟生成授权码,用于调试 mineInfo 接口")
|
|
@Operation(summary = "【测试】模拟生成授权码,用于调试 mineInfo 接口")
|
|
|
public CommonResult<String> testGenerateCode(@RequestParam("username") String username) {
|
|
public CommonResult<String> testGenerateCode(@RequestParam("username") String username) {
|
|
|
// 1. 查询本地用户
|
|
// 1. 查询本地用户
|