forked from nextcloud/user_saml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
161 additions
and
168 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
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]> | ||
|
@@ -79,11 +80,11 @@ protected function run($argument) { | |
|
||
protected function updateCandidatePool($migrateGroups) { | ||
$candidateInfo = $this->config->getAppValue('user_saml', GroupManager::LOCAL_GROUPS_CHECK_FOR_MIGRATION, null); | ||
if($candidateInfo === null) { | ||
if ($candidateInfo === null) { | ||
return; | ||
} | ||
$candidateInfo = \json_decode($candidateInfo, true); | ||
if(!isset($candidateInfo['dropAfter']) || !isset($candidateInfo['groups'])) { | ||
if (!isset($candidateInfo['dropAfter']) || !isset($candidateInfo['groups'])) { | ||
return; | ||
} | ||
$candidateInfo['groups'] = array_diff($candidateInfo['groups'], $migrateGroups); | ||
|
@@ -108,11 +109,11 @@ protected function migrateGroup(string $gid): bool { | |
$affected = $qb->delete('groups') | ||
->where($qb->expr()->eq('gid', $qb->createNamedParameter($gid))) | ||
->execute(); | ||
if($affected === 0) { | ||
if ($affected === 0) { | ||
throw new \RuntimeException('Could not delete group from local backend'); | ||
} | ||
|
||
if(!$this->ownGroupBackend->createGroup($gid)) { | ||
if (!$this->ownGroupBackend->createGroup($gid)) { | ||
throw new \RuntimeException('Could not create group in SAML backend'); | ||
} | ||
|
||
|
@@ -129,20 +130,20 @@ protected function migrateGroup(string $gid): bool { | |
|
||
protected function getGroupsToMigrate(array $samlGroups, array $pool): array { | ||
return array_filter($samlGroups, function (string $gid) use ($pool) { | ||
if(!in_array($gid, $pool)) { | ||
if (!in_array($gid, $pool)) { | ||
return false; | ||
} | ||
|
||
$group = $this->groupManager->get($gid); | ||
if($group === null) { | ||
if ($group === null) { | ||
return false; | ||
} | ||
$reflected = new \ReflectionClass($group); | ||
$backendsProperty = $reflected->getProperty('backends'); | ||
$backendsProperty->setAccessible(true); | ||
$backends = $backendsProperty->getValue($group); | ||
foreach ($backends as $backend) { | ||
if($backend instanceof Database) { | ||
if ($backend instanceof Database) { | ||
return true; | ||
} | ||
} | ||
|
@@ -152,17 +153,15 @@ protected function getGroupsToMigrate(array $samlGroups, array $pool): array { | |
|
||
protected function getMigratableGroups(): array { | ||
$candidateInfo = $this->config->getAppValue('user_saml', GroupManager::LOCAL_GROUPS_CHECK_FOR_MIGRATION, null); | ||
if($candidateInfo === null) { | ||
if ($candidateInfo === null) { | ||
throw new \RuntimeException('No migration of groups to SAML backend anymore'); | ||
} | ||
$candidateInfo = \json_decode($candidateInfo, true); | ||
if(!isset($candidateInfo['dropAfter']) || !isset($candidateInfo['groups']) || $candidateInfo['dropAfter'] < time()) { | ||
if (!isset($candidateInfo['dropAfter']) || !isset($candidateInfo['groups']) || $candidateInfo['dropAfter'] < time()) { | ||
$this->config->deleteAppValue('user_saml', GroupManager::LOCAL_GROUPS_CHECK_FOR_MIGRATION); | ||
throw new \RuntimeException('Period for migration groups is over'); | ||
} | ||
|
||
return $candidateInfo['groups']; | ||
} | ||
|
||
|
||
} |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
/** | ||
* @copyright Copyright (c) 2019 Arthur Schiwon <[email protected]> | ||
|
@@ -86,7 +87,7 @@ public function run(IOutput $output) { | |
protected function findGroupIds(Database $backend): array { | ||
$groupIds = $backend->getGroups(); | ||
$adminGroupIndex = array_search('admin', $groupIds, true); | ||
if($adminGroupIndex !== false) { | ||
if ($adminGroupIndex !== false) { | ||
unset($groupIds[$adminGroupIndex]); | ||
} | ||
return $groupIds; | ||
|
@@ -95,7 +96,7 @@ protected function findGroupIds(Database $backend): array { | |
protected function findBackend(): Database { | ||
$groupBackends = $this->groupManager->getBackends(); | ||
foreach ($groupBackends as $backend) { | ||
if($backend instanceof Database) { | ||
if ($backend instanceof Database) { | ||
return $backend; | ||
break; | ||
} | ||
|
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
Oops, something went wrong.