Skip to content
This repository was archived by the owner on Apr 5, 2024. It is now read-only.

Commit b8d111c

Browse files
authored
FF-465 - Added Cookie auth to fs item info (#122)
* implemented cookie auth in file info endpoint * made code style more uniform
1 parent 7546556 commit b8d111c

File tree

4 files changed

+21
-11
lines changed

4 files changed

+21
-11
lines changed

src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestController.java

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,13 @@ public ResponseEntity<List<FileSystemItem>> getContentsOfFolder(
4242
@GetMapping(FS_BASE_URI + "{fsItemId}/info")
4343
public ResponseEntity<FileSystemItem> getFileOrFolderInfo(
4444
@PathVariable long fsItemId,
45-
@RequestHeader(value = "Authorization") String accessToken
45+
@CookieValue(name = AUTHORIZATION_ACCESS_TOKEN_COOKIE, required = false) String cookieValue,
46+
@RequestHeader(value = "Authorization", required = false) String accessToken
4647
) {
4748

4849
log.info("Requested information about FileSystemItem with id {}.", fsItemId);
49-
return fileSystemRestService.getInfoAboutFileOrFolderByIdAndAccessToken(fsItemId, accessToken);
50+
log.debug("Header was {}, Cookie was {}", accessToken, cookieValue);
51+
return fileSystemRestService.getInfoAboutFileOrFolderByIdAndAccessToken(fsItemId, new Pair<>(cookieValue, accessToken));
5052
}
5153

5254
@GetMapping(FS_BASE_URI + "search")
@@ -63,17 +65,20 @@ public ResponseEntity<List<FileSystemItem>> searchFileOrFolderByName(
6365
public ResponseEntity<List<FileSystemItem>> downloadFileOrFolder(
6466
@RequestParam(name = "ids") List<Long> ids,
6567
@CookieValue(name = AUTHORIZATION_ACCESS_TOKEN_COOKIE, required = false) String cookieValue,
66-
@RequestHeader(value = "Authorization", required = false) String accessToken) {
68+
@RequestHeader(value = "Authorization", required = false) String accessToken
69+
) {
6770

6871
log.info("Tried downloading FileSystemEntities with the ids {}", ids);
72+
log.debug("Header was {}, Cookie was {}", accessToken, cookieValue);
6973
return fileSystemRestService.downloadFileSystemEntity(ids, new Pair<>(cookieValue, accessToken));
7074
}
7175

7276
@PostMapping(FS_BASE_URI + "{fsItemId}/folder/create")
7377
public ResponseEntity<FileSystemItem> createNewFolder(
7478
@PathVariable long fsItemId,
7579
@RequestBody CreateNewFolder newFolder,
76-
@RequestHeader(value = "Authorization") String accessToken) {
80+
@RequestHeader(value = "Authorization") String accessToken
81+
) {
7782

7883
log.info("Tried creating new Folder {}", newFolder);
7984
return fileSystemRestService.createNewFolder(fsItemId, newFolder, accessToken);
@@ -83,7 +88,8 @@ public ResponseEntity<FileSystemItem> createNewFolder(
8388
public ResponseEntity<List<FileSystemItem>> uploadFileOrFolder(
8489
@PathVariable long fsItemId,
8590
@RequestBody FileSystemUpload fileSystemUpload,
86-
@RequestHeader(value = "Authorization") String accessToken) {
91+
@RequestHeader(value = "Authorization") String accessToken
92+
) {
8793

8894
log.info("Tried uploading new FileSystemUpload {}", fileSystemUpload);
8995
return fileSystemRestService.uploadFileSystemItemWithAccessToken(fsItemId, fileSystemUpload, accessToken);
@@ -93,7 +99,8 @@ public ResponseEntity<List<FileSystemItem>> uploadFileOrFolder(
9399
public ResponseEntity<List<FileSystemUploadPreflightResponse>> preflightUploadFileOrFolder(
94100
@PathVariable long fsItemId,
95101
@RequestBody List<FileSystemUpload> fileSystemUpload,
96-
@RequestHeader(value = "Authorization") String accessToken) {
102+
@RequestHeader(value = "Authorization") String accessToken
103+
) {
97104

98105
log.info("Preflight for {} in id {}.", fileSystemUpload, fsItemId);
99106
return fileSystemRestService.preflightUploadOfFileSystemItem(fsItemId, fileSystemUpload, accessToken);

src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestService.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ public ResponseEntity<List<FileSystemItem>> getContentsOfFolderByPathAndAccessTo
4949
}
5050

5151
@Override
52-
public ResponseEntity<FileSystemItem> getInfoAboutFileOrFolderByIdAndAccessToken(long fsItemId, String accessTokenValue) {
53-
User authenticatedUser = authenticationService.bearerAuthenticationWithAccessToken(accessTokenValue);
52+
public ResponseEntity<FileSystemItem> getInfoAboutFileOrFolderByIdAndAccessToken(long fsItemId, Pair<String, String> accessTokenValueOrHeader) {
53+
User authenticatedUser = authenticationService.authenticateUserWithCookieOrHeader(accessTokenValueOrHeader);
5454
return new ResponseEntity<>(fileSystemBusinessService.getFileSystemItemInfo(fsItemId, authenticatedUser), HttpStatus.OK);
5555
}
5656

src/main/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestServiceInterface.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
public interface FileSystemRestServiceInterface {
1414
ResponseEntity<List<FileSystemItem>> getContentsOfFolderByPathAndAccessToken(String path, String accessToken);
1515

16-
ResponseEntity<FileSystemItem> getInfoAboutFileOrFolderByIdAndAccessToken(long fsItemId, String accessToken);
16+
ResponseEntity<FileSystemItem> getInfoAboutFileOrFolderByIdAndAccessToken(long fsItemId, Pair<String, String> authPair);
1717

1818
ResponseEntity<List<FileSystemItem>> findFileOrFolderByNameAndAccessToken(String name, String accessToken);
1919

src/test/java/de/filefighter/rest/domain/filesystem/rest/FileSystemRestControllerUnitTest.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import java.util.List;
1414

1515
import static org.junit.jupiter.api.Assertions.assertEquals;
16+
import static org.mockito.ArgumentMatchers.any;
17+
import static org.mockito.ArgumentMatchers.eq;
1618
import static org.mockito.Mockito.mock;
1719
import static org.mockito.Mockito.when;
1820
import static org.springframework.http.HttpStatus.OK;
@@ -49,10 +51,11 @@ void getFileOrFolderInfo() {
4951

5052
long id = 420;
5153
String token = "token";
54+
String cookieValue = null;
5255

53-
when(fileSystemRestServiceMock.getInfoAboutFileOrFolderByIdAndAccessToken(id, token)).thenReturn(expectedModel);
56+
when(fileSystemRestServiceMock.getInfoAboutFileOrFolderByIdAndAccessToken(eq(id), any())).thenReturn(expectedModel);
5457

55-
ResponseEntity<FileSystemItem> actualModel = fileSystemRestController.getFileOrFolderInfo(id, token);
58+
ResponseEntity<FileSystemItem> actualModel = fileSystemRestController.getFileOrFolderInfo(id, cookieValue, token);
5659
assertEquals(expectedModel, actualModel);
5760
}
5861

0 commit comments

Comments
 (0)