use of org.ambraproject.wombat.util.ClientEndpoint in project wombat by PLOS.
the class SpringSecurityConfiguration method validateHostname.
private void validateHostname(HttpServletRequest request) {
ClientEndpoint clientEndpoint = ClientEndpoint.get(request);
Set<String> hostNames = siteSet.getSites().stream().map((Site site) -> site.getRequestScheme().getHostName()).filter(Optional::isPresent).map(Optional::get).collect(Collectors.toSet());
if (!hostNames.isEmpty() && !hostNames.contains(clientEndpoint.getHostname())) {
throw new AccessDeniedException(String.format("Attempt to validate against foreign hostname %s. " + "Possible hijack attempt.", clientEndpoint.getHostname()));
}
}
use of org.ambraproject.wombat.util.ClientEndpoint in project wombat by PLOS.
the class Link method appendPrefix.
private void appendPrefix(StringBuilder sb, HttpServletRequest request) {
String protocol = new String("http");
String header = request.getHeader("X-Forwarded-Proto");
if (header != null && header.equals("https")) {
protocol = new String("https");
}
sb.append(protocol).append("://");
ClientEndpoint clientEndpoint = ClientEndpoint.get(request);
Optional<String> targetHostname = site.flatMap(s -> s.getRequestScheme().getHostName());
sb.append(targetHostname.orElse(clientEndpoint.getHostname()));
clientEndpoint.getPort().ifPresent(serverPort -> {
sb.append(':').append(serverPort);
});
}
Aggregations