Search in sources :

Example 51 with RestResultBean

use of password.pwm.ws.server.RestResultBean 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 52 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class ConfigEditorServlet method restLdapHealthCheck.

@ActionHandler(action = "ldapHealthCheck")
private ProcessStatus restLdapHealthCheck(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    LOGGER.debug(pwmRequest, "beginning restLdapHealthCheck");
    final String profileID = pwmRequest.readParameterAsString("profile");
    final Configuration config = new Configuration(configManagerBean.getStoredConfiguration());
    final HealthData healthData = LDAPStatusChecker.healthForNewConfiguration(pwmRequest.getPwmApplication(), config, pwmRequest.getLocale(), profileID, true, true);
    final RestResultBean restResultBean = RestResultBean.withData(healthData);
    pwmRequest.outputJsonResult(restResultBean);
    LOGGER.debug(pwmRequest, "completed restLdapHealthCheck in " + TimeDuration.fromCurrent(startTime).asCompactString());
    return ProcessStatus.Halt;
}
Also used : HealthData(password.pwm.ws.server.rest.bean.HealthData) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 53 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class ConfigEditorServlet method restExecuteSettingFunction.

@ActionHandler(action = "executeSettingFunction")
private ProcessStatus restExecuteSettingFunction(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final String bodyString = pwmRequest.readRequestBodyAsString();
    final Map<String, String> requestMap = JsonUtil.deserializeStringMap(bodyString);
    final PwmSetting pwmSetting = PwmSetting.forKey(requestMap.get("setting"));
    final String functionName = requestMap.get("function");
    final String profileID = pwmSetting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
    final String extraData = requestMap.get("extraData");
    try {
        final Class implementingClass = Class.forName(functionName);
        final SettingUIFunction function = (SettingUIFunction) implementingClass.newInstance();
        final Serializable result = function.provideFunction(pwmRequest, configManagerBean.getStoredConfiguration(), pwmSetting, profileID, extraData);
        final RestResultBean restResultBean = RestResultBean.forSuccessMessage(result, pwmRequest, Message.Success_Unknown);
        pwmRequest.outputJsonResult(restResultBean);
    } catch (Exception e) {
        final RestResultBean restResultBean;
        if (e instanceof PwmException) {
            restResultBean = RestResultBean.fromError(((PwmException) e).getErrorInformation(), pwmRequest, true);
        } else {
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error performing user search: " + e.getMessage());
            restResultBean = RestResultBean.fromError(errorInformation, pwmRequest);
        }
        pwmRequest.outputJsonResult(restResultBean);
    }
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) ErrorInformation(password.pwm.error.ErrorInformation) Serializable(java.io.Serializable) SettingUIFunction(password.pwm.config.SettingUIFunction) 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) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 54 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class AdminServlet method processReportCommand.

@ActionHandler(action = "reportCommand")
private ProcessStatus processReportCommand(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
    final ReportService.ReportCommand reportCommand = JavaHelper.readEnumFromString(ReportService.ReportCommand.class, null, pwmRequest.readParameterAsString("command"));
    LOGGER.trace(pwmRequest, "issuing command '" + reportCommand + "' to report engine");
    pwmRequest.getPwmApplication().getReportService().executeCommand(reportCommand);
    final RestResultBean restResultBean = RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : ReportService(password.pwm.svc.report.ReportService) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 55 with RestResultBean

use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.

the class AdminServlet method restStatisticsHandler.

@ActionHandler(action = "statistics")
private ProcessStatus restStatisticsHandler(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException {
    final String statKey = pwmRequest.readParameterAsString("statKey");
    final String statName = pwmRequest.readParameterAsString("statName");
    final String days = pwmRequest.readParameterAsString("days");
    final StatisticsManager statisticsManager = pwmRequest.getPwmApplication().getStatisticsManager();
    final RestStatisticsServer.JsonOutput jsonOutput = new RestStatisticsServer.JsonOutput();
    jsonOutput.EPS = RestStatisticsServer.addEpsStats(statisticsManager);
    if (statName != null && statName.length() > 0) {
        jsonOutput.nameData = RestStatisticsServer.doNameStat(statisticsManager, statName, days);
    } else {
        jsonOutput.keyData = RestStatisticsServer.doKeyStat(statisticsManager, statKey);
    }
    final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
    pwmRequest.outputJsonResult(restResultBean);
    return ProcessStatus.Halt;
}
Also used : StatisticsManager(password.pwm.svc.stats.StatisticsManager) RestStatisticsServer(password.pwm.ws.server.rest.RestStatisticsServer) RestResultBean(password.pwm.ws.server.RestResultBean)

Aggregations

RestResultBean (password.pwm.ws.server.RestResultBean)63 ErrorInformation (password.pwm.error.ErrorInformation)27 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)21 UserIdentity (password.pwm.bean.UserIdentity)16 PwmException (password.pwm.error.PwmException)16 HelpdeskProfile (password.pwm.config.profile.HelpdeskProfile)15 Instant (java.time.Instant)14 PwmOperationalException (password.pwm.error.PwmOperationalException)14 HashMap (java.util.HashMap)11 LinkedHashMap (java.util.LinkedHashMap)11 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)10 IOException (java.io.IOException)10 PwmApplication (password.pwm.PwmApplication)10 PwmSession (password.pwm.http.PwmSession)10 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)9 ArrayList (java.util.ArrayList)8 ServletException (javax.servlet.ServletException)8 UserInfo (password.pwm.ldap.UserInfo)8 AuditRecordFactory (password.pwm.svc.event.AuditRecordFactory)8 HelpdeskAuditRecord (password.pwm.svc.event.HelpdeskAuditRecord)8