Skip to content

Commit

Permalink
Gid collision: append SAML prefix to gid
Browse files Browse the repository at this point in the history
  • Loading branch information
melegiul committed Jul 26, 2021
1 parent c5d9de6 commit 0152278
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 11 deletions.
19 changes: 10 additions & 9 deletions appinfo/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,25 +50,26 @@
$groupBackend = new \OCA\User_SAML\GroupBackend(\OC::$server->getDatabaseConnection());
\OC::$server->getGroupManager()->addBackend($groupBackend);

\OC::$server->registerService('SAMLGroupManager', function(\OCA\User_SAML\GroupBackend $groupBackend) {
$samlSettings = new \OCA\User_SAML\SAMLSettings(
$urlGenerator,
$config,
$request,
$session
);

\OC::$server->registerService('SAMLGroupManager', function(\OCA\User_SAML\GroupBackend $groupBackend, $samlSettings) {
return new OCA\User_SAML\GroupManager(
\OC::$server->getDatabaseConnection(),
\OC::$server->query('SAMLGroupDuplicateChecker'),
\OC::$server->getGroupManager(),
\OC::$server->getUserManager(),
$groupBackend,
\OC::$server->getConfig(),
\OC::$server->getJobList()
\OC::$server->getJobList(),
$samlSettings,
);
});

$samlSettings = new \OCA\User_SAML\SAMLSettings(
$urlGenerator,
$config,
$request,
$session
);

$userData = new \OCA\User_SAML\UserData(
new \OCA\User_SAML\UserResolver(\OC::$server->getUserManager()),
$samlSettings,
Expand Down
11 changes: 9 additions & 2 deletions lib/GroupManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use OC\BackgroundJob\JobList;
use OC\Hooks\PublicEmitter;
use OCA\User_SAML\Jobs\MigrateGroups;
use OCA\User_SAML\SAMLSettings;
use OCP\IConfig;
use OCP\IDBConnection;
use OCP\IGroup;
Expand Down Expand Up @@ -35,6 +36,8 @@ class GroupManager
private $config;
/** @var JobList */
private $jobList;
/** @var SAMLSettings */
private $settings;


public function __construct(
Expand All @@ -44,7 +47,8 @@ public function __construct(
IUserManager $userManager,
GroupBackend $ownGroupBackend,
IConfig $config,
JobList $jobList
JobList $jobList,
SAMLSettings $settings
) {
$this->db = $db;
$this->duplicateChecker = $duplicateChecker;
Expand All @@ -53,6 +57,7 @@ public function __construct(
$this->ownGroupBackend = $ownGroupBackend;
$this->config = $config;
$this->jobList = $jobList;
$this->settings = $settings;
}

public function replaceGroups($uid, $samlGroups) {
Expand Down Expand Up @@ -106,7 +111,9 @@ public function addGroup(IUser $user, $gid) {
$group = $this->createGroupInBackend($gid);
} else if($e->getCode() === 2) {
//FIXME: probably need config flag. Previous to 17, gid was used as displayname
$group = $this->createGroupInBackend('__saml__' . $gid, $gid);
$idpPrefix = $this->settings->getPrefix('saml-attribute-mapping-group_mapping_prefix');
$groupPrefix = $this->config->getAppValue('user_saml', $idpPrefix . 'saml-attribute-mapping-group_mapping_prefix', 'SAML_');
$group = $this->createGroupInBackend($groupPrefix . $gid, $gid);
} else {
throw $e;
}
Expand Down

0 comments on commit 0152278

Please sign in to comment.