当前位置: 首页 > news >正文

第8讲项目整合SpringSecurity

pom.xml加下springsecurity依赖

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-security</artifactId>
</dependency>

SecurityConfig配置文件:

package com.java1234.config;import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.method.configuration.EnableGlobalMethodSecurity;
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;
import org.springframework.security.config.http.SessionCreationPolicy;/*** spring security配置* @author java1234_小锋 (公众号:java1234)* @site www.java1234.vip* @company 南通小锋网络科技有限公司*/
@Configuration
@EnableWebSecurity
@EnableGlobalMethodSecurity(prePostEnabled = true)
public class SecurityConfig extends WebSecurityConfigurerAdapter {private static final String URL_WHITELIST[] ={"/login","/logout","/captcha","/password","/image/**","/test/**"} ;@Overrideprotected void configure(AuthenticationManagerBuilder auth) throws Exception {super.configure(auth);}@Overrideprotected void configure(HttpSecurity http) throws Exception {// 开启跨域 以及csrf攻击 关闭http.cors().and().csrf().disable()// 登录登出配置.formLogin()
//            .successHandler()
//            .failureHandler()
//        .and()
//            .logout()
//            .logoutSuccessHandler()// session禁用配置.and().sessionManagement().sessionCreationPolicy(SessionCreationPolicy.STATELESS)  // 无状态// 拦截规则配置.and().authorizeRequests().antMatchers(URL_WHITELIST).permitAll()  // 白名单 放行.anyRequest().authenticated();// 异常处理配置// 自定义过滤器配置}
}

相关文章:

  • Qt:自定义信号,信号emit,传参问题,信号槽与moc
  • 蓝桥杯刷题--python-6
  • 【后端高频面试题--Nginx篇】
  • OpenCV-36 多边形逼近与凸包
  • 【C++】C++11上
  • OCP的operator——(4)用户任务:使用Operator创建etcd集群
  • ubuntu屏幕小的解决办法
  • ES实战--集群扩展
  • 专业140+总分420+东北大学841通信专业基础考研经验东大电子信息与通信工程,真题,大纲,参考书。
  • 【Spring面试题】
  • 跟着pink老师前端入门教程-day26
  • Acwing语法基础课 8.STL(笔记)
  • 【sgCreateTableColumn】自定义小工具:敏捷开发→自动化生成表格列html代码(表格列生成工具)[基于el-table-column]
  • Flume(二)【Flume 进阶使用】
  • .NET开源的一个小而快并且功能强大的 Windows 动态桌面软件 - DreamScene2
  • [NodeJS] 关于Buffer
  • 【译】React性能工程(下) -- 深入研究React性能调试
  • ComponentOne 2017 V2版本正式发布
  • FastReport在线报表设计器工作原理
  • flask接收请求并推入栈
  • HTML5新特性总结
  • Lucene解析 - 基本概念
  • Mac转Windows的拯救指南
  • Octave 入门
  • SegmentFault 社区上线小程序开发频道,助力小程序开发者生态
  • V4L2视频输入框架概述
  • 工程优化暨babel升级小记
  • 观察者模式实现非直接耦合
  • 每个JavaScript开发人员应阅读的书【1】 - JavaScript: The Good Parts
  • 面试题:给你个id,去拿到name,多叉树遍历
  • 微信小程序设置上一页数据
  • 为物联网而生:高性能时间序列数据库HiTSDB商业化首发!
  • 学习Vue.js的五个小例子
  • 移动端解决方案学习记录
  • 用Python写一份独特的元宵节祝福
  • kubernetes资源对象--ingress
  • 我们雇佣了一只大猴子...
  • #常见电池型号介绍 常见电池尺寸是多少【详解】
  • (Matalb时序预测)WOA-BP鲸鱼算法优化BP神经网络的多维时序回归预测
  • (ZT)薛涌:谈贫说富
  • (全部习题答案)研究生英语读写教程基础级教师用书PDF|| 研究生英语读写教程提高级教师用书PDF
  • (十三)Maven插件解析运行机制
  • (五)c52学习之旅-静态数码管
  • (一)kafka实战——kafka源码编译启动
  • ******之网络***——物理***
  • .MSSQLSERVER 导入导出 命令集--堪称经典,值得借鉴!
  • .mysql secret在哪_MYSQL基本操作(上)
  • .NET CF命令行调试器MDbg入门(二) 设备模拟器
  • .NET Core 控制台程序读 appsettings.json 、注依赖、配日志、设 IOptions
  • .netcore 获取appsettings
  • .net分布式压力测试工具(Beetle.DT)
  • .net连接MySQL的方法
  • @synthesize和@dynamic分别有什么作用?
  • [Angular] 笔记 18:Angular Router
  • [BUUCTF]-PWN:[极客大挑战 2019]Not Bad解析