private static void writeConfig( final ContextManager contextManager, final StoredConfigurationImpl storedConfiguration) throws PwmOperationalException, PwmUnrecoverableException { ConfigurationReader configReader = contextManager.getConfigReader(); PwmApplication pwmApplication = contextManager.getPwmApplication(); try { // add a random security key storedConfiguration.initNewRandomSecurityKey(); storedConfiguration.writeConfigProperty( StoredConfigurationImpl.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); } }
public static void saveConfiguration( final PwmRequest pwmRequest, final StoredConfigurationImpl storedConfiguration) throws PwmUnrecoverableException { { final List<String> errorStrings = storedConfiguration.validateValues(); if (errorStrings != null && !errorStrings.isEmpty()) { final String errorString = errorStrings.get(0); throw new PwmUnrecoverableException( new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] {errorString})); } } try { ContextManager contextManager = ContextManager.getContextManager( pwmRequest.getHttpServletRequest().getSession().getServletContext()); contextManager .getConfigReader() .saveConfiguration( storedConfiguration, contextManager.getPwmApplication(), pwmRequest.getSessionLabel()); contextManager.requestPwmApplicationRestart(); } catch (Exception e) { final String errorString = "error saving file: " + e.getMessage(); LOGGER.error(pwmRequest, errorString); throw new PwmUnrecoverableException( new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] {errorString})); } }
private boolean isEnabled(final ServletRequest servletRequest) { try { final PwmURL pwmURL = new PwmURL((HttpServletRequest) servletRequest); if (pwmURL.isResourceURL() || pwmURL.isWebServiceURL()) { return false; } } catch (Exception e) { LOGGER.error("unable to parse request url, defaulting to non-gzip: " + e.getMessage()); } final PwmApplication pwmApplication; try { pwmApplication = ContextManager.getPwmApplication((HttpServletRequest) servletRequest); return Boolean.parseBoolean( pwmApplication.getConfig().readAppProperty(AppProperty.HTTP_ENABLE_GZIP)); } catch (PwmUnrecoverableException e) { LOGGER.trace( "unable to read http-gzip app-property, defaulting to non-gzip: " + e.getMessage()); } return false; }