spring boot2.x集成spring security5与druid1.1.13(一)
版本:
spring boot 2.1.2.RELEASE
druid-spring-boot-starter 1.1.13
步骤:
一.maven
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.2.RELEASE</version>
</parent>
...
<dependency>
<groupId>com.alibaba</groupId>
<artifactId>druid-spring-boot-starter</artifactId>
<version>1.1.13</version>
</dependency>
二、yml配置
spring:
profiles: dev
datasource:
url: jdbc:mysql://127.0.0.1:3306/sina?useUnicode=true&characterEncoding=utf8&serverTimezone=UTC
name: druidDataSource
type: com.alibaba.druid.pool.DruidDataSource
# driver-class-name: com.mysql.cj.jdbc.Driver
username: root
password: root
druid:
#初始化大小,最小,最大
initial-size: 5
min-idle: 5
max-active: 20
#配置获取连接等待超时的时间
max-wait: 60000
#配置多久检测一次,检测需要关闭空间连接,单位ms
time-between-eviction-runs-millis: 60000
# 配置一个池中最小生存的时间
min-evictable-idle-time-millis: 300000
#用来检测连接是否有效的sql,要求是一个查询语句,常用select 'x'。如果validationQuery为null,testOnBorrow、testOnReturn、testWhileIdle都不会起作用
validation-query: SELECT 1 FROM DUAL
#建议配置为true,不影响性能,并且保证安全性。申请连接的时候检测,如果空闲时间大于timeBetweenEvictionRunsMillis,执行validationQuery检测连接是否有效。
test-while-idle: true
#申请连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能。
test-on-borrow: false
#归还连接时执行validationQuery检测连接是否有效,做了这个配置会降低性能
test-on-return: false
#要启用PSCache,必须配置大于0,当大于0时,poolPreparedStatements自动触发修改为true。在Druid中,不会存在Oracle下PSCache占用内存过多的问题,可以把这个数值配置大一些,比如说100
max-pool-prepared-statement-per-connection-size: 20
#属性类型是字符串,通过别名的方式配置扩展插件,常用的插件有:
#监控统计用的filter:stat
#日志用的filter:log4j
#防御sql注入的filter:wall
filters: stat,wall
#合并多个DruidDataSource的监控数据
use-global-data-source-stat: true
#通过connectProperties属性打开mergeSql功能;慢sql记录
connect-properties: druid.stat.mergeSql=true;druid.stat.slowSqlMillis=5000
# 配置监控服务器
stat-view-servlet:
login-username: admin
login-password: 123456
url-pattern: /druid/*
#添加ip白名单
allow: 127.0.0.1,192.168.0.5
#黑名单,黑白名单有重复,黑优先级高
#deny:
# 禁用HTML页面上的“Reset All”功能
reset-enable: false
# 必须启用,要不会404
enabled: true
web-stat-filter:
#添加过滤规则
url-pattern: /*
#忽略过滤格式
exclusions: "*.js,*.gif,*.jpg,*.png,*.css,*.ico"
enabled: true
async-close-connection-enable: true
aop-patterns: com.sswchat.service.*
filter:
stat:
db-type: mysql
log-slow-sql: true
slow-sql-millis: 2000
enabled: true jpa:
show-sql: true
hibernate:
ddl-auto: create-drop
我的环境在不加enable:true时访问http://127.0.0.1:8080/druid/login.html会报404
三、Security的SecurityConfig配置文件
@Configuration
@EnableWebSecurity
public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
public void configure(WebSecurity web) throws Exception {
web.ignoring().antMatchers("/css/**", "/sign", "/druid/**");
} @Override
protected void configure(HttpSecurity http) throws Exception {
http.authorizeRequests()
//.antMatchers("/css/**","/sign","/druid/**").permitAll()// 与/ css / **和/ index匹配的请求是完全可访问的
.antMatchers("/user/**").hasRole("USER")//与/ user / **匹配的请求要求用户进行身份验证,并且必须与USER角色相关联
.and().formLogin().loginPage("/login")
.failureUrl("/login-error")// 使用自定义登录页面和失败URL启用基于表单的身份验证
.and().csrf().disable();
}
}
配置好后,如果只重写configure(HttpSecurity http),会出现submitlogin 403错误。
spring boot2.x集成spring security5与druid1.1.13(一)的更多相关文章
- Spring Boot2.0使用Spring Security
一.Spring Secutity简介 Spring 是一个非常流行和成功的 Java 应用开发框架.Spring Security 基于 Spring 框架,提供了一套 Web 应用安全性 ...
- Spring Boot中集成Spring Security 专题
check to see if spring security is applied that the appropriate resources are permitted: @Configurat ...
- spring-boot-starter-security Spring Boot中集成Spring Security
spring security是springboot支持的权限控制系统. security.basic.authorize-mode 要使用权限控制模式. security.basic.enabled ...
- spring boot 2.0(一)权威发布spring boot2.0
Spring Boot2.0.0.RELEASE正式发布,在发布Spring Boot2.0的时候还出现一个小插曲,将Spring Boot2.0同步到Maven仓库的时候出现了错误,然后Spring ...
- Spring Boot2.0之整合事物管理
首先Spring 事务分类 1.声明事务 原理:基于编程事务的 2.编程事务 指定范围 扫包去解决 3.事务原理:AOP技术 通过环绕通知进行了拦截 使用Spring 事务注意事项: 不要tr ...
- Spring Boot2+Resilience4j实现容错之Bulkhead
Resilience4j是一个轻量级.易于使用的容错库,其灵感来自Netflix Hystrix,但专为Java 8和函数式编程设计.轻量级,因为库只使用Vavr,它没有任何其他外部库依赖项.相比之下 ...
- SpringMVC 3.1集成Spring Security 3.1
这篇算是一个入门文章,昨天看见有网友提问,spring mvc集成spring security 的时候出错,揣测了一下问题木有解决.我就帮忙给搭建了一个集成框架他说可以,他告诉我这样的文章网上少.今 ...
- 细说shiro之五:在spring框架中集成shiro
官网:https://shiro.apache.org/ 1. 下载在Maven项目中的依赖配置如下: <!-- shiro配置 --> <dependency> <gr ...
- Spring MVC集成Spring Data Reids和Spring Session实现Session共享
说明:Spring MVC中集成Spring Data Redis和Spring Session时版本是一个坑点,比如最新版本的Spring Data Redis已经不包含Jedis了,需要自行引入. ...
随机推荐
- Python基础教程(017)--执行Python的方式解释器运行及其他几种解释器简介
前言 了解Python的解释器 内容 Python的解释器乳交有多个语言的实现 cPython---官方版本的C语言实现 Jython--可以运行在java平台 IronPython--可以运行在.n ...
- mysql审计插件
Audit Plugin安装使用 原文: https://www.cnblogs.com/waynechou/p/mysql_audit.html#_label0 #有卸载方法 下载地址: htt ...
- 5 November in 614
Contest A. ssoj2964 交错的士兵 \(n\) 个数的排列,从左到右依次为 1, 2, -, \(n\).\(n\) 次操作,对于第 \(i\) 次操作,从左到右分成很多段,每段 \( ...
- MySQL 获取本月第一天、下个月第一天等
select curdate(); --获取当前日期 select last_day(curdate()); --获取当月最后一天. select DATE_ADD(curdate(),interva ...
- English-such as, for example, include and contain
such as 后接动词,通常用动名词,有时也可用动词原形 for example 后接动词,用动名词 include vt. 包含,包括 后接动词,用动名词 英英: If one thing inc ...
- 用 Flask 来写个轻博客 (35) — 使用 Flask-RESTful 来构建 RESTful API 之四
Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 POST 请求 身份认证 测试 前文列表 用 Flask 来写个轻博客 ...
- multiprocessing的Process类的简单使用
''' 跨平台的进程创建模块(multiprocessing) 支持跨平台 :window/linux multiprocessing提供一个Process类来代表一个进程对象 ''' from mu ...
- c# 读取和写入excel数据
1. 读取 DataTable GetDataFromExcelByConn(bool hasTitle = false){ OpenFileDialog openFile = new Open ...
- 在学react时候找不到static/js/bundle.js
看如图上面bundle.js,我在项目中和配置文件中都没有找到这个JS文件,然后我就觉得很诧异,然后各种查找,终于找到一篇文章,在此记录一下 第一步:npm run start ...
- python基础----以面向对象的思想编写游戏技能系统
1. 许多程序员对面向对象的思想都很了解,并且也能说得头头是道,但是在工作运用中却用的并不顺手. 当然,我也是其中之一. 不过最近我听了我们老师的讲课,对于面向对象的思想有了更深的理解,今天决定用一个 ...