Spring-secrity配置安全类

package com.example.demo.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 gf
 */
@Configuration
@EnableWebSecurity
public class WebSecurityConfig extends WebSecurityConfigurerAdapter {

    @Override
    protected void configure(HttpSecurity httpSecurity) throws Exception {
        httpSecurity
                //所有security全注解配置实现的开端,表示开始说明需要的授权
                        .authorizeRequests()
                //permitAll()表示这个不需要验证,全部放行 分两个部分 第一部分是拦截的路径 第二部分是访问该路径该路径需要的权限
                        .antMatchers("/**").permitAll()
                //任何的请求 认证后 才可以访问
                        .anyRequest().authenticated()
                //固定写法 表示使csrf拦截失效
                        .and().csrf().disable();

    }

}
©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容