All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.aerospike.vector.client.internal.auth.BearerTokenCallCredentials Maven / Gradle / Ivy

Go to download

This project includes the Java client for Aerospike Vector Search for high-performance data interactions.

The newest version!
package com.aerospike.vector.client.internal.auth;

import io.grpc.CallCredentials;
import io.grpc.Metadata;
import io.grpc.Status;
import java.util.concurrent.Executor;

/** A CallCredentials implementation. */
public class BearerTokenCallCredentials extends CallCredentials {
    private final String value;
    private static final String BEARER_TYPE = "Bearer";
    private static final Metadata.Key AUTHORIZATION_METADATA_KEY =
            Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);

    /**
     * Constructs a new BearerTokenCallCredentials with the given token value.
     *
     * @param value the bearer token value.
     */
    public BearerTokenCallCredentials(String value) {
        this.value = value;
    }

    @Override
    public void applyRequestMetadata(
            RequestInfo requestInfo, Executor executor, MetadataApplier metadataApplier) {
        executor.execute(
                () -> {
                    try {
                        Metadata headers = new Metadata();
                        headers.put(
                                AUTHORIZATION_METADATA_KEY,
                                String.format("%s %s", BEARER_TYPE, value));
                        metadataApplier.apply(headers);
                    } catch (Throwable e) {
                        metadataApplier.fail(Status.UNAUTHENTICATED.withCause(e));
                    }
                });
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy