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

io.dropwizard.bundles.apikey.AuthConfiguration Maven / Gradle / Ivy

The newest version!
package io.dropwizard.bundles.apikey;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.base.Optional;
import com.google.common.collect.Maps;
import java.util.Map;

import static com.google.common.base.Preconditions.checkNotNull;

public class AuthConfiguration {
  private final String cacheSpec;
  private final String realm;
  private final Map keys;

  @JsonCreator
  AuthConfiguration(@JsonProperty("cache-spec") String cacheSpec,
                    @JsonProperty("realm") String realm,
                    @JsonProperty("keys") Map keys) {
    checkNotNull(cacheSpec);
    checkNotNull(realm);
    checkNotNull(keys);

    this.cacheSpec = cacheSpec;
    this.realm = realm;
    this.keys = Maps.transformEntries(keys, new Maps.EntryTransformer() {
      @Override
      public ApiKey transformEntry(String key, String value) {
        return new ApiKey(key, value);
      }
    });
  }

  /**
   * The configuration for how API keys should be cached.  Can be missing.
   */
  @JsonProperty("cache-spec")
  public Optional getCacheSpec() {
    return Optional.fromNullable(cacheSpec);
  }

  /**
   * The realm to use.
   */
  @JsonProperty("realm")
  public String getRealm() {
    return realm;
  }

  /**
   * Return the API keys that this application should support indexed by application.
   */
  @JsonProperty("api-keys")
  public Map getApiKeys() {
    return keys;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy