예제 #1
0
  private static void writeConfig(
      final ContextManager contextManager, final StoredConfiguration storedConfiguration)
      throws PwmOperationalException, PwmUnrecoverableException {
    ConfigurationReader configReader = contextManager.getConfigReader();
    PwmApplication pwmApplication = contextManager.getPwmApplication();

    try {
      // add a random security key
      storedConfiguration.initNewRandomSecurityKey();

      storedConfiguration.writeConfigProperty(
          StoredConfiguration.ConfigProperty.PROPERTY_KEY_CONFIG_IS_EDITABLE, "true");
      configReader.saveConfiguration(storedConfiguration, pwmApplication, null);

      contextManager.requestPwmApplicationRestart();
    } catch (PwmException e) {
      throw new PwmOperationalException(e.getErrorInformation());
    } catch (Exception e) {
      final ErrorInformation errorInformation =
          new ErrorInformation(
              PwmError.ERROR_INVALID_CONFIG,
              "unable to save configuration: " + e.getLocalizedMessage());
      throw new PwmOperationalException(errorInformation);
    }
  }
예제 #2
0
  private void writeConfig(
      final ContextManager contextManager, final ConfigGuideBean configGuideBean)
      throws PwmOperationalException, PwmUnrecoverableException {
    final StoredConfiguration storedConfiguration = configGuideBean.getStoredConfiguration();
    final String configPassword = configGuideBean.getFormData().get(PARAM_CONFIG_PASSWORD);
    if (configPassword != null && configPassword.length() > 0) {
      storedConfiguration.setPassword(configPassword);
    } else {
      storedConfiguration.writeConfigProperty(
          StoredConfiguration.ConfigProperty.PROPERTY_KEY_PASSWORD_HASH, null);
    }

    { // determine Cr Preference setting.
      final String crPref = configGuideBean.getFormData().get(PARAM_CR_STORAGE_PREF);
      if (crPref != null && crPref.length() > 0) {
        storedConfiguration.writeSetting(
            PwmSetting.FORGOTTEN_PASSWORD_WRITE_PREFERENCE, new StringValue(crPref), null);
        storedConfiguration.writeSetting(
            PwmSetting.FORGOTTEN_PASSWORD_READ_PREFERENCE, new StringValue(crPref), null);
      }
    }

    storedConfiguration.readSetting(PwmSetting.APP_PROPERTY_OVERRIDES);
    writeConfig(contextManager, storedConfiguration);
  }