Skip to content

Commit a9974e2

Browse files
committed
Fix #33124: allow admin to stop app
1 parent a2844e0 commit a9974e2

1 file changed

Lines changed: 9 additions & 2 deletions

File tree

src/main/java/eu/openanalytics/containerproxy/api/ProxyStatusController.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
import eu.openanalytics.containerproxy.service.AsyncProxyService;
3636
import eu.openanalytics.containerproxy.service.InvalidParametersException;
3737
import eu.openanalytics.containerproxy.service.ProxyService;
38+
import eu.openanalytics.containerproxy.service.UserService;
3839
import io.swagger.v3.oas.annotations.Operation;
3940
import io.swagger.v3.oas.annotations.Parameter;
4041
import io.swagger.v3.oas.annotations.media.Content;
@@ -66,6 +67,8 @@ public class ProxyStatusController {
6667
private ProxyService proxyService;
6768
@Inject
6869
private AsyncProxyService asyncProxyService;
70+
@Inject
71+
private UserService userService;
6972

7073
@Operation(
7174
summary = "Change the status of a proxy.", tags = "ContainerProxy",
@@ -74,7 +77,7 @@ public class ProxyStatusController {
7477
mediaType = "application/json",
7578
schema = @Schema(implementation = ChangeProxyStatusDto.class),
7679
examples = {
77-
@ExampleObject(name = "Stopping", description = "Stop a proxy.", value = "{\"status\": \"Stopping\"}"),
80+
@ExampleObject(name = "Stopping", description = "Stop a proxy (allowed by admins).", value = "{\"status\": \"Stopping\"}"),
7881
@ExampleObject(name = "Pausing", description = "Pause a proxy.", value = "{\"status\": \"Pausing\"}"),
7982
@ExampleObject(name = "Resuming", description = "Resume a proxy.", value = "{\"status\": \"Resuming\"}"),
8083
@ExampleObject(name = "Resuming with parameters", description = "Resume a proxy.", value = "{\"status\": \"Resuming\", \"parameters\":{\"resources\":\"2 CPU cores - 8G RAM\"," +
@@ -115,10 +118,14 @@ public class ProxyStatusController {
115118
@ResponseBody
116119
@RequestMapping(value = "/api/proxy/{proxyId}/status", method = RequestMethod.PUT)
117120
public ResponseEntity<ApiResponse<Void>> changeProxyStatus(@PathVariable String proxyId, @RequestBody ChangeProxyStatusDto changeProxyStateDto) {
118-
Proxy proxy = proxyService.getUserProxy(proxyId);
121+
Proxy proxy = proxyService.getProxy(proxyId);
119122
if (proxy == null) {
120123
return ApiResponse.failForbidden();
121124
}
125+
if (!userService.isOwner(proxy) && !(changeProxyStateDto.getStatus().equals("Stopping") && userService.isAdmin())) {
126+
// admin is allowed to stop app
127+
return ApiResponse.failForbidden();
128+
}
122129

123130
try {
124131
switch (changeProxyStateDto.getStatus()) {

0 commit comments

Comments
 (0)