public WebReply getHTTPSRedirectWebReply ( HttpServletRequest req ) { Integer httpsPort = ( Integer ) SRTServletRequestUtils . getPrivateAttribute ( req , "SecurityRedirectPort" ) ; if ( httpsPort == null ) { Tr . error ( tc , "SSL_PORT_IS_NULL" ) ; // return a 403 if we don't know what the port is return new DenyReply ( "Resource must be accessed with a secure connection try again using an HTTPS connection." ) ; } URL originalURL = null ; String urlString = null ; try { urlString = req . getRequestURL ( ) . toString ( ) ; originalURL = new URL ( urlString ) ; } catch ( MalformedURLException e ) { Tr . error ( tc , "SSL_REQ_URL_MALFORMED_EXCEPTION" , urlString ) ; // return a 403 if we can't construct the redirect URL return new DenyReply ( "Resource must be accessed with a secure connection try again using an HTTPS connection." ) ; } String queryString = req . getQueryString ( ) ; try { URL redirectURL = new URL ( "https" , originalURL . getHost ( ) , httpsPort , originalURL . getPath ( ) + ( queryString == null ? "" : "?" + queryString ) ) ; //don't add cookies during the redirect as this results in duplicated and incomplete //cookies on the client side return new RedirectReply ( redirectURL . toString ( ) , null ) ; } catch ( MalformedURLException e ) { Tr . error ( tc , "SSL_REQ_URL_MALFORMED_EXCEPTION" , "https" + originalURL . getHost ( ) + httpsPort + originalURL . getPath ( ) + ( queryString == null ? "" : "?" + queryString ) ) ; // return a 403 if we can't construct the redirect URL return new DenyReply ( "Resource must be accessed with a secure connection try again using an HTTPS connection." ) ; } }
Get the new URL for the redirect which contains the https port .