publicauth.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. <?php
  2. /**
  3. * @author Björn Schießle <schiessle@owncloud.com>
  4. * @author Lukas Reschke <lukas@owncloud.com>
  5. * @author Morris Jobke <hey@morrisjobke.de>
  6. * @author Robin Appelman <icewind@owncloud.com>
  7. * @author Thomas Müller <thomas.mueller@tmit.eu>
  8. *
  9. * @copyright Copyright (c) 2015, ownCloud, Inc.
  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\Files_Sharing\Connector;
  26. class PublicAuth extends \Sabre\DAV\Auth\Backend\AbstractBasic {
  27. /**
  28. * @var \OCP\IConfig
  29. */
  30. private $config;
  31. private $share;
  32. /**
  33. * @param \OCP\IConfig $config
  34. */
  35. public function __construct($config) {
  36. $this->config = $config;
  37. }
  38. /**
  39. * Validates a username and password
  40. *
  41. * This method should return true or false depending on if login
  42. * succeeded.
  43. *
  44. * @param string $username
  45. * @param string $password
  46. *
  47. * @return bool
  48. */
  49. protected function validateUserPass($username, $password) {
  50. $linkItem = \OCP\Share::getShareByToken($username, false);
  51. \OC_User::setIncognitoMode(true);
  52. $this->share = $linkItem;
  53. if (!$linkItem) {
  54. return false;
  55. }
  56. // check if the share is password protected
  57. if (isset($linkItem['share_with'])) {
  58. if ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_LINK) {
  59. // Check Password
  60. $newHash = '';
  61. if(\OC::$server->getHasher()->verify($password, $linkItem['share_with'], $newHash)) {
  62. /**
  63. * FIXME: Migrate old hashes to new hash format
  64. * Due to the fact that there is no reasonable functionality to update the password
  65. * of an existing share no migration is yet performed there.
  66. * The only possibility is to update the existing share which will result in a new
  67. * share ID and is a major hack.
  68. *
  69. * In the future the migration should be performed once there is a proper method
  70. * to update the share's password. (for example `$share->updatePassword($password)`
  71. *
  72. * @link https://github.com/owncloud/core/issues/10671
  73. */
  74. if(!empty($newHash)) {
  75. }
  76. return true;
  77. } else {
  78. return false;
  79. }
  80. } elseif ($linkItem['share_type'] == \OCP\Share::SHARE_TYPE_REMOTE) {
  81. return true;
  82. } else {
  83. return false;
  84. }
  85. } else {
  86. return true;
  87. }
  88. }
  89. /**
  90. * @return array
  91. */
  92. public function getShare() {
  93. return $this->share;
  94. }
  95. }