use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class AdminServlet method downloadUserReportCsv.
@ActionHandler(action = "downloadUserReportCsv")
private ProcessStatus downloadUserReportCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmApplication.getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_USER_REPORT_RECORDS_CSV));
final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
try {
final String selectedColumns = pwmRequest.readParameterAsString("selectedColumns", "");
final ReportColumnFilter columnFilter = ReportUtils.toReportColumnFilter(selectedColumns);
final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
reportCsvUtility.outputToCsv(outputStream, true, pwmRequest.getLocale(), columnFilter);
} catch (Exception e) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, e.getMessage());
pwmRequest.respondWithError(errorInformation);
} finally {
outputStream.close();
}
return ProcessStatus.Halt;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ActivateUserUtils method sendPostActivationSms.
static boolean sendPostActivationSms(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ChaiUnavailableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final Configuration config = pwmApplication.getConfig();
final UserInfo userInfo = pwmSession.getUserInfo();
final Locale locale = pwmSession.getSessionStateBean().getLocale();
final LdapProfile ldapProfile = userInfo.getUserIdentity().getLdapProfile(config);
final String message = config.readSettingAsLocalizedString(PwmSetting.SMS_ACTIVATION_TEXT, locale);
final String toSmsNumber;
try {
toSmsNumber = userInfo.readStringAttribute(ldapProfile.readSettingAsString(PwmSetting.SMS_USER_PHONE_ATTRIBUTE));
} catch (Exception e) {
LOGGER.debug(pwmSession.getLabel(), "error reading SMS attribute from user '" + pwmSession.getUserInfo().getUserIdentity() + "': " + e.getMessage());
return false;
}
if (toSmsNumber == null || toSmsNumber.length() < 1) {
LOGGER.debug(pwmSession.getLabel(), "skipping send activation SMS for '" + pwmSession.getUserInfo().getUserIdentity() + "' no SMS number configured");
return false;
}
pwmApplication.sendSmsUsingQueue(toSmsNumber, message, pwmRequest.getSessionLabel(), pwmSession.getSessionManager().getMacroMachine(pwmApplication));
return true;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class AppDashboardData method makeNodeData.
private static List<NodeData> makeNodeData(final PwmApplication pwmApplication, final Locale locale) {
if (pwmApplication.getClusterService().status() != PwmService.STATUS.OPEN) {
return Collections.emptyList();
}
final String notApplicable = Display.getLocalizedMessage(locale, Display.Value_NotApplicable, pwmApplication.getConfig());
final List<NodeData> nodeData = new ArrayList<>();
try {
for (final NodeInfo nodeInfo : pwmApplication.getClusterService().nodes()) {
final String uptime = nodeInfo.getStartupTime() == null ? notApplicable : TimeDuration.fromCurrent(nodeInfo.getStartupTime()).asLongString(locale);
nodeData.add(new NodeData(nodeInfo.getInstanceID(), uptime, JavaHelper.toIsoDate(nodeInfo.getLastSeen()), nodeInfo.getNodeState(), nodeInfo.isConfigMatch()));
}
} catch (PwmUnrecoverableException e) {
LOGGER.trace("error building AppDashboardData node-state: " + e.getMessage());
}
return Collections.unmodifiableList(nodeData);
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class ChangePasswordServlet method processCompleteAction.
@ActionHandler(action = "complete")
public ProcessStatus processCompleteAction(final PwmRequest pwmRequest) throws ServletException, PwmUnrecoverableException, IOException {
final ChangePasswordBean cpb = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
final PasswordChangeProgressChecker.ProgressTracker progressTracker = cpb.getChangeProgressTracker();
boolean isComplete = true;
if (progressTracker != null) {
final PasswordChangeProgressChecker checker = new PasswordChangeProgressChecker(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession().getUserInfo().getUserIdentity(), pwmRequest.getSessionLabel(), pwmRequest.getLocale());
final PasswordChangeProgressChecker.PasswordChangeProgress passwordChangeProgress = checker.figureProgress(progressTracker);
isComplete = passwordChangeProgress.isComplete();
}
if (isComplete) {
if (progressTracker != null) {
final TimeDuration totalTime = TimeDuration.fromCurrent(progressTracker.getBeginTime());
try {
pwmRequest.getPwmApplication().getStatisticsManager().updateAverageValue(Statistic.AVG_PASSWORD_SYNC_TIME, totalTime.getTotalMilliseconds());
LOGGER.trace(pwmRequest, "password sync process marked completed (" + totalTime.asCompactString() + ")");
} catch (Exception e) {
LOGGER.error(pwmRequest, "unable to update average password sync time statistic: " + e.getMessage());
}
}
cpb.setChangeProgressTracker(null);
final Locale locale = pwmRequest.getLocale();
final String completeMessage = pwmRequest.getConfig().readSettingAsLocalizedString(PwmSetting.PASSWORD_COMPLETE_MESSAGE, locale);
pwmRequest.getPwmApplication().getSessionStateService().clearBean(pwmRequest, ChangePasswordBean.class);
if (completeMessage != null && !completeMessage.isEmpty()) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
final String expandedText = macroMachine.expandMacros(completeMessage);
pwmRequest.setAttribute(PwmRequestAttribute.CompleteText, expandedText);
pwmRequest.forwardToJsp(JspUrl.PASSWORD_COMPLETE);
} else {
pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_PasswordChange);
}
} else {
forwardToWaitPage(pwmRequest);
}
return ProcessStatus.Halt;
}
use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.
the class SetupOtpServlet method makeQrCodeDataImageUrl.
private static String makeQrCodeDataImageUrl(final PwmRequest pwmRequest, final OTPUserRecord otpUserRecord) throws PwmUnrecoverableException {
final String otpTypeValue = otpUserRecord.getType().toString().toLowerCase();
final String identifier = StringUtil.urlEncode(otpUserRecord.getIdentifier());
final String secret = StringUtil.urlEncode(otpUserRecord.getSecret());
final String qrCodeContent = "otpauth://" + otpTypeValue + "/" + identifier + "?secret=" + secret;
final int height = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.OTP_QR_IMAGE_HEIGHT));
final int width = Integer.parseInt(pwmRequest.getConfig().readAppProperty(AppProperty.OTP_QR_IMAGE_WIDTH));
final byte[] imageBytes;
try {
imageBytes = QRCode.from(qrCodeContent).withCharset(PwmConstants.DEFAULT_CHARSET.toString()).withSize(width, height).stream().toByteArray();
} catch (Exception e) {
final String errorMsg = "error generating qrcode image: " + e.getMessage() + ", payload length=" + qrCodeContent.length();
LOGGER.error(pwmRequest, errorMsg, e);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
}
return "data:image/png;base64," + StringUtil.base64Encode(imageBytes);
}
Aggregations