use of com.yahoo.vespa.hosted.controller.restapi.Path in project vespa by vespa-engine.
the class ControllerAuthorizationFilter method filter.
// NOTE: Be aware of the ordering of the path pattern matching. Semantics may change if the patterns are evaluated
// in different order.
@Override
public void filter(DiscFilterRequest request, ResponseHandler handler) {
Method method = getMethod(request);
if (isWhiteListedMethod(method))
return;
try {
Path path = new Path(request.getRequestURI());
AthenzPrincipal principal = getPrincipalOrThrow(request);
if (isWhiteListedOperation(path, method)) {
// no authz check
} else if (isHostedOperatorOperation(path, method)) {
verifyIsHostedOperator(principal);
} else if (isTenantAdminOperation(path, method)) {
verifyIsTenantAdmin(principal, getTenantId(path));
} else if (isTenantPipelineOperation(path, method)) {
verifyIsTenantPipelineOperator(principal, getTenantId(path), getApplicationName(path));
} else {
throw new ForbiddenException("No access control is explicitly declared for this api.");
}
} catch (WebApplicationException e) {
authorizationResponseHandler.handle(handler, request, e);
}
}
use of com.yahoo.vespa.hosted.controller.restapi.Path in project vespa by vespa-engine.
the class ZoneApiHandler method proxy.
private HttpResponse proxy(HttpRequest request) {
Path path = new Path(request.getUri().getPath());
if (!path.matches("/zone/v2/{environment}/{region}/{*}")) {
return notFound(path);
}
ZoneId zoneId = ZoneId.from(path.get("environment"), path.get("region"));
if (!zoneRegistry.hasZone(zoneId)) {
throw new IllegalArgumentException("No such zone: " + zoneId.value());
}
try {
return proxy.handle(new ProxyRequest(request, "/zone/v2/"));
} catch (ProxyException | IOException e) {
throw new RuntimeException(e);
}
}
use of com.yahoo.vespa.hosted.controller.restapi.Path in project vespa by vespa-engine.
the class PathTest method testPath.
@Test
public void testPath() {
assertFalse(new Path("").matches("/a/{foo}/bar/{b}"));
;
assertFalse(new Path("///").matches("/a/{foo}/bar/{b}"));
;
assertFalse(new Path("///foo").matches("/a/{foo}/bar/{b}"));
;
assertFalse(new Path("///bar/").matches("/a/{foo}/bar/{b}"));
;
Path path = new Path("/a/1/bar/fuz");
assertTrue(path.matches("/a/{foo}/bar/{b}"));
;
assertEquals("1", path.get("foo"));
assertEquals("fuz", path.get("b"));
}
Aggregations