SpringBoot2.X关闭Security的http认证

package com.imooc.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;

/**
 * @author sherry
 * @description
 * @date Create in 2020/4/11
 * @modified By:
 */

@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
    /**
     * spring boot1.5配置security关闭http基本验证,只需要在application.properites中配置
     * security.basic.enabled=false即可,
     * 但是spring boot 2.0+之后这样配置就不能生效了。
     * 但是我们可以在代码中去配置。
     * 我们可以新建一个类SecurityConfig 继承WebSecurityConfigurerAdapter类,
     * 然后重写父类中的configure(HttpSecurity http) 方法。
     * ————————————————
     *
     * @param http
     * @throws Exception
     */
    @Override
    protected void configure(HttpSecurity http) throws Exception {
        http.authorizeRequests()
                .anyRequest()
                .permitAll()
                .and()
                .logout()
                .permitAll();
    }
}

发布了102 篇原创文章 · 获赞 12 · 访问量 4万+

猜你喜欢

转载自blog.csdn.net/m0_37208669/article/details/105459313