/* * 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 utils; import hsmexampleconsole.HSMExampleConsole; import java.io.FileInputStream; import java.io.InputStream; import java.util.Properties; import org.slf4j.Logger; import org.slf4j.LoggerFactory; /** * * @author TuoiCM */ public class Configuration { // private static final Logger logger = LoggerFactory.getLogger(HSMExampleConsole.class); private static Configuration instance; private Properties prop = new Properties(); private Properties description = new Properties(); private boolean showInfoLog; private boolean showErrorLog; private boolean showFatalLog; private boolean showWarnLog; private boolean showDebugLog; private String username; private String password; private String accessKey; private String secretKey; private String xApiKey; private String regionName; private String serviceName; private int expiration; private String ipList; private String jwtSoftKey; private String jwtSoftKeyPassword; private String hsmModule; private int hsmSlot; private String hsmPin; // // public static Configuration getInstance() { if (instance == null) { instance = new Configuration(); } return instance; } // // private Configuration() { try { ClassLoader loader = Thread.currentThread().getContextClassLoader(); InputStream appProperties = loader.getResourceAsStream("app.properties"); if (appProperties != null) { prop.load(appProperties); if (prop.keySet() == null) { String propertiesFile = Utils.getPropertiesFile("app.properties"); if (propertiesFile != null) { logger.info("READ THE CONFIGUATION FILE FROM " + propertiesFile); InputStream in = new FileInputStream(propertiesFile); prop.load(in); in.close(); } else { logger.error("CANNOT FIND ANY CONFIGUATION FILE. THIS IS A BIG PROBLEM"); } } appProperties.close(); } else { String propertiesFile = Utils.getPropertiesFile("app.properties"); if (propertiesFile != null) { logger.info("READ THE CONFIGUATION FILE FROM " + propertiesFile); prop.load(new FileInputStream(propertiesFile)); } else { logger.error("CANNOT FIND ANY CONFIGUATION FILE. THIS IS A BIG PROBLEM"); } } //------------------------------------------ username = prop.getProperty("tccservice.basic.auth.username"); password = prop.getProperty("tccservice.basic.auth.password"); accessKey = prop.getProperty("tccservice.aws.accesskey"); secretKey = prop.getProperty("tccservice.aws.secretkey"); xApiKey = prop.getProperty("tccservice.aws.xapikey"); regionName = prop.getProperty("tccservice.aws.regionname"); serviceName = prop.getProperty("tccservice.aws.servicename"); expiration = Integer.parseInt(prop.getProperty("tccservice.aws.expiration")); ipList = prop.getProperty("tccservice.ip.whitelist"); jwtSoftKey = prop.getProperty("tccservice.jwt.softkey"); jwtSoftKeyPassword = prop.getProperty("tccservice.jwt.softkeypassword"); hsmModule = prop.getProperty("tccservice.hsm.module"); hsmSlot = Integer.parseInt(prop.getProperty("tccservice.hsm.slot")); hsmPin = prop.getProperty("tccservice.hsm.pin"); } catch (Exception e) { logger.error("ERROR WHILE LOADING APP.PROPERTIES. DETAILS. " + Utils.printStackTrace(e)); } } // // public boolean isShowInfoLog() { return showInfoLog; } public boolean isShowErrorLog() { return showErrorLog; } public boolean isShowFatalLog() { return showFatalLog; } public boolean isShowWarnLog() { return showWarnLog; } public boolean isShowDebugLog() { return showDebugLog; } public Properties getDescription() { return description; } public String getUsername() { return username; } public String getPassword() { return password; } public String getAccessKey() { return accessKey; } public String getSecretKey() { return secretKey; } public String getxApiKey() { return xApiKey; } public String getRegionName() { return regionName; } public String getServiceName() { return serviceName; } public int getExpiration() { return expiration; } public String getIpList() { return ipList; } public String getJwtSoftKey() { return jwtSoftKey; } public String getJwtSoftKeyPassword() { return jwtSoftKeyPassword; } public String getHsmModule() { return hsmModule; } public int getHsmSlot() { return hsmSlot; } public String getHsmPin() { return hsmPin; } // }