springboot集成SpringSecurity权限控制框架&添加账号密码--记录
程序员文章站
2022-09-08 23:43:48
一、pom.xml文件引入jar包org.springframework.boot spring-boot-starter-security 二、application.properties配置#security...
一、pom.xml文件引入jar包
<!-- security -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
二、application.properties配置
#security
spring.security.user.name=admin
spring.security.user.password=admin
三、添加自定义配置类:SecurityConfig.java
package com.example.demo.springsecurity;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.builders.WebSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
@Configuration
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/list");
web.ignoring().antMatchers("/img/*");
}
@Override
public void configure(HttpSecurity http) throws Exception {
// 所用请求禁用security
http.authorizeRequests().anyRequest().permitAll().and().csrf().disable();
}
}
PS:最基本的使用方法,类似于tomcat的 conf/tomcat-users.xml 的用户配置,其它使用后续更新……
本文地址:https://blog.csdn.net/hjl0722/article/details/109641380
上一篇: 逆光小清新的实战技法与后期技巧详情介绍
下一篇: es6学习之解构时应该注意的点