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.

LegacyDAVACL.php 2.0KB

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