springboot集成SpringSecurity权限控制框架&添加账号密码--记录
程序员文章站
2022-04-21 15:27:01
一、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
上一篇: 国家规定:社区团购要严格遵守“九个不得”
下一篇: 你再少还能有我少