mirror of
https://gitee.com/dromara/sa-token.git
synced 2024-11-29 18:37:49 +08:00
新增 homeRoute 配置项:在 /sso/auth 登录后不指定 redirect 参数的情况下默认跳转的路由
This commit is contained in:
parent
4c216069aa
commit
cf1f255a4a
@ -13,6 +13,8 @@ public class SaSsoServerApplication {
|
||||
System.out.println();
|
||||
System.out.println("---------------------- Sa-Token SSO 统一认证中心启动成功 ----------------------");
|
||||
System.out.println("配置信息:" + SaSsoManager.getServerConfig());
|
||||
System.out.println("统一认证登录地址:http://sa-sso-server.com:9000/sso/auth");
|
||||
System.out.println("测试前需要根据官网文档修改hosts文件,测试账号密码:sa / 123456");
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
|
@ -54,6 +54,11 @@ public class SaSsoServerConfig implements Serializable {
|
||||
*/
|
||||
public String allowUrl = "*";
|
||||
|
||||
/**
|
||||
* 主页路由:在 /sso/auth 登录后不指定 redirect 参数的情况下默认跳转的路由
|
||||
*/
|
||||
public String homeRoute;
|
||||
|
||||
/**
|
||||
* 是否打开单点注销功能
|
||||
*/
|
||||
@ -127,6 +132,22 @@ public class SaSsoServerConfig implements Serializable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 主页路由:在 /sso/auth 登录后不指定 redirect 参数的情况下默认跳转的路由
|
||||
*/
|
||||
public String getHomeRoute() {
|
||||
return homeRoute;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param homeRoute 主页路由:在 /sso/auth 登录后不指定 redirect 参数的情况下默认跳转的路由
|
||||
* @return 对象自身
|
||||
*/
|
||||
public SaSsoServerConfig setHomeRoute(String homeRoute) {
|
||||
this.homeRoute = homeRoute;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return 是否打开单点注销功能
|
||||
*/
|
||||
@ -210,6 +231,7 @@ public class SaSsoServerConfig implements Serializable {
|
||||
+ "mode=" + mode
|
||||
+ ", ticketTimeout=" + ticketTimeout
|
||||
+ ", allowUrl=" + allowUrl
|
||||
+ ", homeRoute=" + homeRoute
|
||||
+ ", isSlo=" + isSlo
|
||||
+ ", isHttp=" + isHttp
|
||||
+ ", maxRegClient=" + maxRegClient
|
||||
|
@ -62,4 +62,7 @@ public interface SaSsoErrorCode {
|
||||
/** 提供的 client 参数值无效 */
|
||||
int CODE_30013 = 30013;
|
||||
|
||||
/** 在 /sso/auth 既没有指定 redirect 参数,也没有配置 homeRoute 路由 */
|
||||
int CODE_30014 = 30014;
|
||||
|
||||
}
|
||||
|
@ -106,10 +106,18 @@ public class SaSsoServerProcessor {
|
||||
}
|
||||
// ---- 情况2:在SSO认证中心已经登录,需要重定向回 Client 端,而这又分为两种方式:
|
||||
String mode = req.getParam(paramName.mode, "");
|
||||
String redirect = req.getParam(paramName.redirect);
|
||||
|
||||
// 方式1:直接重定向回Client端 (mode=simple)
|
||||
if(mode.equals(SaSsoConsts.MODE_SIMPLE)) {
|
||||
String redirect = req.getParam(paramName.redirect);
|
||||
|
||||
// 若 redirect 为空,则选择 homeRoute,若 homeRoute 也为空,则抛出异常
|
||||
if(SaFoxUtil.isEmpty(redirect)) {
|
||||
if(SaFoxUtil.isEmpty(cfg.getHomeRoute())) {
|
||||
throw new SaSsoException("未指定 redirect 参数,也未配置 homeRoute 路由,无法完成重定向操作").setCode(SaSsoErrorCode.CODE_30014);
|
||||
}
|
||||
return res.redirect(cfg.getHomeRoute());
|
||||
}
|
||||
ssoServerTemplate.checkRedirectUrl(redirect);
|
||||
return res.redirect(redirect);
|
||||
} else {
|
||||
@ -121,9 +129,16 @@ public class SaSsoServerProcessor {
|
||||
throw new SaSsoException("无效 client 标识:" + client).setCode(SaSsoErrorCode.CODE_30013);
|
||||
}
|
||||
|
||||
// 开始重定向
|
||||
String redirectUrl = ssoServerTemplate.buildRedirectUrl(
|
||||
stpLogic.getLoginId(), client, req.getParam(paramName.redirect));
|
||||
// 若 redirect 为空,则选择 homeRoute,若 homeRoute 也为空,则抛出异常
|
||||
if(SaFoxUtil.isEmpty(redirect)) {
|
||||
if(SaFoxUtil.isEmpty(cfg.getHomeRoute())) {
|
||||
throw new SaSsoException("未指定 redirect 参数,也未配置 homeRoute 路由,无法完成重定向操作").setCode(SaSsoErrorCode.CODE_30014);
|
||||
}
|
||||
return res.redirect(cfg.getHomeRoute());
|
||||
}
|
||||
|
||||
// 构建并跳转
|
||||
String redirectUrl = ssoServerTemplate.buildRedirectUrl(stpLogic.getLoginId(), client, redirect);
|
||||
return res.redirect(redirectUrl);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user