@@ -137,8 +137,7 @@ private function checkToken(): array {
137137 \OC_User::setIncognitoMode (true );
138138
139139 // If already authenticated
140- if ($ this ->session ->exists (self ::DAV_AUTHENTICATED )
141- && $ this ->session ->get (self ::DAV_AUTHENTICATED ) === $ share ->getId ()) {
140+ if ($ this ->isShareInSession ($ share )) {
142141 return [true , $ this ->principalPrefix . $ token ];
143142 }
144143
@@ -180,17 +179,17 @@ protected function validateUserPass($username, $password) {
180179 if ($ share ->getShareType () === IShare::TYPE_LINK
181180 || $ share ->getShareType () === IShare::TYPE_EMAIL
182181 || $ share ->getShareType () === IShare::TYPE_CIRCLE ) {
182+ // Validate password if provided
183183 if ($ this ->shareManager ->checkPassword ($ share , $ password )) {
184184 // If not set, set authenticated session cookie
185- if (!$ this ->session ->exists (self ::DAV_AUTHENTICATED )
186- || $ this ->session ->get (self ::DAV_AUTHENTICATED ) !== $ share ->getId ()) {
187- $ this ->session ->set (self ::DAV_AUTHENTICATED , $ share ->getId ());
185+ if (!$ this ->isShareInSession ($ share )) {
186+ $ this ->addShareToSession ($ share );
188187 }
189188 return true ;
190189 }
191190
192- if ( $ this -> session -> exists (PublicAuth:: DAV_AUTHENTICATED )
193- && $ this ->session -> get (PublicAuth:: DAV_AUTHENTICATED ) === $ share-> getId ( )) {
191+ // We are already authenticated for this share in the session
192+ if ( $ this ->isShareInSession ( $ share )) {
194193 return true ;
195194 }
196195
@@ -224,4 +223,27 @@ public function getShare(): IShare {
224223
225224 return $ this ->share ;
226225 }
226+
227+ private function addShareToSession (IShare $ share ): void {
228+ $ allowedShareIds = $ this ->session ->get (self ::DAV_AUTHENTICATED ) ?? [];
229+ if (!is_array ($ allowedShareIds )) {
230+ $ allowedShareIds = [];
231+ }
232+
233+ $ allowedShareIds [] = $ share ->getId ();
234+ $ this ->session ->set (self ::DAV_AUTHENTICATED , $ allowedShareIds );
235+ }
236+
237+ private function isShareInSession (IShare $ share ): bool {
238+ if (!$ this ->session ->exists (self ::DAV_AUTHENTICATED )) {
239+ return false ;
240+ }
241+
242+ $ allowedShareIds = $ this ->session ->get (self ::DAV_AUTHENTICATED );
243+ if (!is_array ($ allowedShareIds )) {
244+ return false ;
245+ }
246+
247+ return in_array ($ share ->getId (), $ allowedShareIds );
248+ }
227249}
0 commit comments