@@ -26,68 +26,68 @@ |
||
| 26 | 26 | |
| 27 | 27 | interface ILDAPUserPlugin { |
| 28 | 28 | |
| 29 | - /** |
|
| 30 | - * Check if plugin implements actions |
|
| 31 | - * @return int |
|
| 32 | - * |
|
| 33 | - * Returns the supported actions as int to be |
|
| 34 | - * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 35 | - */ |
|
| 36 | - public function respondToActions(); |
|
| 29 | + /** |
|
| 30 | + * Check if plugin implements actions |
|
| 31 | + * @return int |
|
| 32 | + * |
|
| 33 | + * Returns the supported actions as int to be |
|
| 34 | + * compared with OC_USER_BACKEND_CREATE_USER etc. |
|
| 35 | + */ |
|
| 36 | + public function respondToActions(); |
|
| 37 | 37 | |
| 38 | - /** |
|
| 39 | - * Create a new user in LDAP Backend |
|
| 40 | - * |
|
| 41 | - * @param string $uid The UID of the user to create |
|
| 42 | - * @param string $password The password of the new user |
|
| 43 | - * @return bool|string |
|
| 44 | - */ |
|
| 45 | - public function createUser($uid, $password); |
|
| 38 | + /** |
|
| 39 | + * Create a new user in LDAP Backend |
|
| 40 | + * |
|
| 41 | + * @param string $uid The UID of the user to create |
|
| 42 | + * @param string $password The password of the new user |
|
| 43 | + * @return bool|string |
|
| 44 | + */ |
|
| 45 | + public function createUser($uid, $password); |
|
| 46 | 46 | |
| 47 | - /** |
|
| 48 | - * Set password |
|
| 49 | - * |
|
| 50 | - * @param string $uid The username |
|
| 51 | - * @param string $password The new password |
|
| 52 | - * @return bool |
|
| 53 | - * |
|
| 54 | - * Change the password of a user |
|
| 55 | - */ |
|
| 56 | - public function setPassword($uid, $password); |
|
| 47 | + /** |
|
| 48 | + * Set password |
|
| 49 | + * |
|
| 50 | + * @param string $uid The username |
|
| 51 | + * @param string $password The new password |
|
| 52 | + * @return bool |
|
| 53 | + * |
|
| 54 | + * Change the password of a user |
|
| 55 | + */ |
|
| 56 | + public function setPassword($uid, $password); |
|
| 57 | 57 | |
| 58 | - /** |
|
| 59 | - * get the user's home directory |
|
| 60 | - * @param string $uid the username |
|
| 61 | - * @return boolean |
|
| 62 | - */ |
|
| 63 | - public function getHome($uid); |
|
| 58 | + /** |
|
| 59 | + * get the user's home directory |
|
| 60 | + * @param string $uid the username |
|
| 61 | + * @return boolean |
|
| 62 | + */ |
|
| 63 | + public function getHome($uid); |
|
| 64 | 64 | |
| 65 | - /** |
|
| 66 | - * get display name of the user |
|
| 67 | - * @param string $uid user ID of the user |
|
| 68 | - * @return string display name |
|
| 69 | - */ |
|
| 70 | - public function getDisplayName($uid); |
|
| 65 | + /** |
|
| 66 | + * get display name of the user |
|
| 67 | + * @param string $uid user ID of the user |
|
| 68 | + * @return string display name |
|
| 69 | + */ |
|
| 70 | + public function getDisplayName($uid); |
|
| 71 | 71 | |
| 72 | - /** |
|
| 73 | - * set display name of the user |
|
| 74 | - * @param string $uid user ID of the user |
|
| 75 | - * @param string $displayName new user's display name |
|
| 76 | - * @return string display name |
|
| 77 | - */ |
|
| 78 | - public function setDisplayName($uid, $displayName); |
|
| 72 | + /** |
|
| 73 | + * set display name of the user |
|
| 74 | + * @param string $uid user ID of the user |
|
| 75 | + * @param string $displayName new user's display name |
|
| 76 | + * @return string display name |
|
| 77 | + */ |
|
| 78 | + public function setDisplayName($uid, $displayName); |
|
| 79 | 79 | |
| 80 | - /** |
|
| 81 | - * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 82 | - * @param string $uid the Nextcloud user name |
|
| 83 | - * @return boolean either the user can or cannot |
|
| 84 | - */ |
|
| 85 | - public function canChangeAvatar($uid); |
|
| 80 | + /** |
|
| 81 | + * checks whether the user is allowed to change his avatar in Nextcloud |
|
| 82 | + * @param string $uid the Nextcloud user name |
|
| 83 | + * @return boolean either the user can or cannot |
|
| 84 | + */ |
|
| 85 | + public function canChangeAvatar($uid); |
|
| 86 | 86 | |
| 87 | - /** |
|
| 88 | - * Count the number of users |
|
| 89 | - * @return int|bool |
|
| 90 | - */ |
|
| 91 | - public function countUsers(); |
|
| 87 | + /** |
|
| 88 | + * Count the number of users |
|
| 89 | + * @return int|bool |
|
| 90 | + */ |
|
| 91 | + public function countUsers(); |
|
| 92 | 92 | |
| 93 | 93 | } |
@@ -37,274 +37,274 @@ |
||
| 37 | 37 | */ |
| 38 | 38 | class LDAPProvider implements ILDAPProvider, IDeletionFlagSupport { |
| 39 | 39 | |
| 40 | - private $userBackend; |
|
| 41 | - private $groupBackend; |
|
| 42 | - private $logger; |
|
| 43 | - private $helper; |
|
| 44 | - private $deletedUsersIndex; |
|
| 40 | + private $userBackend; |
|
| 41 | + private $groupBackend; |
|
| 42 | + private $logger; |
|
| 43 | + private $helper; |
|
| 44 | + private $deletedUsersIndex; |
|
| 45 | 45 | |
| 46 | - /** |
|
| 47 | - * Create new LDAPProvider |
|
| 48 | - * @param \OCP\IServerContainer $serverContainer |
|
| 49 | - * @param Helper $helper |
|
| 50 | - * @param DeletedUsersIndex $deletedUsersIndex |
|
| 51 | - * @throws \Exception if user_ldap app was not enabled |
|
| 52 | - */ |
|
| 53 | - public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 54 | - $this->logger = $serverContainer->getLogger(); |
|
| 55 | - $this->helper = $helper; |
|
| 56 | - $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 57 | - $userBackendFound = false; |
|
| 58 | - $groupBackendFound = false; |
|
| 59 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 60 | - $this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']); |
|
| 61 | - if ($backend instanceof IUserLDAP) { |
|
| 62 | - $this->userBackend = $backend; |
|
| 63 | - $userBackendFound = true; |
|
| 64 | - break; |
|
| 65 | - } |
|
| 46 | + /** |
|
| 47 | + * Create new LDAPProvider |
|
| 48 | + * @param \OCP\IServerContainer $serverContainer |
|
| 49 | + * @param Helper $helper |
|
| 50 | + * @param DeletedUsersIndex $deletedUsersIndex |
|
| 51 | + * @throws \Exception if user_ldap app was not enabled |
|
| 52 | + */ |
|
| 53 | + public function __construct(IServerContainer $serverContainer, Helper $helper, DeletedUsersIndex $deletedUsersIndex) { |
|
| 54 | + $this->logger = $serverContainer->getLogger(); |
|
| 55 | + $this->helper = $helper; |
|
| 56 | + $this->deletedUsersIndex = $deletedUsersIndex; |
|
| 57 | + $userBackendFound = false; |
|
| 58 | + $groupBackendFound = false; |
|
| 59 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 60 | + $this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']); |
|
| 61 | + if ($backend instanceof IUserLDAP) { |
|
| 62 | + $this->userBackend = $backend; |
|
| 63 | + $userBackendFound = true; |
|
| 64 | + break; |
|
| 65 | + } |
|
| 66 | + } |
|
| 67 | + foreach ($serverContainer->getGroupManager()->getBackends() as $backend){ |
|
| 68 | + $this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']); |
|
| 69 | + if ($backend instanceof IGroupLDAP) { |
|
| 70 | + $this->groupBackend = $backend; |
|
| 71 | + $groupBackendFound = true; |
|
| 72 | + break; |
|
| 73 | + } |
|
| 66 | 74 | } |
| 67 | - foreach ($serverContainer->getGroupManager()->getBackends() as $backend){ |
|
| 68 | - $this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']); |
|
| 69 | - if ($backend instanceof IGroupLDAP) { |
|
| 70 | - $this->groupBackend = $backend; |
|
| 71 | - $groupBackendFound = true; |
|
| 72 | - break; |
|
| 73 | - } |
|
| 74 | - } |
|
| 75 | 75 | |
| 76 | 76 | if (!$userBackendFound or !$groupBackendFound) { |
| 77 | - throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 78 | - } |
|
| 79 | - } |
|
| 77 | + throw new \Exception('To use the LDAPProvider, user_ldap app must be enabled'); |
|
| 78 | + } |
|
| 79 | + } |
|
| 80 | 80 | |
| 81 | - /** |
|
| 82 | - * Translate an user id to LDAP DN |
|
| 83 | - * @param string $uid user id |
|
| 84 | - * @return string with the LDAP DN |
|
| 85 | - * @throws \Exception if translation was unsuccessful |
|
| 86 | - */ |
|
| 87 | - public function getUserDN($uid) { |
|
| 88 | - if(!$this->userBackend->userExists($uid)){ |
|
| 89 | - throw new \Exception('User id not found in LDAP'); |
|
| 90 | - } |
|
| 91 | - $result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid); |
|
| 92 | - if(!$result){ |
|
| 93 | - throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 94 | - } |
|
| 95 | - return $result; |
|
| 96 | - } |
|
| 81 | + /** |
|
| 82 | + * Translate an user id to LDAP DN |
|
| 83 | + * @param string $uid user id |
|
| 84 | + * @return string with the LDAP DN |
|
| 85 | + * @throws \Exception if translation was unsuccessful |
|
| 86 | + */ |
|
| 87 | + public function getUserDN($uid) { |
|
| 88 | + if(!$this->userBackend->userExists($uid)){ |
|
| 89 | + throw new \Exception('User id not found in LDAP'); |
|
| 90 | + } |
|
| 91 | + $result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid); |
|
| 92 | + if(!$result){ |
|
| 93 | + throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 94 | + } |
|
| 95 | + return $result; |
|
| 96 | + } |
|
| 97 | 97 | |
| 98 | - /** |
|
| 99 | - * Translate a group id to LDAP DN. |
|
| 100 | - * @param string $gid group id |
|
| 101 | - * @return string |
|
| 102 | - * @throws \Exception |
|
| 103 | - */ |
|
| 104 | - public function getGroupDN($gid) { |
|
| 105 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 106 | - throw new \Exception('Group id not found in LDAP'); |
|
| 107 | - } |
|
| 108 | - $result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid); |
|
| 109 | - if(!$result){ |
|
| 110 | - throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 111 | - } |
|
| 112 | - return $result; |
|
| 113 | - } |
|
| 98 | + /** |
|
| 99 | + * Translate a group id to LDAP DN. |
|
| 100 | + * @param string $gid group id |
|
| 101 | + * @return string |
|
| 102 | + * @throws \Exception |
|
| 103 | + */ |
|
| 104 | + public function getGroupDN($gid) { |
|
| 105 | + if(!$this->groupBackend->groupExists($gid)){ |
|
| 106 | + throw new \Exception('Group id not found in LDAP'); |
|
| 107 | + } |
|
| 108 | + $result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid); |
|
| 109 | + if(!$result){ |
|
| 110 | + throw new \Exception('Translation to LDAP DN unsuccessful'); |
|
| 111 | + } |
|
| 112 | + return $result; |
|
| 113 | + } |
|
| 114 | 114 | |
| 115 | - /** |
|
| 116 | - * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 117 | - * the DN and the user name, a new one will be created. |
|
| 118 | - * @param string $dn LDAP DN |
|
| 119 | - * @return string with the internal user name |
|
| 120 | - * @throws \Exception if translation was unsuccessful |
|
| 121 | - */ |
|
| 122 | - public function getUserName($dn) { |
|
| 123 | - $result = $this->userBackend->dn2UserName($dn); |
|
| 124 | - if(!$result){ |
|
| 125 | - throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 126 | - } |
|
| 127 | - return $result; |
|
| 128 | - } |
|
| 115 | + /** |
|
| 116 | + * Translate a LDAP DN to an internal user name. If there is no mapping between |
|
| 117 | + * the DN and the user name, a new one will be created. |
|
| 118 | + * @param string $dn LDAP DN |
|
| 119 | + * @return string with the internal user name |
|
| 120 | + * @throws \Exception if translation was unsuccessful |
|
| 121 | + */ |
|
| 122 | + public function getUserName($dn) { |
|
| 123 | + $result = $this->userBackend->dn2UserName($dn); |
|
| 124 | + if(!$result){ |
|
| 125 | + throw new \Exception('Translation to internal user name unsuccessful'); |
|
| 126 | + } |
|
| 127 | + return $result; |
|
| 128 | + } |
|
| 129 | 129 | |
| 130 | - /** |
|
| 131 | - * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 132 | - * @param string $dn the DN in question |
|
| 133 | - * @return string |
|
| 134 | - */ |
|
| 135 | - public function DNasBaseParameter($dn) { |
|
| 136 | - return $this->helper->DNasBaseParameter($dn); |
|
| 137 | - } |
|
| 130 | + /** |
|
| 131 | + * Convert a stored DN so it can be used as base parameter for LDAP queries. |
|
| 132 | + * @param string $dn the DN in question |
|
| 133 | + * @return string |
|
| 134 | + */ |
|
| 135 | + public function DNasBaseParameter($dn) { |
|
| 136 | + return $this->helper->DNasBaseParameter($dn); |
|
| 137 | + } |
|
| 138 | 138 | |
| 139 | - /** |
|
| 140 | - * Sanitize a DN received from the LDAP server. |
|
| 141 | - * @param array $dn the DN in question |
|
| 142 | - * @return array the sanitized DN |
|
| 143 | - */ |
|
| 144 | - public function sanitizeDN($dn) { |
|
| 145 | - return $this->helper->sanitizeDN($dn); |
|
| 146 | - } |
|
| 139 | + /** |
|
| 140 | + * Sanitize a DN received from the LDAP server. |
|
| 141 | + * @param array $dn the DN in question |
|
| 142 | + * @return array the sanitized DN |
|
| 143 | + */ |
|
| 144 | + public function sanitizeDN($dn) { |
|
| 145 | + return $this->helper->sanitizeDN($dn); |
|
| 146 | + } |
|
| 147 | 147 | |
| 148 | - /** |
|
| 149 | - * Return a new LDAP connection resource for the specified user. |
|
| 150 | - * The connection must be closed manually. |
|
| 151 | - * @param string $uid user id |
|
| 152 | - * @return resource of the LDAP connection |
|
| 153 | - * @throws \Exception if user id was not found in LDAP |
|
| 154 | - */ |
|
| 155 | - public function getLDAPConnection($uid) { |
|
| 156 | - if(!$this->userBackend->userExists($uid)){ |
|
| 157 | - throw new \Exception('User id not found in LDAP'); |
|
| 158 | - } |
|
| 159 | - return $this->userBackend->getNewLDAPConnection($uid); |
|
| 160 | - } |
|
| 148 | + /** |
|
| 149 | + * Return a new LDAP connection resource for the specified user. |
|
| 150 | + * The connection must be closed manually. |
|
| 151 | + * @param string $uid user id |
|
| 152 | + * @return resource of the LDAP connection |
|
| 153 | + * @throws \Exception if user id was not found in LDAP |
|
| 154 | + */ |
|
| 155 | + public function getLDAPConnection($uid) { |
|
| 156 | + if(!$this->userBackend->userExists($uid)){ |
|
| 157 | + throw new \Exception('User id not found in LDAP'); |
|
| 158 | + } |
|
| 159 | + return $this->userBackend->getNewLDAPConnection($uid); |
|
| 160 | + } |
|
| 161 | 161 | |
| 162 | - /** |
|
| 163 | - * Return a new LDAP connection resource for the specified user. |
|
| 164 | - * The connection must be closed manually. |
|
| 165 | - * @param string $gid group id |
|
| 166 | - * @return resource of the LDAP connection |
|
| 167 | - * @throws \Exception if group id was not found in LDAP |
|
| 168 | - */ |
|
| 169 | - public function getGroupLDAPConnection($gid) { |
|
| 170 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 171 | - throw new \Exception('Group id not found in LDAP'); |
|
| 172 | - } |
|
| 173 | - return $this->groupBackend->getNewLDAPConnection($gid); |
|
| 174 | - } |
|
| 162 | + /** |
|
| 163 | + * Return a new LDAP connection resource for the specified user. |
|
| 164 | + * The connection must be closed manually. |
|
| 165 | + * @param string $gid group id |
|
| 166 | + * @return resource of the LDAP connection |
|
| 167 | + * @throws \Exception if group id was not found in LDAP |
|
| 168 | + */ |
|
| 169 | + public function getGroupLDAPConnection($gid) { |
|
| 170 | + if(!$this->groupBackend->groupExists($gid)){ |
|
| 171 | + throw new \Exception('Group id not found in LDAP'); |
|
| 172 | + } |
|
| 173 | + return $this->groupBackend->getNewLDAPConnection($gid); |
|
| 174 | + } |
|
| 175 | 175 | |
| 176 | - /** |
|
| 177 | - * Get the LDAP base for users. |
|
| 178 | - * @param string $uid user id |
|
| 179 | - * @return string the base for users |
|
| 180 | - * @throws \Exception if user id was not found in LDAP |
|
| 181 | - */ |
|
| 182 | - public function getLDAPBaseUsers($uid) { |
|
| 183 | - if(!$this->userBackend->userExists($uid)){ |
|
| 184 | - throw new \Exception('User id not found in LDAP'); |
|
| 185 | - } |
|
| 186 | - $access = $this->userBackend->getLDAPAccess($uid); |
|
| 187 | - $bases = $access->getConnection()->ldapBaseUsers; |
|
| 188 | - $dn = $this->getUserDN($uid); |
|
| 189 | - foreach ($bases as $base) { |
|
| 190 | - if($access->isDNPartOfBase($dn, [$base])) { |
|
| 191 | - return $base; |
|
| 192 | - } |
|
| 193 | - } |
|
| 194 | - // should not occur, because the user does not qualify to use NC in this case |
|
| 195 | - $this->logger->info( |
|
| 196 | - 'No matching user base found for user {dn}, available: {bases}.', |
|
| 197 | - [ |
|
| 198 | - 'app' => 'user_ldap', |
|
| 199 | - 'dn' => $dn, |
|
| 200 | - 'bases' => $bases, |
|
| 201 | - ] |
|
| 202 | - ); |
|
| 203 | - return array_shift($bases); |
|
| 204 | - } |
|
| 176 | + /** |
|
| 177 | + * Get the LDAP base for users. |
|
| 178 | + * @param string $uid user id |
|
| 179 | + * @return string the base for users |
|
| 180 | + * @throws \Exception if user id was not found in LDAP |
|
| 181 | + */ |
|
| 182 | + public function getLDAPBaseUsers($uid) { |
|
| 183 | + if(!$this->userBackend->userExists($uid)){ |
|
| 184 | + throw new \Exception('User id not found in LDAP'); |
|
| 185 | + } |
|
| 186 | + $access = $this->userBackend->getLDAPAccess($uid); |
|
| 187 | + $bases = $access->getConnection()->ldapBaseUsers; |
|
| 188 | + $dn = $this->getUserDN($uid); |
|
| 189 | + foreach ($bases as $base) { |
|
| 190 | + if($access->isDNPartOfBase($dn, [$base])) { |
|
| 191 | + return $base; |
|
| 192 | + } |
|
| 193 | + } |
|
| 194 | + // should not occur, because the user does not qualify to use NC in this case |
|
| 195 | + $this->logger->info( |
|
| 196 | + 'No matching user base found for user {dn}, available: {bases}.', |
|
| 197 | + [ |
|
| 198 | + 'app' => 'user_ldap', |
|
| 199 | + 'dn' => $dn, |
|
| 200 | + 'bases' => $bases, |
|
| 201 | + ] |
|
| 202 | + ); |
|
| 203 | + return array_shift($bases); |
|
| 204 | + } |
|
| 205 | 205 | |
| 206 | - /** |
|
| 207 | - * Get the LDAP base for groups. |
|
| 208 | - * @param string $uid user id |
|
| 209 | - * @return string the base for groups |
|
| 210 | - * @throws \Exception if user id was not found in LDAP |
|
| 211 | - */ |
|
| 212 | - public function getLDAPBaseGroups($uid) { |
|
| 213 | - if(!$this->userBackend->userExists($uid)){ |
|
| 214 | - throw new \Exception('User id not found in LDAP'); |
|
| 215 | - } |
|
| 216 | - $bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups; |
|
| 217 | - return array_shift($bases); |
|
| 218 | - } |
|
| 206 | + /** |
|
| 207 | + * Get the LDAP base for groups. |
|
| 208 | + * @param string $uid user id |
|
| 209 | + * @return string the base for groups |
|
| 210 | + * @throws \Exception if user id was not found in LDAP |
|
| 211 | + */ |
|
| 212 | + public function getLDAPBaseGroups($uid) { |
|
| 213 | + if(!$this->userBackend->userExists($uid)){ |
|
| 214 | + throw new \Exception('User id not found in LDAP'); |
|
| 215 | + } |
|
| 216 | + $bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups; |
|
| 217 | + return array_shift($bases); |
|
| 218 | + } |
|
| 219 | 219 | |
| 220 | - /** |
|
| 221 | - * Clear the cache if a cache is used, otherwise do nothing. |
|
| 222 | - * @param string $uid user id |
|
| 223 | - * @throws \Exception if user id was not found in LDAP |
|
| 224 | - */ |
|
| 225 | - public function clearCache($uid) { |
|
| 226 | - if(!$this->userBackend->userExists($uid)){ |
|
| 227 | - throw new \Exception('User id not found in LDAP'); |
|
| 228 | - } |
|
| 229 | - $this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 230 | - } |
|
| 220 | + /** |
|
| 221 | + * Clear the cache if a cache is used, otherwise do nothing. |
|
| 222 | + * @param string $uid user id |
|
| 223 | + * @throws \Exception if user id was not found in LDAP |
|
| 224 | + */ |
|
| 225 | + public function clearCache($uid) { |
|
| 226 | + if(!$this->userBackend->userExists($uid)){ |
|
| 227 | + throw new \Exception('User id not found in LDAP'); |
|
| 228 | + } |
|
| 229 | + $this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache(); |
|
| 230 | + } |
|
| 231 | 231 | |
| 232 | - /** |
|
| 233 | - * Clear the cache if a cache is used, otherwise do nothing. |
|
| 234 | - * Acts on the LDAP connection of a group |
|
| 235 | - * @param string $gid group id |
|
| 236 | - * @throws \Exception if user id was not found in LDAP |
|
| 237 | - */ |
|
| 238 | - public function clearGroupCache($gid) { |
|
| 239 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 240 | - throw new \Exception('Group id not found in LDAP'); |
|
| 241 | - } |
|
| 242 | - $this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache(); |
|
| 243 | - } |
|
| 232 | + /** |
|
| 233 | + * Clear the cache if a cache is used, otherwise do nothing. |
|
| 234 | + * Acts on the LDAP connection of a group |
|
| 235 | + * @param string $gid group id |
|
| 236 | + * @throws \Exception if user id was not found in LDAP |
|
| 237 | + */ |
|
| 238 | + public function clearGroupCache($gid) { |
|
| 239 | + if(!$this->groupBackend->groupExists($gid)){ |
|
| 240 | + throw new \Exception('Group id not found in LDAP'); |
|
| 241 | + } |
|
| 242 | + $this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache(); |
|
| 243 | + } |
|
| 244 | 244 | |
| 245 | - /** |
|
| 246 | - * Check whether a LDAP DN exists |
|
| 247 | - * @param string $dn LDAP DN |
|
| 248 | - * @return bool whether the DN exists |
|
| 249 | - */ |
|
| 250 | - public function dnExists($dn) { |
|
| 251 | - $result = $this->userBackend->dn2UserName($dn); |
|
| 252 | - return !$result ? false : true; |
|
| 253 | - } |
|
| 245 | + /** |
|
| 246 | + * Check whether a LDAP DN exists |
|
| 247 | + * @param string $dn LDAP DN |
|
| 248 | + * @return bool whether the DN exists |
|
| 249 | + */ |
|
| 250 | + public function dnExists($dn) { |
|
| 251 | + $result = $this->userBackend->dn2UserName($dn); |
|
| 252 | + return !$result ? false : true; |
|
| 253 | + } |
|
| 254 | 254 | |
| 255 | - /** |
|
| 256 | - * Flag record for deletion. |
|
| 257 | - * @param string $uid user id |
|
| 258 | - */ |
|
| 259 | - public function flagRecord($uid) { |
|
| 260 | - $this->deletedUsersIndex->markUser($uid); |
|
| 261 | - } |
|
| 255 | + /** |
|
| 256 | + * Flag record for deletion. |
|
| 257 | + * @param string $uid user id |
|
| 258 | + */ |
|
| 259 | + public function flagRecord($uid) { |
|
| 260 | + $this->deletedUsersIndex->markUser($uid); |
|
| 261 | + } |
|
| 262 | 262 | |
| 263 | - /** |
|
| 264 | - * Unflag record for deletion. |
|
| 265 | - * @param string $uid user id |
|
| 266 | - */ |
|
| 267 | - public function unflagRecord($uid) { |
|
| 268 | - //do nothing |
|
| 269 | - } |
|
| 263 | + /** |
|
| 264 | + * Unflag record for deletion. |
|
| 265 | + * @param string $uid user id |
|
| 266 | + */ |
|
| 267 | + public function unflagRecord($uid) { |
|
| 268 | + //do nothing |
|
| 269 | + } |
|
| 270 | 270 | |
| 271 | - /** |
|
| 272 | - * Get the LDAP attribute name for the user's display name |
|
| 273 | - * @param string $uid user id |
|
| 274 | - * @return string the display name field |
|
| 275 | - * @throws \Exception if user id was not found in LDAP |
|
| 276 | - */ |
|
| 277 | - public function getLDAPDisplayNameField($uid) { |
|
| 278 | - if(!$this->userBackend->userExists($uid)){ |
|
| 279 | - throw new \Exception('User id not found in LDAP'); |
|
| 280 | - } |
|
| 281 | - return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name']; |
|
| 282 | - } |
|
| 271 | + /** |
|
| 272 | + * Get the LDAP attribute name for the user's display name |
|
| 273 | + * @param string $uid user id |
|
| 274 | + * @return string the display name field |
|
| 275 | + * @throws \Exception if user id was not found in LDAP |
|
| 276 | + */ |
|
| 277 | + public function getLDAPDisplayNameField($uid) { |
|
| 278 | + if(!$this->userBackend->userExists($uid)){ |
|
| 279 | + throw new \Exception('User id not found in LDAP'); |
|
| 280 | + } |
|
| 281 | + return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name']; |
|
| 282 | + } |
|
| 283 | 283 | |
| 284 | - /** |
|
| 285 | - * Get the LDAP attribute name for the email |
|
| 286 | - * @param string $uid user id |
|
| 287 | - * @return string the email field |
|
| 288 | - * @throws \Exception if user id was not found in LDAP |
|
| 289 | - */ |
|
| 290 | - public function getLDAPEmailField($uid) { |
|
| 291 | - if(!$this->userBackend->userExists($uid)){ |
|
| 292 | - throw new \Exception('User id not found in LDAP'); |
|
| 293 | - } |
|
| 294 | - return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr']; |
|
| 295 | - } |
|
| 284 | + /** |
|
| 285 | + * Get the LDAP attribute name for the email |
|
| 286 | + * @param string $uid user id |
|
| 287 | + * @return string the email field |
|
| 288 | + * @throws \Exception if user id was not found in LDAP |
|
| 289 | + */ |
|
| 290 | + public function getLDAPEmailField($uid) { |
|
| 291 | + if(!$this->userBackend->userExists($uid)){ |
|
| 292 | + throw new \Exception('User id not found in LDAP'); |
|
| 293 | + } |
|
| 294 | + return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr']; |
|
| 295 | + } |
|
| 296 | 296 | |
| 297 | - /** |
|
| 298 | - * Get the LDAP type of association between users and groups |
|
| 299 | - * @param string $gid group id |
|
| 300 | - * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', '' |
|
| 301 | - * @throws \Exception if group id was not found in LDAP |
|
| 302 | - */ |
|
| 303 | - public function getLDAPGroupMemberAssoc($gid) { |
|
| 304 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 305 | - throw new \Exception('Group id not found in LDAP'); |
|
| 306 | - } |
|
| 307 | - return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute']; |
|
| 308 | - } |
|
| 297 | + /** |
|
| 298 | + * Get the LDAP type of association between users and groups |
|
| 299 | + * @param string $gid group id |
|
| 300 | + * @return string the configuration, one of: 'memberUid', 'uniqueMember', 'member', 'gidNumber', '' |
|
| 301 | + * @throws \Exception if group id was not found in LDAP |
|
| 302 | + */ |
|
| 303 | + public function getLDAPGroupMemberAssoc($gid) { |
|
| 304 | + if(!$this->groupBackend->groupExists($gid)){ |
|
| 305 | + throw new \Exception('Group id not found in LDAP'); |
|
| 306 | + } |
|
| 307 | + return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute']; |
|
| 308 | + } |
|
| 309 | 309 | |
| 310 | 310 | } |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $this->deletedUsersIndex = $deletedUsersIndex; |
| 57 | 57 | $userBackendFound = false; |
| 58 | 58 | $groupBackendFound = false; |
| 59 | - foreach ($serverContainer->getUserManager()->getBackends() as $backend){ |
|
| 59 | + foreach ($serverContainer->getUserManager()->getBackends() as $backend) { |
|
| 60 | 60 | $this->logger->debug('instance '.get_class($backend).' user backend.', ['app' => 'user_ldap']); |
| 61 | 61 | if ($backend instanceof IUserLDAP) { |
| 62 | 62 | $this->userBackend = $backend; |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | break; |
| 65 | 65 | } |
| 66 | 66 | } |
| 67 | - foreach ($serverContainer->getGroupManager()->getBackends() as $backend){ |
|
| 67 | + foreach ($serverContainer->getGroupManager()->getBackends() as $backend) { |
|
| 68 | 68 | $this->logger->debug('instance '.get_class($backend).' group backend.', ['app' => 'user_ldap']); |
| 69 | 69 | if ($backend instanceof IGroupLDAP) { |
| 70 | 70 | $this->groupBackend = $backend; |
@@ -85,11 +85,11 @@ discard block |
||
| 85 | 85 | * @throws \Exception if translation was unsuccessful |
| 86 | 86 | */ |
| 87 | 87 | public function getUserDN($uid) { |
| 88 | - if(!$this->userBackend->userExists($uid)){ |
|
| 88 | + if (!$this->userBackend->userExists($uid)) { |
|
| 89 | 89 | throw new \Exception('User id not found in LDAP'); |
| 90 | 90 | } |
| 91 | 91 | $result = $this->userBackend->getLDAPAccess($uid)->username2dn($uid); |
| 92 | - if(!$result){ |
|
| 92 | + if (!$result) { |
|
| 93 | 93 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
| 94 | 94 | } |
| 95 | 95 | return $result; |
@@ -102,11 +102,11 @@ discard block |
||
| 102 | 102 | * @throws \Exception |
| 103 | 103 | */ |
| 104 | 104 | public function getGroupDN($gid) { |
| 105 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 105 | + if (!$this->groupBackend->groupExists($gid)) { |
|
| 106 | 106 | throw new \Exception('Group id not found in LDAP'); |
| 107 | 107 | } |
| 108 | 108 | $result = $this->groupBackend->getLDAPAccess($gid)->groupname2dn($gid); |
| 109 | - if(!$result){ |
|
| 109 | + if (!$result) { |
|
| 110 | 110 | throw new \Exception('Translation to LDAP DN unsuccessful'); |
| 111 | 111 | } |
| 112 | 112 | return $result; |
@@ -121,7 +121,7 @@ discard block |
||
| 121 | 121 | */ |
| 122 | 122 | public function getUserName($dn) { |
| 123 | 123 | $result = $this->userBackend->dn2UserName($dn); |
| 124 | - if(!$result){ |
|
| 124 | + if (!$result) { |
|
| 125 | 125 | throw new \Exception('Translation to internal user name unsuccessful'); |
| 126 | 126 | } |
| 127 | 127 | return $result; |
@@ -153,7 +153,7 @@ discard block |
||
| 153 | 153 | * @throws \Exception if user id was not found in LDAP |
| 154 | 154 | */ |
| 155 | 155 | public function getLDAPConnection($uid) { |
| 156 | - if(!$this->userBackend->userExists($uid)){ |
|
| 156 | + if (!$this->userBackend->userExists($uid)) { |
|
| 157 | 157 | throw new \Exception('User id not found in LDAP'); |
| 158 | 158 | } |
| 159 | 159 | return $this->userBackend->getNewLDAPConnection($uid); |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | * @throws \Exception if group id was not found in LDAP |
| 168 | 168 | */ |
| 169 | 169 | public function getGroupLDAPConnection($gid) { |
| 170 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 170 | + if (!$this->groupBackend->groupExists($gid)) { |
|
| 171 | 171 | throw new \Exception('Group id not found in LDAP'); |
| 172 | 172 | } |
| 173 | 173 | return $this->groupBackend->getNewLDAPConnection($gid); |
@@ -180,14 +180,14 @@ discard block |
||
| 180 | 180 | * @throws \Exception if user id was not found in LDAP |
| 181 | 181 | */ |
| 182 | 182 | public function getLDAPBaseUsers($uid) { |
| 183 | - if(!$this->userBackend->userExists($uid)){ |
|
| 183 | + if (!$this->userBackend->userExists($uid)) { |
|
| 184 | 184 | throw new \Exception('User id not found in LDAP'); |
| 185 | 185 | } |
| 186 | 186 | $access = $this->userBackend->getLDAPAccess($uid); |
| 187 | 187 | $bases = $access->getConnection()->ldapBaseUsers; |
| 188 | 188 | $dn = $this->getUserDN($uid); |
| 189 | 189 | foreach ($bases as $base) { |
| 190 | - if($access->isDNPartOfBase($dn, [$base])) { |
|
| 190 | + if ($access->isDNPartOfBase($dn, [$base])) { |
|
| 191 | 191 | return $base; |
| 192 | 192 | } |
| 193 | 193 | } |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | * @throws \Exception if user id was not found in LDAP |
| 211 | 211 | */ |
| 212 | 212 | public function getLDAPBaseGroups($uid) { |
| 213 | - if(!$this->userBackend->userExists($uid)){ |
|
| 213 | + if (!$this->userBackend->userExists($uid)) { |
|
| 214 | 214 | throw new \Exception('User id not found in LDAP'); |
| 215 | 215 | } |
| 216 | 216 | $bases = $this->userBackend->getLDAPAccess($uid)->getConnection()->ldapBaseGroups; |
@@ -223,7 +223,7 @@ discard block |
||
| 223 | 223 | * @throws \Exception if user id was not found in LDAP |
| 224 | 224 | */ |
| 225 | 225 | public function clearCache($uid) { |
| 226 | - if(!$this->userBackend->userExists($uid)){ |
|
| 226 | + if (!$this->userBackend->userExists($uid)) { |
|
| 227 | 227 | throw new \Exception('User id not found in LDAP'); |
| 228 | 228 | } |
| 229 | 229 | $this->userBackend->getLDAPAccess($uid)->getConnection()->clearCache(); |
@@ -236,7 +236,7 @@ discard block |
||
| 236 | 236 | * @throws \Exception if user id was not found in LDAP |
| 237 | 237 | */ |
| 238 | 238 | public function clearGroupCache($gid) { |
| 239 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 239 | + if (!$this->groupBackend->groupExists($gid)) { |
|
| 240 | 240 | throw new \Exception('Group id not found in LDAP'); |
| 241 | 241 | } |
| 242 | 242 | $this->groupBackend->getLDAPAccess($gid)->getConnection()->clearCache(); |
@@ -275,7 +275,7 @@ discard block |
||
| 275 | 275 | * @throws \Exception if user id was not found in LDAP |
| 276 | 276 | */ |
| 277 | 277 | public function getLDAPDisplayNameField($uid) { |
| 278 | - if(!$this->userBackend->userExists($uid)){ |
|
| 278 | + if (!$this->userBackend->userExists($uid)) { |
|
| 279 | 279 | throw new \Exception('User id not found in LDAP'); |
| 280 | 280 | } |
| 281 | 281 | return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_display_name']; |
@@ -288,7 +288,7 @@ discard block |
||
| 288 | 288 | * @throws \Exception if user id was not found in LDAP |
| 289 | 289 | */ |
| 290 | 290 | public function getLDAPEmailField($uid) { |
| 291 | - if(!$this->userBackend->userExists($uid)){ |
|
| 291 | + if (!$this->userBackend->userExists($uid)) { |
|
| 292 | 292 | throw new \Exception('User id not found in LDAP'); |
| 293 | 293 | } |
| 294 | 294 | return $this->userBackend->getLDAPAccess($uid)->getConnection()->getConfiguration()['ldap_email_attr']; |
@@ -301,7 +301,7 @@ discard block |
||
| 301 | 301 | * @throws \Exception if group id was not found in LDAP |
| 302 | 302 | */ |
| 303 | 303 | public function getLDAPGroupMemberAssoc($gid) { |
| 304 | - if(!$this->groupBackend->groupExists($gid)){ |
|
| 304 | + if (!$this->groupBackend->groupExists($gid)) { |
|
| 305 | 305 | throw new \Exception('Group id not found in LDAP'); |
| 306 | 306 | } |
| 307 | 307 | return $this->groupBackend->getLDAPAccess($gid)->getConnection()->getConfiguration()['ldap_group_member_assoc_attribute']; |