ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
UserPassOrgBase.php
Go to the documentation of this file.
1<?php
2
15
16
20 const STAGEID = 'sspmod_core_Auth_UserPassOrgBase.state';
21
22
26 const AUTHID = 'sspmod_core_Auth_UserPassOrgBase.AuthId';
27
28
32 const ORGID = 'sspmod_core_Auth_UserPassOrgBase.SelectedOrg';
33
34
43
50 protected $rememberUsernameEnabled = FALSE;
51
58 protected $rememberUsernameChecked = FALSE;
59
60
70 public function __construct($info, &$config) {
71 assert('is_array($info)');
72 assert('is_array($config)');
73
74 // Call the parent constructor first, as required by the interface
75 parent::__construct($info, $config);
76
77 // Get the remember username config options
78 if (isset($config['remember.username.enabled'])) {
79 $this->rememberUsernameEnabled = (bool) $config['remember.username.enabled'];
80 unset($config['remember.username.enabled']);
81 }
82 if (isset($config['remember.username.checked'])) {
83 $this->rememberUsernameChecked = (bool) $config['remember.username.checked'];
84 unset($config['remember.username.checked']);
85 }
86
87 $this->usernameOrgMethod = 'none';
88 }
89
90
104 assert('in_array($usernameOrgMethod, array("none", "allow", "force"), TRUE)');
105
106 $this->usernameOrgMethod = $usernameOrgMethod;
107 }
108
109
120 public function getUsernameOrgMethod() {
122 }
123
128 public function getRememberUsernameEnabled() {
130 }
131
136 public function getRememberUsernameChecked() {
138 }
139
140
149 public function authenticate(&$state) {
150 assert('is_array($state)');
151
152 // We are going to need the authId in order to retrieve this authentication source later
154
156
157 $url = SimpleSAML\Module::getModuleURL('core/loginuserpassorg.php');
158 $params = array('AuthState' => $id);
160 }
161
162
177 abstract protected function login($username, $password, $organization);
178
179
190 abstract protected function getOrganizations();
191
192
205 public static function handleLogin($authStateId, $username, $password, $organization) {
206 assert('is_string($authStateId)');
207 assert('is_string($username)');
208 assert('is_string($password)');
209 assert('is_string($organization)');
210
211 /* Retrieve the authentication state. */
213
214 /* Find authentication source. */
215 assert('array_key_exists(self::AUTHID, $state)');
217 if ($source === NULL) {
218 throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
219 }
220
221 $orgMethod = $source->getUsernameOrgMethod();
222 if ($orgMethod !== 'none') {
223 $tmp = explode('@', $username, 2);
224 if (count($tmp) === 2) {
225 $username = $tmp[0];
226 $organization = $tmp[1];
227 } else {
228 if ($orgMethod === 'force') {
229 /* The organization should be a part of the username, but isn't. */
230 throw new SimpleSAML_Error_Error('WRONGUSERPASS');
231 }
232 }
233 }
234
235 /* Attempt to log in. */
236 $attributes = $source->login($username, $password, $organization);
237
238 // Add the selected Org to the state
239 $state[self::ORGID] = $organization;
240 $state['PersistentAuthData'][] = self::ORGID;
241
242 $state['Attributes'] = $attributes;
244 }
245
246
256 public static function listOrganizations($authStateId) {
257 assert('is_string($authStateId)');
258
259 /* Retrieve the authentication state. */
261
262 /* Find authentication source. */
263 assert('array_key_exists(self::AUTHID, $state)');
265 if ($source === NULL) {
266 throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
267 }
268
269 $orgMethod = $source->getUsernameOrgMethod();
270 if ($orgMethod === 'force') {
271 return NULL;
272 }
273
274 return $source->getOrganizations();
275 }
276}
$source
Definition: linkback.php:22
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
An exception for terminatinating execution or to throw for unit testing.
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:324
static completeAuth(&$state)
Complete authentication.
Definition: Source.php:135
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
const AUTHID
The key of the AuthId field in the state.
static listOrganizations($authStateId)
Get available organizations.
login($username, $password, $organization)
Attempt to log in using the given username, password and organization.
getOrganizations()
Retrieve list of organizations.
authenticate(&$state)
Initialize login.
getRememberUsernameChecked()
Getter for the authsource config option remember.username.checked.
const STAGEID
The string used to identify our states.
__construct($info, &$config)
Constructor for this authentication source.
getUsernameOrgMethod()
Retrieve the way organizations as part of the username should be handled.
getRememberUsernameEnabled()
Getter for the authsource config option remember.username.enabled.
const ORGID
The key of the OrgId field in the state, identifies which org was selected.
$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.
static handleLogin($authStateId, $username, $password, $organization)
Handle login request.
if(!array_key_exists('StateId', $_REQUEST)) $id
$info
Definition: index.php:5
$url
$password
Definition: pwgen.php:17
$attributes
$params
Definition: disable.php:11
if(!array_key_exists('AuthState', $_REQUEST)) $authStateId