Skip to content
Snippets Groups Projects
Commit f1868148 authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Started CopyController development

parent b09f782a
No related branches found
No related tags found
No related merge requests found
...@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody; ...@@ -25,7 +25,7 @@ import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.RestController;
@RestController @RestController
public class ArchiveFileController extends FileController { public class ArchiveFileController extends AuthenticatedFileController {
@Autowired @Autowired
private ArchiveService archiveService; private ArchiveService archiveService;
...@@ -63,13 +63,9 @@ public class ArchiveFileController extends FileController { ...@@ -63,13 +63,9 @@ public class ArchiveFileController extends FileController {
FileResponseUtil.getFileResponse(response, file); FileResponseUtil.getFileResponse(response, file);
} }
private TokenPrincipal getPrincipal() { @Override
TokenPrincipal principal = (TokenPrincipal) request.getUserPrincipal(); protected String getCustomAuthErrorMessage() {
return "Tar/Zip archive generation not allowed to anonymous users";
if ("anonymous".equals(principal.getName())) {
throw new PermissionDeniedException("Tar/Zip archive generation not allowed to anonymous users");
} }
return principal;
}
} }
/*
* This file is part of vospace-file-service
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.inaf.ia2.transfer.controller;
import it.inaf.ia2.transfer.auth.TokenPrincipal;
import it.inaf.ia2.transfer.exception.PermissionDeniedException;
public abstract class AuthenticatedFileController extends FileController {
protected TokenPrincipal getPrincipal() {
TokenPrincipal principal = (TokenPrincipal) request.getUserPrincipal();
if ("anonymous".equals(principal.getName())) {
throw new PermissionDeniedException("Tar/Zip archive generation not allowed to anonymous users");
}
return principal;
}
protected abstract String getCustomAuthErrorMessage();
}
/*
* This file is part of vospace-file-service
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.inaf.ia2.transfer.controller;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class CopyController extends AuthenticatedFileController {
@PostMapping(value = "/copy", consumes = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity<?> copyFiles(@RequestBody CopyRequest copyRequest) {
return ResponseEntity.ok(
copyRequest.getJobId() + " copy task accepted by File Service"
);
}
@Override
protected String getCustomAuthErrorMessage() {
return "File Copy not allowed to anonymous users";
}
}
/*
* This file is part of vospace-file-service
* Copyright (C) 2021 Istituto Nazionale di Astrofisica
* SPDX-License-Identifier: GPL-3.0-or-later
*/
package it.inaf.ia2.transfer.controller;
public class CopyRequest {
String jobId;
String target;
String direction;
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
public String getTarget() {
return target;
}
public void setTarget(String target) {
this.target = target;
}
public String getDirection() {
return direction;
}
public void setDirection(String direction) {
this.direction = direction;
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment