boolean includePort = ((inHttp && (serverPort == 80)) || (inHttps && (serverPort == 443)));
boolean includePort = true;
    public void commence(ServletRequest request, ServletResponse response,        AuthenticationException authException)        throws IOException, ServletException {        HttpServletRequest req = (HttpServletRequest) request;        String scheme = request.getScheme();        String serverName = request.getServerName();        int serverPort = portResolver.getServerPort(request);        String contextPath = req.getContextPath();        boolean inHttp = "http".equals(scheme.toLowerCase());        boolean inHttps = "https".equals(scheme.toLowerCase());        boolean includePort = ((inHttp && (serverPort == 80)) ||            (inHttps && (serverPort == 443)));        if ("http".equals(scheme.toLowerCase()) && (serverPort == 80)) {            includePort = false;        }        if ("https".equals(scheme.toLowerCase()) && (serverPort == 443)) {            includePort = false;        }        String redirectUrl = contextPath + loginFormUrl;        if (forceHttps && inHttp) {            Integer httpPort = new Integer(portResolver.getServerPort(request));            Integer httpsPort = (Integer) portMapper.lookupHttpsPort(httpPort);            if (httpsPort != null) {                if (httpsPort.intValue() == 443) {                    includePort = false;                } else {                    includePort = true;                }                redirectUrl = "https://" + serverName +                    ((includePort) ? (":" + httpsPort) : "") + contextPath +                    loginFormUrl;            }        }        if (logger.isDebugEnabled()) {            logger.debug("Redirecting to: " + redirectUrl);        }        ((HttpServletResponse) response).sendRedirect(((HttpServletResponse) response).encodeRedirectURL(                redirectUrl));    }