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.

LockdownManager.php 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. <?php
  2. /**
  3. * @copyright Copyright (c) 2016, Robin Appelman <robin@icewind.nl>
  4. *
  5. * This code is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License, version 3,
  7. * as published by the Free Software Foundation.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU Affero General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Affero General Public License, version 3,
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>
  16. *
  17. */
  18. namespace OC\Lockdown;
  19. use OC\Authentication\Token\IToken;
  20. use OCP\Lockdown\ILockdownManager;
  21. class LockdownManager implements ILockdownManager {
  22. private $enabled = false;
  23. /** @var array|null */
  24. private $scope;
  25. public function enable() {
  26. $this->enabled = true;
  27. }
  28. public function setToken(IToken $token) {
  29. $this->scope = $token->getScopeAsArray();
  30. $this->enable();
  31. }
  32. public function canAccessFilesystem() {
  33. if (!$this->enabled) {
  34. return true;
  35. }
  36. return !$this->scope || $this->scope['filesystem'];
  37. }
  38. public function canAccessApp($app) {
  39. if (!$this->enabled) {
  40. return true;
  41. }
  42. if ($this->scope && $this->scope['apps']) {
  43. return in_array($app, $this->scope['apps']);
  44. } else {
  45. // no limit
  46. return true;
  47. }
  48. }
  49. }