com.alibaba.graphscope.groot.sdk.BasicAuth Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of groot-client Show documentation
Show all versions of groot-client Show documentation
The Java client of Groot, a persistence storage engine
package com.alibaba.graphscope.groot.sdk;
import io.grpc.CallCredentials;
import io.grpc.Metadata;
import io.grpc.Status;
import java.util.Base64;
import java.util.concurrent.Executor;
public class BasicAuth extends CallCredentials {
public static final Metadata.Key AUTH_KEY =
Metadata.Key.of("Authorization", Metadata.ASCII_STRING_MARSHALLER);
public static final String TOKEN_HEAD = "Basic ";
private String secret;
public BasicAuth(String username, String password) {
this.secret = Base64.getEncoder().encodeToString((username + ":" + password).getBytes());
}
@Override
public void applyRequestMetadata(
RequestInfo requestInfo, Executor executor, MetadataApplier metadataApplier) {
executor.execute(
() -> {
try {
Metadata metadata = new Metadata();
metadata.put(AUTH_KEY, TOKEN_HEAD + secret);
metadataApplier.apply(metadata);
} catch (Throwable t) {
metadataApplier.fail(Status.UNAUTHENTICATED.withCause(t));
}
});
}
@Override
public void thisUsesUnstableApi() {}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy