package de.ivu.elect.business.security.control;

import de.ivu.elect.business.konfiguration.entity.ElectKonfigurationWerte;
import de.ivu.elect.business.konfiguration.entity.KonfigurationLoader;
import de.ivu.elect.jee.startup.PostStartup;
import de.ivu.elect.util.ElectRandom;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.inject.Inject;

public class RandomGeneratorPostStartup implements PostStartup {

  private static final Logger LOG = LoggerFactory.getLogger(RandomGeneratorPostStartup.class);

  @Inject
  private transient KonfigurationLoader konfigurationLoader;

  @Override
  public void postStartup() {
    setStrongRandom(konfigurationLoader.resolveBooleanValue(ElectKonfigurationWerte.ELECT_COMMON_RANDOM_GENERATOR_SECURE));
  }

  protected void setStrongRandom(boolean strongRandom) {
    LOG.info("SecureRandom.strong: " + strongRandom);
    ElectRandom.USE_STRONG_RANDOM_GENERATOR.set(strongRandom);
  }
}
