adds an --update flag to check-user for manual sync of the ldap record
Signed-off-by: Arthur Schiwon <blizzz@arthur-schiwon.de>
This commit is contained in:
parent
940a3130b2
commit
40c9a743fa
|
@ -29,32 +29,31 @@ use Symfony\Component\Console\Input\InputArgument;
|
||||||
use Symfony\Component\Console\Input\InputInterface;
|
use Symfony\Component\Console\Input\InputInterface;
|
||||||
use Symfony\Component\Console\Input\InputOption;
|
use Symfony\Component\Console\Input\InputOption;
|
||||||
use Symfony\Component\Console\Output\OutputInterface;
|
use Symfony\Component\Console\Output\OutputInterface;
|
||||||
|
|
||||||
use OCA\User_LDAP\User\DeletedUsersIndex;
|
use OCA\User_LDAP\User\DeletedUsersIndex;
|
||||||
use OCA\User_LDAP\Mapping\UserMapping;
|
use OCA\User_LDAP\Mapping\UserMapping;
|
||||||
use OCA\User_LDAP\Helper as LDAPHelper;
|
use OCA\User_LDAP\Helper;
|
||||||
use OCA\User_LDAP\User_Proxy;
|
use OCA\User_LDAP\User_Proxy;
|
||||||
|
|
||||||
class CheckUser extends Command {
|
class CheckUser extends Command {
|
||||||
/** @var \OCA\User_LDAP\User_Proxy */
|
/** @var User_Proxy */
|
||||||
protected $backend;
|
protected $backend;
|
||||||
|
|
||||||
/** @var \OCA\User_LDAP\Helper */
|
/** @var Helper */
|
||||||
protected $helper;
|
protected $helper;
|
||||||
|
|
||||||
/** @var \OCA\User_LDAP\User\DeletedUsersIndex */
|
/** @var DeletedUsersIndex */
|
||||||
protected $dui;
|
protected $dui;
|
||||||
|
|
||||||
/** @var \OCA\User_LDAP\Mapping\UserMapping */
|
/** @var UserMapping */
|
||||||
protected $mapping;
|
protected $mapping;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param User_Proxy $uBackend
|
* @param User_Proxy $uBackend
|
||||||
* @param LDAPHelper $helper
|
* @param Helper $helper
|
||||||
* @param DeletedUsersIndex $dui
|
* @param DeletedUsersIndex $dui
|
||||||
* @param UserMapping $mapping
|
* @param UserMapping $mapping
|
||||||
*/
|
*/
|
||||||
public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
|
public function __construct(User_Proxy $uBackend, Helper $helper, DeletedUsersIndex $dui, UserMapping $mapping) {
|
||||||
$this->backend = $uBackend;
|
$this->backend = $uBackend;
|
||||||
$this->helper = $helper;
|
$this->helper = $helper;
|
||||||
$this->dui = $dui;
|
$this->dui = $dui;
|
||||||
|
@ -77,6 +76,12 @@ class CheckUser extends Command {
|
||||||
InputOption::VALUE_NONE,
|
InputOption::VALUE_NONE,
|
||||||
'ignores disabled LDAP configuration'
|
'ignores disabled LDAP configuration'
|
||||||
)
|
)
|
||||||
|
->addOption(
|
||||||
|
'update',
|
||||||
|
null,
|
||||||
|
InputOption::VALUE_NONE,
|
||||||
|
'syncs values from LDAP'
|
||||||
|
)
|
||||||
;
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -88,6 +93,9 @@ class CheckUser extends Command {
|
||||||
$exists = $this->backend->userExistsOnLDAP($uid);
|
$exists = $this->backend->userExistsOnLDAP($uid);
|
||||||
if($exists === true) {
|
if($exists === true) {
|
||||||
$output->writeln('The user is still available on LDAP.');
|
$output->writeln('The user is still available on LDAP.');
|
||||||
|
if($input->getOption('update')) {
|
||||||
|
$this->updateUser($uid, $output);
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,4 +141,26 @@ class CheckUser extends Command {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updateUser(string $uid, OutputInterface $output): void {
|
||||||
|
try {
|
||||||
|
$access = $this->backend->getLDAPAccess($uid);
|
||||||
|
$attrs = $access->userManager->getAttributes();
|
||||||
|
$user = $access->userManager->get($uid);
|
||||||
|
$avatarAttributes = $access->getConnection()->resolveRule('avatar');
|
||||||
|
$result = $access->search('objectclass=*', [$user->getDN()], $attrs, 1, 0);
|
||||||
|
foreach ($result[0] as $attribute => $valueSet) {
|
||||||
|
$output->writeln(' ' . $attribute . ': ');
|
||||||
|
foreach ($valueSet as $value) {
|
||||||
|
if (in_array($attribute, $avatarAttributes)) {
|
||||||
|
$value = '{ImageData}';
|
||||||
|
}
|
||||||
|
$output->writeln(' ' . $value);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
$access->batchApplyUserAttributes($result);
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
$output->writeln('<error>Error while trying to lookup and update attributes from LDAP</error>');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue