feat(login): 添加自定义 TokenBean 并更新相关逻辑

This commit is contained in:
曾文豪
2025-03-21 17:51:40 +08:00
parent cb6e1c85b2
commit fba88da506
3 changed files with 21 additions and 6 deletions

View File

@@ -12,6 +12,7 @@ import com.alibaba.fastjson.JSONObject;
import com.tiesheng.annotation.role.RoleAuthority;
import com.tiesheng.annotation.token.TokenIgnore;
import com.tiesheng.database.config.DbBackupConfig;
import com.tiesheng.demo.pojos.CustTokenBean;
import com.tiesheng.demo.pojos.JsonTest;
import com.tiesheng.demo.pojos.PoiBean;
import com.tiesheng.platform.config.ding.PlatformDingConfig;
@@ -43,7 +44,6 @@ import java.util.function.Consumer;
*/
@RestController
@RequestMapping("/test")
@RoleAuthority(value = "test", group = "test")
public class TestController {
@Autowired
@@ -65,7 +65,6 @@ public class TestController {
@RequestMapping("/index")
@TokenIgnore
public void index(HttpServletResponse response) {
globalConfig.redirectWithVer("mobile", "/test", response);
}
@@ -113,8 +112,9 @@ public class TestController {
@GetMapping("/send")
@TokenIgnore
public ApiResp<String> sendMessage() {
public ApiResp<String> sendMessage(CustTokenBean tokenBean) {
tokenBean.test();
// MessageReqResp reqResp = coreMessageService.send(new UserChannel("13567116463", "sms"),
// JSONUtil.createObj().putOpt("action", "sms-visitor-invite"));

View File

@@ -0,0 +1,12 @@
package com.tiesheng.demo.pojos;
import com.tiesheng.util.pojos.TokenBean;
public class CustTokenBean extends TokenBean {
public void test() {
System.out.println("test: " + getId());
}
}

View File

@@ -1,5 +1,6 @@
package com.tiesheng.login.config;
import cn.hutool.core.bean.BeanUtil;
import cn.hutool.core.util.ObjUtil;
import cn.hutool.core.util.StrUtil;
import com.tiesheng.annotation.token.TokenIgnore;
@@ -40,7 +41,7 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
resolvers.add(new HandlerMethodArgumentResolver() {
@Override
public boolean supportsParameter(MethodParameter parameter) {
return parameter.getParameterType().isAssignableFrom(TokenBean.class);
return TokenBean.class.isAssignableFrom(parameter.getParameterType());
}
@Override
@@ -54,7 +55,9 @@ public class TokenWebMvcConfigurer implements WebMvcConfigurer {
TokenIgnore annotation = method.getAnnotation(TokenIgnore.class);
thrExp = annotation == null;
}
return tsTokenConfig.validToken(header, thrExp);
TokenBean tokenBean = tsTokenConfig.validToken(header, thrExp);
return BeanUtil.copyProperties(tokenBean, parameter.getParameterType());
}
});
}