Skip to content

Commit 6a4902a

Browse files
committed
Fix #26372: add filter to /api/proxy for only owned proxies
1 parent 6695906 commit 6a4902a

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.springframework.web.bind.annotation.RequestBody;
3535
import org.springframework.web.bind.annotation.RequestMapping;
3636
import org.springframework.web.bind.annotation.RequestMethod;
37+
import org.springframework.web.bind.annotation.RequestParam;
3738
import org.springframework.web.bind.annotation.RestController;
3839

3940
import eu.openanalytics.containerproxy.model.runtime.Proxy;
@@ -61,7 +62,12 @@ public ResponseEntity<ProxySpec> getProxySpec(@PathVariable String proxySpecId)
6162
}
6263

6364
@RequestMapping(value="/api/proxy", method=RequestMethod.GET, produces=MediaType.APPLICATION_JSON_VALUE)
64-
public List<Proxy> listProxies() {
65+
public List<Proxy> listProxies(@RequestParam(value = "only_owned_proxies", required = false, defaultValue = "false") boolean onlyOwnedProxies) {
66+
if (onlyOwnedProxies) {
67+
// even if the user is an admin this will only return proxies that the user owns
68+
return proxyService.getProxiesOfCurrentUser(null);
69+
}
70+
// if the user is an admin this will return all proxies
6571
return proxyService.getProxies(null, false);
6672
}
6773

src/main/java/eu/openanalytics/containerproxy/service/ProxyService.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,23 @@ public List<Proxy> getProxies(Predicate<Proxy> filter, boolean ignoreAccessContr
224224
return matches;
225225
}
226226

227+
/**
228+
* Find all proxies that match an optional filter and that are owned by the current user.
229+
*
230+
* @param filter The filter to match, or null.
231+
* @return A List of matching proxies, may be empty.
232+
*/
233+
public List<Proxy> getProxiesOfCurrentUser(Predicate<Proxy> filter) {
234+
List<Proxy> matches = new ArrayList<>();
235+
synchronized (activeProxies) {
236+
for (Proxy proxy: activeProxies) {
237+
boolean hasAccess = userService.isOwner(proxy);
238+
if (hasAccess && (filter == null || filter.test(proxy))) matches.add(proxy);
239+
}
240+
}
241+
return matches;
242+
}
243+
227244
/**
228245
* Launch a new proxy using the given ProxySpec.
229246
*

0 commit comments

Comments
 (0)