Commit 28e08649 authored by Manfred Kutas's avatar Manfred Kutas

ZP-864 User with umlauts in user name is not able to login in Outlook.

Released under the Affero GNU General Public License (AGPL) version 3.
parent 7706c21c
...@@ -239,6 +239,31 @@ class Request { ...@@ -239,6 +239,31 @@ class Request {
ZLog::Write(LOGLEVEL_INFO, sprintf("'X-Forwarded-for' indicates remote IP: %s", self::$remoteAddr)); ZLog::Write(LOGLEVEL_INFO, sprintf("'X-Forwarded-for' indicates remote IP: %s", self::$remoteAddr));
} }
} }
// Mobile devices send Authorization header using UTF-8 charset. Outlook sends it using ISO-8859-1 encoding.
// For the successful authentication the user and password must be UTF-8 encoded. Try to determine which
// charset was sent by the client and convert it to UTF-8. See https://jira.z-hub.io/browse/ZP-864.
if (isset($_SERVER['PHP_AUTH_USER'])) {
$encoding = mb_detect_encoding(self::$authUser, "UTF-8, ISO-8859-1");
if ($encoding) {
ZLog::Write(LOGLEVEL_DEBUG, sprintf("Request->ProcessHeaders(): mb_detect_encoding detected '%s' charset. Authorization header will be converted to UTF-8 from it.", $encoding));
self::$authUser = mb_convert_encoding(self::$authUser, "UTF-8", $encoding);
self::$authPassword = mb_convert_encoding(self::$authPassword, "UTF-8", $encoding);
}
else {
$encoding = mb_detect_encoding(self::$authUser, Utils::GetAvailableCharacterEncodings());
if ($encoding) {
ZLog::Write(LOGLEVEL_WARN,
sprintf("Request->ProcessHeaders(): mb_detect_encoding detected '%s' charset. Authorization header will be converted to UTF-8 from it. This charset is not in the default detect list. Please report it to Z-Push developers.",
$encoding));
self::$authUser = mb_convert_encoding(self::$authUser, "UTF-8", $encoding);
self::$authPassword = mb_convert_encoding(self::$authPassword, "UTF-8", $encoding);
}
else {
ZLog::Write(LOGLEVEL_ERROR, "Request->ProcessHeaders(): mb_detect_encoding failed to detect the Authorization header charset. It's possible that user won't be able to login.");
}
}
}
} }
/** /**
......
...@@ -994,6 +994,97 @@ class Utils { ...@@ -994,6 +994,97 @@ class Utils {
$pow = pow(1024, $base - $fBase); $pow = pow(1024, $base - $fBase);
return sprintf ("%.{$precision}f %s", $pow, $units[$fBase]); return sprintf ("%.{$precision}f %s", $pow, $units[$fBase]);
} }
public static function GetAvailableCharacterEncodings() {
return array(
'UCS-4',
'UCS-4BE',
'UCS-4LE',
'UCS-2',
'UCS-2BE',
'UCS-2LE',
'UTF-32',
'UTF-32BE',
'UTF-32LE',
'UTF-16',
'UTF-16BE',
'UTF-16LE',
'UTF-7',
'UTF7-IMAP',
'UTF-8',
'ASCII',
'EUC-JP',
'SJIS',
'eucJP-win',
'SJIS-win',
'ISO-2022-JP',
'ISO-2022-JP-MS',
'CP932',
'CP51932',
'SJIS-mac',
'MacJapanese',
'SJIS-Mobile#DOCOMO',
'SJIS-DOCOMO',
'SJIS-Mobile#KDDI',
'SJIS-KDDI',
'SJIS-Mobile#SOFTBANK',
'SJIS-SOFTBANK',
'UTF-8-Mobile#DOCOMO',
'UTF-8-DOCOMO',
'UTF-8-Mobile#KDDI-A',
'UTF-8-Mobile#KDDI-B',
'UTF-8-KDDI',
'UTF-8-Mobile#SOFTBANK',
'UTF-8-SOFTBANK',
'ISO-2022-JP-MOBILE#KDDI',
'ISO-2022-JP-KDDI',
'JIS',
'JIS-ms',
'CP50220',
'CP50220raw',
'CP50221',
'CP50222',
'ISO-8859-1',
'ISO-8859-2',
'ISO-8859-3',
'ISO-8859-4',
'ISO-8859-5',
'ISO-8859-6',
'ISO-8859-7',
'ISO-8859-8',
'ISO-8859-9',
'ISO-8859-10',
'ISO-8859-13',
'ISO-8859-14',
'ISO-8859-15',
'byte2be',
'byte2le',
'byte4be',
'byte4le',
'BASE64',
'HTML-ENTITIES',
'7bit',
'8bit',
'EUC-CN',
'CP936',
'GB18030',
'HZ',
'EUC-TW',
'CP950',
'BIG-5',
'EUC-KR',
'UHC (CP949)',
'ISO-2022-KR',
'Windows-1251',
'CP1251',
'Windows-1252',
'CP1252',
'CP866 (IBM866)',
'KOI8-R',
'ArmSCII-8',
'ArmSCII8',
);
}
} }
......
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