在URL中获取实际地址,而不是代理地址网址

时间:2019-01-14 07:17:28

标签: java apache azure-active-directory reverse-proxy mod-proxy

我已经以example.test.com的身份对Web应用程序进行了反向代理,并且实际地址为*.*.*.56,当我按下example.test.com时它工作正常,但是当我添加Office 365身份验证时,我通过调试我的Java使用httpRequest.getRequestURL();命令,我需要代理地址,但是我得到的实际地址为***.***.0.56

我尝试使用Java更改URL,但没有运气

String currentUri = httpRequest.getRequestURL().toString();

我需要在代理服务器中进行设置的任何解决方案,以在当前URL中获取代理地址。

我在使用Aure的AAD时说错了,但在反向代理中却是example.test.com

{“ error_description”:“ AADSTS70002:验证凭据时出错。AADSTS50011:回复地址'https:// *。 .56:8080 / abc /'与回复地址'不匹配请求授权代码时提供https://example.test.com/。\r\n跟踪ID:gddsgc97-5667-6574g-9897h-97536vg688 \ r \ n相关ID:565gtdf-j7573-087f-9745a-792835t647 \ r \ nTimestamp:2019-01-14 10:09:54Z“,”错误“:” invalid_client“}

1 个答案:

答案 0 :(得分:1)

您可以在请求标头X-Forwarded-Host中获得原始主机名。

更新:带有过滤器

@WebFilter(filterName = "RequestURLFilter", urlPatterns = {"/*"})
public class RequestURLFilter implements Filter {
    private FilterConfig filterConfig = null;

    public RequestURLFilter() {
    }    

    @Override
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain)
            throws IOException, ServletException {
        ServletRequest wrappedRequest
                = new HttpServletRequestWrapper((HttpServletRequest) request) {
            @Override
            public String getServerName() {
                String forwarded = getHeader("X-Forwarded-Host");
                if (forwarded != null) {
                    return forwarded;
                } else {
                    return super.getServerName();
                }
            }

            @Override
            public String getRequestURI() {
                String info = getPathInfo();
                if (info == null) {
                    info = "";
                }
                return getScheme() + "://" + getServerName() + getContextPath()
                        + getServletPath() + info;
            }

            @Override
            public StringBuffer getRequestURL() {
                return new StringBuffer(getRequestURI());
            }
        };
        chain.doFilter(wrappedRequest, response);
    }

    public FilterConfig getFilterConfig() {
        return (this.filterConfig);
    }

    public void setFilterConfig(FilterConfig filterConfig) {
        this.filterConfig = filterConfig;
    }

    @Override
    public void init(FilterConfig filterConfig) {        
        this.filterConfig = filterConfig;
    }

    @Override
    public void destroy() {
    }
}