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

com.clevercloud.biscuitpulsar.AuthenticationDataBiscuit Maven / Gradle / Ivy

There is a newer version: 3.7.1
Show newest version
package com.clevercloud.biscuitpulsar;

import java.util.Collections;
import java.util.Map;
import java.util.Set;
import java.util.function.Supplier;

import org.apache.pulsar.client.api.AuthenticationDataProvider;

public class AuthenticationDataBiscuit implements AuthenticationDataProvider {
  public final static String HTTP_HEADER_NAME = "Authorization";

  private final Supplier biscuitSupplier;

  public AuthenticationDataBiscuit(Supplier biscuitSupplier) {
    this.biscuitSupplier = biscuitSupplier;
  }

  @Override
  public boolean hasDataForHttp() {
    return true;
  }

  @Override
  public Set> getHttpHeaders() {
    return Collections.singletonMap(HTTP_HEADER_NAME, "Bearer " + getBiscuit()).entrySet();
  }

  @Override
  public boolean hasDataFromCommand() {
    return true;
  }

  @Override
  public String getCommandData() {
    return getBiscuit();
  }

  private String getBiscuit() {
    try {
      return biscuitSupplier.get();
    } catch (Throwable t) {
      throw new RuntimeException("failed to get client biscuit", t);
    }
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy