Skip to content
Snippets Groups Projects
Commit 4cc5d80d authored by Thomas Hackl's avatar Thomas Hackl
Browse files

system account login via WebSSO token

parent b4afcfaa
No related branches found
No related tags found
No related merge requests found
<?php
/**
* Class AddMatrixLoginToken
* Adds the option for the service account to have a login token
* instead of a password.
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* @author Thomas Hackl <hackl@data-quest.de>
* @license http://www.gnu.org/licenses/gpl-2.0.html GPL version 2
* @category Matrix
*/
class AddMatrixLoginToken extends Migration
{
public function description()
{
return 'Adds the option to have a login token for WebSSO instead of a password.';
}
public function up()
{
try {
Config::get()->create('MATRIX_SYSTEM_ACCOUNT_LOGIN_TOKEN', [
'value' => '',
'type' => 'string',
'range' => 'global',
'section' => 'matrix',
'description' => 'WebSSO-Token zum Login des Serviceaccounts. Ist dieser Wert gesetzt, ' .
'wird er statt eines möglicherweise ebenfalls angegebenen Passworts verwendet.'
]);
} catch (Exception $e) {
}
}
public function down()
{
// Remove config entry.
Config::get()->delete('MATRIX_SYSTEM_ACCOUNT_LOGIN_TOKEN');
}
}
\ No newline at end of file
...@@ -56,14 +56,24 @@ class MatrixAccount extends SimpleORMap ...@@ -56,14 +56,24 @@ class MatrixAccount extends SimpleORMap
*/ */
public static function requireSystemAccount() public static function requireSystemAccount()
{ {
if (Config::get()->MATRIX_SYSTEM_ACCOUNT_USERNAME != '' if (trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_USERNAME) != '' &&
&& Config::get()->MATRIX_SYSTEM_ACCOUNT_PASSWORD != '') { (trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_PASSWORD) != '' ||
$account = new Patrix\Account(Config::get()->MATRIX_SYSTEM_ACCOUNT_USERNAME, trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_TOKEN) != '')) {
Config::get()->MATRIX_SYSTEM_ACCOUNT_PASSWORD);
// Login token specified, use this.
if (trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_TOKEN) != '') {
$account = new Patrix\Account(trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_USERNAME), '',
trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_TOKEN));
// No token, login by username and password.
} else {
$account = new Patrix\Account(trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_USERNAME),
trim(Config::get()->MATRIX_SYSTEM_ACCOUNT_PASSWORD));
}
MatrixClient::get()->login($account); MatrixClient::get()->login($account);
return $account; return $account;
} else { } else {
//$username = 'studip-' . Config::get()->STUDIP_INSTALLATION_ID;
$username = 'studip'; $username = 'studip';
$password = self::randomPassword(); $password = self::randomPassword();
$sysaccount = new \Patrix\Account($username, $password); $sysaccount = new \Patrix\Account($username, $password);
...@@ -74,6 +84,7 @@ class MatrixAccount extends SimpleORMap ...@@ -74,6 +84,7 @@ class MatrixAccount extends SimpleORMap
} else { } else {
return null; return null;
} }
} }
} }
......
libpatrix @ 4d31e1a0
Subproject commit 403ac1cf84c817250e8b2757feb07d85dabdad7f Subproject commit 4d31e1a0c3a02b75415b478d698b8096c057d749
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment