全局日志模块

This commit is contained in:
click33
2022-11-02 18:50:15 +08:00
parent cf8cd29a82
commit 8be77d70b5
21 changed files with 776 additions and 129 deletions

View File

@@ -22,6 +22,8 @@ public class DisableController {
2、注销登录 ---- http://localhost:8081/disable/logout
3、禁用账号 ---- http://localhost:8081/disable/disable?userId=10001
4、再次访问登录接口登录失败 ---- http://localhost:8081/disable/login?userId=10001
5、解封账号 ---- http://localhost:8081/disable/untieDisable?userId=10001
6、再次访问登录接口登录成功 ---- http://localhost:8081/disable/login?userId=10001
*/
// 会话登录接口 ---- http://localhost:8081/disable/login?userId=10001
@@ -41,7 +43,7 @@ public class DisableController {
return SaResult.ok("账号退出成功");
}
// 封禁指定账号 ---- http://localhost:8081/disable/disable
// 封禁指定账号 ---- http://localhost:8081/disable/disable?userId=10001
@RequestMapping("disable")
public SaResult disable(long userId) {
/*
@@ -53,4 +55,11 @@ public class DisableController {
return SaResult.ok("账号 " + userId + " 封禁成功");
}
// 解封指定账号 ---- http://localhost:8081/disable/untieDisable?userId=10001
@RequestMapping("untieDisable")
public SaResult untieDisable(long userId) {
StpUtil.untieDisable(userId);
return SaResult.ok("账号 " + userId + " 解封成功");
}
}

View File

@@ -61,6 +61,13 @@ public class SafeAuthController {
return SaResult.error("二级认证失败");
}
// 手动关闭二级认证 ---- http://localhost:8081/safe/closeSafe
@RequestMapping("closeSafe")
public SaResult closeSafe() {
StpUtil.closeSafe();
return SaResult.ok();
}
// ------------------ 指定业务类型进行二级认证

View File

@@ -47,7 +47,19 @@ public class MySaTokenListener implements SaTokenListener {
public void doUntieDisable(String loginType, Object loginId, String service) {
System.out.println("---------- 自定义侦听器实现 doUntieDisable");
}
/** 每次打开二级认证时触发 */
@Override
public void doOpenSafe(String loginType, String tokenValue, String service, long safeTime) {
System.out.println("---------- 自定义侦听器实现 doOpenSafe");
}
/** 每次关闭二级认证时触发 */
@Override
public void doCloseSafe(String loginType, String tokenValue, String service) {
System.out.println("---------- 自定义侦听器实现 doCloseSafe");
}
/** 每次创建Session时触发 */
@Override
public void doCreateSession(String id) {
@@ -65,5 +77,6 @@ public class MySaTokenListener implements SaTokenListener {
public void doRenewTimeout(String tokenValue, Object loginId, long timeout) {
System.out.println("---------- 自定义侦听器实现 doRenewTimeout");
}
}

View File

@@ -31,6 +31,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
public void addInterceptors(InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器打开注解鉴权功能
registry.addInterceptor(new SaInterceptor(handle -> {
// SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
// 指定一条 match 规则
SaRouter
@@ -75,6 +76,7 @@ public class SaTokenConfigure implements WebMvcConfigurer {
// 认证函数: 每次请求执行
.setAuth(obj -> {
// System.out.println("---------- sa全局认证 " + SaHolder.getRequest().getRequestPath());
// SaManager.getLog().debug("----- 请求path={} 提交token={}", SaHolder.getRequest().getRequestPath(), StpUtil.getTokenValue());
// 权限校验 -- 不同模块认证不同权限
// 这里你可以写和拦截器鉴权同样的代码,不同点在于:

View File

@@ -42,6 +42,7 @@ public class StpUserUtil {
* 重置 StpLogic 对象
* <br> 1、更改此账户的 StpLogic 对象
* <br> 2、put 到全局 StpLogic 集合中
* <br> 3、发送日志
*
* @param newStpLogic /
*/
@@ -52,6 +53,9 @@ public class StpUserUtil {
// 添加到全局 StpLogic 集合中
// 以便可以通过 SaManager.getStpLogic(type) 的方式来全局获取到这个 StpLogic
SaManager.putStpLogic(newStpLogic);
// ## 发送日志
SaManager.getLogInput().replaceStpLogic(stpLogic);
}
/**

View File

@@ -42,6 +42,7 @@ public class StpUserUtil {
* 重置 StpLogic 对象
* <br> 1、更改此账户的 StpLogic 对象
* <br> 2、put 到全局 StpLogic 集合中
* <br> 3、发送日志
*
* @param newStpLogic /
*/
@@ -52,6 +53,9 @@ public class StpUserUtil {
// 添加到全局 StpLogic 集合中
// 以便可以通过 SaManager.getStpLogic(type) 的方式来全局获取到这个 StpLogic
SaManager.putStpLogic(newStpLogic);
// ## 发送日志
SaManager.getLogInput().replaceStpLogic(stpLogic);
}
/**