use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ConfigGuideServlet method restWriteSetting.
@ActionHandler(action = "writeSetting")
private ProcessStatus restWriteSetting(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException {
final String profileID = "default";
final String key = pwmRequest.readParameterAsString("key");
final String bodyString = pwmRequest.readRequestBodyAsString();
final PwmSetting setting = PwmSetting.forKey(key);
final ConfigGuideBean configGuideBean = getBean(pwmRequest);
final StoredConfigurationImpl storedConfigurationImpl = ConfigGuideForm.generateStoredConfig(configGuideBean);
final LinkedHashMap<String, Object> returnMap = new LinkedHashMap<>();
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));
}
if (setting == PwmSetting.CHALLENGE_RANDOM_CHALLENGES) {
configGuideBean.getFormData().put(ConfigGuideFormField.CHALLENGE_RESPONSE_DATA, JsonUtil.serialize((Serializable) storedValue.toNativeObject()));
}
} 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", storedConfigurationImpl.isDefaultValue(setting, profileID));
pwmRequest.outputJsonResult(RestResultBean.withData(returnMap));
return ProcessStatus.Halt;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ConfigManagerServlet method doDownloadConfig.
private void doDownloadConfig(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmResponse resp = pwmRequest.getPwmResponse();
try {
final StoredConfigurationImpl storedConfiguration = readCurrentConfiguration(pwmRequest);
final OutputStream responseWriter = resp.getOutputStream();
resp.setHeader(HttpHeader.ContentDisposition, "attachment;filename=" + PwmConstants.DEFAULT_CONFIG_FILE_FILENAME);
resp.setContentType(HttpContentType.xml);
storedConfiguration.toXml(responseWriter);
responseWriter.close();
} catch (Exception e) {
LOGGER.error(pwmSession, "unable to download configuration: " + e.getMessage());
}
}
use of password.pwm.error.PwmUnrecoverableException 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));
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class DebugItemGenerator method outputZipDebugFile.
static void outputZipDebugFile(final PwmRequest pwmRequest, final ZipOutputStream zipOutput, final String pathPrefix) throws IOException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final String debugFileName = "zipDebugGeneration.csv";
final ByteArrayOutputStream debugGeneratorLogBaos = new ByteArrayOutputStream();
final CSVPrinter debugGeneratorLogFile = JavaHelper.makeCsvPrinter(debugGeneratorLogBaos);
for (final Class<? extends DebugItemGenerator.Generator> serviceClass : DEBUG_ZIP_ITEM_GENERATORS) {
try {
final Instant startTime = Instant.now();
LOGGER.trace(pwmRequest, "beginning output of item " + serviceClass.getSimpleName());
final Object newInstance = serviceClass.newInstance();
final DebugItemGenerator.Generator newGeneratorItem = (DebugItemGenerator.Generator) newInstance;
zipOutput.putNextEntry(new ZipEntry(pathPrefix + newGeneratorItem.getFilename()));
newGeneratorItem.outputItem(pwmApplication, pwmRequest, zipOutput);
zipOutput.closeEntry();
zipOutput.flush();
final String finishMsg = "completed output of " + newGeneratorItem.getFilename() + " in " + TimeDuration.fromCurrent(startTime).asCompactString();
LOGGER.trace(pwmRequest, finishMsg);
debugGeneratorLogFile.printRecord(JavaHelper.toIsoDate(Instant.now()), finishMsg);
} catch (Throwable e) {
final String errorMsg = "unexpected error executing debug item output class '" + serviceClass.getName() + "', error: " + e.toString();
LOGGER.error(pwmRequest, errorMsg);
debugGeneratorLogFile.printRecord(JavaHelper.toIsoDate(Instant.now()), errorMsg);
final Writer stackTraceOutput = new StringWriter();
e.printStackTrace(new PrintWriter(stackTraceOutput));
debugGeneratorLogFile.printRecord(stackTraceOutput);
}
}
try {
zipOutput.putNextEntry(new ZipEntry(pathPrefix + debugFileName));
debugGeneratorLogFile.flush();
zipOutput.write(debugGeneratorLogBaos.toByteArray());
zipOutput.closeEntry();
} catch (Exception e) {
LOGGER.error("error generating " + debugFileName + ": " + e.getMessage());
}
zipOutput.flush();
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ForgottenPasswordServlet method processEnterCode.
@ActionHandler(action = "enterCode")
private ProcessStatus processEnterCode(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final ForgottenPasswordBean forgottenPasswordBean = forgottenPasswordBean(pwmRequest);
final String userEnteredCode = pwmRequest.readParameterAsString(PwmConstants.PARAM_TOKEN);
ErrorInformation errorInformation = null;
try {
final TokenPayload tokenPayload = TokenUtil.checkEnteredCode(pwmRequest, userEnteredCode, forgottenPasswordBean.getProgress().getTokenDestination(), null, TokenType.FORGOTTEN_PW, TokenService.TokenEntryType.unauthenticated);
// token correct
if (forgottenPasswordBean.getUserIdentity() == null) {
// clean session, user supplied token (clicked email, etc) and this is first request
ForgottenPasswordUtil.initForgottenPasswordBean(pwmRequest, tokenPayload.getUserIdentity(), forgottenPasswordBean);
}
forgottenPasswordBean.getProgress().getSatisfiedMethods().add(IdentityVerificationMethod.TOKEN);
StatisticsManager.incrementStat(pwmRequest.getPwmApplication(), Statistic.RECOVERY_TOKENS_PASSED);
if (pwmRequest.getConfig().readSettingAsBoolean(PwmSetting.DISPLAY_TOKEN_SUCCESS_BUTTON)) {
pwmRequest.setAttribute(PwmRequestAttribute.TokenDestItems, tokenPayload.getDestination());
pwmRequest.forwardToJsp(JspUrl.RECOVER_PASSWORD_TOKEN_SUCCESS);
return ProcessStatus.Halt;
}
} catch (PwmUnrecoverableException e) {
LOGGER.debug(pwmRequest, "error while checking entered token: ");
errorInformation = e.getErrorInformation();
} catch (PwmOperationalException e) {
final String errorMsg = "token incorrect: " + e.getMessage();
errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT, errorMsg);
}
if (!forgottenPasswordBean.getProgress().getSatisfiedMethods().contains(IdentityVerificationMethod.TOKEN)) {
if (errorInformation == null) {
errorInformation = new ErrorInformation(PwmError.ERROR_TOKEN_INCORRECT);
}
handleUserVerificationBadAttempt(pwmRequest, forgottenPasswordBean, errorInformation);
}
return ProcessStatus.Continue;
}
Aggregations