private void verifyValueValid(ConfigurationKey key, String value, boolean isSamlSP) {
   if (isNullValue(value)
       && (key.isMandatory() || isMandatoryAttributeInSamlSPMode(isSamlSP, key.getKeyName()))) {
     if (isMandatoryFallBack(key.getKeyName())) {
       value = key.getFallBackValue();
     } else {
       throw new RuntimeException(
           "Mandatory attribute " + key.getKeyName() + " can not be set a null value");
     }
   }
 }
  private boolean isSamlSPMode(Properties p) {
    ConfigurationKey[] allKeys = ConfigurationKey.values();
    boolean isSamlSPMode = false;
    for (ConfigurationKey key : allKeys) {
      String keyNameInConfig = key.getKeyName();
      String valueInConfig = (String) p.get(keyNameInConfig);

      if (!isNullValue(valueInConfig) && valueInConfig.equals(AuthenticationMode.SAML_SP.name())) {
        isSamlSPMode = true;
        break;
      }
    }
    return isSamlSPMode;
  }
  public void execute() {
    Connection conn;
    try {
      conn = getConnetion();
    } catch (SQLException e) {
      e.printStackTrace();
      throw new RuntimeException("Could not connect to the database");
    }

    final InputStream in;
    try {
      in = new FileInputStream(propertyFile);
    } catch (FileNotFoundException e) {
      e.printStackTrace();
      throw new RuntimeException("Could not find resource file '" + propertyFile + "'.");
    }
    final Properties p = PropertiesLoader.loadProperties(in);

    try {
      initStartCount(conn);
      ConfigurationKey[] allKeys = ConfigurationKey.values();
      boolean isSamlSP = isSamlSPMode(p);
      for (ConfigurationKey key : allKeys) {
        String keyName = key.getKeyName();
        String value = (String) p.get(keyName);
        if (value == null || value.isEmpty()) {
          if (keyName.equals(ConfigurationKey.MAX_NUMBER_ALLOWED_USERS.name())) {
            value = MAX_NUMBER_ALLOWED_USERS;
          }
          if (keyName.equals(ConfigurationKey.TIMER_INTERVAL_USER_COUNT.name())) {
            value = TIMER_INTERVAL_USER_COUNT;
          }
        }

        if (value != null) {
          if (key.getType() == ConfigurationKey.TYPE_BOOLEAN
              || key.getType() == ConfigurationKey.TYPE_LONG
              || key.getType() == ConfigurationKey.TYPE_STRING
              || key.getType() == ConfigurationKey.TYPE_PASSWORD) {

            value = value.trim();
          }
        }

        verifyValueValid(key, value, isSamlSP);
        if (value != null) {
          verifyAuthMode(keyName, value);
          verifyConfigurationValue(key, value);
          writePropertyToDb(conn, key.getKeyName(), value);
        }
      }
    } finally {
      try {
        conn.close();
      } catch (SQLException e) {
        e.printStackTrace();
        throw new RuntimeException("Could not close resources");
      }
    }
  }