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