Search in sources :

Example 6 with ConfigManagerBean

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

the class ConfigEditorServlet method restFinishEditing.

@ActionHandler(action = "finishEditing")
private ProcessStatus restFinishEditing(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final List<String> validationErrors = configManagerBean.getStoredConfiguration().validateValues();
    if (!validationErrors.isEmpty()) {
        final String errorString = validationErrors.get(0);
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, errorString, new String[] { errorString });
        pwmRequest.outputJsonResult(RestResultBean.fromError(errorInfo, pwmRequest));
        LOGGER.error(pwmSession, errorInfo);
        return ProcessStatus.Halt;
    } else {
        try {
            ConfigManagerServlet.saveConfiguration(pwmRequest, configManagerBean.getStoredConfiguration());
            configManagerBean.setConfiguration(null);
            configManagerBean.setConfiguration(null);
            LOGGER.debug(pwmSession, "save configuration operation completed");
            pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
        } catch (PwmUnrecoverableException e) {
            final ErrorInformation errorInfo = e.getErrorInformation();
            pwmRequest.outputJsonResult(RestResultBean.fromError(errorInfo, pwmRequest));
            LOGGER.error(pwmSession, errorInfo);
        }
    }
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmSession(password.pwm.http.PwmSession)

Example 7 with ConfigManagerBean

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

the class ConfigEditorServlet method setOptions.

@ActionHandler(action = "setOption")
private ProcessStatus setOptions(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    {
        final String updateDescriptionTextCmd = pwmRequest.readParameterAsString("updateNotesText");
        if (updateDescriptionTextCmd != null && "true".equalsIgnoreCase(updateDescriptionTextCmd)) {
            try {
                final String bodyString = pwmRequest.readRequestBodyAsString();
                final String value = JsonUtil.deserialize(bodyString, String.class);
                configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.NOTES, value);
                LOGGER.trace("updated notesText");
            } catch (Exception e) {
                LOGGER.error("error updating notesText: " + e.getMessage());
            }
        }
        {
            final String requestedTemplate = pwmRequest.readParameterAsString("template");
            if (requestedTemplate != null && requestedTemplate.length() > 0) {
                try {
                    final PwmSettingTemplate template = PwmSettingTemplate.valueOf(requestedTemplate);
                    configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.LDAP_TEMPLATE, template.toString());
                    LOGGER.trace("setting template to: " + requestedTemplate);
                } catch (IllegalArgumentException e) {
                    configManagerBean.getStoredConfiguration().writeConfigProperty(ConfigurationProperty.LDAP_TEMPLATE, PwmSettingTemplate.DEFAULT.toString());
                    LOGGER.error("unknown template set request: " + requestedTemplate);
                }
            }
        }
    }
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmSettingTemplate(password.pwm.config.PwmSettingTemplate) 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)

Example 8 with ConfigManagerBean

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

the class ConfigEditorServlet method restSmsHealthCheck.

@ActionHandler(action = "smsHealthCheck")
private ProcessStatus restSmsHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restSmsHealthCheck");
    final List<HealthRecord> returnRecords = new ArrayList<>();
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    if (!SmsQueueManager.smsIsConfigured(config)) {
        returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "SMS not configured"));
    } else {
        final Map<String, String> testParams = pwmRequest.readBodyAsJsonStringMap();
        final SmsItemBean testSmsItem = new SmsItemBean(testParams.get("to"), testParams.get("message"), pwmRequest.getSessionLabel());
        try {
            final String responseBody = SmsQueueManager.sendDirectMessage(pwmRequest.getPwmApplication(), config, pwmRequest.getSessionLabel(), testSmsItem);
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "message sent"));
            returnRecords.add(new HealthRecord(HealthStatus.INFO, HealthTopic.SMS, "response body: \n" + StringUtil.escapeHtml(responseBody)));
        } catch (PwmException e) {
            returnRecords.add(new HealthRecord(HealthStatus.WARN, HealthTopic.SMS, "unable to send message: " + e.getMessage()));
        }
    }
    final HealthData healthData = HealthRecord.asHealthDataBean(config, pwmRequest.getLocale(), returnRecords);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restSmsHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) HealthRecord(password.pwm.health.HealthRecord) Configuration(password.pwm.config.Configuration) SmsItemBean(password.pwm.bean.SmsItemBean) Instant(java.time.Instant) ArrayList(java.util.ArrayList) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 9 with ConfigManagerBean

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

the class ConfigAccessFilter method processFilter.

@Override
void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain filterChain) throws PwmException, IOException, ServletException {
    final PwmApplicationMode appMode = pwmRequest.getPwmApplication().getApplicationMode();
    if (appMode == PwmApplicationMode.NEW) {
        filterChain.doFilter();
        return;
    }
    final boolean blockOldIE = Boolean.parseBoolean(pwmRequest.getPwmApplication().getConfig().readAppProperty(AppProperty.CONFIG_EDITOR_BLOCK_OLD_IE));
    if (blockOldIE) {
        try {
            UserAgentUtils.checkIfPreIE11(pwmRequest);
        } catch (PwmException e) {
            pwmRequest.respondWithError(e.getErrorInformation());
            return;
        }
    }
    final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
    if (checkAuthentication(pwmRequest, configManagerBean) == ProcessStatus.Continue) {
        filterChain.doFilter();
    }
}
Also used : PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmApplicationMode(password.pwm.PwmApplicationMode)

Example 10 with ConfigManagerBean

use of password.pwm.http.bean.ConfigManagerBean 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)

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