Skip to content
Snippets Groups Projects
Commit e031c452 authored by Olav Morken's avatar Olav Morken
Browse files

UserPass(Org)Base: Fix error propagation in UserPass(Org)Base authentication sources.

Thansk to Thijs Kinkhorst for indentifying the problem!

git-svn-id: https://simplesamlphp.googlecode.com/svn/trunk@3179 44740490-163a-0410-bde0-09ae8108e29a
parent 3207229b
No related branches found
No related tags found
No related merge requests found
......@@ -185,13 +185,12 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source {
* Handle login request.
*
* This function is used by the login form (core/www/loginuserpass.php) when the user
* enters a username and password. On success, it will not return. If an error occurs,
* it will return the error code.
* enters a username and password. On success, it will not return. On wrong
* username/password failure, and other errors, it will throw an exception.
*
* @param string $authStateId The identifier of the authentication state.
* @param string $username The username the user wrote.
* @param string $password The password the user wrote.
* @return string Error code in the case of an error.
*/
public static function handleLogin($authStateId, $username, $password) {
assert('is_string($authStateId)');
......@@ -213,16 +212,8 @@ abstract class sspmod_core_Auth_UserPassBase extends SimpleSAML_Auth_Source {
* was called. We should call login() on the same authentication source.
*/
try {
/* Attempt to log in. */
$attributes = $source->login($username, $password);
} catch (SimpleSAML_Error_Error $e) {
/*
* Login failed. Return the error code to the login form, so that it
* can display an error message to the user.
*/
return $e->getErrorCode();
}
/* Attempt to log in. */
$attributes = $source->login($username, $password);
/* Save the attributes we received from the login-function in the $state-array. */
assert('is_array($attributes)');
......
......@@ -196,14 +196,12 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source {
*
* This function is used by the login form (core/www/loginuserpassorg.php) when the user
* enters a username and password. On success, it will not return. On wrong
* username/password failure, it will return the error code. Other failures will throw an
* exception.
* username/password failure, and other errors, it will throw an exception.
*
* @param string $authStateId The identifier of the authentication state.
* @param string $username The username the user wrote.
* @param string $password The password the user wrote.
* @param string $organization The id of the organization the user chose.
* @return string Error code in the case of an error.
*/
public static function handleLogin($authStateId, $username, $password, $organization) {
assert('is_string($authStateId)');
......@@ -230,17 +228,13 @@ abstract class sspmod_core_Auth_UserPassOrgBase extends SimpleSAML_Auth_Source {
} else {
if ($orgMethod === 'force') {
/* The organization should be a part of the username, but isn't. */
return 'WRONGUSERPASS';
throw new SimpleSAML_Error_Error('WRONGUSERPASS');
}
}
}
try {
/* Attempt to log in. */
$attributes = $source->login($username, $password, $organization);
} catch (SimpleSAML_Error_Error $e) {
return $e->getErrorCode();
}
/* Attempt to log in. */
$attributes = $source->login($username, $password, $organization);
// Add the selected Org to the state
$state[self::ORGID] = $organization;
......
......@@ -16,8 +16,8 @@ if ($this->data['errorcode'] !== NULL) {
<div style="border-left: 1px solid #e8e8e8; border-bottom: 1px solid #e8e8e8; background: #f5f5f5">
<img src="/<?php echo $this->data['baseurlpath']; ?>resources/icons/experience/gtk-dialog-error.48x48.png" class="float-l" style="margin: 15px " />
<h2><?php echo $this->t('{login:error_header}'); ?></h2>
<p><b><?php echo $this->t('{errors:title_' . $this->data['errorcode'] . '}'); ?></b></p>
<p><?php echo $this->t('{errors:descr_' . $this->data['errorcode'] . '}'); ?></p>
<p><b><?php echo htmlspecialchars($this->t('{errors:title_' . $this->data['errorcode'] . '}', $this->data['errorparams'])); ?></b></p>
<p><?php echo htmlspecialchars($this->t('{errors:descr_' . $this->data['errorcode'] . '}', $this->data['errorparams'])); ?></p>
</div>
<?php
}
......
......@@ -41,6 +41,9 @@ if (array_key_exists('password', $_REQUEST)) {
$password = '';
}
$errorCode = NULL;
$errorParams = NULL;
if (!empty($_REQUEST['username']) || !empty($password)) {
/* Either username or password set - attempt to log in. */
......@@ -56,9 +59,13 @@ if (!empty($_REQUEST['username']) || !empty($password)) {
setcookie($source->getAuthId() . '-username', $username, $params['expire'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
$errorCode = sspmod_core_Auth_UserPassBase::handleLogin($authStateId, $username, $password);
} else {
$errorCode = NULL;
try {
sspmod_core_Auth_UserPassBase::handleLogin($authStateId, $username, $password);
} catch (SimpleSAML_Error_Error $e) {
/* Login failed. Extract error code and parameters, to display the error. */
$errorCode = $e->getErrorCode();
$errorParams = $e->getParameters();
}
}
$globalConfig = SimpleSAML_Configuration::getInstance();
......@@ -78,6 +85,7 @@ if (array_key_exists('forcedUsername', $state)) {
}
$t->data['links'] = $source->getLoginLinks();
$t->data['errorcode'] = $errorCode;
$t->data['errorparams'] = $errorParams;
if (isset($state['SPMetadata'])) {
$t->data['SPMetadata'] = $state['SPMetadata'];
......
......@@ -50,6 +50,7 @@ if (array_key_exists('organization', $_REQUEST)) {
}
$errorCode = NULL;
$errorParams = NULL;
if ($organizations === NULL || !empty($organization)) {
if (!empty($username) && !empty($password)) {
......@@ -61,7 +62,13 @@ if ($organizations === NULL || !empty($organization)) {
setcookie($source->getAuthId() . '-username', $username, $params['expire'], $params['path'], $params['domain'], $params['secure'], $params['httponly']);
}
$errorCode = sspmod_core_Auth_UserPassOrgBase::handleLogin($authStateId, $username, $password, $organization);
try {
sspmod_core_Auth_UserPassOrgBase::handleLogin($authStateId, $username, $password, $organization);
} catch (SimpleSAML_Error_Error $e) {
/* Login failed. Extract error code and parameters, to display the error. */
$errorCode = $e->getErrorCode();
$errorParams = $e->getParameters();
}
}
}
......@@ -74,6 +81,7 @@ $t->data['rememberUsernameEnabled'] = $source->getRememberUsernameEnabled();
$t->data['rememberUsernameChecked'] = $source->getRememberUsernameChecked();
if (isset($_COOKIE[$source->getAuthId() . '-username'])) $t->data['rememberUsernameChecked'] = TRUE;
$t->data['errorcode'] = $errorCode;
$t->data['errorparams'] = $errorParams;
if ($organizations !== NULL) {
$t->data['selectedOrg'] = $organization;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment