mirror of
https://gitee.com/dromara/sa-token.git
synced 2026-02-27 16:50:24 +08:00
Compare commits
5 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
bbcc016fc7 | ||
|
|
c62f9482df | ||
|
|
d2c0ac3f52 | ||
|
|
51b76f07f4 | ||
|
|
0b32a1f552 |
@@ -189,6 +189,6 @@ QQ交流群:[1002350610 点击加入](https://jq.qq.com/?_wv=1027&k=45H977HM)
|
||||
|
||||
**微信群** :
|
||||
|
||||

|
||||

|
||||
|
||||
<br>
|
||||
|
||||
@@ -16,7 +16,7 @@ public class SaTokenActionDefaultImpl implements SaTokenAction {
|
||||
|
||||
|
||||
/**
|
||||
* 生成一个token
|
||||
* 根据一定的算法生成一个token
|
||||
*/
|
||||
@Override
|
||||
public String createToken(Object loginId, String loginKey) {
|
||||
|
||||
@@ -14,6 +14,7 @@ import com.pj.util.AjaxJson;
|
||||
import cn.dev33.satoken.exception.NotLoginException;
|
||||
import cn.dev33.satoken.exception.NotPermissionException;
|
||||
import cn.dev33.satoken.exception.NotRoleException;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
/**
|
||||
* 全局异常处理
|
||||
@@ -21,10 +22,10 @@ import cn.dev33.satoken.exception.NotRoleException;
|
||||
@RestControllerAdvice // 可指定包前缀,比如:(basePackages = "com.pj.admin")
|
||||
public class GlobalException {
|
||||
|
||||
// 在每个控制器之前触发的操作
|
||||
// 在当前类每个方法进入之前触发的操作
|
||||
@ModelAttribute
|
||||
public void get(HttpServletRequest request) throws IOException {
|
||||
|
||||
StpUtil.checkPermission("user:add");
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -5,7 +5,6 @@ import java.util.List;
|
||||
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RequestParam;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
@@ -20,7 +19,6 @@ import cn.dev33.satoken.annotation.SaCheckPermission;
|
||||
import cn.dev33.satoken.annotation.SaCheckRole;
|
||||
import cn.dev33.satoken.annotation.SaMode;
|
||||
import cn.dev33.satoken.session.SaSessionCustomUtil;
|
||||
import cn.dev33.satoken.stp.SaLoginModel;
|
||||
import cn.dev33.satoken.stp.SaTokenInfo;
|
||||
import cn.dev33.satoken.stp.StpUtil;
|
||||
|
||||
@@ -232,18 +230,15 @@ public class TestController {
|
||||
return AjaxJson.getSuccess();
|
||||
}
|
||||
|
||||
|
||||
@Autowired
|
||||
TestService TestService;
|
||||
|
||||
// 测试AOP注解鉴权: http://localhost:8081/test/testAOP
|
||||
@RequestMapping("testAOP")
|
||||
public AjaxJson testAOP() {
|
||||
System.out.println("testAOP");
|
||||
TestService.getList();
|
||||
return AjaxJson.getSuccess();
|
||||
// 测试指定设备登录 浏览器访问: http://localhost:8081/test/loginByDevice
|
||||
@RequestMapping("loginByDevice")
|
||||
public AjaxJson loginByDevice() {
|
||||
System.out.println("--------------");
|
||||
StpUtil.setLoginId(10001, "PC");
|
||||
return AjaxJson.getSuccessData("登录成功");
|
||||
}
|
||||
|
||||
|
||||
|
||||
// 测试 浏览器访问: http://localhost:8081/test/test
|
||||
@RequestMapping("test")
|
||||
@@ -251,10 +246,10 @@ public class TestController {
|
||||
// StpUtil.getTokenSession().logout();
|
||||
// StpUtil.logoutByLoginId(10001);
|
||||
// StpUtil.setLoginId(10001);
|
||||
StpUtil.setLoginId(10001, new SaLoginModel().setIsTempCookie(true));
|
||||
StpUtil.getLoginId();
|
||||
// StpUtil.setLoginId(10001, new SaLoginModel().setIsTempCookie(true));
|
||||
// StpUtil.getLoginId();
|
||||
|
||||
return AjaxJson.getSuccess();
|
||||
return AjaxJson.getSuccess("访问成功");
|
||||
}
|
||||
|
||||
// 测试 浏览器访问: http://localhost:8081/test/test2
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
package com.pj.test;
|
||||
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import cn.dev33.satoken.annotation.SaCheckLogin;
|
||||
|
||||
/**
|
||||
* 用来测试AOP注解鉴权
|
||||
* @author kong
|
||||
*
|
||||
*/
|
||||
@Service
|
||||
public class TestService {
|
||||
|
||||
@SaCheckLogin
|
||||
public List<String> getList() {
|
||||
System.out.println("getList");
|
||||
return new ArrayList<String>();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -189,6 +189,7 @@ QQ交流群:[1002350610 点击加入](https://jq.qq.com/?_wv=1027&k=45H977HM)
|
||||
|
||||
**微信群** :
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
<br>
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
- [花式token](/use/token-style)
|
||||
- [框架配置](/use/config)
|
||||
- [会话治理](/use/search-session)
|
||||
<!-- - [记住我模式](/use/remember-me) -->
|
||||
|
||||
- **进阶**
|
||||
- [集群、分布式](/senior/dcs)
|
||||
|
||||
@@ -49,7 +49,6 @@
|
||||
可能是404了,SpringBoot环境下如果访问接口404后,会被重定向到`/error`,然后被再次拦截,如果是其它原因,欢迎加群反馈
|
||||
|
||||
|
||||
|
||||
### 权限可以做成动态的吗?
|
||||
权限本来就是动态的,只有jwt那种模式才是非动态的
|
||||
|
||||
@@ -71,9 +70,14 @@
|
||||
步骤:先在配置文件里将`tokenSessionCheckLogin`配置为`false`,然后通过`StpUtil.getTokenSession()`获取Session
|
||||
|
||||
|
||||
### 我只使用header来传输token,还需要打开Cookie模式吗?
|
||||
不需要,如果只使用header来传输token,可以在配置文件关闭Cookie模式,例:`isReadCookie=false`
|
||||
|
||||
|
||||
### 还是有不明白到的地方?
|
||||
请在`github`提交`issues`,或者加入qq群交流(群链接在[首页](README?id=交流群))
|
||||
|
||||
|
||||
### 我能为这个框架贡献代码吗?
|
||||
**可以**,请参照首页的提交pr步骤 ,[贡献代码](README?id=贡献代码)
|
||||
**可以**,请参照首页的提交pr步骤 ,[贡献代码](README?id=贡献代码)
|
||||
|
||||
|
||||
BIN
sa-token-doc/doc/static/login-view.png
vendored
Normal file
BIN
sa-token-doc/doc/static/login-view.png
vendored
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 6.8 KiB |
19
sa-token-doc/doc/use/remember-me.md
Normal file
19
sa-token-doc/doc/use/remember-me.md
Normal file
@@ -0,0 +1,19 @@
|
||||
# [记住我]模式
|
||||
---
|
||||
|
||||
如下图所示,一般网站的登录界面都会有一个 [ 记住我 ] 按钮,当你勾选它后,即时你关闭浏览器再次打开网站,也依然会处于登录状态,无须重复验证密码
|
||||
|
||||

|
||||
|
||||
那么在sa-token中,如何做到 [ 记住我 ] 功能呢?
|
||||
|
||||
|
||||
### 在sa-token中实现记住我功能
|
||||
|
||||
sa-token的登录授权,默认就是`记住我`模式,为了实现`非记住我`模式, 你需要做一些适配
|
||||
|
||||
要
|
||||
|
||||
|
||||
|
||||
|
||||
@@ -32,9 +32,11 @@ public class SaOAuth2Config {
|
||||
|
||||
/**
|
||||
* @param codeTimeout 要设置的 codeTimeout
|
||||
* @return 对象自身
|
||||
*/
|
||||
public void setCodeTimeout(long codeTimeout) {
|
||||
public SaOAuth2Config setCodeTimeout(long codeTimeout) {
|
||||
this.codeTimeout = codeTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -46,9 +48,11 @@ public class SaOAuth2Config {
|
||||
|
||||
/**
|
||||
* @param accessTokenTimeout 要设置的 accessTokenTimeout
|
||||
* @return 对象自身
|
||||
*/
|
||||
public void setAccessTokenTimeout(long accessTokenTimeout) {
|
||||
public SaOAuth2Config setAccessTokenTimeout(long accessTokenTimeout) {
|
||||
this.accessTokenTimeout = accessTokenTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -60,9 +64,11 @@ public class SaOAuth2Config {
|
||||
|
||||
/**
|
||||
* @param refreshTokenTimeout 要设置的 refreshTokenTimeout
|
||||
* @return 对象自身
|
||||
*/
|
||||
public void setRefreshTokenTimeout(long refreshTokenTimeout) {
|
||||
public SaOAuth2Config setRefreshTokenTimeout(long refreshTokenTimeout) {
|
||||
this.refreshTokenTimeout = refreshTokenTimeout;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user