ILIAS  release_5-3 Revision v5.3.23-19-g915713cf615
UserPassBase.php
Go to the documentation of this file.
1 <?php
2 
13 
14 
18  const STAGEID = 'sspmod_core_Auth_UserPassBase.state';
19 
20 
24  const AUTHID = 'sspmod_core_Auth_UserPassBase.AuthId';
25 
26 
33  private $forcedUsername;
34 
39  protected $loginLinks;
40 
47  protected $rememberUsernameEnabled = FALSE;
48 
55  protected $rememberUsernameChecked = FALSE;
56 
65  protected $rememberMeEnabled = FALSE;
66 
73  protected $rememberMeChecked = FALSE;
74 
84  public function __construct($info, &$config) {
85  assert('is_array($info)');
86  assert('is_array($config)');
87 
88  if (isset($config['core:loginpage_links'])) {
89  $this->loginLinks = $config['core:loginpage_links'];
90  }
91 
92  // Call the parent constructor first, as required by the interface
93  parent::__construct($info, $config);
94 
95  // Get the remember username config options
96  if (isset($config['remember.username.enabled'])) {
97  $this->rememberUsernameEnabled = (bool) $config['remember.username.enabled'];
98  unset($config['remember.username.enabled']);
99  }
100  if (isset($config['remember.username.checked'])) {
101  $this->rememberUsernameChecked = (bool) $config['remember.username.checked'];
102  unset($config['remember.username.checked']);
103  }
104 
105  // get the "remember me" config options
107  $this->rememberMeEnabled = $sspcnf->getBoolean('session.rememberme.enable', FALSE);
108  $this->rememberMeChecked = $sspcnf->getBoolean('session.rememberme.checked', FALSE);
109  }
110 
111 
118  assert('is_string($forcedUsername) || is_null($forcedUsername)');
119  $this->forcedUsername = $forcedUsername;
120  }
121 
125  public function getLoginLinks() {
126  return $this->loginLinks;
127  }
128 
133  public function getRememberUsernameEnabled() {
135  }
136 
141  public function getRememberUsernameChecked() {
143  }
144 
149  public function isRememberMeEnabled() {
151  }
152 
157  public function isRememberMeChecked() {
159  }
160 
169  public function authenticate(&$state) {
170  assert('is_array($state)');
171 
172  /*
173  * Save the identifier of this authentication source, so that we can
174  * retrieve it later. This allows us to call the login()-function on
175  * the current object.
176  */
177  $state[self::AUTHID] = $this->authId;
178 
179  // What username we should force, if any
180  if ($this->forcedUsername !== NULL) {
181  /*
182  * This is accessed by the login form, to determine if the user
183  * is allowed to change the username.
184  */
185  $state['forcedUsername'] = $this->forcedUsername;
186  }
187 
188  /* Save the $state-array, so that we can restore it after a redirect. */
189  $id = SimpleSAML_Auth_State::saveState($state, self::STAGEID);
190 
191  /*
192  * Redirect to the login form. We include the identifier of the saved
193  * state array as a parameter to the login form.
194  */
195  $url = SimpleSAML\Module::getModuleURL('core/loginuserpass.php');
196  $params = array('AuthState' => $id);
198 
199  /* The previous function never returns, so this code is never executed. */
200  assert('FALSE');
201  }
202 
203 
217  abstract protected function login($username, $password);
218 
219 
231  public static function handleLogin($authStateId, $username, $password) {
232  assert('is_string($authStateId)');
233  assert('is_string($username)');
234  assert('is_string($password)');
235 
236  /* Here we retrieve the state array we saved in the authenticate-function. */
238 
239  /* Retrieve the authentication source we are executing. */
240  assert('array_key_exists(self::AUTHID, $state)');
242  if ($source === NULL) {
243  throw new Exception('Could not find authentication source with id ' . $state[self::AUTHID]);
244  }
245 
246  /*
247  * $source now contains the authentication source on which authenticate()
248  * was called. We should call login() on the same authentication source.
249  */
250 
251  /* Attempt to log in. */
252  try {
253  $attributes = $source->login($username, $password);
254  } catch (Exception $e) {
255  SimpleSAML\Logger::stats('Unsuccessful login attempt from '.$_SERVER['REMOTE_ADDR'].'.');
256  throw $e;
257  }
258 
259  SimpleSAML\Logger::stats('User \''.$username.'\' successfully authenticated from '.$_SERVER['REMOTE_ADDR']);
260 
261  /* Save the attributes we received from the login-function in the $state-array. */
262  assert('is_array($attributes)');
263  $state['Attributes'] = $attributes;
264 
265  /* Return control to SimpleSAMLphp after successful authentication. */
266  SimpleSAML_Auth_Source::completeAuth($state);
267  }
268 
269 }
$params
Definition: disable.php:11
static handleLogin($authStateId, $username, $password)
Handle login request.
setForcedUsername($forcedUsername)
Set forced username.
getLoginLinks()
Return login links from configuration.
if((!isset($_SERVER['DOCUMENT_ROOT'])) OR(empty($_SERVER['DOCUMENT_ROOT']))) $_SERVER['DOCUMENT_ROOT']
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
getRememberUsernameChecked()
Getter for the authsource config option remember.username.checked.
static getModuleURL($resource, array $parameters=array())
Get absolute URL to a specified module resource.
Definition: Module.php:303
isRememberMeChecked()
Check if the "remember me" checkbox should be checked.
$password
Definition: pwgen.php:17
const AUTHID
The key of the AuthId field in the state.
if(!array_key_exists('stateid', $_REQUEST)) $state
Handle linkback() response from LinkedIn.
Definition: linkback.php:10
static stats($string)
Definition: Logger.php:224
$loginLinks
Links to pages from login page.
login($username, $password)
Attempt to log in using the given username and password.
const STAGEID
The string used to identify our states.
$forcedUsername
Username we should force.
static loadState($id, $stage, $allowMissing=false)
Retrieve saved state.
Definition: State.php:259
authenticate(&$state)
Initialize login.
Create styles array
The data for the language used.
__construct($info, &$config)
Constructor for this authentication source.
isRememberMeEnabled()
Check if the "remember me" feature is enabled.
$url
getRememberUsernameEnabled()
Getter for the authsource config option remember.username.enabled.
$source
Definition: linkback.php:22
static getById($authId, $type=null)
Retrieve authentication source.
Definition: Source.php:324
$info
Definition: index.php:5
if(!array_key_exists('AuthState', $_REQUEST)) $authStateId
static saveState(&$state, $stage, $rawId=false)
Save the state.
Definition: State.php:194
static getInstance($instancename='simplesaml')
Get a configuration file by its instance name.