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
153  $state[self::AUTHID] = $this->authId;
154 
155  $id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
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 }
$params
Definition: disable.php:11
static handleLogin($authStateId, $username, $password, $organization)
Handle login request.
if(!array_key_exists('StateId', $_REQUEST)) $id
$attributes
static redirectTrustedURL($url, $parameters=array())
This function redirects to the specified URL without performing any security checks.
Definition: HTTP.php:962
const AUTHID
The key of the AuthId field in the state.
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
$password
Definition: pwgen.php:17
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static listOrganizations($authStateId)
Get available organizations.
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.
getOrganizations()
Retrieve list of organizations.
authenticate(&$state)
Initialize login.
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
Create styles array
The data for the language used.
login($username, $password, $organization)
Attempt to log in using the given username, password and organization.
getRememberUsernameChecked()
Getter for the authsource config option remember.username.checked.
setUsernameOrgMethod($usernameOrgMethod)
Configure the way organizations as part of the username is handled.
$usernameOrgMethod
What way do we handle the organization as part of the username.
$url
static completeAuth(&$state)
Complete authentication.
Definition: Source.php:135
$source
Definition: linkback.php:22
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:324
$info
Definition: index.php:5
__construct($info, &$config)
Constructor for this authentication source.
getUsernameOrgMethod()
Retrieve the way organizations as part of the username should be handled.
if(!array_key_exists('AuthState', $_REQUEST)) $authStateId
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
const STAGEID
The string used to identify our states.