【Quartz】解密properties配置文件中的账号密码
在配置quartz时,为了保密某些信息(特别是账号密码),通常会使用密文。那么在实际使用这些配置信息时,需要进行解密。本文提供一种解密方法如下:
(1)假设在properties文件中加密了账号密码
#============================================================================
# 基础配置
#============================================================================
org.quartz.scheduler.instanceName = JobScheduler
org.quartz.scheduler.instanceId = AUTO
org.quartz.scheduler.rmi.export = false
org.quartz.scheduler.rmi.proxy = false
org.quartz.scheduler.wrapJobExecutionInUserTransaction = false #============================================================================
# 调度器线程池配置
#============================================================================
org.quartz.threadPool.class = org.quartz.simpl.SimpleThreadPool
org.quartz.threadPool.threadCount = 20
org.quartz.threadPool.threadPriority = 5
org.quartz.jobStore.misfireThreshold = 60000 #============================================================================
# Configure JobStore 作业存储配置
#============================================================================
org.quartz.jobStore.class = org.quartz.impl.jdbcjobstore.JobStoreTX
org.quartz.jobStore.driverDelegateClass = org.quartz.impl.jdbcjobstore.StdJDBCDelegate
org.quartz.jobStore.useProperties = true
org.quartz.jobStore.tablePrefix = QRTZ_
org.quartz.jobStore.dataSource = qzDS org.quartz.jobStore.isClustered = true
org.quartz.jobStore.clusterCheckinInterval = 15000 #============================================================================
# JDBC
#============================================================================
org.quartz.dataSource.qzDS.driver = com.mysql.jdbc.Driver
org.quartz.dataSource.qzDS.URL = jdbc:mysql://localhost:3306/job_scheduler
org.quartz.dataSource.qzDS.user = *****************************
org.quartz.dataSource.qzDS.password = *****************************
org.quartz.dataSource.qzDS.maxConnections = 5
org.quartz.dataSource.qzDS.validationQuery = select 0 from dual
quartz_config.properties
注意:properties文件名不能是quartz.properties,否则Quartz可能还是会使用解密前的配置信息。
(2)写SchedulerConfig.java文件解密账号密码后使用
import org.quartz.Scheduler;
import org.quartz.ee.servlet.QuartzInitializerListener;
import org.springframework.beans.factory.config.PropertiesFactoryBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.scheduling.quartz.SchedulerFactoryBean;
import org.wcc.crypt.Crypter;
import org.wcc.crypt.CrypterFactory; import java.io.IOException;
import java.util.Properties; @Configuration //类似xml中的<beans>标签,一般和@bean注解一起使用来配置一个Bean,让Spring来管理它的生命周期
public class SchedulerConfig { @Bean(name="SchedulerFactory")
public SchedulerFactoryBean schedulerFactoryBean() throws IOException {
SchedulerFactoryBean factory = new SchedulerFactoryBean();
factory.setQuartzProperties(quartzProperties());
return factory;
} /**
* 加载Quartz配置
*
*/
@Bean
public Properties quartzProperties() throws IOException {
//使用Spring的PropertiesFactoryBean对属性配置文件进行管理
PropertiesFactoryBean propertiesFactoryBean = new PropertiesFactoryBean();
propertiesFactoryBean.setLocation(new ClassPathResource("/quartz_config.properties"));
propertiesFactoryBean.afterPropertiesSet(); Properties properties = propertiesFactoryBean.getObject(); // 账号密码解密
Crypter crypter = CrypterFactory.getCrypter(CrypterFactory.AES_CBC);
String user = properties.getProperty("org.quartz.dataSource.qzDS.user");
if (user != null) {
user = crypter.decrypt(user);
properties.setProperty("org.quartz.dataSource.qzDS.user", user);
}
String password = properties.getProperty("org.quartz.dataSource.qzDS.password");
if (password != null) {
password = crypter.decrypt(password);
properties.setProperty("org.quartz.dataSource.qzDS.password", password);
} return properties;
} /**
* 初始化Quartz监听器,让Spring boot启动时初始化Quartz
*
*/
@Bean
public QuartzInitializerListener executorListener() {
return new QuartzInitializerListener();
} /**
* 通过SchedulerFactoryBean获取Scheduler的实例
*/
@Bean(name="Scheduler")
public Scheduler scheduler() throws IOException {
return schedulerFactoryBean().getScheduler();
}
}
【Quartz】解密properties配置文件中的账号密码的更多相关文章
- Java 获取*.properties配置文件中的内容 ,常见的两种方法
import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...
- python3读取sqlyog配置文件中的MySql密码
这个人有什么目的?: 我多多少少听过一些安全圈的大牛说到类似的思路,大意是可以通过扫描各种程序和服务的配置文件(比如SVN的文件,RSYNC的配置文件等), 从中发现敏感信息,从而找到入侵的突破口.沿 ...
- 在OpenErp的配置文件中为数据库密码加密
openerp连接数据库的用户名和密码可以命令行给出, 也可以设置在配置文件中, 如下例所示: db_user = openerp db_password = laoliu 因为它使用了明文的密码 ...
- 单例模式读取properties配置文件中的信息
public class ConfigManager { private static ConfigManager config = null; //创建Properties文件 读取配 ...
- properties 配置文件中值换行的问题
在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ...
- Windows环境下redis 配置文件中设置的密码无效
当我们安装了redis服务后,发现在其配置文件redis.windows.conf(或redis.conf)设置了密码:requirepass ****** 但是打开redis-cli.exe后输入命 ...
- 利用PPPOE认证获取路由器中宽带账号密码
前言 回家时买了一台极路由准备换掉家里老掉牙的阿里路由器,想进后台看一下宽带账号密码,咦???后台密码是什么来着??? 我陷入了沉思,家里的路由器一般都是pppoe拨号,而路由器在与pppoe认证服务 ...
- Java 读取application.properties配置文件中配置
实际开发中若需要读取配置文件application.properties中的配置,代码如下.例:读取配置文件中name属性配置值: 代码如下: import org.springframework.c ...
- springboot项目logback.xml或者logback-spring.xml中读取不到application.yml或application.properties配置文件中的配置解决办法
在springboot项目中我们可能想要实现不同环境的日志项目配置不同,比如我想让不同环境的日志路径不同. 这时候我们很容易想: 1.到将日志路径配置在springboot的:application- ...
随机推荐
- 19-python 自己建立词库并实现文章汉语词频统计
首先在网上下载一个汉语词典的txt文件, 汉语词典 1.用正则去掉词语的解释,即提取出所有汉语词语: import re def getHanYuCi(st): p = re.compile(r'[. ...
- 获取地址栏的URL: PHP JS
1. PHP 获取上一页的URL 在php中可以通过内置的变量的属性来获取上一页的URL: $_SERVER['HTTP_REFERER']. 但是在IE中如果跳转是通过js函数如: window.l ...
- kaggle-泰坦尼克号Titanic-1
大家都熟悉的『Jack and Rose』的故事,豪华游艇倒了,大家都惊恐逃生,可是救生艇的数量有限,无法人人都有,副船长发话了『lady and kid first!』,所以是否获救其实并非随机,而 ...
- Shell编程-03-Shell中的特殊变量和扩展变量
目录 特殊变量 变量扩展 特殊变量 在Shell中的特殊变量主要分别两种位置参数变量.状态变量两种. 位置参数变量 Shell中的位置参数变量主要是指$0.$1.$#等,主要用于从命令 ...
- 线上服务 CPU 100%?一键定位 so easy!
转自: https://my.oschina.net/leejun2005/blog/1524687 摘要: 本文主要针对 Java 服务而言 0.背景 经常做后端服务开发的同学,或多或少都 ...
- Oracle E-Business Suite并发处理机制(Current Processing)
2012年写过一篇关于Oracle E-Business Suite并发管理器的文章,回头看之前总结的内容还是比较单薄,很多点没说到,最近在看这块的内容,索性再写一篇稍微完整的文章来. Oracle ...
- Intellij IDEA如何在一个窗口同时打开多个Maven项目
建立父目录,比如fatherProject,并将多个项目放入该父目录fatherProject下 File-Open...打开父目录fatherProject 引入pom.xml,打开Maven Pr ...
- EJB学习手记
周末两天,看了两天的ejb知识.公司有个转发消息的程序,里面是根据ejb/jms+cdi/event做的,这些之前没接触过. 总而言之,从中学到了很多东西,从ejb到webservice. jboss ...
- Postgresql fillfactor
一个表的填充因子(fillfactor)是一个介于 10 和 100 之间的百分数.100(完全填充)是默认值.如果指定了较小的填充因子,INSERT 操作仅按照填充因子指定的百分率填充表页.每个页上 ...
- Tempdb--查看tempdb使用的脚本
GO /****** Object: StoredProcedure [dbo].[usp_GetTempDBUsedSpace] Script Date: 03/05/2014 13:24:42 * ...