/** * Whether the given targetUrl has a host that is a "foreign" system in which * case {@link HttpServletResponse#encodeRedirectURL} will not be applied. * This method returns {@code true} if the {@link #setHosts(String[])} * property is configured and the target URL has a host that does not match. * @param targetUrl the target redirect URL * @return {@code true} the target URL has a remote host, {@code false} if it * the URL does not have a host or the "host" property is not configured. * @since 4.3 */ protected boolean isRemoteHost(String targetUrl) { if (ObjectUtils.isEmpty(getHosts())) { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); if (StringUtils.isEmpty(targetHost)) { return false; } for (String host : getHosts()) { if (targetHost.equals(host)) { return false; } } return true; }
/** * Whether the given targetUrl has a host that is a "foreign" system in which * case {@link HttpServletResponse#encodeRedirectURL} will not be applied. * This method returns {@code true} if the {@link #setHosts(String[])} * property is configured and the target URL has a host that does not match. * @param targetUrl the target redirect URL * @return {@code true} the target URL has a remote host, {@code false} if it * the URL does not have a host or the "host" property is not configured. * @since 4.3 */ protected boolean isRemoteHost(String targetUrl) { if (ObjectUtils.isEmpty(getHosts())) { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); if (StringUtils.isEmpty(targetHost)) { return false; } for (String host : getHosts()) { if (targetHost.equals(host)) { return false; } } return true; }
/** * Whether the given targetUrl has a host that is a "foreign" system in which * case {@link HttpServletResponse#encodeRedirectURL} will not be applied. * This method returns {@code true} if the {@link #setHosts(String[])} * property is configured and the target URL has a host that does not match. * @param targetUrl the target redirect URL * @return {@code true} the target URL has a remote host, {@code false} if it * the URL does not have a host or the "host" property is not configured. * @since 4.3 */ protected boolean isRemoteHost(String targetUrl) { if (ObjectUtils.isEmpty(getHosts())) { return false; } String targetHost = UriComponentsBuilder.fromUriString(targetUrl).build().getHost(); if (StringUtils.isEmpty(targetHost)) { return false; } for (String host : getHosts()) { if (targetHost.equals(host)) { return false; } } return true; }