Commit d6af8c86 authored by Kevin Rickis's avatar Kevin Rickis Committed by Robert Lyon

Bug 1486699: get_new_username() truncating username badly for SAML

Ends up with username in auth_remote_user being different to the
username in usr table.

behatnotneeded

Change-Id: If6a5a18360ef82da2e3a709899e7d4d1624e8fab
Signed-off-by: Robert Lyon's avatarRobert Lyon <robertl@catalyst.net.nz>
(cherry picked from commit dc3b3292)
(cherry picked from commit 884b9f71)
parent 4503a050
...@@ -182,7 +182,7 @@ class AuthSaml extends Auth { ...@@ -182,7 +182,7 @@ class AuthSaml extends Auth {
$user->authinstance = empty($this->config['parent']) ? $this->instanceid : $this->parent; $user->authinstance = empty($this->config['parent']) ? $this->instanceid : $this->parent;
db_begin(); db_begin();
$user->username = get_new_username($remoteuser); $user->username = get_new_username($remoteuser, 40);
$user->id = create_user($user, array(), $institutionname, $this, $remoteuser); $user->id = create_user($user, array(), $institutionname, $this, $remoteuser);
......
...@@ -1575,9 +1575,9 @@ function load_user_institutions($userid) { ...@@ -1575,9 +1575,9 @@ function load_user_institutions($userid) {
* Return a username which isn't taken and which is similar to a desired username * Return a username which isn't taken and which is similar to a desired username
* *
* @param string $desired * @param string $desired
* @param string $maxlen Maximum length of desired username
*/ */
function get_new_username($desired) { function get_new_username($desired, $maxlen=30) {
$maxlen = 30;
if (function_exists('mb_strtolower')) { if (function_exists('mb_strtolower')) {
$desired = mb_strtolower(mb_substr($desired, 0, $maxlen, 'UTF-8'), 'UTF-8'); $desired = mb_strtolower(mb_substr($desired, 0, $maxlen, 'UTF-8'), 'UTF-8');
} }
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment