mirror of
https://gitee.com/dromara/sa-token.git
synced 2025-10-21 02:57:23 +08:00
feat: sa-token-quick-login 支持 SpringBoot3 项目。 Closes #IAFQNE。fix: #673
This commit is contained in:
@@ -19,10 +19,15 @@
|
||||
<dependencies>
|
||||
<!-- sa-token-spring-boot-starter -->
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>cn.dev33</groupId>
|
||||
<artifactId>sa-token-spring-boot3-starter</artifactId>
|
||||
<optional>true</optional>
|
||||
</dependency>
|
||||
|
||||
<!-- 视图引擎 -->
|
||||
<dependency>
|
||||
|
@@ -48,44 +48,45 @@ public class SaQuickRegister {
|
||||
*/
|
||||
@Bean
|
||||
@ConfigurationProperties(prefix = CONFIG_VERSION)
|
||||
SaQuickConfig getSaQuickConfig() {
|
||||
public SaQuickConfig getSaQuickConfig() {
|
||||
return new SaQuickConfig();
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 注册 Sa-Token 全局过滤器
|
||||
*
|
||||
* @return /
|
||||
* 注册 Sa-Token 全局过滤器
|
||||
*
|
||||
* @return /
|
||||
*/
|
||||
@Bean
|
||||
@Order(SaTokenConsts.ASSEMBLY_ORDER - 1)
|
||||
SaServletFilter getSaServletFilterForQuickLogin() {
|
||||
return new SaServletFilter()
|
||||
|
||||
// 拦截路由
|
||||
.addInclude("/**")
|
||||
// 拦截路由
|
||||
.addInclude("/**")
|
||||
|
||||
// 排除掉登录相关接口,不需要鉴权的
|
||||
.addExclude("/favicon.ico", "/saLogin", "/doLogin", "/sa-res/**")
|
||||
// 排除掉登录相关接口,不需要鉴权的
|
||||
.addExclude("/favicon.ico", "/saLogin", "/doLogin", "/sa-res/**")
|
||||
|
||||
// 认证函数: 每次请求执行
|
||||
.setAuth(obj -> {
|
||||
SaRouter
|
||||
.match(SaFoxUtil.convertStringToList(SaQuickManager.getConfig().getInclude()))
|
||||
.notMatch(SaFoxUtil.convertStringToList(SaQuickManager.getConfig().getExclude()))
|
||||
.check(r -> {
|
||||
// 未登录时直接转发到login.html页面
|
||||
if (SaQuickManager.getConfig().getAuth() && ! StpUtil.isLogin()) {
|
||||
SaHolder.getRequest().forward("/saLogin");
|
||||
SaRouter.back();
|
||||
}
|
||||
});
|
||||
}).
|
||||
|
||||
// 异常处理函数:每次认证函数发生异常时执行此函数
|
||||
setError(e -> {
|
||||
return e.getMessage();
|
||||
});
|
||||
// 认证函数: 每次请求执行
|
||||
.setAuth(obj -> {
|
||||
SaRouter
|
||||
.match(SaFoxUtil.convertStringToList(SaQuickManager.getConfig().getInclude()))
|
||||
.notMatch(SaFoxUtil.convertStringToList(SaQuickManager.getConfig().getExclude()))
|
||||
.check(r -> {
|
||||
// 未登录时直接转发到login.html页面
|
||||
if (SaQuickManager.getConfig().getAuth() && ! StpUtil.isLogin()) {
|
||||
SaHolder.getRequest().forward("/saLogin");
|
||||
SaRouter.back();
|
||||
}
|
||||
});
|
||||
}).
|
||||
|
||||
// 异常处理函数:每次认证函数发生异常时执行此函数
|
||||
setError(e -> {
|
||||
return e.getMessage();
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
|
@@ -15,17 +15,17 @@
|
||||
*/
|
||||
package cn.dev33.satoken.quick.web;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
import cn.dev33.satoken.quick.SaQuickManager;
|
||||
import cn.dev33.satoken.quick.config.SaQuickConfig;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
import cn.dev33.satoken.util.SaFoxUtil;
|
||||
import cn.dev33.satoken.util.SaResult;
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
import org.springframework.web.bind.annotation.PostMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.ResponseBody;
|
||||
|
||||
/**
|
||||
* 登录Controller,处理登录相关请求
|
||||
@@ -55,7 +55,7 @@ public class SaQuickController {
|
||||
*/
|
||||
@PostMapping("/doLogin")
|
||||
@ResponseBody
|
||||
public SaResult doLogin(String name, String pwd) {
|
||||
public SaResult doLogin(@RequestParam("name") String name, @RequestParam("pwd") String pwd) {
|
||||
|
||||
// 参数完整性校验
|
||||
if(SaFoxUtil.isEmpty(name) || SaFoxUtil.isEmpty(pwd)) {
|
||||
|
Reference in New Issue
Block a user