Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
e6020d2
adapt info and give its own name
blizzz May 22, 2019
70bbbb2
remove some not needed components
blizzz May 22, 2019
c9b04ec
convert app init script to Application
blizzz May 22, 2019
1b30bc1
namespace adjustments
blizzz May 24, 2019
6a1b379
keep LDAPConnect working like this for now…
blizzz May 29, 2019
8a5fbb0
fix initialisation for now, add LDAPUserManager dep on LDAP provider
blizzz May 29, 2019
7481f16
conditionally, use actor's LDAP connection and prevent fallback to local
blizzz Jun 3, 2019
1587f5d
Use and LDIF as user creation template
blizzz Jun 3, 2019
dd2795e
User LDIF Template Editor WebUI
blizzz Jun 11, 2019
871f6b7
register hooks on app load
blizzz Jun 14, 2019
57e3b37
add displayname to default template
blizzz Jun 14, 2019
6a2f094
remove duplicate entry
blizzz Jun 14, 2019
fec2fa2
add DI and clean uo setDisplayNameRoutine
blizzz Jun 17, 2019
594dd32
makes us of proper deletion process of the LDAP user
blizzz Jun 18, 2019
8b10c7e
method signatures for changing details and email
blizzz Jun 18, 2019
5bb1d08
updates phpdoc
blizzz Jun 18, 2019
4fc1785
uses API method to flag LDAP user as deleted
blizzz Jun 18, 2019
5c4701e
formatting and cleanup
blizzz Jun 18, 2019
386f5da
removes uid generation as this will be done by provisioning API
blizzz Jun 18, 2019
3cf9151
removes unnecessary construct argument
blizzz Jun 18, 2019
f705241
resolves IConfig dependency on LDAPUserManager
blizzz Jun 18, 2019
ca39d03
adds UI for switches
blizzz Jun 18, 2019
7fd173e
adds UI switches for newUser.requireEmail and newUser.generateUserID
blizzz Jun 18, 2019
5aaddbb
adds Avatar switch
blizzz Jun 18, 2019
900c655
polishes classes:
blizzz Jun 18, 2019
7b98187
removes unneeded log statements
blizzz Jun 18, 2019
774a099
fetches first LDAP configuration prefix instead of guessing
blizzz Jun 19, 2019
e176c08
inserts ILogger dep
blizzz Jun 19, 2019
f976df0
sanitizes the DN before creating the user, so the further process suc…
blizzz Jun 19, 2019
65fdf7b
ensures that display name is initially set, even if not set in LDIF
blizzz Jun 19, 2019
80ea212
removes unneeded file
blizzz Jun 19, 2019
ed16efc
adds test infrastructure and first tests
blizzz Jun 19, 2019
f0c4b1f
fixes syntax for PHP 7.1
blizzz Jun 20, 2019
3f03cf8
adds missing files for integration tests, resolves cyclic dep
blizzz Jun 20, 2019
14f2f1a
bootstraps only, when an active configuration is available.
blizzz Jun 20, 2019
21d00fe
satisfies AppConfiguration traits desire for the testing app
blizzz Jun 20, 2019
0b51150
resolves dependency hell, all traits are already inherited
blizzz Jun 20, 2019
e9b0ab3
fixed default template, an extinct placeholder was used
blizzz Jun 20, 2019
8acbc41
sets user base
blizzz Jun 20, 2019
66b02ee
fixes conversion issue, an array is returned here of course
blizzz Jun 20, 2019
6809496
removes unnecessary objectclass from default template
blizzz Jun 20, 2019
b0da046
fixes lookup being not key insensitive
blizzz Jun 20, 2019
43f8ed0
fixes expected status code
blizzz Jun 20, 2019
4338fed
adjusts to server config switch changes
blizzz Jun 21, 2019
a21af4f
add test for dynamic user id and thus run against master
blizzz Jun 25, 2019
25b8c55
extend tests with displayname
blizzz Jun 25, 2019
a92ceda
also run tests without a cache
blizzz Jun 25, 2019
9bd731d
fix deletion of users (figured without redis)
blizzz Jun 26, 2019
0660d97
uses the user deletion method that deletes the user just once...
blizzz Jun 26, 2019
f9e2464
add test for creating group and creating a new user with that membership
blizzz Jun 27, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix initialisation for now, add LDAPUserManager dep on LDAP provider
nicer fix needs changes in server

Signed-off-by: Arthur Schiwon <[email protected]>
  • Loading branch information
blizzz committed May 29, 2019
commit 8a5fbb0e2c04776124ea184a55048247915450f4
3 changes: 0 additions & 3 deletions appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,6 @@
<author mail="[email protected]" homepage="http://eita.org.br">Alan Freihof Tygel</author>
<author mail="[email protected]" homepage="https://arthur-schiwon.de">Arthur Schiwon</author>
<namespace>LdapWriteSupport</namespace>
<types>
<authentication/>
</types>
<category>integration</category>
<category>organization</category>
<category>tools</category>
Expand Down
27 changes: 23 additions & 4 deletions lib/AppInfo/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use OC;
use OC\Group\Group;
use OC\User\User;
use OCA\LdapWriteSupport\LDAPConnect;
use OCA\LdapWriteSupport\LDAPUserManager;
use OCA\LdapWriteSupport\LDAPGroupManager;
use OCA\User_LDAP\GroupPluginManager;
Expand All @@ -33,11 +34,29 @@ public function registerLDAPPlugins(): void {
return;
}

$this->ldapUserManager = OC::$server->query(LDAPUserManager::class);
$this->ldapGroupManager = OC::$server->query(LDAPGroupManager::class);
\OC_App::loadApp('user_ldap');
$c = $this->getContainer();
$s = $this->getContainer()->getServer();
$p = $s->getLDAPProvider();

$userPluginManager = OC::$server->query(UserPluginManager::class);
$groupPluginManager = OC::$server->query(GroupPluginManager::class);
// resolving LDAP provider fails indeed

$this->ldapUserManager = new LDAPUserManager(
$s->getUserManager(),
$s->getGroupManager(),
$s->getUserSession(),
new LDAPConnect($s->getConfig()),
$s->getConfig(),
$p
);

// $this->ldapUserManager = $c->query(LDAPUserManager::class);
$this->ldapGroupManager = $c->query(LDAPGroupManager::class);

/** @var UserPluginManager $userPluginManager */
$userPluginManager = OC::$server->query('LDAPUserPluginManager');
/** @var GroupPluginManager $groupPluginManager */
$groupPluginManager = OC::$server->query('LDAPGroupPluginManager');

$userPluginManager->register($this->ldapUserManager);
$groupPluginManager->register($this->ldapGroupManager);
Expand Down
74 changes: 29 additions & 45 deletions lib/LDAPUserManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* @author Alan Tygel <[email protected]>
* @author Vinicius Brand <[email protected]>
* @author Daniel Tygel <[email protected]>
* @author Arthur Schiwon <[email protected]>
*
* @license AGPL-3.0
*
Expand All @@ -25,24 +26,27 @@
namespace OCA\LdapWriteSupport;


use InvalidArgumentException;
use OC\HintException;
use OC\User\Backend;
use OCA\User_LDAP\Exceptions\ConstraintViolationException;
use OCA\User_LDAP\ILDAPUserPlugin;
use OCA\User_LDAP\IUserLDAP;
use OCA\User_LDAP\LDAPProvider;
use OCP\IConfig;
use OCP\IGroup;
use OCP\IGroupManager;
use OCP\IImage;
use OCP\IUser;
use OCP\IUserManager;
use OCP\IUserSession;
use OCP\LDAP\ILDAPProvider;


class LDAPUserManager implements ILDAPUserPlugin {

/** @var ILDAPProvider */
private $ldapProvider;

/** @var IUserSession */
private $userSession;

/** @var IGroupManager */
Expand All @@ -57,16 +61,17 @@ class LDAPUserManager implements ILDAPUserPlugin {
/** @var IConfig */
private $ocConfig;

public function __construct(IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession, LDAPConnect $ldapConnect, IConfig $ocConfig) {
public function __construct(IUserManager $userManager, IGroupManager $groupManager, IUserSession $userSession, LDAPConnect $ldapConnect, IConfig $ocConfig, ILDAPProvider $ldapProvider) {
$this->userManager = $userManager;
$this->groupManager = $groupManager;
$this->userSession = $userSession;
$this->ldapConnect = $ldapConnect;
$this->ocConfig = $ocConfig;

$this->userManager->listen('\OC\User', 'changeUser', array($this, 'changeUserHook'));
$this->userManager->listen('\OC\User', 'changeUser', [$this, 'changeUserHook']);

$this->makeLdapBackendFirst();
$this->ldapProvider = $ldapProvider;
}

/**
Expand All @@ -92,22 +97,19 @@ public function respondToActions() {
* @return bool
*/
public function setDisplayName($uid, $displayName) {
/** @var LDAPProvider $provider */
$provider = $this->getLDAPProvider();

$userDN = $this->getUserDN($uid);

$connection = $provider->getLDAPConnection($uid);
$connection = $this->ldapProvider->getLDAPConnection($uid);

$displayNameField = $provider->getLDAPDisplayNameField($uid);
$displayNameField = $this->ldapProvider->getLDAPDisplayNameField($uid);

if (!is_resource($connection)) {
//LDAP not available
\OCP\Util::writeLog('user_ldap', 'LDAP resource not available.', \OCP\Util::DEBUG);
return false;
}
try {
return ldap_mod_replace($connection,$userDN, array($displayNameField => $displayName));
return ldap_mod_replace($connection,$userDN, [$displayNameField => $displayName]);
} catch(ConstraintViolationException $e) {
throw new HintException('DisplayName change rejected.', \OC::$server->getL10N('user_ldap')->t('DisplayName change rejected. Hint: ').$e->getMessage(), $e->getCode());
}
Expand Down Expand Up @@ -140,10 +142,8 @@ public function changeAvatar($user) {
if ($avatar) {
$data = $avatar->data();

$provider = $this->getLDAPProvider();

$connection = $provider->getLDAPConnection($user->getUID());
ldap_mod_replace($connection, $userDN, array('jpegphoto' => $data));
$connection = $this->ldapProvider->getLDAPConnection($user->getUID());
ldap_mod_replace($connection, $userDN, ['jpegphoto' => $data]);
}

}
Expand All @@ -160,10 +160,9 @@ public function changeEmail($user, $newEmail) {
return;
}

$provider = $this->getLDAPProvider();
$emailField = $provider->getLDAPEmailField($user->getUID());
$connection = $provider->getLDAPConnection($user->getUID());
ldap_mod_replace($connection, $userDN, array($emailField => $newEmail));
$emailField = $this->ldapProvider->getLDAPEmailField($user->getUID());
$connection = $this->ldapProvider->getLDAPConnection($user->getUID());
ldap_mod_replace($connection, $userDN, [$emailField => $newEmail]);
}

/**
Expand All @@ -180,7 +179,7 @@ public function createUser($username, $password) {
// NOT allowed in user_ldap: uppercase letters or underscore
if (preg_match('/[A-Z_]/', $username)) {
$l = \OC::$server->getL10N('user_ldap_extended');
throw new \InvalidArgumentException($l->t('Uppercase letters and underscore (_) are not allowed in usernames.'));
throw new InvalidArgumentException($l->t('Uppercase letters and underscore (_) are not allowed in usernames.'));
}

# FIXME could not create user using LDAPProvider, because its methods rely
Expand All @@ -192,19 +191,19 @@ public function createUser($username, $password) {

if ($ret = ldap_add($connection, $newUserDN, $newUserEntry)) {
$message = "Create LDAP user '$username' ($newUserDN)";
\OC::$server->getLogger()->notice($message, array('app' => 'ldapusermanagement'));
\OC::$server->getLogger()->notice($message, ['app' => 'ldap_write_support']);
} else {
$message = "Unable to create LDAP user '$username' ($newUserDN)";
\OC::$server->getLogger()->error($message, array('app' => 'ldapusermanagement'));
\OC::$server->getLogger()->error($message, ['app' => 'ldap_write_support']);
}
ldap_close($connection);
return $ret ? $newUserDN : null;
}

public function buildNewEntry($username, $password) {
$entry = array(
$entry = [
'o' => $username ,
'objectClass' => array( 'inetOrgPerson', 'posixAccount', 'top'),
'objectClass' => ['inetOrgPerson', 'posixAccount', 'top'],
'cn' => $username ,
'gidnumber' => 1, // FIXME: Why this????
'homedirectory' => 'x', // ignored by nextcloud
Expand All @@ -215,14 +214,12 @@ public function buildNewEntry($username, $password) {
'userpassword' => $password ,
'displayName' => $username,
'street' => "address",
);
];
return $entry;
}

public function deleteUser($uid) {
$provider = $this->getLDAPProvider();

$connection = $provider->getLDAPConnection($uid);
$connection = $this->ldapProvider->getLDAPConnection($uid);

$userDN = $this->getUserDN($uid);

Expand All @@ -237,18 +234,18 @@ public function deleteUser($uid) {

if ($res = ldap_delete($connection, $userDN)) {
$message = "Delete LDAP user (isDeleted): " . $uid;
\OC::$server->getLogger()->notice($message, array('app' => 'ldapusermanagement'));
\OC::$server->getLogger()->notice($message, ['app' => 'ldapusermanagement']);

$this->ocConfig->setUserValue($uid, 'user_ldap', 'isDeleted', 1);
} else {
$errno = ldap_errno($connection);
if ($errno == 0x20) { #LDAP_NO_SUCH_OBJECT
$message = "Delete LDAP user (" . $uid. "): object not found. Is already deleted? Assuming YES";
\OC::$server->getLogger()->notice($message, array('app' => 'ldapusermanagement'));
\OC::$server->getLogger()->notice($message, ['app' => 'ldapusermanagement']);
$res = true;
} else {
$message = "Unable to delete LDAP user " . $uid;
\OC::$server->getLogger()->error($message, array('app' => 'ldapusermanagement'));
\OC::$server->getLogger()->error($message, ['app' => 'ldapusermanagement']);
}
}
ldap_close($connection);
Expand Down Expand Up @@ -303,7 +300,7 @@ public function countUsers() {

public function makeLdapBackendFirst() {
$backends = $this->userManager->getBackends();
$otherBackends = array();
$otherBackends = [];
$this->userManager->clearBackends();
foreach ($backends as $backend) {
if ($backend instanceof IUserLDAP) {
Expand All @@ -319,18 +316,6 @@ public function makeLdapBackendFirst() {
}
}

/**
* Provides LDAP Provider. Cannot be established in constructor
*
* @return LDAPProvider
*/
private function getLDAPProvider() {
if (!$this->ldapProvider) {
$this->ldapProvider = \OC::$server->query('LDAPProvider');
}
return $this->ldapProvider;
}

public function changeUserHook($user, $feature, $attr1, $attr2) {
switch ($feature) {
case 'avatar':
Expand All @@ -345,7 +330,6 @@ public function changeUserHook($user, $feature, $attr1, $attr2) {
}

private function getUserDN($uid) {
return $this->getLDAPProvider()->getUserDN($uid);
//return "cn=$uid,".$this->ldapConnect->getLDAPBaseUsers();
return $this->ldapProvider->getUserDN($uid);
}
}