-
-
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 <robin@icewind.nl>
- Loading branch information
1 parent
5671d0c
commit d3686e3
Showing
7 changed files
with
159 additions
and
10 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
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 <robin@icewind.nl> | ||
* | ||
* @author Robin Appelman <robin@icewind.nl> | ||
* | ||
* @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 { | ||
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