DB 접속정보 암호화를 위한 추상 클래스

 

import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang3.StringUtils;

/**
 * DB 접속 정보 암호화
 */
public abstract class SecurityBasicDataSource extends BasicDataSource {

	/**
	 * 사용자아이디 암호화 해제 설정
	 */
	public void setUsername(String username){
         try {
        	if(StringUtils.isNotEmpty(username))
        	{
        		super.setUsername(getDecryptValue(username));
        	} else {
				throw new Exception("usernmae is empty! username = [" + this.username + "]");
			}
		} catch (Exception e) {
			e.printStackTrace();
		} 
    }
   
    /**
     * 비밀번호 암호화 해제 설정
     */
    public void setPassword(String password) {
        try {
        	if(StringUtils.isNotEmpty(password))
        	{
        		super.setPassword(getDecryptValue(password));
        	} else {
        		throw new Exception("password is empty! password = [" + this.password + "]");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**
     * URL 암호화 해제 설정
     */
    public void setUrl(String url) {
		try {
			if (StringUtils.isNotEmpty(url)) {
				super.setUrl(getDecryptValue(url));
			} else {
				throw new Exception("url is empty! url = [" + this.url + "]");
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
    }
    
    /**
     * Parent method implement
     */
	@Override
	public Logger getParentLogger() throws SQLFeatureNotSupportedException {
		return Logger.getLogger(this.getClass().getName());
	}
    
	/**
	 * 복호화 알고리즘 인터페이스
	 * @param encryptValue
	 * @return decryptValue
	 * @throws Exception
	 * @since 2014. 3. 31.
	 */
    protected abstract String getDecryptValue(String encryptValue) throws Exception;
}



+ Recent posts