configure(WebSecurity web)和configure(HttpSecurity http)的区别
时间: 2023-10-08 17:05:17 浏览: 35
在Spring Security中,configure(WebSecurity web)和configure(HttpSecurity http)都是WebSecurityConfigurerAdapter类中的方法,它们的作用略有不同。
- configure(WebSecurity web)方法是用来配置Spring Security的Filter链,它配置的是针对全局的Security策略,比如Security的忽略、Session管理、csrf防护、自定义Filter、异常处理等,这些配置对所有的请求都生效。
- configure(HttpSecurity http)方法是用来配置Http请求的安全处理,它配置的是针对Http请求的安全策略,比如授权、认证、登录、注销等安全控制,这些配置只对Http请求生效。
简单来说,configure(WebSecurity web)配置的是全局的安全策略,而configure(HttpSecurity http)则是对Http请求的安全策略进行配置,两者是互不干扰的。
相关问题
@Override protected void configure(HttpSecurity httpSecurity)是什么意思
`@Override` 是 Java 中的注解,表示该方法是重写了父类或接口中的方法,具有相同的方法名、参数列表和返回类型。
`configure(HttpSecurity httpSecurity)` 方法是 Spring Security 中的一个配置方法,用于配置 WebSecurity 配置类。它的作用是配置 HTTP 请求的安全处理,包括认证、授权、防止 CSRF 攻击等。
通过这个方法,我们可以设置登录页面、登录接口、退出登录接口、访问权限等等。在方法内部,我们可以通过调用 `HttpSecurity` 对象的一系列方法来配置具体的安全规则。
springsecurity configure
在Spring Security中,configure方法是一个关键的配置方法,用于配置安全相关的设置。在这个方法中,我们可以使用不同的重载方法来实现不同的配置。
首先,我们可以使用configure(AuthenticationManagerBuilder auth)方法来配置认证管理器的详细信息。在这个方法中,我们可以定义用户的认证方式,比如内存中的用户、数据库中的用户或者使用自定义的用户认证逻辑。通过这个方法,我们可以配置用户的身份验证方式和角色授权规则。
其次,我们可以使用configure(WebSecurity web)方法来配置WebSecurity。这个方法用于配置Spring Security对静态资源的访问控制。我们可以指定哪些静态资源不需要经过Spring Security的认证和授权。
最后,我们可以使用configure(HttpSecurity httpSecurity)方法来配置HttpSecurity。这个方法用于配置Web应用的安全性。我们可以定义哪些URL需要经过认证,哪些URL可以匿名访问,以及具体的权限规则和拦截策略。
综上所述,通过使用configure方法和其重载方法,我们可以根据需要配置Spring Security的认证和授权规则,定义静态资源的访问控制,以及设定Web应用的安全策略。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* *2* *3* [Spring Security之Config模块详解(TODO)](https://blog.csdn.net/chen517611641/article/details/73277337)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 100%"]
[ .reference_list ]
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)