springboot Interceptor拦截器excludePathPatterns失效

释放双眼,带上耳机,听听看~!

springboot Interceptor拦截器excludePathPatterns失效

使用jwt和HandlerInterceptorAdapter做登录的拦截放行失效,其实更多时候不是配置文件失效,而是我们的代码及相关处理有问题

  • 拦截器:

springboot Interceptor拦截器excludePathPatterns失效

  • 配置文件:

springboot Interceptor拦截器excludePathPatterns失效
这里将登录路径即/admin/yanxue/user/login在addInterceptors中放行后登录请求却报错用户未登录:
springboot Interceptor拦截器excludePathPatterns失效

  • 第一种情况:参数导致的路径不匹配:比如我们需要传入的参数是一个对象,但实际上传入的只有该对象的部分字段,如下面的swagger测试:

springboot Interceptor拦截器excludePathPatterns失效
我们需要传入的参数是一个对象:


1
2
3
4
5
6
7
8
9
10
11
12
1{
2  "accountName": "string",
3  "createTime": "string",
4  "password": "string",
5  "peopleId": "string",
6  "peopleName": "string",
7  "peopleType": "string",
8  "updateTime": "string",
9  "userId": 0
10}
11
12

但实际上我们传入的是:


1
2
3
4
5
6
1{
2  "accountName": "string",
3  "password": "string",
4}
5
6
  • 第二种情况:前端报错415,这是由于请求头中Content-Type是text/html而不是application/json从而导致不匹配而无法访问通过,解决:设置请求头:


1
2
3
4
5
6
7
1url: 'http://localhost:10020/admin/yanxue/user/login',
2method: 'post',
3headers: { 'Content-Type': 'application/json;charset=utf8' },
4dataType: 'json',
5data: qs.stringify(data)
6
7
  • 第三种情况:拦截器中放行的路径含有错误路径:比如我们需要放行的路径是/admin/yanxue/user/login和/admin/yanxue/abcd,但/admin/yanxue/abcd在该项目中并不存在,导致会跳转/error路径,这种状况下如果我们未放行/error同样会报该错误,但是再解决了这个bug之后,我想添加错误路径去做演示,居然通过了,就很难受,只能待下次遇到的时候再来完善该博文了。

给TA打赏
共{{data.count}}人
人已打赏
安全技术

C++ explicit关键字

2022-1-11 12:36:11

安全经验

万事达卡和 VISA 就安全漏洞发出警告

2012-3-31 11:12:22

个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索