Spring Boot集成Jasypt安全框架
2016-09-05 08:47
1291 查看
Jasypt安全框架提供了Spring的集成,主要是实现
PlaceholderConfigurerSupport类或者其子类。
在Sring 3.1之后,则推荐使用PropertySourcesPlaceholderConfigurer类作为属性替换配置类,这里Spring集成Jasypt则使用Jasypt对属性替换配置类的实现。EncryptablePropertySourcesPlaceholderConfigurer。
在Spring中集成比较容易,而且Jasypt官方也给出了配置Bean的方式和使用Jasypt标签的XML方式,而Spring boot集成就稍微有点不一样,需要创建一个自动配置类,并且创建一个注入PlaceholderConfigurerSupport的jasypt实现了的Bean .
下面是一个使用示例:
配置文件的写入和Spring XML的基本类似。application.yml相当于applicationContext.xml,security.properties就是要进行属性替换的配置文件。
application.yml:
security.properties:
创建数据源的时候在使用属性参数时,会对ENC()中的内容进行解密,达到认证成功,创建数据源完成。
http://www.tuicool.com/articles/YZJNzy3
PlaceholderConfigurerSupport类或者其子类。
在Sring 3.1之后,则推荐使用PropertySourcesPlaceholderConfigurer类作为属性替换配置类,这里Spring集成Jasypt则使用Jasypt对属性替换配置类的实现。EncryptablePropertySourcesPlaceholderConfigurer。
在Spring中集成比较容易,而且Jasypt官方也给出了配置Bean的方式和使用Jasypt标签的XML方式,而Spring boot集成就稍微有点不一样,需要创建一个自动配置类,并且创建一个注入PlaceholderConfigurerSupport的jasypt实现了的Bean .
下面是一个使用示例:
import org.jasypt.encryption.pbe.StandardPBEByteEncryptor; import org.jasypt.encryption.pbe.StandardPBEStringEncryptor; import org.jasypt.spring31.properties.EncryptablePropertySourcesPlaceholderConfigurer; import org.springframework.boot.autoconfigure.AutoConfigureOrder; import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; import org.springframework.boot.autoconfigure.condition.SearchStrategy; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.support.PropertySourcesPlaceholderConfigurer; import org.springframework.core.Ordered; import org.springframework.core.io.ClassPathResource; /** * Author : secondriver * Date : 2016/5/26 */ @Configuration @AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) public class EncryptPropertyPlaceholderAutoConfiguration { private static final String SECURITY_PROPERTIES_FILE = "security.properties"; @Bean @ConditionalOnMissingBean(search = SearchStrategy.CURRENT) public static PropertySourcesPlaceholderConfigurer propertySourcesPlaceholderConfigurer() { StandardPBEStringEncryptor encryptor = new StandardPBEStringEncryptor(); encryptor.setAlgorithm(StandardPBEByteEncryptor.DEFAULT_ALGORITHM); encryptor.setPassword("security"); EncryptablePropertySourcesPlaceholderConfigurer configurer = new EncryptablePropertySourcesPlaceholderConfigurer(encryptor); configurer.setLocation(new ClassPathResource(SECURITY_PROPERTIES_FILE)); return configurer; } }
配置文件的写入和Spring XML的基本类似。application.yml相当于applicationContext.xml,security.properties就是要进行属性替换的配置文件。
application.yml:
spring: datasource: url: jdbc:mysql://localhost:3306/abc?useSSL=false username: root password: ${jdbc.password}
security.properties:
jdbc.password=ENC(jWgGELCkuxRuCI2Aqa6cF9VCxYpuKEZr)
创建数据源的时候在使用属性参数时,会对ENC()中的内容进行解密,达到认证成功,创建数据源完成。
http://www.tuicool.com/articles/YZJNzy3
相关文章推荐
- Spring Boot集成Jasypt安全框架
- spring boot 集成框架事例
- Spring Boot系列(十五) 安全框架Apache Shiro(三)RememberMe
- 微服务开发的入门级框架Spring Boot详解:集成Mybatis
- 在前后端分离的SpringBoot项目中集成Shiro权限框架
- Spring Boot之旅:Java安全框架Apache Shiro基本配置(一)
- jasypt 集成spring、spring boot 加密
- 《Spring Boot极简教程》第16章 Spring Boot安全集成Spring Security
- Spring Boot系列(十五) 安全框架Apache Shiro(一)基本功能
- Spring Boot actuator框架的一些安全考虑
- Spring Boot 集成 Spring Security 使用自定义的安全数据源
- 在前后端分离的SpringBoot项目中集成Shiro权限框架
- spring boot 集成框架事例
- Spring Boot系列(十五) 安全框架Apache Shiro(二)缓存-EhCache
- SpringBoot学习笔记-集成其他组件框架记录
- 集成springboot+thymeleaf+redis+加密框架+异常邮件提醒等技术的开源项目
- Spring Boot + Spring Cloud 实现权限管理系统 后端篇(十一):集成 Shiro 框架
- spring boot配置shiro安全框架及用户登录权限验证实现
- Springboot中集成Swagger2框架的方法