Skip to content
Snippets Groups Projects
Unverified Commit b95b0229 authored by Jaime Pérez Crespo's avatar Jaime Pérez Crespo
Browse files

Add a configuration option to specify the base URL for the application protected.

parent fe8688bb
No related branches found
No related tags found
No related merge requests found
......@@ -30,6 +30,28 @@ $config = array(
*/
'baseurlpath' => 'simplesaml/',
/*
* The 'application' configuration array groups a set configuration options
* relative to an application protected by SimpleSAMLphp.
*/
//'application' => array(
/*
* The 'baseURL' configuration option allows you to specify a protocol,
* host and optionally a port that serves as the canonical base for all
* your application's URLs. This is useful when the environment
* observed in the server differs from the one observed by end users,
* for example, when using a load balancer to offload TLS.
*
* Note that this configuration option does not allow setting a path as
* part of the URL. If your setup involves URL rewriting or any other
* tricks that would result in SimpleSAMLphp observing a URL for your
* application's scripts different than the canonical one, you will
* need to compute the right URLs yourself and pass them dynamically
* to SimpleSAMLphp's API.
*/
//'baseURL' => 'https://example.com'
//),
/*
* The following settings are *filesystem paths* which define where
* SimpleSAMLphp can find or write the following things:
......
......@@ -778,15 +778,26 @@ class HTTP
* directory of SimpleSAMLphp, the URI does not contain its relative path, and $uri_pos is false.
*
* It doesn't matter which one of those cases we have. We just know we can't apply our base URL to the
* current URI, so we need to build it back from the PHP environment.
* current URI, so we need to build it back from the PHP environment, unless we have a base URL specified
* for this case in the configuration. First, check if that's the case.
*/
$protocol = 'http';
$protocol .= (self::getServerHTTPS()) ? 's' : '';
$protocol .= '://';
$hostname = self::getServerHost();
$port = self::getServerPort();
return $protocol.$hostname.$port.$_SERVER['REQUEST_URI'];
/** @var \SimpleSAML_Configuration $appcfg */
$appcfg = $cfg->getConfigItem('application', array());
$appurl = $appcfg->getString('baseURL', '');
if (!empty($appurl)) {
$protocol = parse_url($appurl, PHP_URL_SCHEME);
$hostname = parse_url($appurl, PHP_URL_HOST);
$port = parse_url($appurl, PHP_URL_PORT);
$port = !empty($port) ? ':'.$port : '';
} else { // no base URL specified for app, just use the current URL
$protocol = 'http';
$protocol .= (self::getServerHTTPS()) ? 's' : '';
$hostname = self::getServerHost();
$port = self::getServerPort();
}
return $protocol.'://'.$hostname.$port.$_SERVER['REQUEST_URI'];
}
return self::getBaseURL().$rel_path.substr($_SERVER['REQUEST_URI'], $uri_pos + strlen($url_path));
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment