diff options
author | Thijs Kinkhorst <thijs@kinkhorst.com> | 2016-11-15 17:57:32 +0000 |
---|---|---|
committer | Thijs Kinkhorst <thijs@kinkhorst.com> | 2016-11-15 17:57:32 +0000 |
commit | e3acea6ee14837acc134014b2649ede1f904056f (patch) | |
tree | d5cddfdc68f91d59841595e56b2073191b780aa6 /modules/ldap/lib/Auth/Source | |
parent | d7446b0669687b01a520fc536478163e6d0afada (diff) | |
parent | 3a20131cb7a466688a2ced47afad36e4bce42c64 (diff) | |
download | simplesamlphp-origin/twigified.zip simplesamlphp-origin/twigified.tar.gz simplesamlphp-origin/twigified.tar.bz2 |
Merge branch 'master' into twigifiedorigin/twigified
Diffstat (limited to 'modules/ldap/lib/Auth/Source')
-rw-r--r-- | modules/ldap/lib/Auth/Source/LDAP.php | 83 | ||||
-rw-r--r-- | modules/ldap/lib/Auth/Source/LDAPMulti.php | 219 |
2 files changed, 154 insertions, 148 deletions
diff --git a/modules/ldap/lib/Auth/Source/LDAP.php b/modules/ldap/lib/Auth/Source/LDAP.php index 83b35fa..7bf979a 100644 --- a/modules/ldap/lib/Auth/Source/LDAP.php +++ b/modules/ldap/lib/Auth/Source/LDAP.php @@ -10,45 +10,48 @@ * * @package SimpleSAMLphp */ -class sspmod_ldap_Auth_Source_LDAP extends sspmod_core_Auth_UserPassBase { - - /** - * A LDAP configuration object. - */ - private $ldapConfig; - - - /** - * Constructor for this authentication source. - * - * @param array $info Information about this authentication source. - * @param array $config Configuration. - */ - public function __construct($info, $config) { - assert('is_array($info)'); - assert('is_array($config)'); - - // Call the parent constructor first, as required by the interface - parent::__construct($info, $config); - - $this->ldapConfig = new sspmod_ldap_ConfigHelper($config, - 'Authentication source ' . var_export($this->authId, TRUE)); - } - - - /** - * Attempt to log in using the given username and password. - * - * @param string $username The username the user wrote. - * @param string $password The password the user wrote. - * param array $sasl_arg Associative array of SASL options - * @return array Associative array with the users attributes. - */ - protected function login($username, $password, array $sasl_args = NULL) { - assert('is_string($username)'); - assert('is_string($password)'); - - return $this->ldapConfig->login($username, $password, $sasl_args); - } +class sspmod_ldap_Auth_Source_LDAP extends sspmod_core_Auth_UserPassBase +{ + + /** + * A LDAP configuration object. + */ + private $ldapConfig; + + + /** + * Constructor for this authentication source. + * + * @param array $info Information about this authentication source. + * @param array $config Configuration. + */ + public function __construct($info, $config) + { + assert('is_array($info)'); + assert('is_array($config)'); + + // Call the parent constructor first, as required by the interface + parent::__construct($info, $config); + + $this->ldapConfig = new sspmod_ldap_ConfigHelper($config, + 'Authentication source ' . var_export($this->authId, true)); + } + + + /** + * Attempt to log in using the given username and password. + * + * @param string $username The username the user wrote. + * @param string $password The password the user wrote. + * param array $sasl_arg Associative array of SASL options + * @return array Associative array with the users attributes. + */ + protected function login($username, $password, array $sasl_args = null) + { + assert('is_string($username)'); + assert('is_string($password)'); + + return $this->ldapConfig->login($username, $password, $sasl_args); + } } diff --git a/modules/ldap/lib/Auth/Source/LDAPMulti.php b/modules/ldap/lib/Auth/Source/LDAPMulti.php index 4f5adaf..e38118e 100644 --- a/modules/ldap/lib/Auth/Source/LDAPMulti.php +++ b/modules/ldap/lib/Auth/Source/LDAPMulti.php @@ -10,112 +10,115 @@ * * @package SimpleSAMLphp */ -class sspmod_ldap_Auth_Source_LDAPMulti extends sspmod_core_Auth_UserPassOrgBase { - - /** - * An array with descriptions for organizations. - */ - private $orgs; - - /** - * An array of organization IDs to LDAP configuration objects. - */ - private $ldapOrgs; - - /** - * Whether we should include the organization as part of the username. - */ - private $includeOrgInUsername; - - - /** - * Constructor for this authentication source. - * - * @param array $info Information about this authentication source. - * @param array $config Configuration. - */ - public function __construct($info, $config) { - assert('is_array($info)'); - assert('is_array($config)'); - - // 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 $name => $value) { - - if ($name === 'username_organization_method') { - $usernameOrgMethod = $cfgHelper->getValueValidate( - 'username_organization_method', - array('none', 'allow', 'force')); - $this->setUsernameOrgMethod($usernameOrgMethod); - continue; - } - - if ($name === 'include_organization_in_username') { - $this->includeOrgInUsername = $cfgHelper->getBoolean( - 'include_organization_in_username', FALSE); - continue; - } - - $orgCfg = $cfgHelper->getArray($name); - $orgId = $name; - - if (array_key_exists('description', $orgCfg)) { - $this->orgs[$orgId] = $orgCfg['description']; - } else { - $this->orgs[$orgId] = $orgId; - } - - $orgCfg = new sspmod_ldap_ConfigHelper($orgCfg, - 'Authentication source ' . var_export($this->authId, TRUE) . - ', organization ' . var_export($orgId, TRUE)); - $this->ldapOrgs[$orgId] = $orgCfg; - } - } - - - /** - * Attempt to log in using the given username and password. - * - * @param string $username The username the user wrote. - * @param string $password The password the user wrote. - * @param string $org The organization the user chose. - * @return array Associative array with the users attributes. - */ - protected function login($username, $password, $org, array $sasl_args = NULL) { - 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. - SimpleSAML\Logger::warning('Authentication source ' . var_export($this->authId, TRUE) . - ': Organization seems to have disappeared while the user logged in.' . - ' Organization was ' . var_export($org, TRUE)); - throw new SimpleSAML_Error_Error('WRONGUSERPASS'); - } - - if ($this->includeOrgInUsername) { - $username = $username . '@' . $org; - } - - return $this->ldapOrgs[$org]->login($username, $password, $sasl_args); - } - - - /** - * Retrieve list of organizations. - * - * @return array Associative array with the organizations. - */ - protected function getOrganizations() { - return $this->orgs; - } - +class sspmod_ldap_Auth_Source_LDAPMulti extends sspmod_core_Auth_UserPassOrgBase +{ + + /** + * An array with descriptions for organizations. + */ + private $orgs; + + /** + * An array of organization IDs to LDAP configuration objects. + */ + private $ldapOrgs; + + /** + * Whether we should include the organization as part of the username. + */ + private $includeOrgInUsername; + + + /** + * Constructor for this authentication source. + * + * @param array $info Information about this authentication source. + * @param array $config Configuration. + */ + public function __construct($info, $config) + { + assert('is_array($info)'); + assert('is_array($config)'); + + // 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 $name => $value) { + + if ($name === 'username_organization_method') { + $usernameOrgMethod = $cfgHelper->getValueValidate( + 'username_organization_method', + array('none', 'allow', 'force')); + $this->setUsernameOrgMethod($usernameOrgMethod); + continue; + } + + if ($name === 'include_organization_in_username') { + $this->includeOrgInUsername = $cfgHelper->getBoolean( + 'include_organization_in_username', false); + continue; + } + + $orgCfg = $cfgHelper->getArray($name); + $orgId = $name; + + if (array_key_exists('description', $orgCfg)) { + $this->orgs[$orgId] = $orgCfg['description']; + } else { + $this->orgs[$orgId] = $orgId; + } + + $orgCfg = new sspmod_ldap_ConfigHelper($orgCfg, + 'Authentication source ' . var_export($this->authId, true) . + ', organization ' . var_export($orgId, true)); + $this->ldapOrgs[$orgId] = $orgCfg; + } + } + + + /** + * Attempt to log in using the given username and password. + * + * @param string $username The username the user wrote. + * @param string $password The password the user wrote. + * @param string $org The organization the user chose. + * @return array Associative array with the users attributes. + */ + protected function login($username, $password, $org, array $sasl_args = null) + { + 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. + SimpleSAML\Logger::warning('Authentication source ' . var_export($this->authId, true) . + ': Organization seems to have disappeared while the user logged in.' . + ' Organization was ' . var_export($org, true)); + throw new SimpleSAML_Error_Error('WRONGUSERPASS'); + } + + if ($this->includeOrgInUsername) { + $username = $username . '@' . $org; + } + + return $this->ldapOrgs[$org]->login($username, $password, $sasl_args); + } + + + /** + * Retrieve list of organizations. + * + * @return array Associative array with the organizations. + */ + protected function getOrganizations() + { + return $this->orgs; + } } |