summaryrefslogtreecommitdiffstats
path: root/hosted-api/src/main/java/ai/vespa/hosted/api/Authenticator.java
blob: aaff0bfe5e039fe4fd984993c65f0795e89f746a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package ai.vespa.hosted.api;

import javax.net.ssl.SSLContext;
import java.net.http.HttpRequest;
import java.security.NoSuchAlgorithmException;
import java.util.Optional;

/**
 * Adds environment dependent authentication to HTTP request against Vespa deployments.
 *
 * An implementation typically needs to override either of the methods in this interface.
 *
 * @author jonmv
 */
public interface Authenticator {

    /** Returns an SSLContext which provides authentication against a Vespa endpoint. */
    default SSLContext sslContext() {
        try {
            return SSLContext.getDefault();
        }
        catch (NoSuchAlgorithmException e) {
            throw new RuntimeException(e);
        }
    }

    /** Adds necessary authentication data to the given HTTP request builder, to pass the data plane of a Vespa endpoint. */
    default HttpRequest.Builder authenticated(HttpRequest.Builder request) {
        return request;
    }

}