1717package com .cloud .utils .server ;
1818
1919import com .cloud .utils .crypt .EncryptionSecretKeyChecker ;
20+ import com .cloud .utils .StringUtils ;
2021import org .apache .commons .io .IOUtils ;
2122import org .apache .logging .log4j .Logger ;
2223import org .apache .logging .log4j .LogManager ;
2324
25+ import java .io .File ;
2426import java .io .IOException ;
2527import java .io .InputStream ;
2628import java .util .Properties ;
2729
2830public class ServerProperties {
2931 protected Logger logger = LogManager .getLogger (getClass ());
3032
33+ public static final String HTTP_ENABLE = "http.enable" ;
34+ public static final String HTTP_PORT = "http.port" ;
35+ public static final String HTTPS_ENABLE = "https.enable" ;
36+ public static final String HTTPS_PORT = "https.port" ;
37+ public static final String KEYSTORE_FILE = "https.keystore" ;
38+ public static final String PASSWORD_ENCRYPTION_TYPE = "password.encryption.type" ;
39+
3140 private static Properties properties = new Properties ();
3241 private static boolean loaded = false ;
33- public static final String passwordEncryptionType = "password.encryption.type" ;
42+
43+ private static int httpPort = 8080 ;
44+
45+ private static boolean httpsEnable = false ;
46+ private static int httpsPort = 8443 ;
3447
3548 public synchronized static Properties getServerProperties (InputStream inputStream ) {
3649 if (!loaded ) {
@@ -39,7 +52,7 @@ public synchronized static Properties getServerProperties(InputStream inputStrea
3952 serverProps .load (inputStream );
4053
4154 EncryptionSecretKeyChecker checker = new EncryptionSecretKeyChecker ();
42- checker .check (serverProps , passwordEncryptionType );
55+ checker .check (serverProps , PASSWORD_ENCRYPTION_TYPE );
4356
4457 if (EncryptionSecretKeyChecker .useEncryption ()) {
4558 EncryptionSecretKeyChecker .decryptAnyProperties (serverProps );
@@ -50,10 +63,29 @@ public synchronized static Properties getServerProperties(InputStream inputStrea
5063 IOUtils .closeQuietly (inputStream );
5164 }
5265
66+ httpPort = Integer .parseInt (serverProps .getProperty (ServerProperties .HTTP_PORT , "8080" ));
67+
68+ boolean httpsEnabled = Boolean .parseBoolean (serverProps .getProperty (ServerProperties .HTTPS_ENABLE , "false" ));
69+ String keystoreFile = serverProps .getProperty (KEYSTORE_FILE );
70+ httpsEnable = httpsEnabled && StringUtils .isNotEmpty (keystoreFile ) && new File (keystoreFile ).exists ();
71+ httpsPort = Integer .parseInt (serverProps .getProperty (ServerProperties .HTTPS_PORT , "8443" ));
72+
5373 properties = serverProps ;
5474 loaded = true ;
5575 }
5676
5777 return properties ;
5878 }
79+
80+ public static int getHttpPort () {
81+ return httpPort ;
82+ }
83+
84+ public static boolean isHttpsEnabled () {
85+ return httpsEnable ;
86+ }
87+
88+ public static int getHttpsPort () {
89+ return httpsPort ;
90+ }
5991}
0 commit comments