1
0

LegacyDAVACL.php 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, ownCloud, Inc.
  4. *
  5. * @author Christoph Wurst <christoph@winzerhof-wurst.at>
  6. * @author Joas Schilling <coding@schilljs.com>
  7. * @author Lukas Reschke <lukas@statuscode.ch>
  8. * @author Roeland Jago Douma <roeland@famdouma.nl>
  9. * @author Thomas Müller <thomas.mueller@tmit.eu>
  10. *
  11. * @license AGPL-3.0
  12. *
  13. * This code is free software: you can redistribute it and/or modify
  14. * it under the terms of the GNU Affero General Public License, version 3,
  15. * as published by the Free Software Foundation.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU Affero General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU Affero General Public License, version 3,
  23. * along with this program. If not, see <http://www.gnu.org/licenses/>
  24. *
  25. */
  26. namespace OCA\DAV\Connector;
  27. use OCA\DAV\Connector\Sabre\DavAclPlugin;
  28. use Sabre\DAV\INode;
  29. use Sabre\DAV\PropFind;
  30. use Sabre\DAVACL\Xml\Property\Principal;
  31. class LegacyDAVACL extends DavAclPlugin {
  32. /**
  33. * @inheritdoc
  34. */
  35. public function getCurrentUserPrincipals() {
  36. $principalV2 = $this->getCurrentUserPrincipal();
  37. if (is_null($principalV2)) {
  38. return [];
  39. }
  40. $principalV1 = $this->convertPrincipal($principalV2, false);
  41. return array_merge(
  42. [
  43. $principalV2,
  44. $principalV1
  45. ],
  46. $this->getPrincipalMembership($principalV1)
  47. );
  48. }
  49. private function convertPrincipal($principal, $toV2) {
  50. [, $name] = \Sabre\Uri\split($principal);
  51. if ($toV2) {
  52. return "principals/users/$name";
  53. }
  54. return "principals/$name";
  55. }
  56. public function propFind(PropFind $propFind, INode $node) {
  57. /* Overload current-user-principal */
  58. $propFind->handle('{DAV:}current-user-principal', function () {
  59. if ($url = parent::getCurrentUserPrincipal()) {
  60. return new Principal(Principal::HREF, $url . '/');
  61. } else {
  62. return new Principal(Principal::UNAUTHENTICATED);
  63. }
  64. });
  65. return parent::propFind($propFind, $node);
  66. }
  67. }