Skip to content

Commit

Permalink
Merge pull request #7124 from AstunTechnology/jeevesnodeawarelogout-p…
Browse files Browse the repository at this point in the history
…ort-fix

Added some logic into JeevesNodeAwareLogoutSuccessHandler to deal with the case where no port is set in the settings manager
  • Loading branch information
Jo Cook authored Jul 5, 2023
2 parents 94e9c5c + 28cb823 commit 67960df
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,15 @@
import org.fao.geonet.NodeInfo;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.constants.Geonet;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.security.core.Authentication;
import org.springframework.security.web.authentication.AbstractAuthenticationTargetUrlRequestHandler;
import org.springframework.security.web.authentication.logout.LogoutSuccessHandler;
import org.apache.commons.lang3.StringUtils;
import org.fao.geonet.kernel.setting.SettingInfo;


import java.io.IOException;
import java.net.MalformedURLException;
Expand Down Expand Up @@ -84,8 +88,10 @@ protected String determineTargetUrl(HttpServletRequest request, HttpServletRespo

String siteHost = settingManager.getValue(Settings.SYSTEM_SERVER_HOST);
String siteProtocol = settingManager.getValue(Settings.SYSTEM_SERVER_PROTOCOL);
int sitePort = settingManager.getValueAsInt(Settings.SYSTEM_SERVER_PORT);


// some conditional logic to handle the case where there's no port in the settings
SettingInfo si = new SettingInfo();
int sitePort = si.getSitePort();

if (!hostName.equalsIgnoreCase(siteHost) ||
!protocol.equalsIgnoreCase(siteProtocol) ||
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
import org.fao.geonet.kernel.search.index.BatchOpsMetadataReindexer;
import org.fao.geonet.kernel.setting.SettingManager;
import org.fao.geonet.kernel.setting.Settings;
import org.fao.geonet.kernel.setting.SettingInfo;
import org.fao.geonet.lib.Lib;
import org.fao.geonet.repository.*;
import org.fao.geonet.repository.specification.MetadataFileUploadSpecs;
Expand Down Expand Up @@ -916,12 +917,8 @@ private Element buildInfoElem(ServiceContext context, String id, String version)
// add baseUrl of this site (from settings)
String protocol = settingManager.getValue(Settings.SYSTEM_SERVER_PROTOCOL);
String host = settingManager.getValue(Settings.SYSTEM_SERVER_HOST);
String port = settingManager.getValue(Settings.SYSTEM_SERVER_PORT);
if (port.equals("80")) {
port = "";
} else {
port = ":" + port;
}
SettingInfo si = new SettingInfo();
String port = Integer.toString(si.getSitePort());
addElement(info, Edit.Info.Elem.BASEURL, protocol + "://" + host + port + context.getBaseUrl());
addElement(info, Edit.Info.Elem.LOCSERV, "/srv/en");
return info;
Expand Down
17 changes: 17 additions & 0 deletions core/src/main/java/org/fao/geonet/kernel/setting/SettingInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import org.fao.geonet.ApplicationContextHolder;
import org.fao.geonet.constants.Geonet;
import org.apache.commons.lang3.StringUtils;

import static org.fao.geonet.kernel.setting.SettingManager.isPortRequired;

Expand Down Expand Up @@ -68,6 +69,22 @@ public String getSiteUrl() {
return sb.toString();
}

/**
* Handle the case where the port in Settings is empty
*/

public Integer getSitePort() {
SettingManager settingManager = ApplicationContextHolder.get().getBean(SettingManager.class);

// some conditional logic to handle the case where there's no port in the settings
int sitePort = Geonet.DefaultHttpPort.HTTP;
if (StringUtils.isNumeric(settingManager.getValue(Settings.SYSTEM_SERVER_PORT))) {
sitePort = settingManager.getValueAsInt(Settings.SYSTEM_SERVER_PORT);
}

return sitePort;
}

//---------------------------------------------------------------------------

private Integer toIntOrNull(String key) {
Expand Down

0 comments on commit 67960df

Please sign in to comment.