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

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

package io.dropwizard.bundles.apikey;

import com.fasterxml.jackson.annotation.JsonCreator;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSetMultimap;
import com.google.common.collect.Maps;
import com.google.common.collect.Multimap;
import com.google.common.collect.SetMultimap;
import java.util.Map;
import java.util.Optional;

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

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

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

    this.cacheSpec = cacheSpec;
    this.realm = realm;
    this.keys = ImmutableMap.copyOf(Maps.transformEntries(keys, ApiKey::new));
    this.roles = roles != null ? ImmutableSetMultimap.copyOf(roles) : ImmutableSetMultimap.of();
  }

  /**
   * The configuration for how API keys should be cached.  Can be missing.
   */
  @JsonProperty("cache-spec")
  public Optional getCacheSpec() {
    return Optional.ofNullable(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;
  }

  @JsonProperty("roles")
  public Multimap getRoles() {
    return roles;
  }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy