java web 项目配置文件属性加密

2024-08-30 08:58

本文主要是介绍java web 项目配置文件属性加密,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1.未加密

config.properties配置

mail.host=192.168.0.100
mail.username=email_username
mail.password=email_password
mail.smtp.auth=true
mail.smtp.timeout=15000
mail.smtp.port=25

spring-context.xml

<!-- 加载 jdbc.properties 配置文件 -->
<bean  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath*:config.properties</value></list></property>
</bean>

2.已加密

config.properties配置

mail.host=192.168.0.100
mail.username=kpMmZE2dWLPujCGcj6ng6w==
mail.password=LPLELj4DeR/Z2CsM9GQY+A==
mail.smtp.auth=true
mail.smtp.timeout=15000
mail.smtp.port=25

AesPropertyPlaceholderConfigurer

package com.benz.utils;import java.util.Properties;import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;public class AesPropertyPlaceholderConfigurer extends PropertyPlaceholderConfigurer {@Overrideprotected void processProperties(ConfigurableListableBeanFactory beanFactoryToProcess, Properties props)throws BeansException {try {// 邮箱账号String mailUsername = props.getProperty("mail.username");// 邮箱密码String mailPassword = props.getProperty("mail.password");// 校验数据if (ObjectUtils.isNotEmpty(mailUsername) && ObjectUtils.isNotEmpty(mailPassword)) {// 解密属性值,并重新设置props.setProperty("mail.username", AESUtils.aesDecrypt(mailUsername));props.setProperty("mail.password", AESUtils.aesDecrypt(mailPassword));}super.processProperties(beanFactoryToProcess, props);} catch (Exception e) {e.printStackTrace();}}}

spring-context.xml

<!-- 加载 jdbc.properties 配置文件 -->
<!-- <bean  class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"> -->
<!-- 属性解密 -->
<bean  class="com.benz.utils.AesPropertyPlaceholderConfigurer"><property name="locations"><list><value>classpath*:config.properties</value><value>classpath*:jdbc.properties</value></list></property>
</bean>

 

 

 

 

这篇关于java web 项目配置文件属性加密的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/1120365

相关文章

Python Transformer 库安装配置及使用方法

《PythonTransformer库安装配置及使用方法》HuggingFaceTransformers是自然语言处理(NLP)领域最流行的开源库之一,支持基于Transformer架构的预训练模... 目录python 中的 Transformer 库及使用方法一、库的概述二、安装与配置三、基础使用:Pi

SpringBoot条件注解核心作用与使用场景详解

《SpringBoot条件注解核心作用与使用场景详解》SpringBoot的条件注解为开发者提供了强大的动态配置能力,理解其原理和适用场景是构建灵活、可扩展应用的关键,本文将系统梳理所有常用的条件注... 目录引言一、条件注解的核心机制二、SpringBoot内置条件注解详解1、@ConditionalOn

通过Spring层面进行事务回滚的实现

《通过Spring层面进行事务回滚的实现》本文主要介绍了通过Spring层面进行事务回滚的实现,包括声明式事务和编程式事务,具有一定的参考价值,感兴趣的可以了解一下... 目录声明式事务回滚:1. 基础注解配置2. 指定回滚异常类型3. ​不回滚特殊场景编程式事务回滚:1. ​使用 TransactionT

Spring LDAP目录服务的使用示例

《SpringLDAP目录服务的使用示例》本文主要介绍了SpringLDAP目录服务的使用示例... 目录引言一、Spring LDAP基础二、LdapTemplate详解三、LDAP对象映射四、基本LDAP操作4.1 查询操作4.2 添加操作4.3 修改操作4.4 删除操作五、认证与授权六、高级特性与最佳

Spring Shell 命令行实现交互式Shell应用开发

《SpringShell命令行实现交互式Shell应用开发》本文主要介绍了SpringShell命令行实现交互式Shell应用开发,能够帮助开发者快速构建功能丰富的命令行应用程序,具有一定的参考价... 目录引言一、Spring Shell概述二、创建命令类三、命令参数处理四、命令分组与帮助系统五、自定义S

SpringQuartz定时任务核心组件JobDetail与Trigger配置

《SpringQuartz定时任务核心组件JobDetail与Trigger配置》Spring框架与Quartz调度器的集成提供了强大而灵活的定时任务解决方案,本文主要介绍了SpringQuartz定... 目录引言一、Spring Quartz基础架构1.1 核心组件概述1.2 Spring集成优势二、J

Android Studio 配置国内镜像源的实现步骤

《AndroidStudio配置国内镜像源的实现步骤》本文主要介绍了AndroidStudio配置国内镜像源的实现步骤,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,... 目录一、修改 hosts,解决 SDK 下载失败的问题二、修改 gradle 地址,解决 gradle

SpringSecurity JWT基于令牌的无状态认证实现

《SpringSecurityJWT基于令牌的无状态认证实现》SpringSecurity中实现基于JWT的无状态认证是一种常见的做法,本文就来介绍一下SpringSecurityJWT基于令牌的无... 目录引言一、JWT基本原理与结构二、Spring Security JWT依赖配置三、JWT令牌生成与

Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码

《Java中Date、LocalDate、LocalDateTime、LocalTime、时间戳之间的相互转换代码》:本文主要介绍Java中日期时间转换的多种方法,包括将Date转换为LocalD... 目录一、Date转LocalDateTime二、Date转LocalDate三、LocalDateTim

如何配置Spring Boot中的Jackson序列化

《如何配置SpringBoot中的Jackson序列化》在开发基于SpringBoot的应用程序时,Jackson是默认的JSON序列化和反序列化工具,本文将详细介绍如何在SpringBoot中配置... 目录配置Spring Boot中的Jackson序列化1. 为什么需要自定义Jackson配置?2.