Skip to content

Commit 538344d

Browse files
review comments
1 parent 911bb60 commit 538344d

File tree

4 files changed

+37
-31
lines changed

4 files changed

+37
-31
lines changed

client/src/main/java/org/apache/cloudstack/ServerDaemon.java

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,6 @@ public class ServerDaemon implements Daemon {
7474
private static final String BIND_INTERFACE = "bind.interface";
7575
private static final String CONTEXT_PATH = "context.path";
7676
private static final String SESSION_TIMEOUT = "session.timeout";
77-
private static final String HTTP_ENABLE = "http.enable";
78-
private static final String HTTP_PORT = "http.port";
79-
private static final String HTTPS_PORT = "https.port";
8077
private static final String KEYSTORE_PASSWORD = "https.keystore.password";
8178
private static final String WEBAPP_DIR = "webapp.dir";
8279
private static final String ACCESS_LOG = "access.log";
@@ -138,10 +135,10 @@ public void init(final DaemonContext context) {
138135
}
139136
setBindInterface(properties.getProperty(BIND_INTERFACE, null));
140137
setContextPath(properties.getProperty(CONTEXT_PATH, "/client"));
141-
setHttpEnable(Boolean.valueOf(properties.getProperty(HTTP_ENABLE, "true")));
142-
setHttpPort(Integer.valueOf(properties.getProperty(HTTP_PORT, "8080")));
138+
setHttpEnable(Boolean.valueOf(properties.getProperty(ServerProperties.HTTP_ENABLE, "true")));
139+
setHttpPort(Integer.valueOf(properties.getProperty(ServerProperties.HTTP_PORT, "8080")));
143140
setHttpsEnable(Boolean.valueOf(properties.getProperty(ServerProperties.HTTPS_ENABLE, "false")));
144-
setHttpsPort(Integer.valueOf(properties.getProperty(HTTPS_PORT, "8443")));
141+
setHttpsPort(Integer.valueOf(properties.getProperty(ServerProperties.HTTPS_PORT, "8443")));
145142
setKeystoreFile(properties.getProperty(ServerProperties.KEYSTORE_FILE));
146143
setKeystorePassword(properties.getProperty(KEYSTORE_PASSWORD));
147144
setWebAppLocation(properties.getProperty(WEBAPP_DIR));

server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ public interface UserPasswordResetManager {
7878

7979
ConfigKey<String> UserPasswordResetDomainURL = new ConfigKey<>(ConfigKey.CATEGORY_ADVANCED,
8080
String.class, "user.password.reset.mail.domain.url", null,
81-
"Domain URL (along with http:// or https:// as applicable) for reset password links sent to the user via email. " +
81+
"Domain URL (along with scheme - http:// or https:// and port as applicable) for reset password links sent to the user via email. " +
8282
"If this is not set, CloudStack would determine the domain url based on the first management server from 'host' setting " +
8383
"and http scheme based on the https.enabled flag from server.properties file in the management server.", true,
8484
ConfigKey.Scope.Global);

server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -183,17 +183,22 @@ public void setResetTokenAndSend(UserAccount userAccount) {
183183
final String subject = "Password Reset Request";
184184
String domainUrl = UserPasswordResetDomainURL.value();
185185
if (StringUtils.isBlank(domainUrl)) {
186-
domainUrl = ManagementServerAddresses.value().split(",")[0];
187-
}
188-
domainUrl = domainUrl.replaceAll("/+$", "");
189-
190-
if (!domainUrl.startsWith("http://") && !domainUrl.startsWith("https://")) {
186+
String mgmtServerAddr = ManagementServerAddresses.value().split(",")[0];
187+
if (ServerProperties.isHttpsEnabled()) {
188+
domainUrl = "https://" + mgmtServerAddr + ":" + ServerProperties.getHttpsPort();
189+
} else {
190+
domainUrl = "http://" + mgmtServerAddr + ":" + ServerProperties.getHttpPort();
191+
}
192+
} else if (!domainUrl.startsWith("http://") && !domainUrl.startsWith("https://")) {
191193
if (ServerProperties.isHttpsEnabled()) {
192194
domainUrl = "https://" + domainUrl;
193195
} else {
194196
domainUrl = "http://" + domainUrl;
195197
}
196198
}
199+
200+
domainUrl = domainUrl.replaceAll("/+$", "");
201+
197202
String resetLink = String.format("%s/client/#/user/resetPassword?username=%s&token=%s",
198203
domainUrl, username, resetToken);
199204
String content = getMessageBody(userAccount, resetToken, resetLink);

utils/src/main/java/com/cloud/utils/server/ServerProperties.java

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,29 +16,35 @@
1616
// under the License.
1717
package com.cloud.utils.server;
1818

19-
import com.cloud.utils.PropertiesUtil;
2019
import com.cloud.utils.crypt.EncryptionSecretKeyChecker;
2120
import com.cloud.utils.StringUtils;
2221
import org.apache.commons.io.IOUtils;
2322
import org.apache.logging.log4j.Logger;
2423
import org.apache.logging.log4j.LogManager;
2524

2625
import java.io.File;
27-
import java.io.FileInputStream;
2826
import java.io.IOException;
2927
import java.io.InputStream;
3028
import java.util.Properties;
3129

3230
public class ServerProperties {
3331
protected Logger logger = LogManager.getLogger(getClass());
3432

33+
public static final String HTTP_ENABLE = "http.enable";
34+
public static final String HTTP_PORT = "http.port";
3535
public static final String HTTPS_ENABLE = "https.enable";
36+
public static final String HTTPS_PORT = "https.port";
3637
public static final String KEYSTORE_FILE = "https.keystore";
3738
public static final String PASSWORD_ENCRYPTION_TYPE = "password.encryption.type";
3839

3940
private static Properties properties = new Properties();
4041
private static boolean loaded = false;
4142

43+
private static int httpPort = 8080;
44+
45+
private static boolean httpsEnable = false;
46+
private static int httpsPort = 8443;
47+
4248
public synchronized static Properties getServerProperties(InputStream inputStream) {
4349
if (!loaded) {
4450
Properties serverProps = new Properties();
@@ -57,31 +63,29 @@ public synchronized static Properties getServerProperties(InputStream inputStrea
5763
IOUtils.closeQuietly(inputStream);
5864
}
5965

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+
6073
properties = serverProps;
6174
loaded = true;
6275
}
6376

6477
return properties;
6578
}
6679

67-
public static boolean isHttpsEnabled() {
68-
final File confFile = PropertiesUtil.findConfigFile("server.properties");
69-
if (confFile == null) {
70-
return false;
71-
}
80+
public static int getHttpPort() {
81+
return httpPort;
82+
}
7283

73-
try {
74-
InputStream is = new FileInputStream(confFile);
75-
final Properties properties = ServerProperties.getServerProperties(is);
76-
if (properties == null) {
77-
return false;
78-
}
84+
public static boolean isHttpsEnabled() {
85+
return httpsEnable;
86+
}
7987

80-
boolean httpsEnable = Boolean.parseBoolean(properties.getProperty(HTTPS_ENABLE, "false"));
81-
String keystoreFile = properties.getProperty(KEYSTORE_FILE);
82-
return httpsEnable && StringUtils.isNotEmpty(keystoreFile) && new File(keystoreFile).exists();
83-
} catch (final IOException e) {
84-
return false;
85-
}
88+
public static int getHttpsPort() {
89+
return httpsPort;
8690
}
8791
}

0 commit comments

Comments
 (0)