@@ -139,11 +139,13 @@ public String dashboard(@RequestParam(value = "error", required = false) String
139139 }
140140 }
141141
142- // Fehlermeldungen beim Upload
142+ // Fehlermeldungen
143143 if ("uploadError" .equals (error )) {
144144 model .addAttribute ("error" , "There was an Error while Uploading. Try again later." );
145145 } else if ("uploadInProgress" .equals (error )) {
146146 model .addAttribute ("error" , "There is an current Upload in Progress." );
147+ } else if ("NoAccess" .equals (error )) {
148+ model .addAttribute ("error" , "You aren't Allowed to see this." );
147149 } else if (error != null ) {
148150 model .addAttribute ("error" , "An Error occurred." );
149151 }
@@ -287,9 +289,18 @@ public ResponseEntity<ByteArrayResource> downloadFile(@PathVariable Long id) {
287289 */
288290 @ GetMapping ("/file/{fileId}" )
289291 public ResponseEntity <Resource > getFile (@ PathVariable Long fileId ) {
292+ UserDetails currentUserDetails = (UserDetails ) SecurityContextHolder .getContext ().getAuthentication ().getPrincipal ();
293+ User currentUser = userRepository .findByUsername (currentUserDetails .getUsername ()).orElseThrow ();
294+
290295 UploadedFile file = uploadedFileRepository .findById (fileId )
291296 .orElseThrow (() -> new ResourceNotFoundException ("File not found" ));
292297
298+ // Berechtigungsprüfung
299+ if (!file .getFileOwner ().getId ().equals (currentUser .getId ())
300+ && !fileAuthorizationService .isUserAuthorized (fileId , currentUser .getId ())) {
301+ throw new ResourceNotFoundException ("File not found" ); // oder AccessDeniedException
302+ }
303+
293304 return ResponseEntity .ok ()
294305 .contentType (MediaType .parseMediaType (file .getFileType ()))
295306 .body (new ByteArrayResource (file .getFileData ()));
0 commit comments