@@ -31,84 +31,84 @@ |
||
31 | 31 | * @package OCA\User_LDAP |
32 | 32 | */ |
33 | 33 | class DeletedUsersIndex { |
34 | - /** |
|
35 | - * @var \OCP\IConfig $config |
|
36 | - */ |
|
37 | - protected $config; |
|
34 | + /** |
|
35 | + * @var \OCP\IConfig $config |
|
36 | + */ |
|
37 | + protected $config; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @var \OCP\IDBConnection $db |
|
41 | - */ |
|
42 | - protected $db; |
|
39 | + /** |
|
40 | + * @var \OCP\IDBConnection $db |
|
41 | + */ |
|
42 | + protected $db; |
|
43 | 43 | |
44 | - /** |
|
45 | - * @var \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
46 | - */ |
|
47 | - protected $mapping; |
|
44 | + /** |
|
45 | + * @var \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
46 | + */ |
|
47 | + protected $mapping; |
|
48 | 48 | |
49 | - /** |
|
50 | - * @var array $deletedUsers |
|
51 | - */ |
|
52 | - protected $deletedUsers; |
|
49 | + /** |
|
50 | + * @var array $deletedUsers |
|
51 | + */ |
|
52 | + protected $deletedUsers; |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param \OCP\IConfig $config |
|
56 | - * @param \OCP\IDBConnection $db |
|
57 | - * @param \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
58 | - */ |
|
59 | - public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) { |
|
60 | - $this->config = $config; |
|
61 | - $this->db = $db; |
|
62 | - $this->mapping = $mapping; |
|
63 | - } |
|
54 | + /** |
|
55 | + * @param \OCP\IConfig $config |
|
56 | + * @param \OCP\IDBConnection $db |
|
57 | + * @param \OCA\User_LDAP\Mapping\UserMapping $mapping |
|
58 | + */ |
|
59 | + public function __construct(\OCP\IConfig $config, \OCP\IDBConnection $db, UserMapping $mapping) { |
|
60 | + $this->config = $config; |
|
61 | + $this->db = $db; |
|
62 | + $this->mapping = $mapping; |
|
63 | + } |
|
64 | 64 | |
65 | - /** |
|
66 | - * reads LDAP users marked as deleted from the database |
|
67 | - * @return \OCA\User_LDAP\User\OfflineUser[] |
|
68 | - */ |
|
69 | - private function fetchDeletedUsers() { |
|
70 | - $deletedUsers = $this->config->getUsersForUserValue( |
|
71 | - 'user_ldap', 'isDeleted', '1'); |
|
65 | + /** |
|
66 | + * reads LDAP users marked as deleted from the database |
|
67 | + * @return \OCA\User_LDAP\User\OfflineUser[] |
|
68 | + */ |
|
69 | + private function fetchDeletedUsers() { |
|
70 | + $deletedUsers = $this->config->getUsersForUserValue( |
|
71 | + 'user_ldap', 'isDeleted', '1'); |
|
72 | 72 | |
73 | - $userObjects = array(); |
|
74 | - foreach($deletedUsers as $user) { |
|
75 | - $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); |
|
76 | - } |
|
77 | - $this->deletedUsers = $userObjects; |
|
73 | + $userObjects = array(); |
|
74 | + foreach($deletedUsers as $user) { |
|
75 | + $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); |
|
76 | + } |
|
77 | + $this->deletedUsers = $userObjects; |
|
78 | 78 | |
79 | - return $this->deletedUsers; |
|
80 | - } |
|
79 | + return $this->deletedUsers; |
|
80 | + } |
|
81 | 81 | |
82 | - /** |
|
83 | - * returns all LDAP users that are marked as deleted |
|
84 | - * @return \OCA\User_LDAP\User\OfflineUser[] |
|
85 | - */ |
|
86 | - public function getUsers() { |
|
87 | - if(is_array($this->deletedUsers)) { |
|
88 | - return $this->deletedUsers; |
|
89 | - } |
|
90 | - return $this->fetchDeletedUsers(); |
|
91 | - } |
|
82 | + /** |
|
83 | + * returns all LDAP users that are marked as deleted |
|
84 | + * @return \OCA\User_LDAP\User\OfflineUser[] |
|
85 | + */ |
|
86 | + public function getUsers() { |
|
87 | + if(is_array($this->deletedUsers)) { |
|
88 | + return $this->deletedUsers; |
|
89 | + } |
|
90 | + return $this->fetchDeletedUsers(); |
|
91 | + } |
|
92 | 92 | |
93 | - /** |
|
94 | - * whether at least one user was detected as deleted |
|
95 | - * @return bool |
|
96 | - */ |
|
97 | - public function hasUsers() { |
|
98 | - if($this->deletedUsers === false) { |
|
99 | - $this->fetchDeletedUsers(); |
|
100 | - } |
|
101 | - if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
102 | - return true; |
|
103 | - } |
|
104 | - return false; |
|
105 | - } |
|
93 | + /** |
|
94 | + * whether at least one user was detected as deleted |
|
95 | + * @return bool |
|
96 | + */ |
|
97 | + public function hasUsers() { |
|
98 | + if($this->deletedUsers === false) { |
|
99 | + $this->fetchDeletedUsers(); |
|
100 | + } |
|
101 | + if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
102 | + return true; |
|
103 | + } |
|
104 | + return false; |
|
105 | + } |
|
106 | 106 | |
107 | - /** |
|
108 | - * marks a user as deleted |
|
109 | - * @param string $ocName |
|
110 | - */ |
|
111 | - public function markUser($ocName) { |
|
112 | - $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); |
|
113 | - } |
|
107 | + /** |
|
108 | + * marks a user as deleted |
|
109 | + * @param string $ocName |
|
110 | + */ |
|
111 | + public function markUser($ocName) { |
|
112 | + $this->config->setUserValue($ocName, 'user_ldap', 'isDeleted', '1'); |
|
113 | + } |
|
114 | 114 | } |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | 'user_ldap', 'isDeleted', '1'); |
72 | 72 | |
73 | 73 | $userObjects = array(); |
74 | - foreach($deletedUsers as $user) { |
|
74 | + foreach ($deletedUsers as $user) { |
|
75 | 75 | $userObjects[] = new OfflineUser($user, $this->config, $this->db, $this->mapping); |
76 | 76 | } |
77 | 77 | $this->deletedUsers = $userObjects; |
@@ -84,7 +84,7 @@ discard block |
||
84 | 84 | * @return \OCA\User_LDAP\User\OfflineUser[] |
85 | 85 | */ |
86 | 86 | public function getUsers() { |
87 | - if(is_array($this->deletedUsers)) { |
|
87 | + if (is_array($this->deletedUsers)) { |
|
88 | 88 | return $this->deletedUsers; |
89 | 89 | } |
90 | 90 | return $this->fetchDeletedUsers(); |
@@ -95,10 +95,10 @@ discard block |
||
95 | 95 | * @return bool |
96 | 96 | */ |
97 | 97 | public function hasUsers() { |
98 | - if($this->deletedUsers === false) { |
|
98 | + if ($this->deletedUsers === false) { |
|
99 | 99 | $this->fetchDeletedUsers(); |
100 | 100 | } |
101 | - if(is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
101 | + if (is_array($this->deletedUsers) && count($this->deletedUsers) > 0) { |
|
102 | 102 | return true; |
103 | 103 | } |
104 | 104 | return false; |
@@ -30,13 +30,13 @@ |
||
30 | 30 | * defines methods that are required by User class for LDAP interaction |
31 | 31 | */ |
32 | 32 | interface IUserTools { |
33 | - public function getConnection(); |
|
33 | + public function getConnection(); |
|
34 | 34 | |
35 | - public function readAttribute($dn, $attr, $filter = 'objectClass=*'); |
|
35 | + public function readAttribute($dn, $attr, $filter = 'objectClass=*'); |
|
36 | 36 | |
37 | - public function stringResemblesDN($string); |
|
37 | + public function stringResemblesDN($string); |
|
38 | 38 | |
39 | - public function dn2username($dn, $ldapname = null); |
|
39 | + public function dn2username($dn, $ldapname = null); |
|
40 | 40 | |
41 | - public function username2dn($name); |
|
41 | + public function username2dn($name); |
|
42 | 42 | } |
@@ -24,26 +24,26 @@ |
||
24 | 24 | |
25 | 25 | interface IUserLDAP { |
26 | 26 | |
27 | - //Functions used by LDAPProvider |
|
27 | + //Functions used by LDAPProvider |
|
28 | 28 | |
29 | - /** |
|
30 | - * Return access for LDAP interaction. |
|
31 | - * @param string $uid |
|
32 | - * @return Access instance of Access for LDAP interaction |
|
33 | - */ |
|
34 | - public function getLDAPAccess($uid); |
|
29 | + /** |
|
30 | + * Return access for LDAP interaction. |
|
31 | + * @param string $uid |
|
32 | + * @return Access instance of Access for LDAP interaction |
|
33 | + */ |
|
34 | + public function getLDAPAccess($uid); |
|
35 | 35 | |
36 | - /** |
|
37 | - * Return a new LDAP connection for the specified user. |
|
38 | - * @param string $uid |
|
39 | - * @return resource of the LDAP connection |
|
40 | - */ |
|
41 | - public function getNewLDAPConnection($uid); |
|
36 | + /** |
|
37 | + * Return a new LDAP connection for the specified user. |
|
38 | + * @param string $uid |
|
39 | + * @return resource of the LDAP connection |
|
40 | + */ |
|
41 | + public function getNewLDAPConnection($uid); |
|
42 | 42 | |
43 | - /** |
|
44 | - * Return the username for the given LDAP DN, if available. |
|
45 | - * @param string $dn |
|
46 | - * @return string|false with the username |
|
47 | - */ |
|
48 | - public function dn2UserName($dn); |
|
43 | + /** |
|
44 | + * Return the username for the given LDAP DN, if available. |
|
45 | + * @param string $dn |
|
46 | + * @return string|false with the username |
|
47 | + */ |
|
48 | + public function dn2UserName($dn); |
|
49 | 49 | } |
@@ -27,13 +27,13 @@ |
||
27 | 27 | |
28 | 28 | |
29 | 29 | abstract class BackendUtility { |
30 | - protected $access; |
|
30 | + protected $access; |
|
31 | 31 | |
32 | - /** |
|
33 | - * constructor, make sure the subclasses call this one! |
|
34 | - * @param Access $access an instance of Access for LDAP interaction |
|
35 | - */ |
|
36 | - public function __construct(Access $access) { |
|
37 | - $this->access = $access; |
|
38 | - } |
|
32 | + /** |
|
33 | + * constructor, make sure the subclasses call this one! |
|
34 | + * @param Access $access an instance of Access for LDAP interaction |
|
35 | + */ |
|
36 | + public function __construct(Access $access) { |
|
37 | + $this->access = $access; |
|
38 | + } |
|
39 | 39 | } |
@@ -28,52 +28,52 @@ |
||
28 | 28 | namespace OCA\User_LDAP; |
29 | 29 | |
30 | 30 | class WizardResult { |
31 | - protected $changes = array(); |
|
32 | - protected $options = array(); |
|
33 | - protected $markedChange = false; |
|
31 | + protected $changes = array(); |
|
32 | + protected $options = array(); |
|
33 | + protected $markedChange = false; |
|
34 | 34 | |
35 | - /** |
|
36 | - * @param string $key |
|
37 | - * @param mixed $value |
|
38 | - */ |
|
39 | - public function addChange($key, $value) { |
|
40 | - $this->changes[$key] = $value; |
|
41 | - } |
|
35 | + /** |
|
36 | + * @param string $key |
|
37 | + * @param mixed $value |
|
38 | + */ |
|
39 | + public function addChange($key, $value) { |
|
40 | + $this->changes[$key] = $value; |
|
41 | + } |
|
42 | 42 | |
43 | - /** |
|
44 | - * |
|
45 | - */ |
|
46 | - public function markChange() { |
|
47 | - $this->markedChange = true; |
|
48 | - } |
|
43 | + /** |
|
44 | + * |
|
45 | + */ |
|
46 | + public function markChange() { |
|
47 | + $this->markedChange = true; |
|
48 | + } |
|
49 | 49 | |
50 | - /** |
|
51 | - * @param string $key |
|
52 | - * @param array|string $values |
|
53 | - */ |
|
54 | - public function addOptions($key, $values) { |
|
55 | - if(!is_array($values)) { |
|
56 | - $values = array($values); |
|
57 | - } |
|
58 | - $this->options[$key] = $values; |
|
59 | - } |
|
50 | + /** |
|
51 | + * @param string $key |
|
52 | + * @param array|string $values |
|
53 | + */ |
|
54 | + public function addOptions($key, $values) { |
|
55 | + if(!is_array($values)) { |
|
56 | + $values = array($values); |
|
57 | + } |
|
58 | + $this->options[$key] = $values; |
|
59 | + } |
|
60 | 60 | |
61 | - /** |
|
62 | - * @return bool |
|
63 | - */ |
|
64 | - public function hasChanges() { |
|
65 | - return (count($this->changes) > 0 || $this->markedChange); |
|
66 | - } |
|
61 | + /** |
|
62 | + * @return bool |
|
63 | + */ |
|
64 | + public function hasChanges() { |
|
65 | + return (count($this->changes) > 0 || $this->markedChange); |
|
66 | + } |
|
67 | 67 | |
68 | - /** |
|
69 | - * @return array |
|
70 | - */ |
|
71 | - public function getResultArray() { |
|
72 | - $result = array(); |
|
73 | - $result['changes'] = $this->changes; |
|
74 | - if(count($this->options) > 0) { |
|
75 | - $result['options'] = $this->options; |
|
76 | - } |
|
77 | - return $result; |
|
78 | - } |
|
68 | + /** |
|
69 | + * @return array |
|
70 | + */ |
|
71 | + public function getResultArray() { |
|
72 | + $result = array(); |
|
73 | + $result['changes'] = $this->changes; |
|
74 | + if(count($this->options) > 0) { |
|
75 | + $result['options'] = $this->options; |
|
76 | + } |
|
77 | + return $result; |
|
78 | + } |
|
79 | 79 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @param array|string $values |
53 | 53 | */ |
54 | 54 | public function addOptions($key, $values) { |
55 | - if(!is_array($values)) { |
|
55 | + if (!is_array($values)) { |
|
56 | 56 | $values = array($values); |
57 | 57 | } |
58 | 58 | $this->options[$key] = $values; |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | public function getResultArray() { |
72 | 72 | $result = array(); |
73 | 73 | $result['changes'] = $this->changes; |
74 | - if(count($this->options) > 0) { |
|
74 | + if (count($this->options) > 0) { |
|
75 | 75 | $result['options'] = $this->options; |
76 | 76 | } |
77 | 77 | return $result; |
@@ -30,31 +30,31 @@ |
||
30 | 30 | use OCA\User_LDAP\User_Proxy; |
31 | 31 | |
32 | 32 | abstract class UUIDFix extends QueuedJob { |
33 | - /** @var AbstractMapping */ |
|
34 | - protected $mapper; |
|
33 | + /** @var AbstractMapping */ |
|
34 | + protected $mapper; |
|
35 | 35 | |
36 | - /** @var Proxy */ |
|
37 | - protected $proxy; |
|
36 | + /** @var Proxy */ |
|
37 | + protected $proxy; |
|
38 | 38 | |
39 | - public function run($argument) { |
|
40 | - $isUser = $this->proxy instanceof User_Proxy; |
|
41 | - foreach($argument['records'] as $record) { |
|
42 | - $access = $this->proxy->getLDAPAccess($record['name']); |
|
43 | - $uuid = $access->getUUID($record['dn'], $isUser); |
|
44 | - if($uuid === false) { |
|
45 | - // record not found, no prob, continue with the next |
|
46 | - continue; |
|
47 | - } |
|
48 | - if($uuid !== $record['uuid']) { |
|
49 | - $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
39 | + public function run($argument) { |
|
40 | + $isUser = $this->proxy instanceof User_Proxy; |
|
41 | + foreach($argument['records'] as $record) { |
|
42 | + $access = $this->proxy->getLDAPAccess($record['name']); |
|
43 | + $uuid = $access->getUUID($record['dn'], $isUser); |
|
44 | + if($uuid === false) { |
|
45 | + // record not found, no prob, continue with the next |
|
46 | + continue; |
|
47 | + } |
|
48 | + if($uuid !== $record['uuid']) { |
|
49 | + $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * @param Proxy $proxy |
|
56 | - */ |
|
57 | - public function overrideProxy(Proxy $proxy) { |
|
58 | - $this->proxy = $proxy; |
|
59 | - } |
|
54 | + /** |
|
55 | + * @param Proxy $proxy |
|
56 | + */ |
|
57 | + public function overrideProxy(Proxy $proxy) { |
|
58 | + $this->proxy = $proxy; |
|
59 | + } |
|
60 | 60 | } |
@@ -38,14 +38,14 @@ |
||
38 | 38 | |
39 | 39 | public function run($argument) { |
40 | 40 | $isUser = $this->proxy instanceof User_Proxy; |
41 | - foreach($argument['records'] as $record) { |
|
41 | + foreach ($argument['records'] as $record) { |
|
42 | 42 | $access = $this->proxy->getLDAPAccess($record['name']); |
43 | 43 | $uuid = $access->getUUID($record['dn'], $isUser); |
44 | - if($uuid === false) { |
|
44 | + if ($uuid === false) { |
|
45 | 45 | // record not found, no prob, continue with the next |
46 | 46 | continue; |
47 | 47 | } |
48 | - if($uuid !== $record['uuid']) { |
|
48 | + if ($uuid !== $record['uuid']) { |
|
49 | 49 | $this->mapper->setUUIDbyDN($uuid, $record['dn']); |
50 | 50 | } |
51 | 51 | } |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | $this->isAllowed($input->getOption('force')); |
87 | 87 | $this->confirmUserIsMapped($uid); |
88 | 88 | $exists = $this->backend->userExistsOnLDAP($uid); |
89 | - if($exists === true) { |
|
89 | + if ($exists === true) { |
|
90 | 90 | $output->writeln('The user is still available on LDAP.'); |
91 | 91 | return; |
92 | 92 | } |
@@ -94,9 +94,9 @@ discard block |
||
94 | 94 | $this->dui->markUser($uid); |
95 | 95 | $output->writeln('The user does not exists on LDAP anymore.'); |
96 | 96 | $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
97 | - . $uid . '"'); |
|
97 | + . $uid.'"'); |
|
98 | 98 | } catch (\Exception $e) { |
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
99 | + $output->writeln('<error>'.$e->getMessage().'</error>'); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | |
@@ -121,7 +121,7 @@ discard block |
||
121 | 121 | * @return true |
122 | 122 | */ |
123 | 123 | protected function isAllowed($force) { |
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
124 | + if ($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | 125 | throw new \Exception('Cannot check user existence, because ' |
126 | 126 | . 'disabled LDAP configurations are present.'); |
127 | 127 | } |
@@ -36,101 +36,101 @@ |
||
36 | 36 | use OCA\User_LDAP\User_Proxy; |
37 | 37 | |
38 | 38 | class CheckUser extends Command { |
39 | - /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | - protected $backend; |
|
41 | - |
|
42 | - /** @var \OCA\User_LDAP\Helper */ |
|
43 | - protected $helper; |
|
44 | - |
|
45 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | - protected $dui; |
|
47 | - |
|
48 | - /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | - protected $mapping; |
|
50 | - |
|
51 | - /** |
|
52 | - * @param User_Proxy $uBackend |
|
53 | - * @param LDAPHelper $helper |
|
54 | - * @param DeletedUsersIndex $dui |
|
55 | - * @param UserMapping $mapping |
|
56 | - */ |
|
57 | - public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | - $this->backend = $uBackend; |
|
59 | - $this->helper = $helper; |
|
60 | - $this->dui = $dui; |
|
61 | - $this->mapping = $mapping; |
|
62 | - parent::__construct(); |
|
63 | - } |
|
64 | - |
|
65 | - protected function configure() { |
|
66 | - $this |
|
67 | - ->setName('ldap:check-user') |
|
68 | - ->setDescription('checks whether a user exists on LDAP.') |
|
69 | - ->addArgument( |
|
70 | - 'ocName', |
|
71 | - InputArgument::REQUIRED, |
|
72 | - 'the user name as used in Nextcloud' |
|
73 | - ) |
|
74 | - ->addOption( |
|
75 | - 'force', |
|
76 | - null, |
|
77 | - InputOption::VALUE_NONE, |
|
78 | - 'ignores disabled LDAP configuration' |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
82 | - |
|
83 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | - try { |
|
85 | - $uid = $input->getArgument('ocName'); |
|
86 | - $this->isAllowed($input->getOption('force')); |
|
87 | - $this->confirmUserIsMapped($uid); |
|
88 | - $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | - if($exists === true) { |
|
90 | - $output->writeln('The user is still available on LDAP.'); |
|
91 | - return; |
|
92 | - } |
|
93 | - |
|
94 | - $this->dui->markUser($uid); |
|
95 | - $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | - $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | - . $uid . '"'); |
|
98 | - } catch (\Exception $e) { |
|
99 | - $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | - } |
|
101 | - } |
|
102 | - |
|
103 | - /** |
|
104 | - * checks whether a user is actually mapped |
|
105 | - * @param string $ocName the username as used in Nextcloud |
|
106 | - * @throws \Exception |
|
107 | - * @return true |
|
108 | - */ |
|
109 | - protected function confirmUserIsMapped($ocName) { |
|
110 | - $dn = $this->mapping->getDNByName($ocName); |
|
111 | - if ($dn === false) { |
|
112 | - throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | - } |
|
114 | - |
|
115 | - return true; |
|
116 | - } |
|
117 | - |
|
118 | - /** |
|
119 | - * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | - * @throws \Exception |
|
121 | - * @return true |
|
122 | - */ |
|
123 | - protected function isAllowed($force) { |
|
124 | - if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | - throw new \Exception('Cannot check user existence, because ' |
|
126 | - . 'disabled LDAP configurations are present.'); |
|
127 | - } |
|
128 | - |
|
129 | - // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | - // action is triggered manually, while the setting only controls the |
|
131 | - // background job. |
|
132 | - |
|
133 | - return true; |
|
134 | - } |
|
39 | + /** @var \OCA\User_LDAP\User_Proxy */ |
|
40 | + protected $backend; |
|
41 | + |
|
42 | + /** @var \OCA\User_LDAP\Helper */ |
|
43 | + protected $helper; |
|
44 | + |
|
45 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
46 | + protected $dui; |
|
47 | + |
|
48 | + /** @var \OCA\User_LDAP\Mapping\UserMapping */ |
|
49 | + protected $mapping; |
|
50 | + |
|
51 | + /** |
|
52 | + * @param User_Proxy $uBackend |
|
53 | + * @param LDAPHelper $helper |
|
54 | + * @param DeletedUsersIndex $dui |
|
55 | + * @param UserMapping $mapping |
|
56 | + */ |
|
57 | + public function __construct(User_Proxy $uBackend, LDAPHelper $helper, DeletedUsersIndex $dui, UserMapping $mapping) { |
|
58 | + $this->backend = $uBackend; |
|
59 | + $this->helper = $helper; |
|
60 | + $this->dui = $dui; |
|
61 | + $this->mapping = $mapping; |
|
62 | + parent::__construct(); |
|
63 | + } |
|
64 | + |
|
65 | + protected function configure() { |
|
66 | + $this |
|
67 | + ->setName('ldap:check-user') |
|
68 | + ->setDescription('checks whether a user exists on LDAP.') |
|
69 | + ->addArgument( |
|
70 | + 'ocName', |
|
71 | + InputArgument::REQUIRED, |
|
72 | + 'the user name as used in Nextcloud' |
|
73 | + ) |
|
74 | + ->addOption( |
|
75 | + 'force', |
|
76 | + null, |
|
77 | + InputOption::VALUE_NONE, |
|
78 | + 'ignores disabled LDAP configuration' |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | + |
|
83 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
84 | + try { |
|
85 | + $uid = $input->getArgument('ocName'); |
|
86 | + $this->isAllowed($input->getOption('force')); |
|
87 | + $this->confirmUserIsMapped($uid); |
|
88 | + $exists = $this->backend->userExistsOnLDAP($uid); |
|
89 | + if($exists === true) { |
|
90 | + $output->writeln('The user is still available on LDAP.'); |
|
91 | + return; |
|
92 | + } |
|
93 | + |
|
94 | + $this->dui->markUser($uid); |
|
95 | + $output->writeln('The user does not exists on LDAP anymore.'); |
|
96 | + $output->writeln('Clean up the user\'s remnants by: ./occ user:delete "' |
|
97 | + . $uid . '"'); |
|
98 | + } catch (\Exception $e) { |
|
99 | + $output->writeln('<error>' . $e->getMessage(). '</error>'); |
|
100 | + } |
|
101 | + } |
|
102 | + |
|
103 | + /** |
|
104 | + * checks whether a user is actually mapped |
|
105 | + * @param string $ocName the username as used in Nextcloud |
|
106 | + * @throws \Exception |
|
107 | + * @return true |
|
108 | + */ |
|
109 | + protected function confirmUserIsMapped($ocName) { |
|
110 | + $dn = $this->mapping->getDNByName($ocName); |
|
111 | + if ($dn === false) { |
|
112 | + throw new \Exception('The given user is not a recognized LDAP user.'); |
|
113 | + } |
|
114 | + |
|
115 | + return true; |
|
116 | + } |
|
117 | + |
|
118 | + /** |
|
119 | + * checks whether the setup allows reliable checking of LDAP user existence |
|
120 | + * @throws \Exception |
|
121 | + * @return true |
|
122 | + */ |
|
123 | + protected function isAllowed($force) { |
|
124 | + if($this->helper->haveDisabledConfigurations() && !$force) { |
|
125 | + throw new \Exception('Cannot check user existence, because ' |
|
126 | + . 'disabled LDAP configurations are present.'); |
|
127 | + } |
|
128 | + |
|
129 | + // we don't check ldapUserCleanupInterval from config.php because this |
|
130 | + // action is triggered manually, while the setting only controls the |
|
131 | + // background job. |
|
132 | + |
|
133 | + return true; |
|
134 | + } |
|
135 | 135 | |
136 | 136 | } |
@@ -33,39 +33,39 @@ |
||
33 | 33 | use Symfony\Component\Console\Output\OutputInterface; |
34 | 34 | |
35 | 35 | class DeleteConfig extends Command { |
36 | - /** @var \OCA\User_LDAP\Helper */ |
|
37 | - protected $helper; |
|
36 | + /** @var \OCA\User_LDAP\Helper */ |
|
37 | + protected $helper; |
|
38 | 38 | |
39 | - /** |
|
40 | - * @param Helper $helper |
|
41 | - */ |
|
42 | - public function __construct(Helper $helper) { |
|
43 | - $this->helper = $helper; |
|
44 | - parent::__construct(); |
|
45 | - } |
|
39 | + /** |
|
40 | + * @param Helper $helper |
|
41 | + */ |
|
42 | + public function __construct(Helper $helper) { |
|
43 | + $this->helper = $helper; |
|
44 | + parent::__construct(); |
|
45 | + } |
|
46 | 46 | |
47 | - protected function configure() { |
|
48 | - $this |
|
49 | - ->setName('ldap:delete-config') |
|
50 | - ->setDescription('deletes an existing LDAP configuration') |
|
51 | - ->addArgument( |
|
52 | - 'configID', |
|
53 | - InputArgument::REQUIRED, |
|
54 | - 'the configuration ID' |
|
55 | - ) |
|
56 | - ; |
|
57 | - } |
|
47 | + protected function configure() { |
|
48 | + $this |
|
49 | + ->setName('ldap:delete-config') |
|
50 | + ->setDescription('deletes an existing LDAP configuration') |
|
51 | + ->addArgument( |
|
52 | + 'configID', |
|
53 | + InputArgument::REQUIRED, |
|
54 | + 'the configuration ID' |
|
55 | + ) |
|
56 | + ; |
|
57 | + } |
|
58 | 58 | |
59 | 59 | |
60 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | - $configPrefix = $input->getArgument('configID'); |
|
60 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
61 | + $configPrefix = $input->getArgument('configID'); |
|
62 | 62 | |
63 | - $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
63 | + $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
64 | 64 | |
65 | - if($success) { |
|
66 | - $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | - } else { |
|
68 | - $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | - } |
|
70 | - } |
|
65 | + if($success) { |
|
66 | + $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
67 | + } else { |
|
68 | + $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
69 | + } |
|
70 | + } |
|
71 | 71 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | |
63 | 63 | $success = $this->helper->deleteServerConfiguration($configPrefix); |
64 | 64 | |
65 | - if($success) { |
|
65 | + if ($success) { |
|
66 | 66 | $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
67 | 67 | } else { |
68 | 68 | $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
@@ -34,59 +34,59 @@ |
||
34 | 34 | |
35 | 35 | class TestConfig extends Command { |
36 | 36 | |
37 | - protected function configure() { |
|
38 | - $this |
|
39 | - ->setName('ldap:test-config') |
|
40 | - ->setDescription('tests an LDAP configuration') |
|
41 | - ->addArgument( |
|
42 | - 'configID', |
|
43 | - InputArgument::REQUIRED, |
|
44 | - 'the configuration ID' |
|
45 | - ) |
|
46 | - ; |
|
47 | - } |
|
37 | + protected function configure() { |
|
38 | + $this |
|
39 | + ->setName('ldap:test-config') |
|
40 | + ->setDescription('tests an LDAP configuration') |
|
41 | + ->addArgument( |
|
42 | + 'configID', |
|
43 | + InputArgument::REQUIRED, |
|
44 | + 'the configuration ID' |
|
45 | + ) |
|
46 | + ; |
|
47 | + } |
|
48 | 48 | |
49 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | - $helper = new Helper(\OC::$server->getConfig()); |
|
51 | - $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
52 | - $configID = $input->getArgument('configID'); |
|
53 | - if(!in_array($configID, $availableConfigs)) { |
|
54 | - $output->writeln("Invalid configID"); |
|
55 | - return; |
|
56 | - } |
|
49 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
50 | + $helper = new Helper(\OC::$server->getConfig()); |
|
51 | + $availableConfigs = $helper->getServerConfigurationPrefixes(); |
|
52 | + $configID = $input->getArgument('configID'); |
|
53 | + if(!in_array($configID, $availableConfigs)) { |
|
54 | + $output->writeln("Invalid configID"); |
|
55 | + return; |
|
56 | + } |
|
57 | 57 | |
58 | - $result = $this->testConfig($configID); |
|
59 | - if($result === 0) { |
|
60 | - $output->writeln('The configuration is valid and the connection could be established!'); |
|
61 | - } else if($result === 1) { |
|
62 | - $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
63 | - } else if($result === 2) { |
|
64 | - $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
65 | - } else { |
|
66 | - $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
67 | - } |
|
68 | - } |
|
58 | + $result = $this->testConfig($configID); |
|
59 | + if($result === 0) { |
|
60 | + $output->writeln('The configuration is valid and the connection could be established!'); |
|
61 | + } else if($result === 1) { |
|
62 | + $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
|
63 | + } else if($result === 2) { |
|
64 | + $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
|
65 | + } else { |
|
66 | + $output->writeln('Your LDAP server was kidnapped by aliens.'); |
|
67 | + } |
|
68 | + } |
|
69 | 69 | |
70 | - /** |
|
71 | - * tests the specified connection |
|
72 | - * @param string $configID |
|
73 | - * @return int |
|
74 | - */ |
|
75 | - protected function testConfig($configID) { |
|
76 | - $lw = new \OCA\User_LDAP\LDAP(); |
|
77 | - $connection = new Connection($lw, $configID); |
|
70 | + /** |
|
71 | + * tests the specified connection |
|
72 | + * @param string $configID |
|
73 | + * @return int |
|
74 | + */ |
|
75 | + protected function testConfig($configID) { |
|
76 | + $lw = new \OCA\User_LDAP\LDAP(); |
|
77 | + $connection = new Connection($lw, $configID); |
|
78 | 78 | |
79 | - //ensure validation is run before we attempt the bind |
|
80 | - $connection->getConfiguration(); |
|
79 | + //ensure validation is run before we attempt the bind |
|
80 | + $connection->getConfiguration(); |
|
81 | 81 | |
82 | - if(!$connection->setConfiguration(array( |
|
83 | - 'ldap_configuration_active' => 1, |
|
84 | - ))) { |
|
85 | - return 1; |
|
86 | - } |
|
87 | - if($connection->bind()) { |
|
88 | - return 0; |
|
89 | - } |
|
90 | - return 2; |
|
91 | - } |
|
82 | + if(!$connection->setConfiguration(array( |
|
83 | + 'ldap_configuration_active' => 1, |
|
84 | + ))) { |
|
85 | + return 1; |
|
86 | + } |
|
87 | + if($connection->bind()) { |
|
88 | + return 0; |
|
89 | + } |
|
90 | + return 2; |
|
91 | + } |
|
92 | 92 | } |
@@ -50,17 +50,17 @@ discard block |
||
50 | 50 | $helper = new Helper(\OC::$server->getConfig()); |
51 | 51 | $availableConfigs = $helper->getServerConfigurationPrefixes(); |
52 | 52 | $configID = $input->getArgument('configID'); |
53 | - if(!in_array($configID, $availableConfigs)) { |
|
53 | + if (!in_array($configID, $availableConfigs)) { |
|
54 | 54 | $output->writeln("Invalid configID"); |
55 | 55 | return; |
56 | 56 | } |
57 | 57 | |
58 | 58 | $result = $this->testConfig($configID); |
59 | - if($result === 0) { |
|
59 | + if ($result === 0) { |
|
60 | 60 | $output->writeln('The configuration is valid and the connection could be established!'); |
61 | - } else if($result === 1) { |
|
61 | + } else if ($result === 1) { |
|
62 | 62 | $output->writeln('The configuration is invalid. Please have a look at the logs for further details.'); |
63 | - } else if($result === 2) { |
|
63 | + } else if ($result === 2) { |
|
64 | 64 | $output->writeln('The configuration is valid, but the Bind failed. Please check the server settings and credentials.'); |
65 | 65 | } else { |
66 | 66 | $output->writeln('Your LDAP server was kidnapped by aliens.'); |
@@ -79,12 +79,12 @@ discard block |
||
79 | 79 | //ensure validation is run before we attempt the bind |
80 | 80 | $connection->getConfiguration(); |
81 | 81 | |
82 | - if(!$connection->setConfiguration(array( |
|
82 | + if (!$connection->setConfiguration(array( |
|
83 | 83 | 'ldap_configuration_active' => 1, |
84 | 84 | ))) { |
85 | 85 | return 1; |
86 | 86 | } |
87 | - if($connection->bind()) { |
|
87 | + if ($connection->bind()) { |
|
88 | 88 | return 0; |
89 | 89 | } |
90 | 90 | return 2; |