取消springsecurity默認的登錄驗證

取消springsecurity默認的登錄驗證

問題描述

springboot 2.x,訪問swagger-ui.html時,會自動跳轉到springsecurity的login頁,自定義過濾路徑的攔截器無效。

解決方法一

修改依賴,項目因爲使用了一些加密功能才引入springsecurity依賴,原依賴如下

		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-starter-security</artifactId>
		</dependency>

查看所用到的類屬於哪個jar包,就只引入相關jar包
在這裏插入圖片描述

修改後的依賴爲

		<dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-core</artifactId>
        </dependency>

既保留了所需功能,又去除了權限驗證

方法二

禁用springsecurity的csrf驗證

@Configuration
@EnableWebSecurity
public class SecurityConfiguration extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http
        .csrf()
        .disable()
        .authorizeRequests()
        .anyRequest()
        .permitAll()
        .and()
        .logout()
        .permitAll();
    }

}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章