Search in sources :

Example 31 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ConfigEditorServlet method restSearchSettings.

@ActionHandler(action = "search")
private ProcessStatus restSearchSettings(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String bodyData = pwmRequest.readRequestBodyAsString();
    final Map<String, String> valueMap = JsonUtil.deserializeStringMap(bodyData);
    final Locale locale = pwmRequest.getLocale();
    final RestResultBean restResultBean;
    final String searchTerm = valueMap.get("search");
    final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
    if (searchTerm != null && !searchTerm.isEmpty()) {
        final ArrayList<StoredConfigurationImpl.ConfigRecordID> searchResults = new ArrayList<>(configManagerBean.getStoredConfiguration().search(searchTerm, locale));
        final ConcurrentHashMap<String, Map<String, SearchResultItem>> returnData = new ConcurrentHashMap<>();
        searchResults.parallelStream().filter(recordID -> recordID.getRecordType() == StoredConfigurationImpl.ConfigRecordID.RecordType.SETTING).forEach(recordID -> {
            final PwmSetting setting = (PwmSetting) recordID.getRecordID();
            final SearchResultItem item = new SearchResultItem(setting.getCategory().toString(), storedConfiguration.readSetting(setting, recordID.getProfileID()).toDebugString(locale), setting.getCategory().toMenuLocationDebug(recordID.getProfileID(), locale), storedConfiguration.isDefaultValue(setting, recordID.getProfileID()), recordID.getProfileID());
            final String returnCategory = item.getNavigation();
            returnData.putIfAbsent(returnCategory, new ConcurrentHashMap<>());
            returnData.get(returnCategory).put(setting.getKey(), item);
        });
        final TreeMap<String, Map<String, SearchResultItem>> outputMap = new TreeMap<>();
        for (final String key : returnData.keySet()) {
            outputMap.put(key, new TreeMap<>(returnData.get(key)));
        }
        restResultBean = RestResultBean.withData(outputMap);
        LOGGER.trace(pwmRequest, "finished search operation with " + returnData.size() + " results in " + TimeDuration.fromCurrent(startTime).asCompactString());
    } else {
        restResultBean = RestResultBean.withData(new ArrayList<StoredConfigurationImpl.ConfigRecordID>());
    }
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : Locale(java.util.Locale) SmsItemBean(password.pwm.bean.SmsItemBean) PwmSetting(password.pwm.config.PwmSetting) ServletException(javax.servlet.ServletException) AppProperty(password.pwm.AppProperty) PwmConstants(password.pwm.PwmConstants) PwmError(password.pwm.error.PwmError) Message(password.pwm.i18n.Message) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ValueMetaData(password.pwm.config.stored.ValueMetaData) ErrorInformation(password.pwm.error.ErrorInformation) ByteArrayInputStream(java.io.ByteArrayInputStream) SessionLabel(password.pwm.bean.SessionLabel) Locale(java.util.Locale) RestResultBean(password.pwm.ws.server.RestResultBean) Map(java.util.Map) UserIdentity(password.pwm.bean.UserIdentity) HealthStatus(password.pwm.health.HealthStatus) PwmSettingCategory(password.pwm.config.PwmSettingCategory) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) JsonUtil(password.pwm.util.java.JsonUtil) ValueFactory(password.pwm.config.value.ValueFactory) ProcessStatus(password.pwm.http.ProcessStatus) PwmOperationalException(password.pwm.error.PwmOperationalException) Collection(java.util.Collection) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Set(java.util.Set) PwmSettingTemplate(password.pwm.config.PwmSettingTemplate) Instant(java.time.Instant) Serializable(java.io.Serializable) ConfigurationChecker(password.pwm.health.ConfigurationChecker) List(java.util.List) HttpMethod(password.pwm.http.HttpMethod) HealthRecord(password.pwm.health.HealthRecord) StoredValue(password.pwm.config.StoredValue) PasswordData(password.pwm.util.PasswordData) LDAPStatusChecker(password.pwm.health.LDAPStatusChecker) ConfigurationProperty(password.pwm.config.stored.ConfigurationProperty) ActionValue(password.pwm.config.value.ActionValue) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) LdapBrowser(password.pwm.ldap.LdapBrowser) PwmSettingTemplateSet(password.pwm.config.PwmSettingTemplateSet) Configuration(password.pwm.config.Configuration) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) PwmSettingSyntax(password.pwm.config.PwmSettingSyntax) MacroMachine(password.pwm.util.macro.MacroMachine) PwmSession(password.pwm.http.PwmSession) ControlledPwmServlet(password.pwm.http.servlet.ControlledPwmServlet) PwmApplication(password.pwm.PwmApplication) SettingUIFunction(password.pwm.config.SettingUIFunction) StringUtil(password.pwm.util.java.StringUtil) RestRandomPasswordServer(password.pwm.ws.server.rest.RestRandomPasswordServer) HashMap(java.util.HashMap) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmRequest(password.pwm.http.PwmRequest) TreeSet(java.util.TreeSet) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) AbstractPwmServlet(password.pwm.http.servlet.AbstractPwmServlet) ResourceBundle(java.util.ResourceBundle) StringTokenizer(java.util.StringTokenizer) RemoteWebServiceValue(password.pwm.config.value.RemoteWebServiceValue) PwmException(password.pwm.error.PwmException) HealthTopic(password.pwm.health.HealthTopic) JspUrl(password.pwm.http.JspUrl) RandomPasswordGenerator(password.pwm.util.RandomPasswordGenerator) FileValue(password.pwm.config.value.FileValue) PwmApplicationMode(password.pwm.PwmApplicationMode) PwmHttpRequestWrapper(password.pwm.http.PwmHttpRequestWrapper) PwmLogger(password.pwm.util.logging.PwmLogger) IOException(java.io.IOException) ConfigManagerServlet(password.pwm.http.servlet.configmanager.ConfigManagerServlet) X509CertificateValue(password.pwm.config.value.X509CertificateValue) WebServlet(javax.servlet.annotation.WebServlet) DatabaseStatusChecker(password.pwm.health.DatabaseStatusChecker) PrivateKeyValue(password.pwm.config.value.PrivateKeyValue) SmsQueueManager(password.pwm.util.queue.SmsQueueManager) TreeMap(java.util.TreeMap) HttpsServerCertificateManager(password.pwm.util.secure.HttpsServerCertificateManager) Config(password.pwm.i18n.Config) Collections(java.util.Collections) TimeDuration(password.pwm.util.java.TimeDuration) HealthData(password.pwm.ws.server.rest.bean.HealthData) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Instant(java.time.Instant) ArrayList(java.util.ArrayList) TreeMap(java.util.TreeMap) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) TreeMap(java.util.TreeMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 32 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ConfigEditorServlet method preProcessCheck.

@Override
public ProcessStatus preProcessCheck(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    if (configManagerBean.getStoredConfiguration() == null) {
        final StoredConfigurationImpl loadedConfig = ConfigManagerServlet.readCurrentConfiguration(pwmRequest);
        configManagerBean.setConfiguration(loadedConfig);
    }
    return ProcessStatus.Continue;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl)

Example 33 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl in project pwm by pwm-project.

the class ConfigEditorServlet method restWriteSetting.

@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
    final String key = pwmRequest.readParameterAsString("key");
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final PwmSetting setting = PwmSetting.forKey(key);
    final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
    final UserIdentity loggedInUser = pwmRequest.getPwmSession().isAuthenticated() ? pwmRequest.getPwmSession().getUserInfo().getUserIdentity() : null;
    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> valueMap = JsonUtil.deserializeStringMap(bodyString);
        final Map<String, String> outputMap = new LinkedHashMap<>(valueMap);
        storedConfig.writeLocaleBundleMap(bundleName.getTheClass().getName(), keyName, outputMap);
        returnMap.put("isDefault", outputMap.isEmpty());
        returnMap.put("key", key);
    } else {
        final String profileID = setting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
        try {
            final StoredValue storedValue = ValueFactory.fromJson(setting, bodyString);
            final List<String> errorMsgs = storedValue.validateValue(setting);
            if (errorMsgs != null && !errorMsgs.isEmpty()) {
                returnMap.put("errorMessage", setting.getLabel(pwmRequest.getLocale()) + ": " + errorMsgs.get(0));
            }
            storedConfig.writeSetting(setting, profileID, storedValue, loggedInUser);
        } catch (Exception e) {
            final String errorMsg = "error writing default value for setting " + setting.toString() + ", error: " + e.getMessage();
            LOGGER.error(errorMsg, e);
            throw new IllegalStateException(errorMsg, e);
        }
        returnMap.put("key", key);
        returnMap.put("category", setting.getCategory().toString());
        returnMap.put("syntax", setting.getSyntax().toString());
        returnMap.put("isDefault", storedConfig.isDefaultValue(setting, profileID));
    }
    pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
    return ProcessStatus.Halt;
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) UserIdentity(password.pwm.bean.UserIdentity) StoredValue(password.pwm.config.StoredValue) 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) LinkedHashMap(java.util.LinkedHashMap) PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StringTokenizer(java.util.StringTokenizer)

Example 34 with StoredConfigurationImpl

use of password.pwm.config.stored.StoredConfigurationImpl 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)

Aggregations

StoredConfigurationImpl (password.pwm.config.stored.StoredConfigurationImpl)34 PwmException (password.pwm.error.PwmException)11 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)11 IOException (java.io.IOException)9 ServletException (javax.servlet.ServletException)9 PwmSetting (password.pwm.config.PwmSetting)9 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)8 LinkedHashMap (java.util.LinkedHashMap)8 ConfigurationReader (password.pwm.config.stored.ConfigurationReader)7 ErrorInformation (password.pwm.error.ErrorInformation)7 PwmOperationalException (password.pwm.error.PwmOperationalException)7 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)7 ConfigGuideBean (password.pwm.http.bean.ConfigGuideBean)6 ArrayList (java.util.ArrayList)5 PwmApplication (password.pwm.PwmApplication)5 StoredValue (password.pwm.config.StoredValue)5 PwmLocaleBundle (password.pwm.i18n.PwmLocaleBundle)5 RestResultBean (password.pwm.ws.server.RestResultBean)5 Instant (java.time.Instant)4 List (java.util.List)4