Search in sources :

Example 16 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.

the class ConfigEditorServlet method restReadSetting.

@ActionHandler(action = "readSetting")
private ProcessStatus restReadSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
    final String key = pwmRequest.readParameterAsString("key");
    final Object returnValue;
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    final PwmSetting theSetting = PwmSetting.forKey(key);
    if (key.startsWith("localeBundle")) {
        final StringTokenizer st = new StringTokenizer(key, "-");
        st.nextToken();
        final PwmLocaleBundle bundleName = PwmLocaleBundle.valueOf(st.nextToken());
        final String keyName = st.nextToken();
        final Map<String, String> bundleMap = storedConfig.readLocaleBundleMap(bundleName.getTheClass().getName(), keyName);
        if (bundleMap == null || bundleMap.isEmpty()) {
            final Map<String, String> defaultValueMap = new LinkedHashMap<>();
            final String defaultLocaleValue = ResourceBundle.getBundle(bundleName.getTheClass().getName(), PwmConstants.DEFAULT_LOCALE).getString(keyName);
            for (final Locale locale : pwmRequest.getConfig().getKnownLocales()) {
                final ResourceBundle localeBundle = ResourceBundle.getBundle(bundleName.getTheClass().getName(), locale);
                if (locale.toString().equalsIgnoreCase(PwmConstants.DEFAULT_LOCALE.toString())) {
                    defaultValueMap.put("", defaultLocaleValue);
                } else {
                    final String valueStr = localeBundle.getString(keyName);
                    if (!defaultLocaleValue.equals(valueStr)) {
                        final String localeStr = locale.toString();
                        defaultValueMap.put(localeStr, localeBundle.getString(keyName));
                    }
                }
            }
            returnValue = defaultValueMap;
            returnMap.put("isDefault", true);
        } else {
            returnValue = bundleMap;
            returnMap.put("isDefault", false);
        }
        returnMap.put("key", key);
    } else if (theSetting == null) {
        final String errorStr = "readSettingAsString request for unknown key: " + key;
        LOGGER.warn(errorStr);
        pwmRequest.outputJsonResult(RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorStr)));
        return ProcessStatus.Halt;
    } else {
        final String profile = theSetting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
        switch(theSetting.getSyntax()) {
            case PASSWORD:
                returnValue = Collections.singletonMap("isDefault", storedConfig.isDefaultValue(theSetting, profile));
                break;
            case X509CERT:
                returnValue = ((X509CertificateValue) storedConfig.readSetting(theSetting, profile)).toInfoMap(true);
                break;
            case PRIVATE_KEY:
                returnValue = ((PrivateKeyValue) storedConfig.readSetting(theSetting, profile)).toInfoMap(true);
                break;
            case ACTION:
                returnValue = ((ActionValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            case REMOTE_WEB_SERVICE:
                returnValue = ((RemoteWebServiceValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            case FILE:
                returnValue = ((FileValue) storedConfig.readSetting(theSetting, profile)).toInfoMap();
                break;
            default:
                returnValue = storedConfig.readSetting(theSetting, profile).toNativeObject();
        }
        returnMap.put("isDefault", storedConfig.isDefaultValue(theSetting, profile));
        if (theSetting.getSyntax() == PwmSettingSyntax.SELECT) {
            returnMap.put("options", theSetting.getOptions());
        }
        {
            final ValueMetaData settingMetaData = storedConfig.readSettingMetadata(theSetting, profile);
            if (settingMetaData != null) {
                if (settingMetaData.getModifyDate() != null) {
                    returnMap.put("modifyTime", settingMetaData.getModifyDate());
                }
                if (settingMetaData.getUserIdentity() != null) {
                    returnMap.put("modifyUser", settingMetaData.getUserIdentity());
                }
            }
        }
        returnMap.put("key", key);
        returnMap.put("category", theSetting.getCategory().toString());
        returnMap.put("syntax", theSetting.getSyntax().toString());
    }
    returnMap.put("value", returnValue);
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) PrivateKeyValue(password.pwm.config.value.PrivateKeyValue) FileValue(password.pwm.config.value.FileValue) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) LinkedHashMap(java.util.LinkedHashMap) X509CertificateValue(password.pwm.config.value.X509CertificateValue) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) StringTokenizer(java.util.StringTokenizer) ActionValue(password.pwm.config.value.ActionValue) RemoteWebServiceValue(password.pwm.config.value.RemoteWebServiceValue) ValueMetaData(password.pwm.config.stored.ValueMetaData) ResourceBundle(java.util.ResourceBundle)

Example 17 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.

the class ConfigEditorServlet method restReadChangeLog.

@ActionHandler(action = "readChangeLog")
private ProcessStatus restReadChangeLog(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final Locale locale = pwmRequest.getLocale();
    final HashMap<String, Object> returnObj = new HashMap<>();
    returnObj.put("html", configManagerBean.getStoredConfiguration().changeLogAsDebugString(locale, true));
    returnObj.put("modified", configManagerBean.getStoredConfiguration().isModified());
    try {
        final ConfigurationChecker configurationChecker = new ConfigurationChecker();
        final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
        final List<HealthRecord> healthRecords = configurationChecker.doHealthCheck(config, pwmRequest.getLocale());
        final HealthData healthData = new HealthData();
        healthData.setOverall("CONFIG");
        healthData.setRecords(password.pwm.ws.server.rest.bean.HealthRecord.fromHealthRecords(healthRecords, locale, config));
        returnObj.put("health", healthData);
    } catch (Exception e) {
        LOGGER.error(pwmRequest, "error generating health records: " + e.getMessage());
    }
    final RestResultBean restResultBean = RestResultBean.withData(returnObj);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) ConfigurationChecker(password.pwm.health.ConfigurationChecker) HealthData(password.pwm.ws.server.rest.bean.HealthData) Configuration(password.pwm.config.Configuration) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 18 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.

the class ConfigEditorServlet method doUploadFile.

@ActionHandler(action = "uploadFile")
private ProcessStatus doUploadFile(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String key = pwmRequest.readParameterAsString("key");
    final PwmSetting setting = PwmSetting.forKey(key);
    final int maxFileSize = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.CONFIG_MAX_JDBC_JAR_SIZE));
    if (setting == PwmSetting.HTTPS_CERT) {
        try {
            final PasswordData passwordData = pwmRequest.readParameterAsPassword("password");
            final String alias = pwmRequest.readParameterAsString("alias");
            final HttpsServerCertificateManager.KeyStoreFormat keyStoreFormat;
            try {
                keyStoreFormat = HttpsServerCertificateManager.KeyStoreFormat.valueOf(pwmRequest.readParameterAsString("format"));
            } catch (IllegalArgumentException e) {
                throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, "unknown format type: " + e.getMessage(), new String[] { "format" }));
            }
            final Map<String, PwmRequest.FileUploadItem> fileUploads = pwmRequest.readFileUploads(maxFileSize, 1);
            final ByteArrayInputStream fileIs = new ByteArrayInputStream(fileUploads.get(PwmConstants.PARAM_FILE_UPLOAD).getContent().getBytes());
            HttpsServerCertificateManager.importKey(configManagerBean.getStoredConfiguration(), keyStoreFormat, fileIs, passwordData, alias);
            pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
            return ProcessStatus.Halt;
        } catch (PwmException e) {
            LOGGER.error(pwmRequest, "error during https certificate upload: " + e.getMessage());
            pwmRequest.respondWithError(e.getErrorInformation(), false);
            return ProcessStatus.Halt;
        }
    }
    final FileValue fileValue = ConfigEditorServletUtils.readFileUploadToSettingValue(pwmRequest, maxFileSize);
    if (fileValue != null) {
        final UserIdentity userIdentity = pwmRequest.isAuthenticated() ? pwmRequest.getPwmSession().getUserInfo().getUserIdentity() : null;
        configManagerBean.getStoredConfiguration().writeSetting(setting, fileValue, userIdentity);
        pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    }
    return ProcessStatus.Halt;
}
Also used : FileValue(password.pwm.config.value.FileValue) UserIdentity(password.pwm.bean.UserIdentity) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) HttpsServerCertificateManager(password.pwm.util.secure.HttpsServerCertificateManager) PwmSetting(password.pwm.config.PwmSetting) PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) PasswordData(password.pwm.util.PasswordData) ByteArrayInputStream(java.io.ByteArrayInputStream)

Example 19 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.

the class ConfigEditorServlet method restDatabaseHealthCheck.

@ActionHandler(action = "databaseHealthCheck")
private ProcessStatus restDatabaseHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restDatabaseHealthCheck");
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    final List<HealthRecord> healthRecords = DatabaseStatusChecker.checkNewDatabaseStatus(pwmRequest.getPwmApplication(), config);
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), healthRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restDatabaseHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 20 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean in project pwm by pwm-project.

the class ConfigEditorServlet method restConfigSettingData.

@ActionHandler(action = "settingData")
private ProcessStatus restConfigSettingData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>(generateSettingData(pwmRequest.getPwmApplication(), configManagerBean.getStoredConfiguration(), pwmRequest.getSessionLabel(), pwmRequest.getLocale()));
    if (pwmRequest.getPwmApplication().getApplicationMode() == PwmApplicationMode.CONFIGURATION && !PwmConstants.TRIAL_MODE) {
        if (!configManagerBean.isConfigUnlockedWarningShown()) {
            returnMap.put("configUnlocked", true);
            configManagerBean.setConfigUnlockedWarningShown(true);
        }
    }
    final RestResultBean restResultBean = RestResultBean.withData(new LinkedHashMap<>(returnMap));
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) LinkedHashMap(java.util.LinkedHashMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)21 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)10 PwmException (password.pwm.error.PwmException)9 RestResultBean (password.pwm.ws.server.RestResultBean)9 PwmSetting (password.pwm.config.PwmSetting)7 StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)7 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)6 IOException (java.io.IOException)6 Instant (java.time.Instant)6 LinkedHashMap (java.util.LinkedHashMap)6 ServletException (javax.servlet.ServletException)6 ErrorInformation (password.pwm.error.ErrorInformation)6 PwmOperationalException (password.pwm.error.PwmOperationalException)6 Configuration (password.pwm.config.Configuration)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 HealthData (password.pwm.ws.server.rest.bean.HealthData)5 StringTokenizer (java.util.StringTokenizer)4 UserIdentity (password.pwm.bean.UserIdentity)4 HealthRecord (password.pwm.health.HealthRecord)4 ArrayList (java.util.ArrayList)3