mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-09-18 17:48:03 +08:00
在登录时强制性检查账号 id 是否为异常值,如果是则登录失败。
This commit is contained in:
@@ -521,17 +521,22 @@ public class StpLogic {
|
||||
*/
|
||||
protected void checkLoginArgs(Object id, SaLoginModel loginModel) {
|
||||
|
||||
// 1、先检查一下,传入的账号id是否可用
|
||||
// 1、账号 id 不能为空
|
||||
if(SaFoxUtil.isEmpty(id)) {
|
||||
throw new SaTokenException("loginId 不能为空").setCode(SaErrorCode.CODE_11002);
|
||||
}
|
||||
|
||||
// 2、判断账号id是否为简单类型
|
||||
// 2、账号 id 不能是异常标记值
|
||||
if(NotLoginException.ABNORMAL_LIST.contains(id.toString())) {
|
||||
throw new SaTokenException("loginId 不能为以下值:" + NotLoginException.ABNORMAL_LIST);
|
||||
}
|
||||
|
||||
// 3、账号 id 不能是简单类型
|
||||
if( ! SaFoxUtil.isBasicType(id.getClass())) {
|
||||
SaManager.log.warn("loginId 应该为简单类型,例如:String | int | long,不推荐使用复杂类型:" + id.getClass());
|
||||
}
|
||||
|
||||
// 3、判断当前 StpLogic 是否支持 extra 扩展参数
|
||||
// 4、判断当前 StpLogic 是否支持 extra 扩展参数
|
||||
if( ! isSupportExtra()) {
|
||||
// 如果不支持,开发者却传入了 extra 扩展参数,那么就打印警告信息
|
||||
Map<String, Object> extraData = loginModel.getExtraData();
|
||||
@@ -1040,8 +1045,8 @@ public class StpLogic {
|
||||
* @return /
|
||||
*/
|
||||
public boolean isValidLoginId(Object loginId) {
|
||||
// 判断标准:不为null,且不在异常标记项里面
|
||||
return loginId != null && !NotLoginException.ABNORMAL_LIST.contains(loginId.toString());
|
||||
// 判断标准:不为 null、空字符串,且不在异常标记项里面
|
||||
return SaFoxUtil.isNotEmpty(loginId) && !NotLoginException.ABNORMAL_LIST.contains(loginId.toString());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -1,7 +1,7 @@
|
||||
package com.pj.test;
|
||||
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import com.pj.satoken.StpUserUtil;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -18,7 +18,7 @@ public class TestController {
|
||||
// 测试登录 ---- http://localhost:8081/test/login
|
||||
@RequestMapping("login")
|
||||
public SaResult login(@RequestParam(defaultValue = "10001") long id) {
|
||||
StpUserUtil.login(id);
|
||||
StpUtil.login(id);
|
||||
return SaResult.ok("登录成功");
|
||||
}
|
||||
|
||||
@@ -27,7 +27,7 @@ public class TestController {
|
||||
public SaResult test() {
|
||||
System.out.println("------------进来了");
|
||||
// 返回
|
||||
return SaResult.data("");
|
||||
return SaResult.data(null);
|
||||
}
|
||||
|
||||
// 测试 浏览器访问: http://localhost:8081/test/test2
|
||||
|
Reference in New Issue
Block a user