@@ -42,89 +42,89 @@ |
||
42 | 42 | */ |
43 | 43 | class PublicAuth extends AbstractBasic { |
44 | 44 | |
45 | - /** @var \OCP\Share\IShare */ |
|
46 | - private $share; |
|
45 | + /** @var \OCP\Share\IShare */ |
|
46 | + private $share; |
|
47 | 47 | |
48 | - /** @var IManager */ |
|
49 | - private $shareManager; |
|
48 | + /** @var IManager */ |
|
49 | + private $shareManager; |
|
50 | 50 | |
51 | - /** @var ISession */ |
|
52 | - private $session; |
|
51 | + /** @var ISession */ |
|
52 | + private $session; |
|
53 | 53 | |
54 | - /** @var IRequest */ |
|
55 | - private $request; |
|
54 | + /** @var IRequest */ |
|
55 | + private $request; |
|
56 | 56 | |
57 | - /** |
|
58 | - * @param IRequest $request |
|
59 | - * @param IManager $shareManager |
|
60 | - * @param ISession $session |
|
61 | - */ |
|
62 | - public function __construct(IRequest $request, |
|
63 | - IManager $shareManager, |
|
64 | - ISession $session) { |
|
65 | - $this->request = $request; |
|
66 | - $this->shareManager = $shareManager; |
|
67 | - $this->session = $session; |
|
57 | + /** |
|
58 | + * @param IRequest $request |
|
59 | + * @param IManager $shareManager |
|
60 | + * @param ISession $session |
|
61 | + */ |
|
62 | + public function __construct(IRequest $request, |
|
63 | + IManager $shareManager, |
|
64 | + ISession $session) { |
|
65 | + $this->request = $request; |
|
66 | + $this->shareManager = $shareManager; |
|
67 | + $this->session = $session; |
|
68 | 68 | |
69 | - // setup realm |
|
70 | - $defaults = new \OCP\Defaults(); |
|
71 | - $this->realm = $defaults->getName(); |
|
72 | - } |
|
69 | + // setup realm |
|
70 | + $defaults = new \OCP\Defaults(); |
|
71 | + $this->realm = $defaults->getName(); |
|
72 | + } |
|
73 | 73 | |
74 | - /** |
|
75 | - * Validates a username and password |
|
76 | - * |
|
77 | - * This method should return true or false depending on if login |
|
78 | - * succeeded. |
|
79 | - * |
|
80 | - * @param string $username |
|
81 | - * @param string $password |
|
82 | - * |
|
83 | - * @return bool |
|
84 | - * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
85 | - */ |
|
86 | - protected function validateUserPass($username, $password) { |
|
87 | - try { |
|
88 | - $share = $this->shareManager->getShareByToken($username); |
|
89 | - } catch (ShareNotFound $e) { |
|
90 | - return false; |
|
91 | - } |
|
74 | + /** |
|
75 | + * Validates a username and password |
|
76 | + * |
|
77 | + * This method should return true or false depending on if login |
|
78 | + * succeeded. |
|
79 | + * |
|
80 | + * @param string $username |
|
81 | + * @param string $password |
|
82 | + * |
|
83 | + * @return bool |
|
84 | + * @throws \Sabre\DAV\Exception\NotAuthenticated |
|
85 | + */ |
|
86 | + protected function validateUserPass($username, $password) { |
|
87 | + try { |
|
88 | + $share = $this->shareManager->getShareByToken($username); |
|
89 | + } catch (ShareNotFound $e) { |
|
90 | + return false; |
|
91 | + } |
|
92 | 92 | |
93 | - $this->share = $share; |
|
93 | + $this->share = $share; |
|
94 | 94 | |
95 | - \OC_User::setIncognitoMode(true); |
|
95 | + \OC_User::setIncognitoMode(true); |
|
96 | 96 | |
97 | - // check if the share is password protected |
|
98 | - if ($share->getPassword() !== null) { |
|
99 | - if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
100 | - if ($this->shareManager->checkPassword($share, $password)) { |
|
101 | - return true; |
|
102 | - } else if ($this->session->exists('public_link_authenticated') |
|
103 | - && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
104 | - return true; |
|
105 | - } else { |
|
106 | - if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
107 | - // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
108 | - http_response_code(401); |
|
109 | - header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
110 | - throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
111 | - } |
|
112 | - return false; |
|
113 | - } |
|
114 | - } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
115 | - return true; |
|
116 | - } else { |
|
117 | - return false; |
|
118 | - } |
|
119 | - } else { |
|
120 | - return true; |
|
121 | - } |
|
122 | - } |
|
97 | + // check if the share is password protected |
|
98 | + if ($share->getPassword() !== null) { |
|
99 | + if ($share->getShareType() === \OCP\Share::SHARE_TYPE_LINK || $share->getShareType() === \OCP\Share::SHARE_TYPE_EMAIL) { |
|
100 | + if ($this->shareManager->checkPassword($share, $password)) { |
|
101 | + return true; |
|
102 | + } else if ($this->session->exists('public_link_authenticated') |
|
103 | + && $this->session->get('public_link_authenticated') === (string)$share->getId()) { |
|
104 | + return true; |
|
105 | + } else { |
|
106 | + if (in_array('XMLHttpRequest', explode(',', $this->request->getHeader('X-Requested-With')))) { |
|
107 | + // do not re-authenticate over ajax, use dummy auth name to prevent browser popup |
|
108 | + http_response_code(401); |
|
109 | + header('WWW-Authenticate','DummyBasic realm="' . $this->realm . '"'); |
|
110 | + throw new \Sabre\DAV\Exception\NotAuthenticated('Cannot authenticate over ajax calls'); |
|
111 | + } |
|
112 | + return false; |
|
113 | + } |
|
114 | + } else if ($share->getShareType() === \OCP\Share::SHARE_TYPE_REMOTE) { |
|
115 | + return true; |
|
116 | + } else { |
|
117 | + return false; |
|
118 | + } |
|
119 | + } else { |
|
120 | + return true; |
|
121 | + } |
|
122 | + } |
|
123 | 123 | |
124 | - /** |
|
125 | - * @return \OCP\Share\IShare |
|
126 | - */ |
|
127 | - public function getShare() { |
|
128 | - return $this->share; |
|
129 | - } |
|
124 | + /** |
|
125 | + * @return \OCP\Share\IShare |
|
126 | + */ |
|
127 | + public function getShare() { |
|
128 | + return $this->share; |
|
129 | + } |
|
130 | 130 | } |