Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于配置context-paht为/api的配置 #30

Open
carryxiong opened this issue Feb 2, 2021 · 3 comments
Open

关于配置context-paht为/api的配置 #30

carryxiong opened this issue Feb 2, 2021 · 3 comments
Labels
bug Something isn't working enhancement New feature or request

Comments

@carryxiong
Copy link

你这样配置了这个context-path为api,然后白名单里面又设置/api/auth/login放行,但是这个配置不会生效。
springsecurity默认匹配url的时候,不会携带项目名,也就是你的/api。
这里问题很大,我调试了很久才找到问题。不明白你测试的时候怎么会通过的,你登录的时候接口不会报错吗。

@shaohan0228
Copy link

我也是,我默认context-path为/时,无法达到同样的效果
结果发现spring security做匹配的时候,是不会携带context-path做匹配的

// 登录接口
.antMatchers(HttpMethod.POST, SecurityConstants.LOGIN_WHITELIST).permitAll()
// 指定路径下的资源需要验证了的用户才能访问
.antMatchers(SecurityConstants.FILTER_ALL).authenticated()
.antMatchers(HttpMethod.DELETE, SecurityConstants.FILTER_ALL).hasRole("ADMIN")
// 其他都放行了
.anyRequest().permitAll()

这一段,实际上只有.anyRequest().permitAll()生效了

@carryxiong
Copy link
Author

我也是,我默认context-path为/时,无法达到同样的效果
结果发现spring security做匹配的时候,是不会携带context-path做匹配的

// 登录接口
.antMatchers(HttpMethod.POST, SecurityConstants.LOGIN_WHITELIST).permitAll()
// 指定路径下的资源需要验证了的用户才能访问
.antMatchers(SecurityConstants.FILTER_ALL).authenticated()
.antMatchers(HttpMethod.DELETE, SecurityConstants.FILTER_ALL).hasRole("ADMIN")
// 其他都放行了
.anyRequest().permitAll()

这一段,实际上只有.anyRequest().permitAll()生效了

是的,统统失败了,这个还是我调试了很久,找到匹配源码才发现/api并没有参与匹配,所以这个demo问题很大,就觉得作者调试的时候为啥这么严重的bug没发现。

@Snailclimb
Copy link
Owner

我脑子瓦特了!哈哈哈!已经修改了~感谢两位老哥 @carryxiong @shaohan0228 🤟

@Snailclimb Snailclimb added bug Something isn't working enhancement New feature or request labels Feb 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants