public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        ServletRequest xRequest;
        if (request instanceof HttpServletRequest && response instanceof HttpServletResponse) {
            if (!request.isSecure() && matchesOne(request.getRemoteAddr(), securedRemoteAddresses)) {
                xRequest = new HttpServletRequestWrapper((HttpServletRequest) request) {
                    @Override
                    public boolean isSecure() {
                        return true;
                    }
                };
            } else {
                xRequest = request;
            }
            if (logger.isDebugEnabled()) {
                logger.debug("Incoming request uri=" + ((HttpServletRequest) request).getRequestURI() + " with originalSecure='"
                        + request.isSecure() + "', remoteAddr='" + request.getRemoteAddr() + "' will be seen with newSecure='"
                        + xRequest.isSecure() + "'");
            }
        } else {
            xRequest = request;
        }

        chain.doFilter(xRequest, response);
    }