Spring Security HttpSecurity配置

Spring Security HttpSecurity配置,第1张

Spring Security HttpSecurity配置

requestMatchers()
配置URL是否将被该URL处理
SecurityFilterChain
。因此,如果一个URL不匹配它,整个URL
SecurityFilterChain
将被跳过,这意味着Spring Security在此之后将不再处理这个URL。如果未配置,则默认为匹配所有URL。

authorizeRequests()
配置为URL配置授权内容,例如是否需要进行身份验证或仅某些角色可以访问它等。它仅对由该SecurityFilterChain处理的那些URL(即与匹配的URL
requestMatchers()
)有效。

因此,回到您的第一个示例:

  http.requestMatchers() //1        .antMatchers("/login", "/oauth/authorize") //2        .and() //3        .authorizeRequests() //4        .anyRequest() //5        .authenticated() //6;

这意味着此SecurityFilterChain仅对

/login
和起作用
/oauth/authorize
。这两个URL都需要进行身份验证。此SecurityFilterChain将不会处理所有其他URL。因此,是否
/user/me
需要通过身份验证与Spring
Security无关。

http       .authorizeRequests() //1        .antMatchers("/login", "/oauth/authorize", "/img/**").permitAll() //2        .anyRequest() //3        .authenticated() //4

这意味着所有URL都将由此SecurityFilterChain(默认值为

requestMatchers()
)处理。
/login
/oauth/authorize
并且
/img/**
不需要任何授权。其他URL需要进行身份验证。



欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/zaji/4896156.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-11-12
下一篇2022-11-12

发表评论

登录后才能评论

评论列表(0条)

    保存