Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some logic into JeevesNodeAwareLogoutSuccessHandler to deal with the case where no port is set in the settings manager #7124

Merged
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 @@ -917,12 +918,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