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

org.infrastructurebuilder.util.DefaultBasicCredentialsMapSupplier Maven / Gradle / Ivy

Go to download

Lightly encumberd Standard interfaces (and exceptions) for JVM-based applications within IB codebases

There is a newer version: 0.21.1
Show newest version
/**
 * Copyright © 2019 admin ([email protected])
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.infrastructurebuilder.util;

import java.util.Collections;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap;

import javax.inject.Inject;
import javax.inject.Named;

@Named
public class DefaultBasicCredentialsMapSupplier implements BasicCredentialsMapSupplier {

  private Map _map;
  private final Map interimMap = new ConcurrentHashMap<>();

  @Inject
  public DefaultBasicCredentialsMapSupplier(final Map map) {
    Objects.requireNonNull(map).forEach((k, v) -> addCredentials(k, v));
  }

  public void addCredentials(final String id, final BasicCredentials b) {
    if (interimMap.containsKey(Objects.requireNonNull(id)) || _map != null)
      throw new IBCryptoException(
          "Cannot replace or extend a value in a DefaultBasicCredentialsMapSupplier " + id);
    interimMap.put(id, Objects.requireNonNull(b));
  }

  @Override
  public Map get() {
    if (_map == null) {
      _map = Collections.unmodifiableMap(interimMap);
    }
    return _map;
  }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy