-
-
Notifications
You must be signed in to change notification settings - Fork 4.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
also support saving the kerberos tickets in database
Signed-off-by: Robin Appelman <[email protected]>
- Loading branch information
1 parent
b5abd91
commit 1491368
Showing
6 changed files
with
157 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
apps/files_external/lib/Lib/Auth/SMB/KerberosSsoDatabase.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
<?php | ||
|
||
/** | ||
* @copyright Copyright (c) 2018 Robin Appelman <[email protected]> | ||
* | ||
* @author Robin Appelman <[email protected]> | ||
* | ||
* @license GNU AGPL version 3 or any later version | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU Affero General Public License as | ||
* published by the Free Software Foundation, either version 3 of the | ||
* License, or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU Affero General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU Affero General Public License | ||
* along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
* | ||
*/ | ||
|
||
namespace OCA\Files_External\Lib\Auth\SMB; | ||
|
||
use Icewind\SMB\KerberosTicket; | ||
use OCA\Files_External\Lib\Auth\AuthMechanism; | ||
use OCA\Files_External\Lib\DefinitionParameter; | ||
use OCA\Files_External\Lib\InsufficientDataForMeaningfulAnswerException; | ||
use OCP\IL10N; | ||
use OCP\ISession; | ||
use OCP\IUser; | ||
use OCP\Security\ICredentialsManager; | ||
|
||
class KerberosSsoDatabase extends AuthMechanism { | ||
Check notice Code scanning / Psalm PropertyNotSetInConstructor Note
Property OCA\Files_External\Lib\Auth\SMB\KerberosSsoDatabase::$scheme is not defined in constructor of OCA\Files_External\Lib\Auth\SMB\KerberosSsoDatabase or in any private or final methods called in the constructor
|
||
private ICredentialsManager $credentialsManager; | ||
|
||
public function __construct(IL10N $l, ICredentialsManager $credentialsManager) { | ||
$realm = new DefinitionParameter('default_realm', 'Default realm'); | ||
$realm | ||
->setType(DefinitionParameter::VALUE_TEXT) | ||
->setFlag(DefinitionParameter::FLAG_OPTIONAL) | ||
->setTooltip($l->t('Kerberos default realm, defaults to "WORKGROUP"')); | ||
$this | ||
->setIdentifier('smb::kerberos_sso_database') | ||
->setScheme(self::SCHEME_SMB) | ||
->setText($l->t('Kerberos ticket SSO, save in database')) | ||
->addParameter($realm); | ||
$this->credentialsManager = $credentialsManager; | ||
} | ||
|
||
public function getTicket(?IUser $user): KerberosTicket { | ||
if (!isset($user)) { | ||
throw new InsufficientDataForMeaningfulAnswerException('No kerberos ticket saved'); | ||
} | ||
try { | ||
$envTicket = KerberosTicket::fromEnv(); | ||
} catch (\Exception $e) { | ||
$envTicket = null; | ||
} | ||
if ($envTicket) { | ||
$this->credentialsManager->store($user->getUID(), 'kerberos_ticket', base64_encode($envTicket->save())); | ||
return $envTicket; | ||
} | ||
|
||
$savedTicket = $this->credentialsManager->retrieve($user->getUID(), 'kerberos_ticket'); | ||
if (!$savedTicket) { | ||
throw new InsufficientDataForMeaningfulAnswerException('No kerberos ticket saved'); | ||
} | ||
return KerberosTicket::load(base64_decode($savedTicket)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters