cn.zhuqi.mavenssh.ext.util.PPConfigurer.java Source code

Java tutorial

Introduction

Here is the source code for cn.zhuqi.mavenssh.ext.util.PPConfigurer.java

Source

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package cn.zhuqi.mavenssh.ext.util;

import java.util.Properties;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
import org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer;

/**
 *
 * @author Administrator
 */
public class PPConfigurer extends PreferencesPlaceholderConfigurer {

    @Override
    protected void processProperties(ConfigurableListableBeanFactory beanFactory, Properties properties)
            throws BeansException {
        String originalUrl = properties.getProperty("jdbc.url");
        String originalUsername = properties.getProperty("jdbc.username");
        String originalPassword = properties.getProperty("jdbc.password");
        if (originalUrl != null) {
            String newUrl = SecUtil.decrypt(originalUrl);
            properties.put("jdbc.url", newUrl);
        }
        if (originalUsername != null) {
            String newUsername = SecUtil.decrypt(SecUtil.decrypt(originalUsername));
            properties.put("jdbc.username", newUsername);

        }
        if (originalPassword != null) {
            String newPassword = SecUtil.decrypt(SecUtil.decrypt(originalPassword));
            properties.put("jdbc.password", newPassword);
        }
        super.processProperties(beanFactory, properties);
    }
}