use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ActivateUserServlet method handleActivateRequest.
@ActionHandler(action = "activate")
public ProcessStatus handleActivateRequest(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final LocalSessionStateBean ssBean = pwmSession.getSessionStateBean();
if (CaptchaUtility.captchaEnabledForRequest(pwmRequest)) {
if (!CaptchaUtility.verifyReCaptcha(pwmRequest)) {
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_BAD_CAPTCHA_RESPONSE);
throw new PwmUnrecoverableException(errorInfo);
}
}
pwmApplication.getSessionStateService().clearBean(pwmRequest, ActivateUserBean.class);
final List<FormConfiguration> configuredActivationForm = config.readSettingAsForm(PwmSetting.ACTIVATE_USER_FORM);
Map<FormConfiguration, String> formValues = new HashMap<>();
try {
// read the values from the request
formValues = FormUtility.readFormValuesFromRequest(pwmRequest, configuredActivationForm, ssBean.getLocale());
// check for intruders
pwmApplication.getIntruderManager().convenience().checkAttributes(formValues);
// read the context attr
final String contextParam = pwmRequest.readParameterAsString(PwmConstants.PARAM_CONTEXT);
// read the profile attr
final String ldapProfile = pwmRequest.readParameterAsString(PwmConstants.PARAM_LDAP_PROFILE);
// see if the values meet the configured form requirements.
FormUtility.validateFormValues(config, formValues, ssBean.getLocale());
final String searchFilter = ActivateUserUtils.figureLdapSearchFilter(pwmRequest);
// read an ldap user object based on the params
final UserIdentity userIdentity;
{
final UserSearchEngine userSearchEngine = pwmApplication.getUserSearchEngine();
final SearchConfiguration searchConfiguration = SearchConfiguration.builder().contexts(Collections.singletonList(contextParam)).filter(searchFilter).formValues(formValues).ldapProfile(ldapProfile).build();
userIdentity = userSearchEngine.performSingleUserSearch(searchConfiguration, pwmRequest.getSessionLabel());
}
ActivateUserUtils.validateParamsAgainstLDAP(pwmRequest, formValues, userIdentity);
final List<UserPermission> userPermissions = config.readSettingAsUserPermission(PwmSetting.ACTIVATE_USER_QUERY_MATCH);
if (!LdapPermissionTester.testUserPermissions(pwmApplication, pwmSession.getLabel(), userIdentity, userPermissions)) {
final String errorMsg = "user " + userIdentity + " attempted activation, but does not match query string";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_ACTIVATE_NO_PERMISSION, errorMsg);
pwmApplication.getIntruderManager().convenience().markUserIdentity(userIdentity, pwmSession);
pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
throw new PwmUnrecoverableException(errorInformation);
}
final ActivateUserBean activateUserBean = pwmApplication.getSessionStateService().getBean(pwmRequest, ActivateUserBean.class);
activateUserBean.setUserIdentity(userIdentity);
activateUserBean.setFormValidated(true);
pwmApplication.getIntruderManager().convenience().clearAttributes(formValues);
pwmApplication.getIntruderManager().convenience().clearAddressAndSession(pwmSession);
} catch (PwmOperationalException e) {
pwmApplication.getIntruderManager().convenience().markAttributes(formValues, pwmSession);
pwmApplication.getIntruderManager().convenience().markAddressAndSession(pwmSession);
setLastError(pwmRequest, e.getErrorInformation());
LOGGER.debug(pwmSession.getLabel(), e.getErrorInformation().toDebugStr());
}
return ProcessStatus.Continue;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ConfigEditorServlet method restTestMacro.
@ActionHandler(action = "testMacro")
private ProcessStatus restTestMacro(final PwmRequest pwmRequest) throws IOException, ServletException {
try {
final Map<String, String> inputMap = pwmRequest.readBodyAsJsonStringMap(PwmHttpRequestWrapper.Flag.BypassValidation);
if (inputMap == null || !inputMap.containsKey("input")) {
pwmRequest.outputJsonResult(RestResultBean.withData("missing input"));
return ProcessStatus.Halt;
}
final MacroMachine macroMachine;
if (pwmRequest.isAuthenticated()) {
macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
} else {
macroMachine = MacroMachine.forNonUserSpecific(pwmRequest.getPwmApplication(), pwmRequest.getSessionLabel());
}
final String input = inputMap.get("input");
final String output = macroMachine.expandMacros(input);
pwmRequest.outputJsonResult(RestResultBean.withData(output));
} catch (PwmUnrecoverableException e) {
LOGGER.error(pwmRequest, e.getErrorInformation());
pwmRequest.respondWithError(e.getErrorInformation());
}
return ProcessStatus.Halt;
}
use of password.pwm.error.PwmUnrecoverableException 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;
}
use of password.pwm.error.PwmUnrecoverableException 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;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ConfigGuideUtils method writeConfig.
static void writeConfig(final ContextManager contextManager, final StoredConfigurationImpl storedConfiguration) throws PwmOperationalException, PwmUnrecoverableException {
final ConfigurationReader configReader = contextManager.getConfigReader();
final PwmApplication pwmApplication = contextManager.getPwmApplication();
try {
// add a random security key
storedConfiguration.initNewRandomSecurityKey();
configReader.saveConfiguration(storedConfiguration, pwmApplication, null);
contextManager.requestPwmApplicationRestart();
} catch (PwmException e) {
throw new PwmOperationalException(e.getErrorInformation());
} catch (Exception e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_INVALID_CONFIG, "unable to save configuration: " + e.getLocalizedMessage());
throw new PwmOperationalException(errorInformation);
}
}
Aggregations