Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/user_saml.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorbne86 <b.von.st.vieth@fz-juelich.de>2017-03-10 18:27:45 +0300
committerSérgio Faria <sergio.faria@is4health.com>2018-03-19 19:07:33 +0300
commit18aa824206c1ed75a76fac6440357179c23b5d1d (patch)
treedf5f7ca7aea0a9cfce23fe1eab3e88c76df6315d /lib
parentee38ad3a179c9a12dbc22c0d58220476aad59709 (diff)
first version for group-mapping. groups are added and user assigned to groups. until now no group removal
Signed-off-by: bne86 <b.von.st.vieth@fz-juelich.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/Settings/Admin.php5
-rw-r--r--lib/UserBackend.php28
2 files changed, 32 insertions, 1 deletions
diff --git a/lib/Settings/Admin.php b/lib/Settings/Admin.php
index 7ae9e9c0..919f4bde 100644
--- a/lib/Settings/Admin.php
+++ b/lib/Settings/Admin.php
@@ -112,6 +112,11 @@ class Admin implements ISettings {
'type' => 'line',
'required' => false,
],
+ 'group_mapping' => [
+ 'text' => $this->l10n->t('Attribute to map the users groups to.'),
+ 'type' => 'line',
+ 'required' => true,
+ ],
];
$type = $this->config->getAppValue('user_saml', 'type');
diff --git a/lib/UserBackend.php b/lib/UserBackend.php
index aa5bf405..d5d3c846 100644
--- a/lib/UserBackend.php
+++ b/lib/UserBackend.php
@@ -25,6 +25,7 @@ use OCP\Authentication\IApacheBackend;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\IDBConnection;
use OCP\IUserManager;
+use OCP\IGroupManager;
use OCP\UserInterface;
use OCP\IUserBackend;
use OCP\IConfig;
@@ -42,6 +43,8 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
private $db;
/** @var IUserManager */
private $userManager;
+ /** @var IGroupManager */
+ private $groupManager;
/** @var \OCP\UserInterface[] */
private static $backends = [];
@@ -51,17 +54,20 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
* @param ISession $session
* @param IDBConnection $db
* @param IUserManager $userManager
+ * @param IGroupManager $groupManager
*/
public function __construct(IConfig $config,
IURLGenerator $urlGenerator,
ISession $session,
IDBConnection $db,
- IUserManager $userManager) {
+ IUserManager $userManager,
+ IGroupManager $groupManager) {
$this->config = $config;
$this->urlGenerator = $urlGenerator;
$this->session = $session;
$this->db = $db;
$this->userManager = $userManager;
+ $this->groupManager = $groupManager;
}
/**
@@ -466,6 +472,13 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
$newQuota = null;
}
+ try {
+ $newGroups = $this->getAttributeValue('saml-attribute-mapping-group_mapping', $attributes);
+ } catch (\InvalidArgumentException $e) {
+ $newGroups = null;
+ }
+
+
if ($user !== null) {
$currentEmail = (string)$user->getEMailAddress();
if ($newEmail !== null
@@ -488,6 +501,19 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend {
if ($newQuota !== null) {
$user->setQuota($newQuota);
}
+
+ if ($newGroups !==null) {
+ $groups = explode(' ', $newGroups);
+ foreach ($groups as $group) {
+ if (!($this->groupManager->groupExists($group))) {
+ $this->groupManager->createGroup($group);
+ }
+ $groupInBackend = $this->groupManager->get($group);
+ if (!$groupInBackend->inGroup($user)) {
+ $groupInBackend->addUser($user);
+ }
+ }
+ }
}
}
}