Search in sources :

Example 1 with Method

use of com.yahoo.jdisc.http.HttpRequest.Method in project vespa by vespa-engine.

the class ConnectionControlSearcherTestCase method doSearch.

private Result doSearch(URI uri, long connectedAtMillis, long nowMillis) {
    SocketAddress remoteAddress = Mockito.mock(SocketAddress.class);
    Version version = Version.HTTP_1_1;
    Method method = Method.GET;
    CurrentContainer container = Mockito.mock(CurrentContainer.class);
    Mockito.when(container.newReference(Mockito.any())).thenReturn(Mockito.mock(Container.class));
    final com.yahoo.jdisc.http.HttpRequest serverRequest = com.yahoo.jdisc.http.HttpRequest.newServerRequest(container, uri, method, version, remoteAddress, connectedAtMillis);
    HttpRequest incoming = new HttpRequest(serverRequest, new ByteArrayInputStream(new byte[0]));
    Query query = new Query(incoming);
    Execution e = new Execution(new Chain<Searcher>(ConnectionControlSearcher.createTestInstance(() -> nowMillis)), Execution.Context.createContextStub());
    Result r = e.search(query);
    return r;
}
Also used : HttpRequest(com.yahoo.container.jdisc.HttpRequest) Query(com.yahoo.search.Query) Searcher(com.yahoo.search.Searcher) ConnectionControlSearcher(com.yahoo.search.searchers.ConnectionControlSearcher) Method(com.yahoo.jdisc.http.HttpRequest.Method) CurrentContainer(com.yahoo.jdisc.service.CurrentContainer) Result(com.yahoo.search.Result) Container(com.yahoo.jdisc.Container) CurrentContainer(com.yahoo.jdisc.service.CurrentContainer) Execution(com.yahoo.search.searchchain.Execution) Version(com.yahoo.jdisc.http.HttpRequest.Version) ByteArrayInputStream(java.io.ByteArrayInputStream) SocketAddress(java.net.SocketAddress)

Example 2 with Method

use of com.yahoo.jdisc.http.HttpRequest.Method 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);
    }
}
Also used : Path(com.yahoo.vespa.hosted.controller.restapi.Path) ForbiddenException(javax.ws.rs.ForbiddenException) WebApplicationException(javax.ws.rs.WebApplicationException) AthenzPrincipal(com.yahoo.vespa.athenz.api.AthenzPrincipal) Method(com.yahoo.jdisc.http.HttpRequest.Method)

Aggregations

Method (com.yahoo.jdisc.http.HttpRequest.Method)2 HttpRequest (com.yahoo.container.jdisc.HttpRequest)1 Container (com.yahoo.jdisc.Container)1 Version (com.yahoo.jdisc.http.HttpRequest.Version)1 CurrentContainer (com.yahoo.jdisc.service.CurrentContainer)1 Query (com.yahoo.search.Query)1 Result (com.yahoo.search.Result)1 Searcher (com.yahoo.search.Searcher)1 Execution (com.yahoo.search.searchchain.Execution)1 ConnectionControlSearcher (com.yahoo.search.searchers.ConnectionControlSearcher)1 AthenzPrincipal (com.yahoo.vespa.athenz.api.AthenzPrincipal)1 Path (com.yahoo.vespa.hosted.controller.restapi.Path)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 SocketAddress (java.net.SocketAddress)1 ForbiddenException (javax.ws.rs.ForbiddenException)1 WebApplicationException (javax.ws.rs.WebApplicationException)1