diff --git a/config-templates/authsources.php b/config-templates/authsources.php index 7ca97b9cd5464b3b16459212b72a10acc09ae0e5..62cf02864e4679f52ca8eac6bf04a2cc09a91017 100644 --- a/config-templates/authsources.php +++ b/config-templates/authsources.php @@ -121,8 +121,27 @@ $config = array( 'ldap:LDAPMulti', /* - * A list of available LDAP servers / user groups. The value of each element is - * an array in the same format as an LDAP authentication source. + * The way the organization as part of the username should be handled. + * Three possible values: + * - 'none': No handling of the organization. Allows '@' to be part + * of the username. + * - 'allow': Will allow users to type 'username@organization'. + * - 'force': Force users to type 'username@organization'. The dropdown + * list will be hidden. + * + * The default is 'none'. + */ + 'username_organization_method' => 'none', + + /* + * A list of available LDAP servers. + * + * The index is an identifier for the organization/group. When + * 'username_organization_method' is set to something other than 'none', + * the organization-part of the username is matched against the index. + * + * The value of each element is an array in the same format as an LDAP + * authentication source. */ 'employees' => array( /* diff --git a/modules/ldap/docs/ldap.txt b/modules/ldap/docs/ldap.txt index 9ed6e6f8d31e41ddfe210fac459fac1cc893b6a1..3caa9cc4aaccf8d74fe1eb73d0214e0e90a0c6fb 100644 --- a/modules/ldap/docs/ldap.txt +++ b/modules/ldap/docs/ldap.txt @@ -119,9 +119,27 @@ and add an entry which uses this module: 'ldap:LDAPMulti', /* - * A list of available LDAP servers. The index is only an identifier, - * and can be any string. The value of each element is an array in the - * same format as an LDAP authentication source. + * The way the organization as part of the username should be handled. + * Three possible values: + * - 'none': No handling of the organization. Allows '@' to be part + * of the username. + * - 'allow': Will allow users to type 'username@organization'. + * - 'force': Force users to type 'username@organization'. The dropdown + * list will be hidden. + * + * The default is 'none'. + */ + 'username_organization_method' => 'none', + + /* + * A list of available LDAP servers. + * + * The index is an identifier for the organization/group. When + * 'username_organization_method' is set to something other than 'none', + * the organization-part of the username is matched against the index. + * + * The value of each element is an array in the same format as an LDAP + * authentication source. */ 'employees' => array( /* @@ -167,4 +185,3 @@ All options from the `ldap:LDAP` configuration can be used in each group, and you should refer to the documentation for that module for more information about available options. - diff --git a/modules/ldap/lib/Auth/Source/LDAPMulti.php b/modules/ldap/lib/Auth/Source/LDAPMulti.php index 34f3fb425e9fa1e4898f644f43d1ed077f6c521a..4c56749f51596100a28479ea95704dafa8fef10c 100644 --- a/modules/ldap/lib/Auth/Source/LDAPMulti.php +++ b/modules/ldap/lib/Auth/Source/LDAPMulti.php @@ -37,9 +37,25 @@ class sspmod_ldap_Auth_Source_LDAPMulti extends sspmod_core_Auth_UserPassOrgBase /* Call the parent constructor first, as required by the interface. */ parent::__construct($info, $config); + $cfgHelper = SimpleSAML_Configuration::loadFromArray($config, + 'Authentication source ' . var_export($this->authId, TRUE)); + + $this->orgs = array(); $this->ldapOrgs = array(); - foreach ($config as $orgId => $orgCfg) { + foreach ($config as $name => $value) { + + if ($name === 'username_organization_method') { + $usernameOrgMethod = $cfgHelper->getValueValidate( + 'username_organization_method', + array('none', 'allow', 'force')); + $this->setUsernameOrgMethod($usernameOrgMethod); + continue; + } + + $orgCfg = $cfgHelper->getArray($name); + $orgId = $name; + if (array_key_exists('description', $orgCfg)) { $this->orgs[$orgId] = $orgCfg['description']; } else { @@ -65,6 +81,7 @@ class sspmod_ldap_Auth_Source_LDAPMulti extends sspmod_core_Auth_UserPassOrgBase protected function login($username, $password, $org) { assert('is_string($username)'); assert('is_string($password)'); + assert('is_string($org)'); if (!array_key_exists($org, $this->ldapOrgs)) { /* The user has selected an organization which doesn't exist anymore. */