dromara / dromara/Sa-Token

SaInterceptor拦截器中功能未生效

Open
#679 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
19k
Forks
2.9k
PR merge metrics
No merged PRs in 30d

Description

### 使用版本:
1.39.0

### 报错信息:
我想在SaInterceptor中对越权访问的用户记录日志,但是代码好像没有生效。

### 希望结果:
对越权访问的用户记录日志

### 复现步骤:
@Override
public void addInterceptors(InterceptorRegistry registry) {
// 注册 Sa-Token 拦截器,打开注解式鉴权功能
registry.addInterceptor(new SaInterceptor(handle -> {
Object loginId = StpUtil.getLoginId();
log.info("loginId is {}", loginId);
try {
Account account = accountService.findById((String) loginId);
String role = account.getRoleType().name();

SaRouter.match("/**").check(r -> {
StpUtil.checkRole(role);
});
} catch (NotRoleException | CommonException e){
log.info("not role exception.");
}
})).addPathPatterns("/**");
}

< 备注:如果复现步骤比较复杂,请将 demo 上传到 gitee 并留下地址 >

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the Spring MVC interceptor registration shown in the issue and trace how SaInterceptor invokes its handler, then inspect the SaRouter and StpUtil role-check flow. Reproduce the unauthorized request with version 1.39.0 and verify whether the handler reaches the exception path. Done means an unauthorized access reliably produces the requested log entry.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
authorization, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.