You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

UserMapping.php 2.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
  6. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  7. *
  8. * @license AGPL-3.0
  9. *
  10. * This code is free software: you can redistribute it and/or modify
  11. * it under the terms of the GNU Affero General Public License, version 3,
  12. * as published by the Free Software Foundation.
  13. *
  14. * This program is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. * GNU Affero General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Affero General Public License, version 3,
  20. * along with this program. If not, see <http://www.gnu.org/licenses/>
  21. *
  22. */
  23. namespace OCA\User_LDAP\Mapping;
  24. use OCP\HintException;
  25. use OCP\IDBConnection;
  26. use OCP\IRequest;
  27. use OCP\Server;
  28. use OCP\Support\Subscription\IAssertion;
  29. /**
  30. * Class UserMapping
  31. *
  32. * @package OCA\User_LDAP\Mapping
  33. */
  34. class UserMapping extends AbstractMapping {
  35. private IAssertion $assertion;
  36. protected const PROV_API_REGEX = '/\/ocs\/v[1-9].php\/cloud\/(groups|users)/';
  37. public function __construct(IDBConnection $dbc, IAssertion $assertion) {
  38. $this->assertion = $assertion;
  39. parent::__construct($dbc);
  40. }
  41. /**
  42. * @throws HintException
  43. */
  44. public function map($fdn, $name, $uuid): bool {
  45. try {
  46. $this->assertion->createUserIsLegit();
  47. } catch (HintException $e) {
  48. static $isProvisioningApi = null;
  49. if ($isProvisioningApi === null) {
  50. $request = Server::get(IRequest::class);
  51. $isProvisioningApi = \preg_match(self::PROV_API_REGEX, $request->getRequestUri()) === 1;
  52. }
  53. if ($isProvisioningApi) {
  54. // only throw when prov API is being used, since functionality
  55. // should not break for end users (e.g. when sharing).
  56. // On direct API usage, e.g. on users page, this is desired.
  57. throw $e;
  58. }
  59. return false;
  60. }
  61. return parent::map($fdn, $name, $uuid);
  62. }
  63. /**
  64. * returns the DB table name which holds the mappings
  65. * @return string
  66. */
  67. protected function getTableName(bool $includePrefix = true) {
  68. $p = $includePrefix ? '*PREFIX*' : '';
  69. return $p . 'ldap_user_mapping';
  70. }
  71. }