commit 915733b8d6696997988e1b8b08a8334a18eeea7d Author: Florian Best Date: Thu Jul 9 08:04:55 2020 +0200 Bug #51492: add change password dialog to SAML login diff --git saml/univention-saml/debian/changelog saml/univention-saml/debian/changelog index 1dc16b2664..4957b85dd2 100644 --- saml/univention-saml/debian/changelog +++ saml/univention-saml/debian/changelog @@ -1,3 +1,9 @@ +univention-saml (6.0.3-1) unstable; urgency=medium + + * Bug #51492: add change password dialog to SAML login + + -- Florian Best Thu, 09 Jul 2020 08:04:51 +0200 + univention-saml (6.0.2-45) unstable; urgency=medium * Bug #47567: Add saml serviceproviders to groups diff --git saml/univention-saml/debian/control saml/univention-saml/debian/control index 5ca6234abf..2ef4e9055a 100644 --- saml/univention-saml/debian/control +++ saml/univention-saml/debian/control @@ -20,6 +20,7 @@ Depends: memcached, openssl, php-cgi, + php-curl, php-krb5, php-ldap, php-mcrypt, diff --git saml/univention-saml/simplesamlphp/modules/uldap/lib/Auth/Source/uLDAP.php saml/univention-saml/simplesamlphp/modules/uldap/lib/Auth/Source/uLDAP.php index f9939fcf30..0535e880db 100644 --- saml/univention-saml/simplesamlphp/modules/uldap/lib/Auth/Source/uLDAP.php +++ saml/univention-saml/simplesamlphp/modules/uldap/lib/Auth/Source/uLDAP.php @@ -53,6 +53,8 @@ class sspmod_uldap_Auth_Source_uLDAP extends sspmod_core_Auth_UserPassBase { assert('is_string($username)'); assert('is_string($password)'); + $password = $this->checkPasswordChange($username, $password); + try { $attributes = $this->ldapConfig->login($username, $password, $sasl_args); } catch (SimpleSAML_Error_Error $e) { @@ -69,6 +71,43 @@ class sspmod_uldap_Auth_Source_uLDAP extends sspmod_core_Auth_UserPassBase { } + private function checkPasswordChange($username, $password) { + if (!isset($_POST['new_password'])) { + return $password; + } + $new_password = $_POST['new_password']; + assert('is_string($new_password)'); + + $config = SimpleSAML_Configuration::getInstance(); + $language = new \SimpleSAML\Locale\Language($config); + $url = 'https://' . $config->getValue('hostfqdn') . '/univention/auth'; + $data = json_encode(array("options" => array("username" => $username, "password" => $password, "new_password" => $new_password))); + $ch = curl_init(); + curl_setopt($ch, CURLOPT_URL, $url); + curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type: application/json', sprintf('Accept-Language: %s; q=1, en; q=0.5', $language->getLanguage()))); + curl_setopt($ch, CURLOPT_USERAGENT, 'simplesamlphp'); + curl_setopt($ch, CURLOPT_REFERER, 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['REQUEST_URI']); + curl_setopt($ch, CURLOPT_POST, TRUE); + curl_setopt($ch, CURLOPT_POSTFIELDS, $data); + curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE); + $response = curl_exec($ch); + if ($response === FALSE) { + SimpleSAML\Logger::debug('Error: ' . curl_error($ch)); + } + $httpcode = curl_getinfo($ch, CURLINFO_RESPONSE_CODE); + SimpleSAML\Logger::debug('Password changing response: ' . var_export(array($httpcode, $response), true)); + if (FALSE !== $response && strpos(curl_getinfo($ch, CURLINFO_CONTENT_TYPE), 'application/json') >= 0) { + $response = json_decode($response, TRUE); + } else { + $response = array('message' => $response); + } + if ($httpcode !== 200) { + throw new SimpleSAML_Error_Error(array('PW_CHANGE_FAILED', '%s' => $response['message'])); + } + curl_close($ch); + return $new_password; + } + /** * Investigate login failure diff --git saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.definition.json saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.definition.json index b336079dfd..1ea4ea2450 100644 --- saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.definition.json +++ saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.definition.json @@ -5,6 +5,12 @@ "descr_WRONGUSERPASS": { "en": "Either no user with the given username could be found, or the password you gave was wrong. Please check the username and try again." }, + "title_PW_CHANGE_FAILED": { + "en": "Changing password failed" + }, + "descr_PW_CHANGE_FAILED": { + "en": "%s" + }, "title_LDAP_ACCDISABLED": { "en": "Account disabled" }, diff --git saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.translation.json saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.translation.json index 2a38490408..999eaf0454 100644 --- saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.translation.json +++ saml/univention-saml/simplesamlphp/modules/univentiontheme/dictionaries/errors_static.translation.json @@ -5,6 +5,12 @@ "descr_WRONGUSERPASS": { "de": "Entweder es konnte kein Nutzer mit dem angegebenen Nutzernamen gefunden werden oder das Passwort ist falsch. \u00dcberpr\u00fcfen Sie die Zugangsdaten und probieren Sie es nochmal" }, + "title_PW_CHANGE_FAILED": { + "de": "Passwort ändern fehlgeschlagen" + }, + "descr_PW_CHANGE_FAILED": { + "de": "%s" + }, "title_LDAP_ACCDISABLED": { "de": "Account deaktiviert" }, diff --git saml/univention-saml/simplesamlphp/modules/univentiontheme/themes/univention/core/loginuserpass.php saml/univention-saml/simplesamlphp/modules/univentiontheme/themes/univention/core/loginuserpass.php index 014e6eca77..550d2b6011 100644 --- saml/univention-saml/simplesamlphp/modules/univentiontheme/themes/univention/core/loginuserpass.php +++ saml/univention-saml/simplesamlphp/modules/univentiontheme/themes/univention/core/loginuserpass.php @@ -2,9 +2,12 @@ $this->includeAtTemplateBase('includes/header.php'); $this->data['header'] = $this->t('{login:user_pass_header}'); + +$PW_EXPIRED = $this->data['errorcode'] !== NULL && in_array($this->data['errorcode'], array('LDAP_PWCHANGE', 'KRB_PWCHANGE', 'SAMBA_PWCHANGE')); +// echo '
'; var_dump($this->data); echo '
'; ?>
-

t('{univentiontheme:login:loginat}'), $this->configuration->getValue('domainname', ''))); ?>

+

t('{univentiontheme:login:loginat}', array('%s' => $this->configuration->getValue('domainname', '')))); ?>

data['SPMetadata']['privacypolicy'])) { printf('

%s

', htmlspecialchars($this->data['SPMetadata']['privacypolicy'], ENT_QUOTES), htmlspecialchars($this->t('{consent:consent:consent_privacypolicy}'))); @@ -17,29 +20,14 @@ if (isset($this->data['SPMetadata']['privacypolicy'])) {
- -
- - -
+
data['errorcode'] !== NULL) { - echo('' . $this->t('{login:help_header}') . ''); - echo('' . $this->t('{login:help_text}') . ''); -} -*/ - if ($this->data['errorcode'] !== NULL) { ?>

t('{univentiontheme:errors:title_' . $this->data['errorcode'] . '}', $this->data['errorparams'])); ?>.
data['errorcode'], array('LDAP_PWCHANGE', 'KRB_PWCHANGE', 'SAMBA_PWCHANGE'))) { +if ($PW_EXPIRED) { $password_change_url = $this->configuration->getValue('password_change_url', ''); $password_change_url = $password_change_url ? $password_change_url : str_replace('/univention/saml/metadata', '/univention/login/', $this->data['SPMetadata']['entityid']); echo ''; @@ -55,6 +43,15 @@ if (in_array($this->data['errorcode'], array('LDAP_PWCHANGE', 'KRB_PWCHANGE', 'S +

+ > + + +
data['stateparams'] as $name => $value) { @@ -90,8 +87,32 @@ foreach ($this->data['organizations'] as $orgId => $orgDesc) { - + + + + +
+ + + + + +data['stateparams'] as $name => $value) { + echo ''; +} +?>
+ +