Search in sources :

Example 1 with ConfigManagerBean

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

the class ConfigManagerServlet method restLockConfiguration.

private void restLockConfiguration(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException, ChaiUnavailableException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    if (PwmConstants.TRIAL_MODE) {
        final String msg = LocaleHelper.getLocalizedMessage(Admin.Notice_TrialRestrictConfig, pwmRequest);
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_TRIAL_VIOLATION, msg);
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    if (!pwmSession.isAuthenticated()) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_AUTHENTICATION_REQUIRED, "You must be authenticated before restricting the configuration");
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    if (!pwmSession.getSessionManager().checkPermission(pwmApplication, Permission.PWMADMIN)) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "You must be authenticated with admin privileges before restricting the configuration");
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo);
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    try {
        final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest);
        if (!storedConfiguration.hasPassword()) {
            final ErrorInformation errorInfo = new ErrorInformation(PwmError.CONFIG_FORMAT_ERROR, null, new String[] { "Please set a configuration password before restricting the configuration" });
            final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
            LOGGER.debug(pwmSession, errorInfo);
            pwmRequest.outputJsonResult(restResultBean);
            return;
        }
        storedConfiguration.writeConfigProperty(ConfigurationProperty.CONFIG_IS_EDITABLE, "false");
        saveConfiguration(pwmRequest, storedConfiguration);
        final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
        configManagerBean.setConfiguration(null);
    } catch (PwmException e) {
        final ErrorInformation errorInfo = e.getErrorInformation();
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    } catch (Exception e) {
        final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
        final RestResultBean restResultBean = RestResultBean.fromError(errorInfo, pwmRequest);
        LOGGER.debug(pwmSession, errorInfo.toDebugStr());
        pwmRequest.outputJsonResult(restResultBean);
        return;
    }
    final HashMap<String, String> resultData = new HashMap<>();
    LOGGER.info(pwmSession, "Configuration Locked");
    pwmRequest.outputJsonResult(RestResultBean.withData(resultData));
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmApplication(password.pwm.PwmApplication) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) PwmSession(password.pwm.http.PwmSession) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 2 with ConfigManagerBean

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

the class ConfigEditorServlet method restSetConfigurationPassword.

@ActionHandler(action = "setConfigurationPassword")
private ProcessStatus restSetConfigurationPassword(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    try {
        final Map<String, String> postData = pwmRequest.readBodyAsJsonStringMap();
        final String password = postData.get("password");
        configManagerBean.getStoredConfiguration().setPassword(password);
        configManagerBean.setPasswordVerified(true);
        LOGGER.debug(pwmRequest, "config password updated");
        final RestResultBean restResultBean = RestResultBean.forConfirmMessage(pwmRequest, Config.Confirm_ConfigPasswordStored);
        pwmRequest.outputJsonResult(restResultBean);
    } catch (PwmOperationalException e) {
        final RestResultBean restResultBean = RestResultBean.fromError(e.getErrorInformation(), pwmRequest);
        pwmRequest.outputJsonResult(restResultBean);
    }
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) RestResultBean(password.pwm.ws.server.RestResultBean) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 3 with ConfigManagerBean

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

the class ConfigEditorServlet method restMenuTreeData.

@ActionHandler(action = "menuTreeData")
private ProcessStatus restMenuTreeData(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final Instant startTime = Instant.now();
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final ArrayList<NavTreeItem> navigationData = new ArrayList<>();
    final Map<String, Object> inputParameters = pwmRequest.readBodyAsJsonMap(PwmHttpRequestWrapper.Flag.BypassValidation);
    final boolean modifiedSettingsOnly = (boolean) inputParameters.get("modifiedSettingsOnly");
    final double level = (double) inputParameters.get("level");
    final String filterText = (String) inputParameters.get("text");
    {
        // root node
        final NavTreeItem categoryInfo = new NavTreeItem();
        categoryInfo.setId("ROOT");
        categoryInfo.setName("ROOT");
        navigationData.add(categoryInfo);
    }
    {
        final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
        final List<PwmSettingCategory> categories = NavTreeHelper.filteredCategories(pwmRequest.getPwmApplication(), storedConfiguration, pwmRequest.getLocale(), modifiedSettingsOnly, level, filterText);
        navigationData.addAll(NavTreeHelper.makeSettingNavItems(categories, storedConfiguration, pwmRequest.getLocale()));
    }
    boolean includeDisplayText = true;
    if (level >= 1) {
        for (final PwmLocaleBundle localeBundle : PwmLocaleBundle.values()) {
            if (!localeBundle.isAdminOnly()) {
                final Set<String> modifiedKeys = new TreeSet<>();
                if (modifiedSettingsOnly) {
                    modifiedKeys.addAll(NavTreeHelper.determineModifiedKeysSettings(localeBundle, pwmRequest.getConfig(), configManagerBean.getStoredConfiguration()));
                }
                if (!modifiedSettingsOnly || !modifiedKeys.isEmpty()) {
                    final NavTreeItem categoryInfo = new NavTreeItem();
                    categoryInfo.setId(localeBundle.toString());
                    categoryInfo.setName(localeBundle.getTheClass().getSimpleName());
                    categoryInfo.setParent("DISPLAY_TEXT");
                    categoryInfo.setType(NavTreeHelper.NavItemType.displayText);
                    categoryInfo.setKeys(new TreeSet<>(modifiedSettingsOnly ? modifiedKeys : localeBundle.getKeys()));
                    navigationData.add(categoryInfo);
                    includeDisplayText = true;
                }
            }
        }
    }
    if (includeDisplayText) {
        final NavTreeItem categoryInfo = new NavTreeItem();
        categoryInfo.setId("DISPLAY_TEXT");
        categoryInfo.setName("Display Text");
        categoryInfo.setType(NavTreeHelper.NavItemType.navigation);
        categoryInfo.setParent("ROOT");
        navigationData.add(categoryInfo);
    }
    NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.NOTES.toString(), navigationData);
    NavTreeHelper.moveNavItemToTopOfList(PwmSettingCategory.TEMPLATES.toString(), navigationData);
    LOGGER.trace(pwmRequest, "completed navigation tree data request in " + TimeDuration.fromCurrent(startTime).asCompactString());
    pwmRequest.outputJsonResult(RestResultBean.withData(navigationData));
    return ProcessStatus.Halt;
}
Also used : StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) Instant(java.time.Instant) ArrayList(java.util.ArrayList) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) TreeSet(java.util.TreeSet) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 with ConfigManagerBean

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

the class ConfigEditorServlet method restResetSetting.

@ActionHandler(action = "resetSetting")
private ProcessStatus restResetSetting(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    final StoredConfigurationImpl storedConfig = configManagerBean.getStoredConfiguration();
    final UserIdentity loggedInUser = pwmRequest.getUserInfoIfLoggedIn();
    final String key = pwmRequest.readParameterAsString("key");
    final PwmSetting setting = 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();
        storedConfig.resetLocaleBundleMap(bundleName.getTheClass().getName(), keyName);
    } else {
        final String profileID = setting.getCategory().hasProfiles() ? pwmRequest.readParameterAsString("profile") : null;
        storedConfig.resetSetting(setting, profileID, loggedInUser);
    }
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    return ProcessStatus.Halt;
}
Also used : PwmSetting(password.pwm.config.PwmSetting) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) StringTokenizer(java.util.StringTokenizer) PwmLocaleBundle(password.pwm.i18n.PwmLocaleBundle) UserIdentity(password.pwm.bean.UserIdentity)

Example 5 with ConfigManagerBean

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

the class ConfigEditorServlet method restCancelEditing.

@ActionHandler(action = "cancelEditing")
private ProcessStatus restCancelEditing(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigManagerBean configManagerBean = getBean(pwmRequest);
    configManagerBean.setConfiguration(null);
    pwmRequest.outputJsonResult(RestResultBean.forSuccessMessage(pwmRequest, Message.Success_Unknown));
    return ProcessStatus.Halt;
}
Also used : ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean)

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