日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 前端技术 > javascript >内容正文

javascript

Spring Boot集成Jasypt安全框架

發布時間:2024/9/21 javascript 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Spring Boot集成Jasypt安全框架 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

Jasypt安全框架提供了Spring的集成,主要是實現

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安全框架的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。