Example usage for org.springframework.security.web PortResolver getServerPort

List of usage examples for org.springframework.security.web PortResolver getServerPort

Introduction

In this page you can find the example usage for org.springframework.security.web PortResolver getServerPort.

Prototype

int getServerPort(ServletRequest request);

Source Link

Document

Indicates the port the ServletRequest was received on.

Usage

From source file:org.springframework.security.web.savedrequest.DefaultSavedRequest.java

@SuppressWarnings("unchecked")
public DefaultSavedRequest(HttpServletRequest request, PortResolver portResolver) {
    Assert.notNull(request, "Request required");
    Assert.notNull(portResolver, "PortResolver required");

    // Cookies/*from   w w  w .j  a  v  a 2s  . c om*/
    addCookies(request.getCookies());

    // Headers
    Enumeration<String> names = request.getHeaderNames();

    while (names.hasMoreElements()) {
        String name = names.nextElement();
        // Skip If-Modified-Since and If-None-Match header. SEC-1412, SEC-1624.
        if (HEADER_IF_MODIFIED_SINCE.equalsIgnoreCase(name) || HEADER_IF_NONE_MATCH.equalsIgnoreCase(name)) {
            continue;
        }
        Enumeration<String> values = request.getHeaders(name);

        while (values.hasMoreElements()) {
            this.addHeader(name, values.nextElement());
        }
    }

    // Locales
    addLocales(request.getLocales());

    // Parameters
    addParameters(request.getParameterMap());

    // Primitives
    this.method = request.getMethod();
    this.pathInfo = request.getPathInfo();
    this.queryString = request.getQueryString();
    this.requestURI = request.getRequestURI();
    this.serverPort = portResolver.getServerPort(request);
    this.requestURL = request.getRequestURL().toString();
    this.scheme = request.getScheme();
    this.serverName = request.getServerName();
    this.contextPath = request.getContextPath();
    this.servletPath = request.getServletPath();
}

From source file:org.springframework.security.web.savedrequest.DefaultSavedRequest.java

/**
 * Determines if the current request matches the <code>DefaultSavedRequest</code>.
 * <p>/*ww w  .  ja va2s . c  o  m*/
 * All URL arguments are considered but not cookies, locales, headers or parameters.
 *
 * @param request      the actual request to be matched against this one
 * @param portResolver used to obtain the server port of the request
 * @return true if the request is deemed to match this one.
 */
public boolean doesRequestMatch(HttpServletRequest request, PortResolver portResolver) {

    if (!propertyEquals("pathInfo", this.pathInfo, request.getPathInfo())) {
        return false;
    }

    if (!propertyEquals("queryString", this.queryString, request.getQueryString())) {
        return false;
    }

    if (!propertyEquals("requestURI", this.requestURI, request.getRequestURI())) {
        return false;
    }

    if (!"GET".equals(request.getMethod()) && "GET".equals(method)) {
        // A save GET should not match an incoming non-GET method
        return false;
    }

    if (!propertyEquals("serverPort", Integer.valueOf(this.serverPort),
            Integer.valueOf(portResolver.getServerPort(request)))) {
        return false;
    }

    if (!propertyEquals("requestURL", this.requestURL, request.getRequestURL().toString())) {
        return false;
    }

    if (!propertyEquals("scheme", this.scheme, request.getScheme())) {
        return false;
    }

    if (!propertyEquals("serverName", this.serverName, request.getServerName())) {
        return false;
    }

    if (!propertyEquals("contextPath", this.contextPath, request.getContextPath())) {
        return false;
    }

    return propertyEquals("servletPath", this.servletPath, request.getServletPath());

}