欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springboot集成SpringSecurity权限控制框架&添加账号密码--记录

程序员文章站 2022-09-08 23:43:48
一、pom.xml文件引入jar包org.springframework.bootspring-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