try to use httpservlet getServerName
package com.quorum.tessera.api.filter;
import com.quorum.tessera.config.ServerConfig;
+import com.quorum.tessera.ssl.util.HostnameUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -19,11 +20,14 @@ public class PrivateApiFilter implements ContainerRequestFilter {
private HttpServletRequest httpServletRequest;
- private final String hostname;
+ private final String bindingAddress;
+
+ private final String advertisedAddress;
public PrivateApiFilter(final ServerConfig serverConfig) {
try {
- this.hostname = new URI(serverConfig.getBindingAddress()).getHost();
+ this.bindingAddress = new URI(serverConfig.getBindingAddress()).getHost();
+ this.advertisedAddress = new URI(serverConfig.getHostName()).getHost();
} catch (final URISyntaxException ex) {
throw new RuntimeException(ex);
}
@@ -45,12 +49,11 @@ public class PrivateApiFilter implements ContainerRequestFilter {
return;
}
- final String remoteAddress = httpServletRequest.getRemoteAddr();
- final String remoteHost = httpServletRequest.getRemoteHost();
+ final String serverName = httpServletRequest.getServerName();
- LOGGER.info("Allowed host: {}, RemoteAddr: {}, RemoteHost: {}", hostname, remoteAddress, remoteHost);
+ LOGGER.info("Connecting host: {}, BindingAddress: {}, AdvertisedAddress: {}", serverName, bindingAddress, advertisedAddress);
- final boolean allowed = hostname.equals(remoteAddress) || hostname.equals(remoteHost);
+ final boolean allowed = serverName.equals(bindingAddress) || serverName.equals(advertisedAddress);
if (!allowed) {
requestContext.abortWith(Response.status(Response.Status.UNAUTHORIZED).build());
