ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
LDAPMulti.php
Go to the documentation of this file.
1<?php
2
14{
15
19 private $orgs;
20
24 private $ldapOrgs;
25
30
31
38 public function __construct($info, $config)
39 {
40 assert('is_array($info)');
41 assert('is_array($config)');
42
43 // Call the parent constructor first, as required by the interface
44 parent::__construct($info, $config);
45
47 'Authentication source ' . var_export($this->authId, true));
48
49
50 $this->orgs = array();
51 $this->ldapOrgs = array();
52 foreach ($config as $name => $value) {
53
54 if ($name === 'username_organization_method') {
55 $usernameOrgMethod = $cfgHelper->getValueValidate(
56 'username_organization_method',
57 array('none', 'allow', 'force'));
59 continue;
60 }
61
62 if ($name === 'include_organization_in_username') {
63 $this->includeOrgInUsername = $cfgHelper->getBoolean(
64 'include_organization_in_username', false);
65 continue;
66 }
67
68 $orgCfg = $cfgHelper->getArray($name);
69 $orgId = $name;
70
71 if (array_key_exists('description', $orgCfg)) {
72 $this->orgs[$orgId] = $orgCfg['description'];
73 } else {
74 $this->orgs[$orgId] = $orgId;
75 }
76
77 $orgCfg = new sspmod_ldap_ConfigHelper($orgCfg,
78 'Authentication source ' . var_export($this->authId, true) .
79 ', organization ' . var_export($orgId, true));
80 $this->ldapOrgs[$orgId] = $orgCfg;
81 }
82 }
83
84
93 protected function login($username, $password, $org, array $sasl_args = null)
94 {
95 assert('is_string($username)');
96 assert('is_string($password)');
97 assert('is_string($org)');
98
99 if (!array_key_exists($org, $this->ldapOrgs)) {
100 // The user has selected an organization which doesn't exist anymore.
101 SimpleSAML\Logger::warning('Authentication source ' . var_export($this->authId, true) .
102 ': Organization seems to have disappeared while the user logged in.' .
103 ' Organization was ' . var_export($org, true));
104 throw new SimpleSAML_Error_Error('WRONGUSERPASS');
105 }
106
107 if ($this->includeOrgInUsername) {
108 $username = $username . '@' . $org;
109 }
110
111 return $this->ldapOrgs[$org]->login($username, $password, $sasl_args);
112 }
113
114
120 protected function getOrganizations()
121 {
122 return $this->orgs;
123 }
124}
An exception for terminatinating execution or to throw for unit testing.
static warning($string)
Definition: Logger.php:179
static loadFromArray($config, $location='[ARRAY]', $instance=null)
Loads a configuration from the given array.
$usernameOrgMethod
What way do we handle the organization as part of the username.
setUsernameOrgMethod($usernameOrgMethod)
Configure the way organizations as part of the username is handled.
$ldapOrgs
An array of organization IDs to LDAP configuration objects.
Definition: LDAPMulti.php:24
$includeOrgInUsername
Whether we should include the organization as part of the username.
Definition: LDAPMulti.php:29
getOrganizations()
Retrieve list of organizations.
Definition: LDAPMulti.php:120
login($username, $password, $org, array $sasl_args=null)
Attempt to log in using the given username and password.
Definition: LDAPMulti.php:93
__construct($info, $config)
Constructor for this authentication source.
Definition: LDAPMulti.php:38
$orgs
An array with descriptions for organizations.
Definition: LDAPMulti.php:19
if($format !==null) $name
Definition: metadata.php:146
$info
Definition: index.php:5
$password
Definition: pwgen.php:17