diff options
author | Daniel Klaffenbach <daniel.klaffenbach@hrz.tu-chemnitz.de> | 2018-04-19 15:12:41 +0300 |
---|---|---|
committer | Daniel Klaffenbach <daniel.klaffenbach@hrz.tu-chemnitz.de> | 2018-11-22 11:45:08 +0300 |
commit | 624d1a23b9afd648db3b1eab00bc390ed96ac0e1 (patch) | |
tree | c843232bbac2a51b9b6c21d9ba663467552bcab0 /lib/UserBackend.php | |
parent | 24883d3c6631565f691fbb432e9ab569f2306bb5 (diff) |
Implement mapping of user's home directory
Signed-off-by: Daniel Klaffenbach <daniel.klaffenbach@hrz.tu-chemnitz.de>
Diffstat (limited to 'lib/UserBackend.php')
-rw-r--r-- | lib/UserBackend.php | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/lib/UserBackend.php b/lib/UserBackend.php index 55056610..6c0bddc4 100644 --- a/lib/UserBackend.php +++ b/lib/UserBackend.php @@ -105,16 +105,29 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { } /** - * Creates an user if it does not exists + * Creates a user if it does not exist. In case home directory mapping + * is enabled we also set up the user's home from $attributes. * * @param string $uid + * @param array $attributes */ - public function createUserIfNotExists($uid) { + public function createUserIfNotExists($uid, array $attributes = array()) { if(!$this->userExistsInDatabase($uid)) { $values = [ 'uid' => $uid, ]; + // Try to get the mapped home directory of the user + try { + $home = $this->getAttributeValue('saml-attribute-mapping-home_mapping', $attributes); + } catch (\InvalidArgumentException $e) { + $home = null; + } + + if ($home !== null) { + $values['home'] = $home; + } + /* @var $qb IQueryBuilder */ $qb = $this->db->getQueryBuilder(); $qb->insert('user_saml_users'); @@ -150,6 +163,7 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { public function implementsActions($actions) { $availableActions = \OC\User\Backend::CHECK_PASSWORD; $availableActions |= \OC\User\Backend::GET_DISPLAYNAME; + $availableActions |= \OC\User\Backend::GET_HOME; return (bool)($availableActions & $actions); } @@ -201,6 +215,27 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { } /** + * Returns the user's home directory, if home directory mapping is set up. + * + * @param string $uid the username + * @return string + */ + public function getHome($uid) { + if($this->userExistsInDatabase($uid)) { + $qb = $this->db->getQueryBuilder(); + $qb->select('home') + ->from('user_saml_users') + ->where($qb->expr()->eq('uid', $qb->createNamedParameter($uid))) + ->setMaxResults(1); + $result = $qb->execute(); + $users = $result->fetchAll(); + if (isset($users[0]['home'])) { + return $users[0]['home']; + } + } + } + + /** * Get a list of all users * * @param string $search @@ -596,7 +631,6 @@ class UserBackend implements IApacheBackend, UserInterface, IUserBackend { $newGroups = null; } - if ($user !== null) { $currentEmail = (string)$user->getEMailAddress(); if ($newEmail !== null |