1 16 package org.jmanage.core.util; 17 18 import org.jmanage.core.util.Loggers; 19 import org.jmanage.core.util.CoreUtils; 20 21 import java.util.Properties ; 22 import java.util.logging.Logger ; 23 import java.util.logging.Level ; 24 import java.io.*; 25 26 34 public class JManageProperties extends Properties { 35 36 private static final Logger logger = 37 Loggers.getLogger(JManageProperties.class); 38 39 private String JMANAGE_PROPERTY_FILE = CoreUtils.getConfigDir() + 40 "/jmanage.properties"; 41 42 43 public static String LOGIN_MAX_ATTEMPTS = "login.maxAttempts"; 44 private static String JMANAGE_HASH_ALGORITHM = "jmanage.hash.algorithm"; 45 46 private static String JETTY_STOP_PORT = "STOP.PORT"; 47 48 49 private static String JMANAGE_URL = "jmanage.url"; 50 private static String CLI_SSL_IGNORE_BAD_SSL_CERT = 51 "jmanage.cli.ssl.ignoreBadSSLCertificate"; 52 private static String CLI_SSL_TRUST_STORE_PWD = 53 "jmanage.cli.ssl.trustStorePassword"; 54 55 56 private static String ALERT_EMAIL_FROM_NAME = "alert.email.from.name"; 57 private static String EMAIL_HOST = "email.host"; 58 private static String ALERT_EMAIL_FROM_EMAIL = "alert.email.from.email"; 59 60 61 private static String DISPLAY_MBEAN_CANONICAL_NAME = 62 "jmanage.objectName.displayCanonicalName"; 63 64 65 private static String BOOLEAN_INPUT_TYPE = "jmanage.html.booleanInputType"; 66 67 68 private static JManageProperties jManageProperties = new JManageProperties(); 69 70 76 private JManageProperties(){ 77 super(); 78 try{ 79 InputStream property = 80 new FileInputStream(JMANAGE_PROPERTY_FILE); 81 load(property); 82 }catch(Throwable e){ 83 logger.log(Level.WARNING, "Error reading " + 84 JMANAGE_PROPERTY_FILE + ". error: " + e.getMessage()); 85 } 86 } 87 88 93 public static JManageProperties getInstance() { 94 return jManageProperties; 95 } 96 97 public static String getJManageURL(){ 98 return jManageProperties.getProperty(JMANAGE_URL); 99 } 100 101 public static String getHashAlgorithm(){ 102 return jManageProperties.getProperty(JMANAGE_HASH_ALGORITHM, "SHA-1"); 103 } 104 105 public static String getStopPort(){ 106 return jManageProperties.getProperty(JETTY_STOP_PORT, "9099"); 107 } 108 109 public static boolean isIgnoreBadSSLCertificate(){ 110 String value = 111 jManageProperties.getProperty(CLI_SSL_IGNORE_BAD_SSL_CERT, "false"); 112 return value.equalsIgnoreCase("true"); 113 } 114 115 public static String getSSLTrustStorePassword(){ 116 return jManageProperties.getProperty(CLI_SSL_TRUST_STORE_PWD, "changeit"); 117 } 118 119 public void storeMaxLoginAttempts(int maxLoginAttempt){ 120 this.setProperty(LOGIN_MAX_ATTEMPTS, 121 Integer.toString(maxLoginAttempt)); 122 try{ 123 FileOutputStream fileOutputStream = 124 new FileOutputStream(JMANAGE_PROPERTY_FILE); 125 this.store(fileOutputStream, null); 126 } catch( Exception e){ 127 throw new RuntimeException (e); 128 } 129 } 130 131 public static String getAlertEmailFromName(){ 132 return jManageProperties.getProperty(ALERT_EMAIL_FROM_NAME); 133 } 134 public static String getEmailHost(){ 135 return jManageProperties.getProperty(EMAIL_HOST); 136 } 137 public static String getAlertEmailFrom(){ 138 return jManageProperties.getProperty(ALERT_EMAIL_FROM_EMAIL); 139 } 140 public static boolean isBooleanInputTypeRadio(){ 141 return "radio".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE)); 142 } 143 public static boolean isBooleanInputTypeCheckbox(){ 144 return "checkbox".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE)); 145 } 146 public static boolean isBooleanInputTypeSelect() { 147 return "select".equals(jManageProperties.getProperty(BOOLEAN_INPUT_TYPE)); 148 } 149 150 154 public static boolean isDisplayCanonicalName(){ 155 return "true".equals( 156 jManageProperties.getProperty(DISPLAY_MBEAN_CANONICAL_NAME)); 157 } 158 } 159 | Popular Tags |