aboutsummaryrefslogtreecommitdiffstats
path: root/apps/user_ldap/lib
diff options
context:
space:
mode:
authorMarc Hefter <marchefter@march42.net>2022-05-07 16:27:20 +0200
committerMarc Hefter <marchefter@gmail.com>2023-04-06 08:19:39 +0200
commit404d26aa4a950e246f11ce421c48faef764fce31 (patch)
tree8535e3de7f5b23e28478fdab652058cc93920eb4 /apps/user_ldap/lib
parente63a6f5cdbaf3d9034470d4ef096fdb344fddf8f (diff)
downloadnextcloud-server-404d26aa4a950e246f11ce421c48faef764fce31.tar.gz
nextcloud-server-404d26aa4a950e246f11ce421c48faef764fce31.zip
feature addition: [user_ldap] update user profile from LDAP; WIP work-in-progress; TODO update profile
Signed-off-by: Marc Hefter <marchefter@march42.net>
Diffstat (limited to 'apps/user_ldap/lib')
-rw-r--r--apps/user_ldap/lib/Configuration.php22
-rw-r--r--apps/user_ldap/lib/Connection.php7
-rw-r--r--apps/user_ldap/lib/User/Manager.php8
-rw-r--r--apps/user_ldap/lib/User/User.php96
4 files changed, 133 insertions, 0 deletions
diff --git a/apps/user_ldap/lib/Configuration.php b/apps/user_ldap/lib/Configuration.php
index 59fac50b90b..91780155251 100644
--- a/apps/user_ldap/lib/Configuration.php
+++ b/apps/user_ldap/lib/Configuration.php
@@ -10,6 +10,7 @@
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Lennart Rosam <hello@takuto.de>
* @author Lukas Reschke <lukas@statuscode.ch>
+ * @author Marc Hefter <marchefter@march42.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Robin McCorkell <robin@mccorkell.me.uk>
* @author Roeland Jago Douma <roeland@famdouma.nl>
@@ -123,6 +124,13 @@ class Configuration {
'ldapExtStorageHomeAttribute' => null,
'ldapMatchingRuleInChainState' => self::LDAP_SERVER_FEATURE_UNKNOWN,
'ldapConnectionTimeout' => 15,
+ 'ldapAttributePhone' => null,
+ 'ldapAttributeWebsite' => null,
+ 'ldapAttributeAddress' => null,
+ 'ldapAttributeOrganisation' => null,
+ 'ldapAttributeRole' => null,
+ 'ldapAttributeHeadline' => null,
+ 'ldapAttributeBiography' => null,
];
public function __construct(string $configPrefix, bool $autoRead = true) {
@@ -469,6 +477,13 @@ class Configuration {
'ldap_ext_storage_home_attribute' => '',
'ldap_matching_rule_in_chain_state' => self::LDAP_SERVER_FEATURE_UNKNOWN,
'ldap_connection_timeout' => 15,
+ 'ldap_attr_phone' => '',
+ 'ldap_attr_website' => '',
+ 'ldap_attr_address' => '',
+ 'ldap_attr_organisation' => '',
+ 'ldap_attr_role' => '',
+ 'ldap_attr_headline' => '',
+ 'ldap_attr_biography' => '',
];
}
@@ -535,6 +550,13 @@ class Configuration {
'ldap_matching_rule_in_chain_state' => 'ldapMatchingRuleInChainState',
'ldapIgnoreNamingRules' => 'ldapIgnoreNamingRules', // sysconfig
'ldap_connection_timeout' => 'ldapConnectionTimeout',
+ 'ldap_attr_phone' => 'ldapAttributePhone',
+ 'ldap_attr_website' => 'ldapAttributeWebsite',
+ 'ldap_attr_address' => 'ldapAttributeAddress',
+ 'ldap_attr_organisation' => 'ldapAttributeOrganisation',
+ 'ldap_attr_role' => 'ldapAttributeRole',
+ 'ldap_attr_headline' => 'ldapAttributeHeadline',
+ 'ldap_attr_biography' => 'ldapAttributeBiography',
];
return $array;
}
diff --git a/apps/user_ldap/lib/Connection.php b/apps/user_ldap/lib/Connection.php
index 6700890c8c7..85c8b5ceda3 100644
--- a/apps/user_ldap/lib/Connection.php
+++ b/apps/user_ldap/lib/Connection.php
@@ -73,6 +73,13 @@ use Psr\Log\LoggerInterface;
* @property int hasMemberOfFilterSupport
* @property int useMemberOfToDetectMembership
* @property string ldapMatchingRuleInChainState
+ * @property string ldapAttributePhone
+ * @property string ldapAttributeWebsite
+ * @property string ldapAttributeAddress
+ * @property string ldapAttributeOrganisation
+ * @property string ldapAttributeRole
+ * @property string ldapAttributeHeadline
+ * @property string ldapAttributeBiography
*/
class Connection extends LDAPUtility {
/**
diff --git a/apps/user_ldap/lib/User/Manager.php b/apps/user_ldap/lib/User/Manager.php
index b1915ab57b5..8e0ad9c5df9 100644
--- a/apps/user_ldap/lib/User/Manager.php
+++ b/apps/user_ldap/lib/User/Manager.php
@@ -6,6 +6,7 @@
* @author Christoph Wurst <christoph@winzerhof-wurst.at>
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
+ * @author Marc Hefter <marchefter@march42.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Roeland Jago Douma <roeland@famdouma.nl>
* @author Roger Szabo <roger.szabo@web.de>
@@ -152,6 +153,13 @@ class Manager {
$this->access->getConnection()->ldapUserDisplayName,
$this->access->getConnection()->ldapUserDisplayName2,
$this->access->getConnection()->ldapExtStorageHomeAttribute,
+ $this->access->getConnection()->ldapAttributePhone,
+ $this->access->getConnection()->ldapAttributeWebsite,
+ $this->access->getConnection()->ldapAttributeAddress,
+ $this->access->getConnection()->ldapAttributeOrganisation,
+ $this->access->getConnection()->ldapAttributeRole,
+ $this->access->getConnection()->ldapAttributeHeadline,
+ $this->access->getConnection()->ldapAttributeBiography,
];
$homeRule = (string)$this->access->getConnection()->homeFolderNamingRule;
diff --git a/apps/user_ldap/lib/User/User.php b/apps/user_ldap/lib/User/User.php
index edf43494777..81ced78dab9 100644
--- a/apps/user_ldap/lib/User/User.php
+++ b/apps/user_ldap/lib/User/User.php
@@ -7,6 +7,7 @@
* @author Joas Schilling <coding@schilljs.com>
* @author Jörn Friedrich Dreyer <jfd@butonic.de>
* @author Juan Pablo Villafáñez <jvillafanez@solidgear.es>
+ * @author Marc Hefter <marchefter@march42.net>
* @author Morris Jobke <hey@morrisjobke.de>
* @author Philipp Staiger <philipp@staiger.it>
* @author Roger Szabo <roger.szabo@web.de>
@@ -35,6 +36,7 @@ use OCA\User_LDAP\Access;
use OCA\User_LDAP\Connection;
use OCA\User_LDAP\Exceptions\AttributeNotSet;
use OCA\User_LDAP\FilesystemHelper;
+use OCP\Accounts\IAccountManager;
use OCP\IAvatarManager;
use OCP\IConfig;
use OCP\ILogger;
@@ -109,6 +111,17 @@ class User {
public const USER_PREFKEY_FIRSTLOGIN = 'firstLoginAccomplished';
/**
+ * DB config keys for user profile
+ */
+ public const USER_PREFKEY_PHONE = 'profile_phone';
+ public const USER_PREFKEY_WEBSITE = 'profile_website';
+ public const USER_PREFKEY_ADDRESS = 'profile_address';
+ public const USER_PREFKEY_ORGANISATION = 'profile_organisation';
+ public const USER_PREFKEY_ROLE = 'profile_role';
+ public const USER_PREFKEY_HEADLINE = 'profile_headline';
+ public const USER_PREFKEY_BIOGRAPHY = 'profile_biography';
+
+ /**
* @brief constructor, make sure the subclasses call this one!
* @param string $username the internal username
* @param string $dn the LDAP DN
@@ -231,6 +244,49 @@ class User {
}
unset($attr);
+ //User Profile Field - Phone number
+ $attr = strtolower($this->connection->ldapAttributePhone);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_PHONE, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - website
+ $attr = strtolower($this->connection->ldapAttributeWebsite);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_WEBSITE, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - Address
+ $attr = strtolower($this->connection->ldapAttributeAddress);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_ADDRESS, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - organisation
+ $attr = strtolower($this->connection->ldapAttributeAddress);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_ORGANISATION, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - role
+ $attr = strtolower($this->connection->ldapAttributeAddress);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_ROLE, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - headline
+ $attr = strtolower($this->connection->ldapAttributeAddress);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_HEADLINE, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+ //User Profile Field - biography
+ $attr = strtolower($this->connection->ldapAttributeAddress);
+ if (isset($ldapEntry[$attr])) {
+ $this->updateProfile(self::USER_PREFKEY_BIOGRAPHY, $ldapEntry[$attr][0]);
+ }
+ unset($attr);
+
//Avatar
/** @var Connection $connection */
$connection = $this->access->getConnection();
@@ -512,6 +568,46 @@ class User {
return $quotaValue === 'none' || $quotaValue === 'default' || \OC_Helper::computerFileSize($quotaValue) !== false;
}
+/* user profile settings and LDAP attributes
+ * ***
+ * interface IAccountManager
+ * public const PROPERTY_PHONE = 'phone';
+ * public const PROPERTY_EMAIL = 'email';
+ * public const PROPERTY_WEBSITE = 'website';
+ * public const PROPERTY_ADDRESS = 'address';
+ * public const PROPERTY_TWITTER = 'twitter';
+ * public const PROPERTY_ORGANISATION = 'organisation';
+ * public const PROPERTY_ROLE = 'role';
+ * public const PROPERTY_HEADLINE = 'headline';
+ * public const PROPERTY_BIOGRAPHY = 'biography';
+ * public const PROPERTY_PROFILE_ENABLED = 'profile_enabled';
+ * public function getAccount(IUser $user): IAccount;
+ * public function updateAccount(IAccount $account): void;
+ */
+ /**
+ * fetches values from LDAP and stores it as Nextcloud user value
+ * @param string $valueFromLDAP if known, to save an LDAP read request
+ * @return null
+ */
+ public function updateProfile(string $property, $valueFromLDAP = null) {
+ if ($this->wasRefreshed($property)) {
+ return;
+ }
+ if ($valueFromLDAP !== null) {
+ //$propertyValue = (string)$valueFromLDAP;
+ $propertyValue = [$valueFromLDAP];
+ }
+ if ($propertyValue && isset($propertyValue[0])) {
+ $value = $propertyValue[0];
+ $this->config->setUserValue($this->getUsername(), 'user_ldap', $property, $value);
+ // TODO: update user profile data; call \OCP\Accounts\IAccount::setProperty
+ return $value;
+ } else {
+ $this->config->deleteUserValue($this->getUsername(), 'user_ldap', $property);
+ return '';
+ }
+ }
+
/**
* called by a post_login hook to save the avatar picture
*