Damans227 commented on code in PR #13209:
URL: https://github.com/apache/cloudstack/pull/13209#discussion_r4283820239


##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -222,6 +215,44 @@ public void setResetTokenAndSend(UserAccount userAccount) {
                 userAccount, userAccount.getAccountId(), 
userAccount.getDomainId(), email, resetTokenExpiryTime);
     }
 
+    private String getResetLinkDomain(String requestDomain) {
+        if (StringUtils.isNotBlank(requestDomain)) {
+            logger.debug("Searching for GUI theme with common name that 
matches the request's domain: [{}]", requestDomain);
+            List<Long> commonNameDetails = 
guiThemeDetailsDao.listGuiThemeIdsByCommonName(requestDomain);
+
+            if (!commonNameDetails.isEmpty()) {
+                logger.debug("GUI theme with ID {} was found; using request's 
domain for password reset link.", commonNameDetails.get(0));
+                return requestDomain;
+            } else {
+                logger.debug("No GUI theme was found with a common name that 
matches the request's domain.");
+            }
+        }
+
+        String configurationDomain = UserPasswordResetDomainURL.value();
+        if (StringUtils.isNotBlank(configurationDomain)) {
+            logger.debug("Defaulting reset link's domain to the [{}] 
configuration value: [{}].", UserPasswordResetDomainURL.key(), 
UserPasswordResetDomainURL.value());
+            return configurationDomain;
+        }
+
+        logger.debug("Using the first IP address in the [{}] configuration for 
the reset password email domain because the [{}] configuration is not 
defined.", ManagementServerAddresses.key(), UserPasswordResetDomainURL.key());
+        return ManagementServerAddresses.value().split(",")[0];
+    }
+
+    private String formatResetLinkDomain(String resetLinkDomain) {
+        String protocol = ServerProperties.isHttpsEnabled() ? "https" : "http";
+
+        if (InetAddressUtils.isIPv4Address(resetLinkDomain)) {

Review Comment:
   if the host setting is a name instead of an ip, the link loses the port now. 
wont that break setups that serve the ui on 8080 with no proxy?



##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -222,6 +215,44 @@ public void setResetTokenAndSend(UserAccount userAccount) {
                 userAccount, userAccount.getAccountId(), 
userAccount.getDomainId(), email, resetTokenExpiryTime);
     }
 
+    private String getResetLinkDomain(String requestDomain) {
+        if (StringUtils.isNotBlank(requestDomain)) {
+            logger.debug("Searching for GUI theme with common name that 
matches the request's domain: [{}]", requestDomain);
+            List<Long> commonNameDetails = 
guiThemeDetailsDao.listGuiThemeIdsByCommonName(requestDomain);
+
+            if (!commonNameDetails.isEmpty()) {
+                logger.debug("GUI theme with ID {} was found; using request's 
domain for password reset link.", commonNameDetails.get(0));
+                return requestDomain;
+            } else {
+                logger.debug("No GUI theme was found with a common name that 
matches the request's domain.");
+            }
+        }
+
+        String configurationDomain = UserPasswordResetDomainURL.value();
+        if (StringUtils.isNotBlank(configurationDomain)) {
+            logger.debug("Defaulting reset link's domain to the [{}] 
configuration value: [{}].", UserPasswordResetDomainURL.key(), 
UserPasswordResetDomainURL.value());
+            return configurationDomain;
+        }
+
+        logger.debug("Using the first IP address in the [{}] configuration for 
the reset password email domain because the [{}] configuration is not 
defined.", ManagementServerAddresses.key(), UserPasswordResetDomainURL.key());
+        return ManagementServerAddresses.value().split(",")[0];
+    }
+
+    private String formatResetLinkDomain(String resetLinkDomain) {
+        String protocol = ServerProperties.isHttpsEnabled() ? "https" : "http";
+
+        if (InetAddressUtils.isIPv4Address(resetLinkDomain)) {
+            int port = protocol.equals("https") ? 
ServerProperties.getHttpsPort() : ServerProperties.getHttpPort();
+            resetLinkDomain = resetLinkDomain + ":" + port;
+        }
+
+        if (!resetLinkDomain.startsWith("http")) {

Review Comment:
   should this check for http:// and https:// like before? a name like 
httpd.example.com would never get the scheme added here



##########
server/src/main/java/org/apache/cloudstack/user/UserPasswordResetManagerImpl.java:
##########
@@ -222,6 +215,44 @@ public void setResetTokenAndSend(UserAccount userAccount) {
                 userAccount, userAccount.getAccountId(), 
userAccount.getDomainId(), email, resetTokenExpiryTime);
     }
 
+    private String getResetLinkDomain(String requestDomain) {
+        if (StringUtils.isNotBlank(requestDomain)) {
+            logger.debug("Searching for GUI theme with common name that 
matches the request's domain: [{}]", requestDomain);
+            List<Long> commonNameDetails = 
guiThemeDetailsDao.listGuiThemeIdsByCommonName(requestDomain);

Review Comment:
   does this also match removed themes? removing a theme keeps its details, so 
an old common name would still match here



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to