diff --git a/modules/radius/docs/radius.txt b/modules/radius/docs/radius.txt index b411a97925bba6a806e8a6017b6823ccde7cb4a8..ae5e70d3afa29370e7592adad844d2f22cc3558c 100644 --- a/modules/radius/docs/radius.txt +++ b/modules/radius/docs/radius.txt @@ -52,6 +52,15 @@ authentication source which uses the `radius:Radius` module to */ 'nas_identifier' => 'client.example.org', + /* + * An optional realm that will be suffixed to the username entered + * by the user. When set to "example.edu", and the user enters + * "bob" as their username, the radius server will be queried for + * the username "bob@example.edu". + * Optional, defaults to NULL. + */ + 'realm' => 'example.edu', + /* * The attribute name we should store the username in. Ths username * will not be saved in any attribute if this is NULL. diff --git a/modules/radius/lib/Auth/Source/Radius.php b/modules/radius/lib/Auth/Source/Radius.php index 93c1b13c38e264c772a6d2dc808760864153092e..994780686e8f94c63a2c5942c2f6b1a29129009f 100644 --- a/modules/radius/lib/Auth/Source/Radius.php +++ b/modules/radius/lib/Auth/Source/Radius.php @@ -39,6 +39,11 @@ class sspmod_radius_Auth_Source_Radius extends sspmod_core_Auth_UserPassBase */ private $retries; + /** + * The realm to be added to the entered username. + */ + private $realm; + /** * The attribute name where the username should be stored. */ @@ -90,6 +95,7 @@ class sspmod_radius_Auth_Source_Radius extends sspmod_core_Auth_UserPassBase } $this->timeout = $config->getInteger('timeout', 5); $this->retries = $config->getInteger('retries', 3); + $this->realm = $config->getString('realm', null); $this->usernameAttribute = $config->getString('username_attribute', null); $this->nasIdentifier = $config->getString('nas_identifier', isset($_SERVER['HTTP_HOST']) ? $_SERVER['HTTP_HOST'] : 'localhost'); @@ -139,10 +145,14 @@ class sspmod_radius_Auth_Source_Radius extends sspmod_core_Auth_UserPassBase radius_strerror($radius)); } - radius_put_attr($radius, RADIUS_USER_NAME, $username); + if ($this->realm === null) { + radius_put_attr($radius, RADIUS_USER_NAME, $username); + } else { + radius_put_attr($radius, RADIUS_USER_NAME, $username . '@' . $this->realm); + } radius_put_attr($radius, RADIUS_USER_PASSWORD, $password); - if ($this->nasIdentifier != null) { + if ($this->nasIdentifier !== null) { radius_put_attr($radius, RADIUS_NAS_IDENTIFIER, $this->nasIdentifier); }