@@ -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; |
@@ -47,7 +47,7 @@ discard block |
||
47 | 47 | public function __construct(ILDAPWrapper $ldap) { |
48 | 48 | $this->ldap = $ldap; |
49 | 49 | $memcache = \OC::$server->getMemCacheFactory(); |
50 | - if($memcache->isAvailable()) { |
|
50 | + if ($memcache->isAvailable()) { |
|
51 | 51 | $this->cache = $memcache->create(); |
52 | 52 | } |
53 | 53 | } |
@@ -64,7 +64,7 @@ discard block |
||
64 | 64 | static $groupMap; |
65 | 65 | static $db; |
66 | 66 | static $coreUserManager; |
67 | - if(is_null($fs)) { |
|
67 | + if (is_null($fs)) { |
|
68 | 68 | $ocConfig = \OC::$server->getConfig(); |
69 | 69 | $fs = new FilesystemHelper(); |
70 | 70 | $log = new LogWrapper(); |
@@ -88,7 +88,7 @@ discard block |
||
88 | 88 | * @return mixed |
89 | 89 | */ |
90 | 90 | protected function getAccess($configPrefix) { |
91 | - if(!isset(self::$accesses[$configPrefix])) { |
|
91 | + if (!isset(self::$accesses[$configPrefix])) { |
|
92 | 92 | $this->addAccess($configPrefix); |
93 | 93 | } |
94 | 94 | return self::$accesses[$configPrefix]; |
@@ -142,8 +142,8 @@ discard block |
||
142 | 142 | * @return mixed, the result of the specified method |
143 | 143 | */ |
144 | 144 | protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
145 | - $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
146 | - if($result === $passOnWhen) { |
|
145 | + $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
146 | + if ($result === $passOnWhen) { |
|
147 | 147 | $result = $this->walkBackends($id, $method, $parameters); |
148 | 148 | } |
149 | 149 | return $result; |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | */ |
156 | 156 | private function getCacheKey($key) { |
157 | 157 | $prefix = 'LDAP-Proxy-'; |
158 | - if(is_null($key)) { |
|
158 | + if (is_null($key)) { |
|
159 | 159 | return $prefix; |
160 | 160 | } |
161 | 161 | return $prefix.md5($key); |
@@ -166,7 +166,7 @@ discard block |
||
166 | 166 | * @return mixed|null |
167 | 167 | */ |
168 | 168 | public function getFromCache($key) { |
169 | - if(is_null($this->cache) || !$this->isCached($key)) { |
|
169 | + if (is_null($this->cache) || !$this->isCached($key)) { |
|
170 | 170 | return null; |
171 | 171 | } |
172 | 172 | $key = $this->getCacheKey($key); |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | * @return bool |
180 | 180 | */ |
181 | 181 | public function isCached($key) { |
182 | - if(is_null($this->cache)) { |
|
182 | + if (is_null($this->cache)) { |
|
183 | 183 | return false; |
184 | 184 | } |
185 | 185 | $key = $this->getCacheKey($key); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @param mixed $value |
192 | 192 | */ |
193 | 193 | public function writeToCache($key, $value) { |
194 | - if(is_null($this->cache)) { |
|
194 | + if (is_null($this->cache)) { |
|
195 | 195 | return; |
196 | 196 | } |
197 | 197 | $key = $this->getCacheKey($key); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | } |
201 | 201 | |
202 | 202 | public function clearCache() { |
203 | - if(is_null($this->cache)) { |
|
203 | + if (is_null($this->cache)) { |
|
204 | 204 | return; |
205 | 205 | } |
206 | 206 | $this->cache->clear($this->getCacheKey(null)); |
@@ -35,168 +35,168 @@ |
||
35 | 35 | use OCA\User_LDAP\User\Manager; |
36 | 36 | |
37 | 37 | abstract class Proxy { |
38 | - static private $accesses = array(); |
|
39 | - private $ldap = null; |
|
40 | - |
|
41 | - /** @var \OCP\ICache|null */ |
|
42 | - private $cache; |
|
43 | - |
|
44 | - /** |
|
45 | - * @param ILDAPWrapper $ldap |
|
46 | - */ |
|
47 | - public function __construct(ILDAPWrapper $ldap) { |
|
48 | - $this->ldap = $ldap; |
|
49 | - $memcache = \OC::$server->getMemCacheFactory(); |
|
50 | - if($memcache->isAvailable()) { |
|
51 | - $this->cache = $memcache->create(); |
|
52 | - } |
|
53 | - } |
|
54 | - |
|
55 | - /** |
|
56 | - * @param string $configPrefix |
|
57 | - */ |
|
58 | - private function addAccess($configPrefix) { |
|
59 | - static $ocConfig; |
|
60 | - static $fs; |
|
61 | - static $log; |
|
62 | - static $avatarM; |
|
63 | - static $userMap; |
|
64 | - static $groupMap; |
|
65 | - static $db; |
|
66 | - static $coreUserManager; |
|
67 | - if(is_null($fs)) { |
|
68 | - $ocConfig = \OC::$server->getConfig(); |
|
69 | - $fs = new FilesystemHelper(); |
|
70 | - $log = new LogWrapper(); |
|
71 | - $avatarM = \OC::$server->getAvatarManager(); |
|
72 | - $db = \OC::$server->getDatabaseConnection(); |
|
73 | - $userMap = new UserMapping($db); |
|
74 | - $groupMap = new GroupMapping($db); |
|
75 | - $coreUserManager = \OC::$server->getUserManager(); |
|
76 | - } |
|
77 | - $userManager = |
|
78 | - new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager); |
|
79 | - $connector = new Connection($this->ldap, $configPrefix); |
|
80 | - $access = new Access($connector, $this->ldap, $userManager, new Helper()); |
|
81 | - $access->setUserMapper($userMap); |
|
82 | - $access->setGroupMapper($groupMap); |
|
83 | - self::$accesses[$configPrefix] = $access; |
|
84 | - } |
|
85 | - |
|
86 | - /** |
|
87 | - * @param string $configPrefix |
|
88 | - * @return mixed |
|
89 | - */ |
|
90 | - protected function getAccess($configPrefix) { |
|
91 | - if(!isset(self::$accesses[$configPrefix])) { |
|
92 | - $this->addAccess($configPrefix); |
|
93 | - } |
|
94 | - return self::$accesses[$configPrefix]; |
|
95 | - } |
|
96 | - |
|
97 | - /** |
|
98 | - * @param string $uid |
|
99 | - * @return string |
|
100 | - */ |
|
101 | - protected function getUserCacheKey($uid) { |
|
102 | - return 'user-'.$uid.'-lastSeenOn'; |
|
103 | - } |
|
104 | - |
|
105 | - /** |
|
106 | - * @param string $gid |
|
107 | - * @return string |
|
108 | - */ |
|
109 | - protected function getGroupCacheKey($gid) { |
|
110 | - return 'group-'.$gid.'-lastSeenOn'; |
|
111 | - } |
|
112 | - |
|
113 | - /** |
|
114 | - * @param string $id |
|
115 | - * @param string $method |
|
116 | - * @param array $parameters |
|
117 | - * @param bool $passOnWhen |
|
118 | - * @return mixed |
|
119 | - */ |
|
120 | - abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
121 | - |
|
122 | - /** |
|
123 | - * @param string $id |
|
124 | - * @param string $method |
|
125 | - * @param array $parameters |
|
126 | - * @return mixed |
|
127 | - */ |
|
128 | - abstract protected function walkBackends($id, $method, $parameters); |
|
129 | - |
|
130 | - /** |
|
131 | - * Takes care of the request to the User backend |
|
132 | - * @param string $id |
|
133 | - * @param string $method string, the method of the user backend that shall be called |
|
134 | - * @param array $parameters an array of parameters to be passed |
|
135 | - * @param bool $passOnWhen |
|
136 | - * @return mixed, the result of the specified method |
|
137 | - */ |
|
138 | - protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
|
139 | - $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
140 | - if($result === $passOnWhen) { |
|
141 | - $result = $this->walkBackends($id, $method, $parameters); |
|
142 | - } |
|
143 | - return $result; |
|
144 | - } |
|
145 | - |
|
146 | - /** |
|
147 | - * @param string|null $key |
|
148 | - * @return string |
|
149 | - */ |
|
150 | - private function getCacheKey($key) { |
|
151 | - $prefix = 'LDAP-Proxy-'; |
|
152 | - if(is_null($key)) { |
|
153 | - return $prefix; |
|
154 | - } |
|
155 | - return $prefix.md5($key); |
|
156 | - } |
|
157 | - |
|
158 | - /** |
|
159 | - * @param string $key |
|
160 | - * @return mixed|null |
|
161 | - */ |
|
162 | - public function getFromCache($key) { |
|
163 | - if(is_null($this->cache) || !$this->isCached($key)) { |
|
164 | - return null; |
|
165 | - } |
|
166 | - $key = $this->getCacheKey($key); |
|
167 | - |
|
168 | - return json_decode(base64_decode($this->cache->get($key))); |
|
169 | - } |
|
170 | - |
|
171 | - /** |
|
172 | - * @param string $key |
|
173 | - * @return bool |
|
174 | - */ |
|
175 | - public function isCached($key) { |
|
176 | - if(is_null($this->cache)) { |
|
177 | - return false; |
|
178 | - } |
|
179 | - $key = $this->getCacheKey($key); |
|
180 | - return $this->cache->hasKey($key); |
|
181 | - } |
|
182 | - |
|
183 | - /** |
|
184 | - * @param string $key |
|
185 | - * @param mixed $value |
|
186 | - */ |
|
187 | - public function writeToCache($key, $value) { |
|
188 | - if(is_null($this->cache)) { |
|
189 | - return; |
|
190 | - } |
|
191 | - $key = $this->getCacheKey($key); |
|
192 | - $value = base64_encode(json_encode($value)); |
|
193 | - $this->cache->set($key, $value, '2592000'); |
|
194 | - } |
|
195 | - |
|
196 | - public function clearCache() { |
|
197 | - if(is_null($this->cache)) { |
|
198 | - return; |
|
199 | - } |
|
200 | - $this->cache->clear($this->getCacheKey(null)); |
|
201 | - } |
|
38 | + static private $accesses = array(); |
|
39 | + private $ldap = null; |
|
40 | + |
|
41 | + /** @var \OCP\ICache|null */ |
|
42 | + private $cache; |
|
43 | + |
|
44 | + /** |
|
45 | + * @param ILDAPWrapper $ldap |
|
46 | + */ |
|
47 | + public function __construct(ILDAPWrapper $ldap) { |
|
48 | + $this->ldap = $ldap; |
|
49 | + $memcache = \OC::$server->getMemCacheFactory(); |
|
50 | + if($memcache->isAvailable()) { |
|
51 | + $this->cache = $memcache->create(); |
|
52 | + } |
|
53 | + } |
|
54 | + |
|
55 | + /** |
|
56 | + * @param string $configPrefix |
|
57 | + */ |
|
58 | + private function addAccess($configPrefix) { |
|
59 | + static $ocConfig; |
|
60 | + static $fs; |
|
61 | + static $log; |
|
62 | + static $avatarM; |
|
63 | + static $userMap; |
|
64 | + static $groupMap; |
|
65 | + static $db; |
|
66 | + static $coreUserManager; |
|
67 | + if(is_null($fs)) { |
|
68 | + $ocConfig = \OC::$server->getConfig(); |
|
69 | + $fs = new FilesystemHelper(); |
|
70 | + $log = new LogWrapper(); |
|
71 | + $avatarM = \OC::$server->getAvatarManager(); |
|
72 | + $db = \OC::$server->getDatabaseConnection(); |
|
73 | + $userMap = new UserMapping($db); |
|
74 | + $groupMap = new GroupMapping($db); |
|
75 | + $coreUserManager = \OC::$server->getUserManager(); |
|
76 | + } |
|
77 | + $userManager = |
|
78 | + new Manager($ocConfig, $fs, $log, $avatarM, new \OCP\Image(), $db, $coreUserManager); |
|
79 | + $connector = new Connection($this->ldap, $configPrefix); |
|
80 | + $access = new Access($connector, $this->ldap, $userManager, new Helper()); |
|
81 | + $access->setUserMapper($userMap); |
|
82 | + $access->setGroupMapper($groupMap); |
|
83 | + self::$accesses[$configPrefix] = $access; |
|
84 | + } |
|
85 | + |
|
86 | + /** |
|
87 | + * @param string $configPrefix |
|
88 | + * @return mixed |
|
89 | + */ |
|
90 | + protected function getAccess($configPrefix) { |
|
91 | + if(!isset(self::$accesses[$configPrefix])) { |
|
92 | + $this->addAccess($configPrefix); |
|
93 | + } |
|
94 | + return self::$accesses[$configPrefix]; |
|
95 | + } |
|
96 | + |
|
97 | + /** |
|
98 | + * @param string $uid |
|
99 | + * @return string |
|
100 | + */ |
|
101 | + protected function getUserCacheKey($uid) { |
|
102 | + return 'user-'.$uid.'-lastSeenOn'; |
|
103 | + } |
|
104 | + |
|
105 | + /** |
|
106 | + * @param string $gid |
|
107 | + * @return string |
|
108 | + */ |
|
109 | + protected function getGroupCacheKey($gid) { |
|
110 | + return 'group-'.$gid.'-lastSeenOn'; |
|
111 | + } |
|
112 | + |
|
113 | + /** |
|
114 | + * @param string $id |
|
115 | + * @param string $method |
|
116 | + * @param array $parameters |
|
117 | + * @param bool $passOnWhen |
|
118 | + * @return mixed |
|
119 | + */ |
|
120 | + abstract protected function callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
121 | + |
|
122 | + /** |
|
123 | + * @param string $id |
|
124 | + * @param string $method |
|
125 | + * @param array $parameters |
|
126 | + * @return mixed |
|
127 | + */ |
|
128 | + abstract protected function walkBackends($id, $method, $parameters); |
|
129 | + |
|
130 | + /** |
|
131 | + * Takes care of the request to the User backend |
|
132 | + * @param string $id |
|
133 | + * @param string $method string, the method of the user backend that shall be called |
|
134 | + * @param array $parameters an array of parameters to be passed |
|
135 | + * @param bool $passOnWhen |
|
136 | + * @return mixed, the result of the specified method |
|
137 | + */ |
|
138 | + protected function handleRequest($id, $method, $parameters, $passOnWhen = false) { |
|
139 | + $result = $this->callOnLastSeenOn($id, $method, $parameters, $passOnWhen); |
|
140 | + if($result === $passOnWhen) { |
|
141 | + $result = $this->walkBackends($id, $method, $parameters); |
|
142 | + } |
|
143 | + return $result; |
|
144 | + } |
|
145 | + |
|
146 | + /** |
|
147 | + * @param string|null $key |
|
148 | + * @return string |
|
149 | + */ |
|
150 | + private function getCacheKey($key) { |
|
151 | + $prefix = 'LDAP-Proxy-'; |
|
152 | + if(is_null($key)) { |
|
153 | + return $prefix; |
|
154 | + } |
|
155 | + return $prefix.md5($key); |
|
156 | + } |
|
157 | + |
|
158 | + /** |
|
159 | + * @param string $key |
|
160 | + * @return mixed|null |
|
161 | + */ |
|
162 | + public function getFromCache($key) { |
|
163 | + if(is_null($this->cache) || !$this->isCached($key)) { |
|
164 | + return null; |
|
165 | + } |
|
166 | + $key = $this->getCacheKey($key); |
|
167 | + |
|
168 | + return json_decode(base64_decode($this->cache->get($key))); |
|
169 | + } |
|
170 | + |
|
171 | + /** |
|
172 | + * @param string $key |
|
173 | + * @return bool |
|
174 | + */ |
|
175 | + public function isCached($key) { |
|
176 | + if(is_null($this->cache)) { |
|
177 | + return false; |
|
178 | + } |
|
179 | + $key = $this->getCacheKey($key); |
|
180 | + return $this->cache->hasKey($key); |
|
181 | + } |
|
182 | + |
|
183 | + /** |
|
184 | + * @param string $key |
|
185 | + * @param mixed $value |
|
186 | + */ |
|
187 | + public function writeToCache($key, $value) { |
|
188 | + if(is_null($this->cache)) { |
|
189 | + return; |
|
190 | + } |
|
191 | + $key = $this->getCacheKey($key); |
|
192 | + $value = base64_encode(json_encode($value)); |
|
193 | + $this->cache->set($key, $value, '2592000'); |
|
194 | + } |
|
195 | + |
|
196 | + public function clearCache() { |
|
197 | + if(is_null($this->cache)) { |
|
198 | + return; |
|
199 | + } |
|
200 | + $this->cache->clear($this->getCacheKey(null)); |
|
201 | + } |
|
202 | 202 | } |
@@ -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 ownCloud' |
|
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 ownCloud |
|
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 ownCloud' |
|
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 ownCloud |
|
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 | } |
@@ -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 | } |
@@ -87,16 +87,16 @@ discard block |
||
87 | 87 | * @throws \InvalidArgumentException |
88 | 88 | */ |
89 | 89 | protected function validateOffsetAndLimit($offset, $limit) { |
90 | - if($limit < 0) { |
|
90 | + if ($limit < 0) { |
|
91 | 91 | throw new \InvalidArgumentException('limit must be 0 or greater'); |
92 | 92 | } |
93 | - if($offset < 0) { |
|
93 | + if ($offset < 0) { |
|
94 | 94 | throw new \InvalidArgumentException('offset must be 0 or greater'); |
95 | 95 | } |
96 | - if($limit === 0 && $offset !== 0) { |
|
96 | + if ($limit === 0 && $offset !== 0) { |
|
97 | 97 | throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
98 | 98 | } |
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
99 | + if ($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | 100 | throw new \InvalidArgumentException('offset must be a multiple of limit'); |
101 | 101 | } |
102 | 102 | } |
@@ -110,7 +110,7 @@ discard block |
||
110 | 110 | $limit = intval($input->getOption('limit')); |
111 | 111 | $this->validateOffsetAndLimit($offset, $limit); |
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
113 | + if ($input->getOption('group')) { |
|
114 | 114 | $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
115 | 115 | $getMethod = 'getGroups'; |
116 | 116 | $printID = false; |
@@ -121,8 +121,8 @@ discard block |
||
121 | 121 | } |
122 | 122 | |
123 | 123 | $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
124 | - foreach($result as $id => $name) { |
|
125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
124 | + foreach ($result as $id => $name) { |
|
125 | + $line = $name.($printID ? ' ('.$id.')' : ''); |
|
126 | 126 | $output->writeln($line); |
127 | 127 | } |
128 | 128 | } |
@@ -37,93 +37,93 @@ |
||
37 | 37 | use OCP\IConfig; |
38 | 38 | |
39 | 39 | class Search extends Command { |
40 | - /** @var \OCP\IConfig */ |
|
41 | - protected $ocConfig; |
|
40 | + /** @var \OCP\IConfig */ |
|
41 | + protected $ocConfig; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param \OCP\IConfig $ocConfig |
|
45 | - */ |
|
46 | - public function __construct(IConfig $ocConfig) { |
|
47 | - $this->ocConfig = $ocConfig; |
|
48 | - parent::__construct(); |
|
49 | - } |
|
43 | + /** |
|
44 | + * @param \OCP\IConfig $ocConfig |
|
45 | + */ |
|
46 | + public function __construct(IConfig $ocConfig) { |
|
47 | + $this->ocConfig = $ocConfig; |
|
48 | + parent::__construct(); |
|
49 | + } |
|
50 | 50 | |
51 | - protected function configure() { |
|
52 | - $this |
|
53 | - ->setName('ldap:search') |
|
54 | - ->setDescription('executes a user or group search') |
|
55 | - ->addArgument( |
|
56 | - 'search', |
|
57 | - InputArgument::REQUIRED, |
|
58 | - 'the search string (can be empty)' |
|
59 | - ) |
|
60 | - ->addOption( |
|
61 | - 'group', |
|
62 | - null, |
|
63 | - InputOption::VALUE_NONE, |
|
64 | - 'searches groups instead of users' |
|
65 | - ) |
|
66 | - ->addOption( |
|
67 | - 'offset', |
|
68 | - null, |
|
69 | - InputOption::VALUE_REQUIRED, |
|
70 | - 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | - 0 |
|
72 | - ) |
|
73 | - ->addOption( |
|
74 | - 'limit', |
|
75 | - null, |
|
76 | - InputOption::VALUE_REQUIRED, |
|
77 | - 'limit the results. 0 means no limit, defaults to 15', |
|
78 | - 15 |
|
79 | - ) |
|
80 | - ; |
|
81 | - } |
|
51 | + protected function configure() { |
|
52 | + $this |
|
53 | + ->setName('ldap:search') |
|
54 | + ->setDescription('executes a user or group search') |
|
55 | + ->addArgument( |
|
56 | + 'search', |
|
57 | + InputArgument::REQUIRED, |
|
58 | + 'the search string (can be empty)' |
|
59 | + ) |
|
60 | + ->addOption( |
|
61 | + 'group', |
|
62 | + null, |
|
63 | + InputOption::VALUE_NONE, |
|
64 | + 'searches groups instead of users' |
|
65 | + ) |
|
66 | + ->addOption( |
|
67 | + 'offset', |
|
68 | + null, |
|
69 | + InputOption::VALUE_REQUIRED, |
|
70 | + 'The offset of the result set. Needs to be a multiple of limit. defaults to 0.', |
|
71 | + 0 |
|
72 | + ) |
|
73 | + ->addOption( |
|
74 | + 'limit', |
|
75 | + null, |
|
76 | + InputOption::VALUE_REQUIRED, |
|
77 | + 'limit the results. 0 means no limit, defaults to 15', |
|
78 | + 15 |
|
79 | + ) |
|
80 | + ; |
|
81 | + } |
|
82 | 82 | |
83 | - /** |
|
84 | - * Tests whether the offset and limit options are valid |
|
85 | - * @param int $offset |
|
86 | - * @param int $limit |
|
87 | - * @throws \InvalidArgumentException |
|
88 | - */ |
|
89 | - protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | - if($limit < 0) { |
|
91 | - throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | - } |
|
93 | - if($offset < 0) { |
|
94 | - throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | - } |
|
96 | - if($limit === 0 && $offset !== 0) { |
|
97 | - throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | - } |
|
99 | - if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | - throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | - } |
|
102 | - } |
|
83 | + /** |
|
84 | + * Tests whether the offset and limit options are valid |
|
85 | + * @param int $offset |
|
86 | + * @param int $limit |
|
87 | + * @throws \InvalidArgumentException |
|
88 | + */ |
|
89 | + protected function validateOffsetAndLimit($offset, $limit) { |
|
90 | + if($limit < 0) { |
|
91 | + throw new \InvalidArgumentException('limit must be 0 or greater'); |
|
92 | + } |
|
93 | + if($offset < 0) { |
|
94 | + throw new \InvalidArgumentException('offset must be 0 or greater'); |
|
95 | + } |
|
96 | + if($limit === 0 && $offset !== 0) { |
|
97 | + throw new \InvalidArgumentException('offset must be 0 if limit is also set to 0'); |
|
98 | + } |
|
99 | + if($offset > 0 && ($offset % $limit !== 0)) { |
|
100 | + throw new \InvalidArgumentException('offset must be a multiple of limit'); |
|
101 | + } |
|
102 | + } |
|
103 | 103 | |
104 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | - $helper = new Helper(); |
|
106 | - $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | - $ldapWrapper = new LDAP(); |
|
104 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
105 | + $helper = new Helper(); |
|
106 | + $configPrefixes = $helper->getServerConfigurationPrefixes(true); |
|
107 | + $ldapWrapper = new LDAP(); |
|
108 | 108 | |
109 | - $offset = intval($input->getOption('offset')); |
|
110 | - $limit = intval($input->getOption('limit')); |
|
111 | - $this->validateOffsetAndLimit($offset, $limit); |
|
109 | + $offset = intval($input->getOption('offset')); |
|
110 | + $limit = intval($input->getOption('limit')); |
|
111 | + $this->validateOffsetAndLimit($offset, $limit); |
|
112 | 112 | |
113 | - if($input->getOption('group')) { |
|
114 | - $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | - $getMethod = 'getGroups'; |
|
116 | - $printID = false; |
|
117 | - } else { |
|
118 | - $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
119 | - $getMethod = 'getDisplayNames'; |
|
120 | - $printID = true; |
|
121 | - } |
|
113 | + if($input->getOption('group')) { |
|
114 | + $proxy = new Group_Proxy($configPrefixes, $ldapWrapper); |
|
115 | + $getMethod = 'getGroups'; |
|
116 | + $printID = false; |
|
117 | + } else { |
|
118 | + $proxy = new User_Proxy($configPrefixes, $ldapWrapper, $this->ocConfig); |
|
119 | + $getMethod = 'getDisplayNames'; |
|
120 | + $printID = true; |
|
121 | + } |
|
122 | 122 | |
123 | - $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
124 | - foreach($result as $id => $name) { |
|
125 | - $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
126 | - $output->writeln($line); |
|
127 | - } |
|
128 | - } |
|
123 | + $result = $proxy->$getMethod($input->getArgument('search'), $limit, $offset); |
|
124 | + foreach($result as $id => $name) { |
|
125 | + $line = $name . ($printID ? ' ('.$id.')' : ''); |
|
126 | + $output->writeln($line); |
|
127 | + } |
|
128 | + } |
|
129 | 129 | } |
@@ -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}'"); |
@@ -32,39 +32,39 @@ |
||
32 | 32 | use \OCA\User_LDAP\Helper; |
33 | 33 | |
34 | 34 | class DeleteConfig extends Command { |
35 | - /** @var \OCA\User_LDAP\Helper */ |
|
36 | - protected $helper; |
|
35 | + /** @var \OCA\User_LDAP\Helper */ |
|
36 | + protected $helper; |
|
37 | 37 | |
38 | - /** |
|
39 | - * @param Helper $helper |
|
40 | - */ |
|
41 | - public function __construct(Helper $helper) { |
|
42 | - $this->helper = $helper; |
|
43 | - parent::__construct(); |
|
44 | - } |
|
38 | + /** |
|
39 | + * @param Helper $helper |
|
40 | + */ |
|
41 | + public function __construct(Helper $helper) { |
|
42 | + $this->helper = $helper; |
|
43 | + parent::__construct(); |
|
44 | + } |
|
45 | 45 | |
46 | - protected function configure() { |
|
47 | - $this |
|
48 | - ->setName('ldap:delete-config') |
|
49 | - ->setDescription('deletes an existing LDAP configuration') |
|
50 | - ->addArgument( |
|
51 | - 'configID', |
|
52 | - InputArgument::REQUIRED, |
|
53 | - 'the configuration ID' |
|
54 | - ) |
|
55 | - ; |
|
56 | - } |
|
46 | + protected function configure() { |
|
47 | + $this |
|
48 | + ->setName('ldap:delete-config') |
|
49 | + ->setDescription('deletes an existing LDAP configuration') |
|
50 | + ->addArgument( |
|
51 | + 'configID', |
|
52 | + InputArgument::REQUIRED, |
|
53 | + 'the configuration ID' |
|
54 | + ) |
|
55 | + ; |
|
56 | + } |
|
57 | 57 | |
58 | 58 | |
59 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
60 | - $configPrefix = $input->getArgument('configID'); |
|
59 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
60 | + $configPrefix = $input->getArgument('configID'); |
|
61 | 61 | |
62 | - $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
62 | + $success = $this->helper->deleteServerConfiguration($configPrefix); |
|
63 | 63 | |
64 | - if($success) { |
|
65 | - $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
66 | - } else { |
|
67 | - $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
68 | - } |
|
69 | - } |
|
64 | + if($success) { |
|
65 | + $output->writeln("Deleted configuration with configID '{$configPrefix}'"); |
|
66 | + } else { |
|
67 | + $output->writeln("Cannot delete configuration with configID '{$configPrefix}'"); |
|
68 | + } |
|
69 | + } |
|
70 | 70 | } |
@@ -71,7 +71,7 @@ |
||
71 | 71 | 'Dir', 'Sharer')); |
72 | 72 | $rows = array(); |
73 | 73 | $resultSet = $this->dui->getUsers(); |
74 | - foreach($resultSet as $user) { |
|
74 | + foreach ($resultSet as $user) { |
|
75 | 75 | $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
76 | 76 | $lastLogin = ($user->getLastLogin() > 0) ? |
77 | 77 | $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
@@ -34,61 +34,61 @@ |
||
34 | 34 | use OCP\IDateTimeFormatter; |
35 | 35 | |
36 | 36 | class ShowRemnants extends Command { |
37 | - /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
38 | - protected $dui; |
|
37 | + /** @var \OCA\User_LDAP\User\DeletedUsersIndex */ |
|
38 | + protected $dui; |
|
39 | 39 | |
40 | - /** @var \OCP\IDateTimeFormatter */ |
|
41 | - protected $dateFormatter; |
|
40 | + /** @var \OCP\IDateTimeFormatter */ |
|
41 | + protected $dateFormatter; |
|
42 | 42 | |
43 | - /** |
|
44 | - * @param DeletedUsersIndex $dui |
|
45 | - * @param IDateTimeFormatter $dateFormatter |
|
46 | - */ |
|
47 | - public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
48 | - $this->dui = $dui; |
|
49 | - $this->dateFormatter = $dateFormatter; |
|
50 | - parent::__construct(); |
|
51 | - } |
|
43 | + /** |
|
44 | + * @param DeletedUsersIndex $dui |
|
45 | + * @param IDateTimeFormatter $dateFormatter |
|
46 | + */ |
|
47 | + public function __construct(DeletedUsersIndex $dui, IDateTimeFormatter $dateFormatter) { |
|
48 | + $this->dui = $dui; |
|
49 | + $this->dateFormatter = $dateFormatter; |
|
50 | + parent::__construct(); |
|
51 | + } |
|
52 | 52 | |
53 | - protected function configure() { |
|
54 | - $this |
|
55 | - ->setName('ldap:show-remnants') |
|
56 | - ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.') |
|
57 | - ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.'); |
|
58 | - } |
|
53 | + protected function configure() { |
|
54 | + $this |
|
55 | + ->setName('ldap:show-remnants') |
|
56 | + ->setDescription('shows which users are not available on LDAP anymore, but have remnants in ownCloud.') |
|
57 | + ->addOption('json', null, InputOption::VALUE_NONE, 'return JSON array instead of pretty table.'); |
|
58 | + } |
|
59 | 59 | |
60 | - /** |
|
61 | - * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted |
|
62 | - * |
|
63 | - * {@inheritdoc} |
|
64 | - */ |
|
65 | - protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | - /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
67 | - $table = $this->getHelperSet()->get('table'); |
|
68 | - $table->setHeaders(array( |
|
69 | - 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
70 | - 'Dir', 'Sharer')); |
|
71 | - $rows = array(); |
|
72 | - $resultSet = $this->dui->getUsers(); |
|
73 | - foreach($resultSet as $user) { |
|
74 | - $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
|
75 | - $lastLogin = ($user->getLastLogin() > 0) ? |
|
76 | - $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
|
77 | - $rows[] = array('ocName' => $user->getOCName(), |
|
78 | - 'displayName' => $user->getDisplayName(), |
|
79 | - 'uid' => $user->getUID(), |
|
80 | - 'dn' => $user->getDN(), |
|
81 | - 'lastLogin' => $lastLogin, |
|
82 | - 'homePath' => $user->getHomePath(), |
|
83 | - 'sharer' => $hAS |
|
84 | - ); |
|
85 | - } |
|
60 | + /** |
|
61 | + * executes the command, i.e. creeates and outputs a table of LDAP users marked as deleted |
|
62 | + * |
|
63 | + * {@inheritdoc} |
|
64 | + */ |
|
65 | + protected function execute(InputInterface $input, OutputInterface $output) { |
|
66 | + /** @var \Symfony\Component\Console\Helper\Table $table */ |
|
67 | + $table = $this->getHelperSet()->get('table'); |
|
68 | + $table->setHeaders(array( |
|
69 | + 'ownCloud name', 'Display Name', 'LDAP UID', 'LDAP DN', 'Last Login', |
|
70 | + 'Dir', 'Sharer')); |
|
71 | + $rows = array(); |
|
72 | + $resultSet = $this->dui->getUsers(); |
|
73 | + foreach($resultSet as $user) { |
|
74 | + $hAS = $user->getHasActiveShares() ? 'Y' : 'N'; |
|
75 | + $lastLogin = ($user->getLastLogin() > 0) ? |
|
76 | + $this->dateFormatter->formatDate($user->getLastLogin()) : '-'; |
|
77 | + $rows[] = array('ocName' => $user->getOCName(), |
|
78 | + 'displayName' => $user->getDisplayName(), |
|
79 | + 'uid' => $user->getUID(), |
|
80 | + 'dn' => $user->getDN(), |
|
81 | + 'lastLogin' => $lastLogin, |
|
82 | + 'homePath' => $user->getHomePath(), |
|
83 | + 'sharer' => $hAS |
|
84 | + ); |
|
85 | + } |
|
86 | 86 | |
87 | - if ($input->getOption('json')) { |
|
88 | - $output->writeln(json_encode($rows)); |
|
89 | - } else { |
|
90 | - $table->setRows($rows); |
|
91 | - $table->render($output); |
|
92 | - } |
|
93 | - } |
|
87 | + if ($input->getOption('json')) { |
|
88 | + $output->writeln(json_encode($rows)); |
|
89 | + } else { |
|
90 | + $table->setRows($rows); |
|
91 | + $table->render($output); |
|
92 | + } |
|
93 | + } |
|
94 | 94 | } |
@@ -26,13 +26,13 @@ |
||
26 | 26 | namespace OCA\User_LDAP; |
27 | 27 | |
28 | 28 | abstract class LDAPUtility { |
29 | - protected $ldap; |
|
29 | + protected $ldap; |
|
30 | 30 | |
31 | - /** |
|
32 | - * constructor, make sure the subclasses call this one! |
|
33 | - * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper |
|
34 | - */ |
|
35 | - public function __construct(ILDAPWrapper $ldapWrapper) { |
|
36 | - $this->ldap = $ldapWrapper; |
|
37 | - } |
|
31 | + /** |
|
32 | + * constructor, make sure the subclasses call this one! |
|
33 | + * @param ILDAPWrapper $ldapWrapper an instance of an ILDAPWrapper |
|
34 | + */ |
|
35 | + public function __construct(ILDAPWrapper $ldapWrapper) { |
|
36 | + $this->ldap = $ldapWrapper; |
|
37 | + } |
|
38 | 38 | } |
@@ -62,7 +62,7 @@ |
||
62 | 62 | // assign default values |
63 | 63 | $config = new Configuration('', false); |
64 | 64 | $defaults = $config->getDefaults(); |
65 | - foreach($defaults as $key => $default) { |
|
65 | + foreach ($defaults as $key => $default) { |
|
66 | 66 | $parameters[$key.'_default'] = $default; |
67 | 67 | } |
68 | 68 |
@@ -31,59 +31,59 @@ |
||
31 | 31 | use OCP\Template; |
32 | 32 | |
33 | 33 | class Admin implements ISettings { |
34 | - /** @var IL10N */ |
|
35 | - private $l; |
|
34 | + /** @var IL10N */ |
|
35 | + private $l; |
|
36 | 36 | |
37 | - /** |
|
38 | - * @param IL10N $l |
|
39 | - */ |
|
40 | - public function __construct(IL10N $l) { |
|
41 | - $this->l = $l; |
|
42 | - } |
|
37 | + /** |
|
38 | + * @param IL10N $l |
|
39 | + */ |
|
40 | + public function __construct(IL10N $l) { |
|
41 | + $this->l = $l; |
|
42 | + } |
|
43 | 43 | |
44 | - /** |
|
45 | - * @return TemplateResponse |
|
46 | - */ |
|
47 | - public function getForm() { |
|
48 | - $helper = new Helper(); |
|
49 | - $prefixes = $helper->getServerConfigurationPrefixes(); |
|
50 | - $hosts = $helper->getServerConfigurationHosts(); |
|
44 | + /** |
|
45 | + * @return TemplateResponse |
|
46 | + */ |
|
47 | + public function getForm() { |
|
48 | + $helper = new Helper(); |
|
49 | + $prefixes = $helper->getServerConfigurationPrefixes(); |
|
50 | + $hosts = $helper->getServerConfigurationHosts(); |
|
51 | 51 | |
52 | - $wControls = new Template('user_ldap', 'part.wizardcontrols'); |
|
53 | - $wControls = $wControls->fetchPage(); |
|
54 | - $sControls = new Template('user_ldap', 'part.settingcontrols'); |
|
55 | - $sControls = $sControls->fetchPage(); |
|
52 | + $wControls = new Template('user_ldap', 'part.wizardcontrols'); |
|
53 | + $wControls = $wControls->fetchPage(); |
|
54 | + $sControls = new Template('user_ldap', 'part.settingcontrols'); |
|
55 | + $sControls = $sControls->fetchPage(); |
|
56 | 56 | |
57 | - $parameters['serverConfigurationPrefixes'] = $prefixes; |
|
58 | - $parameters['serverConfigurationHosts'] = $hosts; |
|
59 | - $parameters['settingControls'] = $sControls; |
|
60 | - $parameters['wizardControls'] = $wControls; |
|
57 | + $parameters['serverConfigurationPrefixes'] = $prefixes; |
|
58 | + $parameters['serverConfigurationHosts'] = $hosts; |
|
59 | + $parameters['settingControls'] = $sControls; |
|
60 | + $parameters['wizardControls'] = $wControls; |
|
61 | 61 | |
62 | - // assign default values |
|
63 | - $config = new Configuration('', false); |
|
64 | - $defaults = $config->getDefaults(); |
|
65 | - foreach($defaults as $key => $default) { |
|
66 | - $parameters[$key.'_default'] = $default; |
|
67 | - } |
|
62 | + // assign default values |
|
63 | + $config = new Configuration('', false); |
|
64 | + $defaults = $config->getDefaults(); |
|
65 | + foreach($defaults as $key => $default) { |
|
66 | + $parameters[$key.'_default'] = $default; |
|
67 | + } |
|
68 | 68 | |
69 | - return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
70 | - } |
|
69 | + return new TemplateResponse('user_ldap', 'settings', $parameters); |
|
70 | + } |
|
71 | 71 | |
72 | - /** |
|
73 | - * @return string the section ID, e.g. 'sharing' |
|
74 | - */ |
|
75 | - public function getSection() { |
|
76 | - return 'ldap'; |
|
77 | - } |
|
72 | + /** |
|
73 | + * @return string the section ID, e.g. 'sharing' |
|
74 | + */ |
|
75 | + public function getSection() { |
|
76 | + return 'ldap'; |
|
77 | + } |
|
78 | 78 | |
79 | - /** |
|
80 | - * @return int whether the form should be rather on the top or bottom of |
|
81 | - * the admin section. The forms are arranged in ascending order of the |
|
82 | - * priority values. It is required to return a value between 0 and 100. |
|
83 | - * |
|
84 | - * E.g.: 70 |
|
85 | - */ |
|
86 | - public function getPriority() { |
|
87 | - return 5; |
|
88 | - } |
|
79 | + /** |
|
80 | + * @return int whether the form should be rather on the top or bottom of |
|
81 | + * the admin section. The forms are arranged in ascending order of the |
|
82 | + * priority values. It is required to return a value between 0 and 100. |
|
83 | + * |
|
84 | + * E.g.: 70 |
|
85 | + */ |
|
86 | + public function getPriority() { |
|
87 | + return 5; |
|
88 | + } |
|
89 | 89 | } |
@@ -42,10 +42,10 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
44 | 44 | parent::__construct($ldap); |
45 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
45 | + foreach ($serverConfigPrefixes as $configPrefix) { |
|
46 | 46 | $this->backends[$configPrefix] = |
47 | 47 | new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
48 | - if(is_null($this->refBackend)) { |
|
48 | + if (is_null($this->refBackend)) { |
|
49 | 49 | $this->refBackend = &$this->backends[$configPrefix]; |
50 | 50 | } |
51 | 51 | } |
@@ -60,13 +60,13 @@ discard block |
||
60 | 60 | */ |
61 | 61 | protected function walkBackends($uid, $method, $parameters) { |
62 | 62 | $cacheKey = $this->getUserCacheKey($uid); |
63 | - foreach($this->backends as $configPrefix => $backend) { |
|
63 | + foreach ($this->backends as $configPrefix => $backend) { |
|
64 | 64 | $instance = $backend; |
65 | - if(!method_exists($instance, $method) |
|
65 | + if (!method_exists($instance, $method) |
|
66 | 66 | && method_exists($this->getAccess($configPrefix), $method)) { |
67 | 67 | $instance = $this->getAccess($configPrefix); |
68 | 68 | } |
69 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
69 | + if ($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
70 | 70 | $this->writeToCache($cacheKey, $configPrefix); |
71 | 71 | return $result; |
72 | 72 | } |
@@ -86,22 +86,22 @@ discard block |
||
86 | 86 | $cacheKey = $this->getUserCacheKey($uid); |
87 | 87 | $prefix = $this->getFromCache($cacheKey); |
88 | 88 | //in case the uid has been found in the past, try this stored connection first |
89 | - if(!is_null($prefix)) { |
|
90 | - if(isset($this->backends[$prefix])) { |
|
89 | + if (!is_null($prefix)) { |
|
90 | + if (isset($this->backends[$prefix])) { |
|
91 | 91 | $instance = $this->backends[$prefix]; |
92 | - if(!method_exists($instance, $method) |
|
92 | + if (!method_exists($instance, $method) |
|
93 | 93 | && method_exists($this->getAccess($prefix), $method)) { |
94 | 94 | $instance = $this->getAccess($prefix); |
95 | 95 | } |
96 | 96 | $result = call_user_func_array(array($instance, $method), $parameters); |
97 | - if($result === $passOnWhen) { |
|
97 | + if ($result === $passOnWhen) { |
|
98 | 98 | //not found here, reset cache to null if user vanished |
99 | 99 | //because sometimes methods return false with a reason |
100 | 100 | $userExists = call_user_func_array( |
101 | 101 | array($this->backends[$prefix], 'userExists'), |
102 | 102 | array($uid) |
103 | 103 | ); |
104 | - if(!$userExists) { |
|
104 | + if (!$userExists) { |
|
105 | 105 | $this->writeToCache($cacheKey, null); |
106 | 106 | } |
107 | 107 | } |
@@ -143,7 +143,7 @@ discard block |
||
143 | 143 | public function getUsers($search = '', $limit = 10, $offset = 0) { |
144 | 144 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
145 | 145 | $users = array(); |
146 | - foreach($this->backends as $backend) { |
|
146 | + foreach ($this->backends as $backend) { |
|
147 | 147 | $backendUsers = $backend->getUsers($search, $limit, $offset); |
148 | 148 | if (is_array($backendUsers)) { |
149 | 149 | $users = array_merge($users, $backendUsers); |
@@ -191,7 +191,7 @@ discard block |
||
191 | 191 | * @return string|false |
192 | 192 | */ |
193 | 193 | public function loginName2UserName($loginName) { |
194 | - $id = 'LOGINNAME,' . $loginName; |
|
194 | + $id = 'LOGINNAME,'.$loginName; |
|
195 | 195 | return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
196 | 196 | } |
197 | 197 | |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | * @return string|false with the username |
203 | 203 | */ |
204 | 204 | public function dn2UserName($dn) { |
205 | - $id = 'DN,' . $dn; |
|
205 | + $id = 'DN,'.$dn; |
|
206 | 206 | return $this->handleRequest($id, 'dn2UserName', array($dn)); |
207 | 207 | } |
208 | 208 | |
@@ -243,7 +243,7 @@ discard block |
||
243 | 243 | public function getDisplayNames($search = '', $limit = null, $offset = null) { |
244 | 244 | //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
245 | 245 | $users = array(); |
246 | - foreach($this->backends as $backend) { |
|
246 | + foreach ($this->backends as $backend) { |
|
247 | 247 | $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
248 | 248 | if (is_array($backendUsers)) { |
249 | 249 | $users = $users + $backendUsers; |
@@ -287,7 +287,7 @@ discard block |
||
287 | 287 | */ |
288 | 288 | public function countUsers() { |
289 | 289 | $users = false; |
290 | - foreach($this->backends as $backend) { |
|
290 | + foreach ($this->backends as $backend) { |
|
291 | 291 | $backendUsers = $backend->countUsers(); |
292 | 292 | if ($backendUsers !== false) { |
293 | 293 | $users += $backendUsers; |
@@ -33,274 +33,274 @@ |
||
33 | 33 | use OCP\IConfig; |
34 | 34 | |
35 | 35 | class User_Proxy extends Proxy implements \OCP\IUserBackend, \OCP\UserInterface, IUserLDAP { |
36 | - private $backends = array(); |
|
37 | - private $refBackend = null; |
|
36 | + private $backends = array(); |
|
37 | + private $refBackend = null; |
|
38 | 38 | |
39 | - /** |
|
40 | - * Constructor |
|
41 | - * @param array $serverConfigPrefixes array containing the config Prefixes |
|
42 | - */ |
|
43 | - public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
|
44 | - parent::__construct($ldap); |
|
45 | - foreach($serverConfigPrefixes as $configPrefix) { |
|
46 | - $this->backends[$configPrefix] = |
|
47 | - new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
|
48 | - if(is_null($this->refBackend)) { |
|
49 | - $this->refBackend = &$this->backends[$configPrefix]; |
|
50 | - } |
|
51 | - } |
|
52 | - } |
|
39 | + /** |
|
40 | + * Constructor |
|
41 | + * @param array $serverConfigPrefixes array containing the config Prefixes |
|
42 | + */ |
|
43 | + public function __construct(array $serverConfigPrefixes, ILDAPWrapper $ldap, IConfig $ocConfig) { |
|
44 | + parent::__construct($ldap); |
|
45 | + foreach($serverConfigPrefixes as $configPrefix) { |
|
46 | + $this->backends[$configPrefix] = |
|
47 | + new User_LDAP($this->getAccess($configPrefix), $ocConfig); |
|
48 | + if(is_null($this->refBackend)) { |
|
49 | + $this->refBackend = &$this->backends[$configPrefix]; |
|
50 | + } |
|
51 | + } |
|
52 | + } |
|
53 | 53 | |
54 | - /** |
|
55 | - * Tries the backends one after the other until a positive result is returned from the specified method |
|
56 | - * @param string $uid the uid connected to the request |
|
57 | - * @param string $method the method of the user backend that shall be called |
|
58 | - * @param array $parameters an array of parameters to be passed |
|
59 | - * @return mixed the result of the method or false |
|
60 | - */ |
|
61 | - protected function walkBackends($uid, $method, $parameters) { |
|
62 | - $cacheKey = $this->getUserCacheKey($uid); |
|
63 | - foreach($this->backends as $configPrefix => $backend) { |
|
64 | - $instance = $backend; |
|
65 | - if(!method_exists($instance, $method) |
|
66 | - && method_exists($this->getAccess($configPrefix), $method)) { |
|
67 | - $instance = $this->getAccess($configPrefix); |
|
68 | - } |
|
69 | - if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
70 | - $this->writeToCache($cacheKey, $configPrefix); |
|
71 | - return $result; |
|
72 | - } |
|
73 | - } |
|
74 | - return false; |
|
75 | - } |
|
54 | + /** |
|
55 | + * Tries the backends one after the other until a positive result is returned from the specified method |
|
56 | + * @param string $uid the uid connected to the request |
|
57 | + * @param string $method the method of the user backend that shall be called |
|
58 | + * @param array $parameters an array of parameters to be passed |
|
59 | + * @return mixed the result of the method or false |
|
60 | + */ |
|
61 | + protected function walkBackends($uid, $method, $parameters) { |
|
62 | + $cacheKey = $this->getUserCacheKey($uid); |
|
63 | + foreach($this->backends as $configPrefix => $backend) { |
|
64 | + $instance = $backend; |
|
65 | + if(!method_exists($instance, $method) |
|
66 | + && method_exists($this->getAccess($configPrefix), $method)) { |
|
67 | + $instance = $this->getAccess($configPrefix); |
|
68 | + } |
|
69 | + if($result = call_user_func_array(array($instance, $method), $parameters)) { |
|
70 | + $this->writeToCache($cacheKey, $configPrefix); |
|
71 | + return $result; |
|
72 | + } |
|
73 | + } |
|
74 | + return false; |
|
75 | + } |
|
76 | 76 | |
77 | - /** |
|
78 | - * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
79 | - * @param string $uid the uid connected to the request |
|
80 | - * @param string $method the method of the user backend that shall be called |
|
81 | - * @param array $parameters an array of parameters to be passed |
|
82 | - * @param mixed $passOnWhen the result matches this variable |
|
83 | - * @return mixed the result of the method or false |
|
84 | - */ |
|
85 | - protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
86 | - $cacheKey = $this->getUserCacheKey($uid); |
|
87 | - $prefix = $this->getFromCache($cacheKey); |
|
88 | - //in case the uid has been found in the past, try this stored connection first |
|
89 | - if(!is_null($prefix)) { |
|
90 | - if(isset($this->backends[$prefix])) { |
|
91 | - $instance = $this->backends[$prefix]; |
|
92 | - if(!method_exists($instance, $method) |
|
93 | - && method_exists($this->getAccess($prefix), $method)) { |
|
94 | - $instance = $this->getAccess($prefix); |
|
95 | - } |
|
96 | - $result = call_user_func_array(array($instance, $method), $parameters); |
|
97 | - if($result === $passOnWhen) { |
|
98 | - //not found here, reset cache to null if user vanished |
|
99 | - //because sometimes methods return false with a reason |
|
100 | - $userExists = call_user_func_array( |
|
101 | - array($this->backends[$prefix], 'userExists'), |
|
102 | - array($uid) |
|
103 | - ); |
|
104 | - if(!$userExists) { |
|
105 | - $this->writeToCache($cacheKey, null); |
|
106 | - } |
|
107 | - } |
|
108 | - return $result; |
|
109 | - } |
|
110 | - } |
|
111 | - return false; |
|
112 | - } |
|
77 | + /** |
|
78 | + * Asks the backend connected to the server that supposely takes care of the uid from the request. |
|
79 | + * @param string $uid the uid connected to the request |
|
80 | + * @param string $method the method of the user backend that shall be called |
|
81 | + * @param array $parameters an array of parameters to be passed |
|
82 | + * @param mixed $passOnWhen the result matches this variable |
|
83 | + * @return mixed the result of the method or false |
|
84 | + */ |
|
85 | + protected function callOnLastSeenOn($uid, $method, $parameters, $passOnWhen) { |
|
86 | + $cacheKey = $this->getUserCacheKey($uid); |
|
87 | + $prefix = $this->getFromCache($cacheKey); |
|
88 | + //in case the uid has been found in the past, try this stored connection first |
|
89 | + if(!is_null($prefix)) { |
|
90 | + if(isset($this->backends[$prefix])) { |
|
91 | + $instance = $this->backends[$prefix]; |
|
92 | + if(!method_exists($instance, $method) |
|
93 | + && method_exists($this->getAccess($prefix), $method)) { |
|
94 | + $instance = $this->getAccess($prefix); |
|
95 | + } |
|
96 | + $result = call_user_func_array(array($instance, $method), $parameters); |
|
97 | + if($result === $passOnWhen) { |
|
98 | + //not found here, reset cache to null if user vanished |
|
99 | + //because sometimes methods return false with a reason |
|
100 | + $userExists = call_user_func_array( |
|
101 | + array($this->backends[$prefix], 'userExists'), |
|
102 | + array($uid) |
|
103 | + ); |
|
104 | + if(!$userExists) { |
|
105 | + $this->writeToCache($cacheKey, null); |
|
106 | + } |
|
107 | + } |
|
108 | + return $result; |
|
109 | + } |
|
110 | + } |
|
111 | + return false; |
|
112 | + } |
|
113 | 113 | |
114 | - /** |
|
115 | - * Check if backend implements actions |
|
116 | - * @param int $actions bitwise-or'ed actions |
|
117 | - * @return boolean |
|
118 | - * |
|
119 | - * Returns the supported actions as int to be |
|
120 | - * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
121 | - */ |
|
122 | - public function implementsActions($actions) { |
|
123 | - //it's the same across all our user backends obviously |
|
124 | - return $this->refBackend->implementsActions($actions); |
|
125 | - } |
|
114 | + /** |
|
115 | + * Check if backend implements actions |
|
116 | + * @param int $actions bitwise-or'ed actions |
|
117 | + * @return boolean |
|
118 | + * |
|
119 | + * Returns the supported actions as int to be |
|
120 | + * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
121 | + */ |
|
122 | + public function implementsActions($actions) { |
|
123 | + //it's the same across all our user backends obviously |
|
124 | + return $this->refBackend->implementsActions($actions); |
|
125 | + } |
|
126 | 126 | |
127 | - /** |
|
128 | - * Backend name to be shown in user management |
|
129 | - * @return string the name of the backend to be shown |
|
130 | - */ |
|
131 | - public function getBackendName() { |
|
132 | - return $this->refBackend->getBackendName(); |
|
133 | - } |
|
127 | + /** |
|
128 | + * Backend name to be shown in user management |
|
129 | + * @return string the name of the backend to be shown |
|
130 | + */ |
|
131 | + public function getBackendName() { |
|
132 | + return $this->refBackend->getBackendName(); |
|
133 | + } |
|
134 | 134 | |
135 | - /** |
|
136 | - * Get a list of all users |
|
137 | - * |
|
138 | - * @param string $search |
|
139 | - * @param null|int $limit |
|
140 | - * @param null|int $offset |
|
141 | - * @return string[] an array of all uids |
|
142 | - */ |
|
143 | - public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
144 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
145 | - $users = array(); |
|
146 | - foreach($this->backends as $backend) { |
|
147 | - $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
148 | - if (is_array($backendUsers)) { |
|
149 | - $users = array_merge($users, $backendUsers); |
|
150 | - } |
|
151 | - } |
|
152 | - return $users; |
|
153 | - } |
|
135 | + /** |
|
136 | + * Get a list of all users |
|
137 | + * |
|
138 | + * @param string $search |
|
139 | + * @param null|int $limit |
|
140 | + * @param null|int $offset |
|
141 | + * @return string[] an array of all uids |
|
142 | + */ |
|
143 | + public function getUsers($search = '', $limit = 10, $offset = 0) { |
|
144 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
145 | + $users = array(); |
|
146 | + foreach($this->backends as $backend) { |
|
147 | + $backendUsers = $backend->getUsers($search, $limit, $offset); |
|
148 | + if (is_array($backendUsers)) { |
|
149 | + $users = array_merge($users, $backendUsers); |
|
150 | + } |
|
151 | + } |
|
152 | + return $users; |
|
153 | + } |
|
154 | 154 | |
155 | - /** |
|
156 | - * check if a user exists |
|
157 | - * @param string $uid the username |
|
158 | - * @return boolean |
|
159 | - */ |
|
160 | - public function userExists($uid) { |
|
161 | - return $this->handleRequest($uid, 'userExists', array($uid)); |
|
162 | - } |
|
155 | + /** |
|
156 | + * check if a user exists |
|
157 | + * @param string $uid the username |
|
158 | + * @return boolean |
|
159 | + */ |
|
160 | + public function userExists($uid) { |
|
161 | + return $this->handleRequest($uid, 'userExists', array($uid)); |
|
162 | + } |
|
163 | 163 | |
164 | - /** |
|
165 | - * check if a user exists on LDAP |
|
166 | - * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
167 | - * name or an instance of that user |
|
168 | - * @return boolean |
|
169 | - */ |
|
170 | - public function userExistsOnLDAP($user) { |
|
171 | - $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
172 | - return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
173 | - } |
|
164 | + /** |
|
165 | + * check if a user exists on LDAP |
|
166 | + * @param string|\OCA\User_LDAP\User\User $user either the ownCloud user |
|
167 | + * name or an instance of that user |
|
168 | + * @return boolean |
|
169 | + */ |
|
170 | + public function userExistsOnLDAP($user) { |
|
171 | + $id = ($user instanceof User) ? $user->getUsername() : $user; |
|
172 | + return $this->handleRequest($id, 'userExistsOnLDAP', array($user)); |
|
173 | + } |
|
174 | 174 | |
175 | - /** |
|
176 | - * Check if the password is correct |
|
177 | - * @param string $uid The username |
|
178 | - * @param string $password The password |
|
179 | - * @return bool |
|
180 | - * |
|
181 | - * Check if the password is correct without logging in the user |
|
182 | - */ |
|
183 | - public function checkPassword($uid, $password) { |
|
184 | - return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
185 | - } |
|
175 | + /** |
|
176 | + * Check if the password is correct |
|
177 | + * @param string $uid The username |
|
178 | + * @param string $password The password |
|
179 | + * @return bool |
|
180 | + * |
|
181 | + * Check if the password is correct without logging in the user |
|
182 | + */ |
|
183 | + public function checkPassword($uid, $password) { |
|
184 | + return $this->handleRequest($uid, 'checkPassword', array($uid, $password)); |
|
185 | + } |
|
186 | 186 | |
187 | - /** |
|
188 | - * returns the username for the given login name, if available |
|
189 | - * |
|
190 | - * @param string $loginName |
|
191 | - * @return string|false |
|
192 | - */ |
|
193 | - public function loginName2UserName($loginName) { |
|
194 | - $id = 'LOGINNAME,' . $loginName; |
|
195 | - return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
196 | - } |
|
187 | + /** |
|
188 | + * returns the username for the given login name, if available |
|
189 | + * |
|
190 | + * @param string $loginName |
|
191 | + * @return string|false |
|
192 | + */ |
|
193 | + public function loginName2UserName($loginName) { |
|
194 | + $id = 'LOGINNAME,' . $loginName; |
|
195 | + return $this->handleRequest($id, 'loginName2UserName', array($loginName)); |
|
196 | + } |
|
197 | 197 | |
198 | - /** |
|
199 | - * returns the username for the given LDAP DN, if available |
|
200 | - * |
|
201 | - * @param string $dn |
|
202 | - * @return string|false with the username |
|
203 | - */ |
|
204 | - public function dn2UserName($dn) { |
|
205 | - $id = 'DN,' . $dn; |
|
206 | - return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
207 | - } |
|
198 | + /** |
|
199 | + * returns the username for the given LDAP DN, if available |
|
200 | + * |
|
201 | + * @param string $dn |
|
202 | + * @return string|false with the username |
|
203 | + */ |
|
204 | + public function dn2UserName($dn) { |
|
205 | + $id = 'DN,' . $dn; |
|
206 | + return $this->handleRequest($id, 'dn2UserName', array($dn)); |
|
207 | + } |
|
208 | 208 | |
209 | - /** |
|
210 | - * get the user's home directory |
|
211 | - * @param string $uid the username |
|
212 | - * @return boolean |
|
213 | - */ |
|
214 | - public function getHome($uid) { |
|
215 | - return $this->handleRequest($uid, 'getHome', array($uid)); |
|
216 | - } |
|
209 | + /** |
|
210 | + * get the user's home directory |
|
211 | + * @param string $uid the username |
|
212 | + * @return boolean |
|
213 | + */ |
|
214 | + public function getHome($uid) { |
|
215 | + return $this->handleRequest($uid, 'getHome', array($uid)); |
|
216 | + } |
|
217 | 217 | |
218 | - /** |
|
219 | - * get display name of the user |
|
220 | - * @param string $uid user ID of the user |
|
221 | - * @return string display name |
|
222 | - */ |
|
223 | - public function getDisplayName($uid) { |
|
224 | - return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
225 | - } |
|
218 | + /** |
|
219 | + * get display name of the user |
|
220 | + * @param string $uid user ID of the user |
|
221 | + * @return string display name |
|
222 | + */ |
|
223 | + public function getDisplayName($uid) { |
|
224 | + return $this->handleRequest($uid, 'getDisplayName', array($uid)); |
|
225 | + } |
|
226 | 226 | |
227 | - /** |
|
228 | - * checks whether the user is allowed to change his avatar in ownCloud |
|
229 | - * @param string $uid the ownCloud user name |
|
230 | - * @return boolean either the user can or cannot |
|
231 | - */ |
|
232 | - public function canChangeAvatar($uid) { |
|
233 | - return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
234 | - } |
|
227 | + /** |
|
228 | + * checks whether the user is allowed to change his avatar in ownCloud |
|
229 | + * @param string $uid the ownCloud user name |
|
230 | + * @return boolean either the user can or cannot |
|
231 | + */ |
|
232 | + public function canChangeAvatar($uid) { |
|
233 | + return $this->handleRequest($uid, 'canChangeAvatar', array($uid), true); |
|
234 | + } |
|
235 | 235 | |
236 | - /** |
|
237 | - * Get a list of all display names and user ids. |
|
238 | - * @param string $search |
|
239 | - * @param string|null $limit |
|
240 | - * @param string|null $offset |
|
241 | - * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
242 | - */ |
|
243 | - public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
244 | - //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
245 | - $users = array(); |
|
246 | - foreach($this->backends as $backend) { |
|
247 | - $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
248 | - if (is_array($backendUsers)) { |
|
249 | - $users = $users + $backendUsers; |
|
250 | - } |
|
251 | - } |
|
252 | - return $users; |
|
253 | - } |
|
236 | + /** |
|
237 | + * Get a list of all display names and user ids. |
|
238 | + * @param string $search |
|
239 | + * @param string|null $limit |
|
240 | + * @param string|null $offset |
|
241 | + * @return array an array of all displayNames (value) and the corresponding uids (key) |
|
242 | + */ |
|
243 | + public function getDisplayNames($search = '', $limit = null, $offset = null) { |
|
244 | + //we do it just as the /OC_User implementation: do not play around with limit and offset but ask all backends |
|
245 | + $users = array(); |
|
246 | + foreach($this->backends as $backend) { |
|
247 | + $backendUsers = $backend->getDisplayNames($search, $limit, $offset); |
|
248 | + if (is_array($backendUsers)) { |
|
249 | + $users = $users + $backendUsers; |
|
250 | + } |
|
251 | + } |
|
252 | + return $users; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * delete a user |
|
257 | - * @param string $uid The username of the user to delete |
|
258 | - * @return bool |
|
259 | - * |
|
260 | - * Deletes a user |
|
261 | - */ |
|
262 | - public function deleteUser($uid) { |
|
263 | - return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
264 | - } |
|
255 | + /** |
|
256 | + * delete a user |
|
257 | + * @param string $uid The username of the user to delete |
|
258 | + * @return bool |
|
259 | + * |
|
260 | + * Deletes a user |
|
261 | + */ |
|
262 | + public function deleteUser($uid) { |
|
263 | + return $this->handleRequest($uid, 'deleteUser', array($uid)); |
|
264 | + } |
|
265 | 265 | |
266 | - /** |
|
267 | - * @return bool |
|
268 | - */ |
|
269 | - public function hasUserListings() { |
|
270 | - return $this->refBackend->hasUserListings(); |
|
271 | - } |
|
266 | + /** |
|
267 | + * @return bool |
|
268 | + */ |
|
269 | + public function hasUserListings() { |
|
270 | + return $this->refBackend->hasUserListings(); |
|
271 | + } |
|
272 | 272 | |
273 | - /** |
|
274 | - * Count the number of users |
|
275 | - * @return int|bool |
|
276 | - */ |
|
277 | - public function countUsers() { |
|
278 | - $users = false; |
|
279 | - foreach($this->backends as $backend) { |
|
280 | - $backendUsers = $backend->countUsers(); |
|
281 | - if ($backendUsers !== false) { |
|
282 | - $users += $backendUsers; |
|
283 | - } |
|
284 | - } |
|
285 | - return $users; |
|
286 | - } |
|
273 | + /** |
|
274 | + * Count the number of users |
|
275 | + * @return int|bool |
|
276 | + */ |
|
277 | + public function countUsers() { |
|
278 | + $users = false; |
|
279 | + foreach($this->backends as $backend) { |
|
280 | + $backendUsers = $backend->countUsers(); |
|
281 | + if ($backendUsers !== false) { |
|
282 | + $users += $backendUsers; |
|
283 | + } |
|
284 | + } |
|
285 | + return $users; |
|
286 | + } |
|
287 | 287 | |
288 | - /** |
|
289 | - * Return access for LDAP interaction. |
|
290 | - * @param string $uid |
|
291 | - * @return Access instance of Access for LDAP interaction |
|
292 | - */ |
|
293 | - public function getLDAPAccess($uid) { |
|
294 | - return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
295 | - } |
|
288 | + /** |
|
289 | + * Return access for LDAP interaction. |
|
290 | + * @param string $uid |
|
291 | + * @return Access instance of Access for LDAP interaction |
|
292 | + */ |
|
293 | + public function getLDAPAccess($uid) { |
|
294 | + return $this->handleRequest($uid, 'getLDAPAccess', array($uid)); |
|
295 | + } |
|
296 | 296 | |
297 | - /** |
|
298 | - * Return a new LDAP connection for the specified user. |
|
299 | - * The connection needs to be closed manually. |
|
300 | - * @param string $uid |
|
301 | - * @return resource of the LDAP connection |
|
302 | - */ |
|
303 | - public function getNewLDAPConnection($uid) { |
|
304 | - return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
305 | - } |
|
297 | + /** |
|
298 | + * Return a new LDAP connection for the specified user. |
|
299 | + * The connection needs to be closed manually. |
|
300 | + * @param string $uid |
|
301 | + * @return resource of the LDAP connection |
|
302 | + */ |
|
303 | + public function getNewLDAPConnection($uid) { |
|
304 | + return $this->handleRequest($uid, 'getNewLDAPConnection', array($uid)); |
|
305 | + } |
|
306 | 306 | } |