在配置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配置文件中的账号密码的更多相关文章

  1. Java 获取*.properties配置文件中的内容 ,常见的两种方法

    import java.io.InputStream; import java.util.Enumeration; import java.util.List; import java.util.Pr ...

  2. python3读取sqlyog配置文件中的MySql密码

    这个人有什么目的?: 我多多少少听过一些安全圈的大牛说到类似的思路,大意是可以通过扫描各种程序和服务的配置文件(比如SVN的文件,RSYNC的配置文件等), 从中发现敏感信息,从而找到入侵的突破口.沿 ...

  3. 在OpenErp的配置文件中为数据库密码加密

      openerp连接数据库的用户名和密码可以命令行给出, 也可以设置在配置文件中, 如下例所示: db_user = openerp db_password = laoliu 因为它使用了明文的密码 ...

  4. 单例模式读取properties配置文件中的信息

    public class ConfigManager {    private static ConfigManager config = null;    //创建Properties文件  读取配 ...

  5. properties 配置文件中值换行的问题

    在使用properties配置文件的时候我们经常碰到如下两个问题 1:当a=b中的b值内容特别长的时候为了阅读方便我们手动换行,但如果我们直接回车那么后面的数据就会丢失.那如何解决呢? 例如: a=a ...

  6. Windows环境下redis 配置文件中设置的密码无效

    当我们安装了redis服务后,发现在其配置文件redis.windows.conf(或redis.conf)设置了密码:requirepass ****** 但是打开redis-cli.exe后输入命 ...

  7. 利用PPPOE认证获取路由器中宽带账号密码

    前言 回家时买了一台极路由准备换掉家里老掉牙的阿里路由器,想进后台看一下宽带账号密码,咦???后台密码是什么来着??? 我陷入了沉思,家里的路由器一般都是pppoe拨号,而路由器在与pppoe认证服务 ...

  8. Java 读取application.properties配置文件中配置

    实际开发中若需要读取配置文件application.properties中的配置,代码如下.例:读取配置文件中name属性配置值: 代码如下: import org.springframework.c ...

  9. springboot项目logback.xml或者logback-spring.xml中读取不到application.yml或application.properties配置文件中的配置解决办法

    在springboot项目中我们可能想要实现不同环境的日志项目配置不同,比如我想让不同环境的日志路径不同. 这时候我们很容易想: 1.到将日志路径配置在springboot的:application- ...

随机推荐

  1. Linux下Thunderbird要安装的插件

    网络时代,总少不了跟邮件打交道,日常生活使用时多数是直接用网页版邮箱,在职场中一般要求用邮件客户端.使用Windows的朋友一般要么用Outlook,要么用Foxmail,其实,我们还有一个很不错的选 ...

  2. Castle ActiveRecord学习(六)数据验证

    参考.来源:http://www.cnblogs.com/Terrylee/archive/2006/04/13/374173.html https://github.com/castleprojec ...

  3. SystemTap 内核调试

    一.简介 Systemtap是一个Linux下的全新的调式.诊断和性能测量工具,是我目前所知的最强大的内核调试工具. 参考: http://m.blog.csdn.net/blog/hnllei/75 ...

  4. windows10 查看进程端口的情况

    以程序 winnfsd.exe 为例: 1 查看进程号 PID C:\Users\leo>tasklist|findstr winnfsd.exe winnfsd.exe             ...

  5. linux git server 简易搭建 (ssh访问)

    git的服务器搭建,如果无需权限控制,仅团队内部使用,初始化一个服务器仓库,其他人通过ssh访问这个文件夹即可.如需复杂的管理,建议使用gitlab. yum install git -y id gi ...

  6. [原创]Cef3 2623.1397 开启ppapi flash插件

    最近发现WKE播放Flash或者游戏时会有很多BUG,例如视频无法播放或者是Stage3D无法使用等问题. 经过研究应该是精简版本导致的,所以决定尝试使用CEF3移植入SOUI,但是DEMO中版本有点 ...

  7. mutex 实现 只允许一个进程

    static class Program { [STAThread] static void Main() { bool createdNew=false; Mutex mutex = new Mut ...

  8. Redis数据结构(六)

    Redis数据结构(Sort-set)(游戏排名和微博热点话题排名上应用): 特点:可存储有序但不重复的数据,根据分数指定存储顺序 1 Sort-set和Set的区别: (1)sort的每个成员都是以 ...

  9. 跳转AppStore 评分

    -(void)goToAppStore { NSString *str = [NSString stringWithFormat: @"itms-apps://ax.itunes.apple ...

  10. Linux文件扩展思考随笔

    Linux文件时间 ============================================================ ls -l 文件名 仅看到的是最后被修改的时间 Linux ...