3535import eu .openanalytics .containerproxy .service .AsyncProxyService ;
3636import eu .openanalytics .containerproxy .service .InvalidParametersException ;
3737import eu .openanalytics .containerproxy .service .ProxyService ;
38+ import eu .openanalytics .containerproxy .service .UserService ;
3839import io .swagger .v3 .oas .annotations .Operation ;
3940import io .swagger .v3 .oas .annotations .Parameter ;
4041import 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