!402 判断不同端 clientid 是否有效

Merge pull request !402 from MichelleChung/5.X
feature/model
疯狂的狮子Li 1 year ago committed by Gitee
commit 17acf2ba7a
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

@ -66,6 +66,7 @@ public class EmailAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);

@ -76,6 +76,7 @@ public class PasswordAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);

@ -66,6 +66,7 @@ public class SmsAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);

@ -103,6 +103,7 @@ public class SocialAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);

@ -61,6 +61,7 @@ public class XcxAuthStrategy implements IAuthStrategy {
// 例如: 后台用户30分钟过期 app用户1天过期
model.setTimeout(client.getTimeout());
model.setActiveTimeout(client.getActiveTimeout());
model.setExtra(LoginHelper.CLIENT_KEY, clientId);
// 生成token
LoginHelper.login(loginUser, model);

@ -34,6 +34,7 @@ public class LoginHelper {
public static final String LOGIN_USER_KEY = "loginUser";
public static final String TENANT_KEY = "tenantId";
public static final String USER_KEY = "userId";
public static final String CLIENT_KEY = "clientid";
/**
*

@ -1,9 +1,13 @@
package org.dromara.common.security.config;
import cn.dev33.satoken.exception.NotLoginException;
import cn.dev33.satoken.interceptor.SaInterceptor;
import cn.dev33.satoken.router.SaRouter;
import cn.dev33.satoken.stp.StpUtil;
import org.dromara.common.core.utils.ServletUtils;
import org.dromara.common.core.utils.SpringUtils;
import org.dromara.common.core.utils.StringUtils;
import org.dromara.common.satoken.utils.LoginHelper;
import org.dromara.common.security.config.properties.SecurityProperties;
import org.dromara.common.security.handler.AllUrlHandler;
import lombok.RequiredArgsConstructor;
@ -44,6 +48,18 @@ public class SecurityConfig implements WebMvcConfigurer {
// 检查是否登录 是否有token
StpUtil.checkLogin();
// 检查 header 里的 clientId 与 token 里的是否一致
String headerCid = ServletUtils.getRequest().getHeader(LoginHelper.CLIENT_KEY);
String clientId = StpUtil.getExtra(LoginHelper.CLIENT_KEY).toString();
if (!StringUtils.equals(headerCid, clientId)) {
// token 无效
throw NotLoginException.newInstance(
StpUtil.getLoginType(),
NotLoginException.INVALID_TOKEN,
NotLoginException.NOT_TOKEN_MESSAGE,
StpUtil.getTokenValue());
}
// 有效率影响 用于临时测试
// if (log.isDebugEnabled()) {
// log.debug("剩余有效时间: {}", StpUtil.getTokenTimeout());

Loading…
Cancel
Save