Search in sources :

Example 91 with PwmUnrecoverableException

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;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) OutputStream(java.io.OutputStream) ReportCsvUtility(password.pwm.svc.report.ReportCsvUtility) ReportColumnFilter(password.pwm.svc.report.ReportColumnFilter) LocalDBException(password.pwm.util.localdb.LocalDBException) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) DatabaseException(password.pwm.util.db.DatabaseException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Example 92 with PwmUnrecoverableException

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;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) Configuration(password.pwm.config.Configuration) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) UserInfo(password.pwm.ldap.UserInfo) PwmSession(password.pwm.http.PwmSession) LdapProfile(password.pwm.config.profile.LdapProfile) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ImpossiblePasswordPolicyException(com.novell.ldapchai.exception.ImpossiblePasswordPolicyException) PwmDataValidationException(password.pwm.error.PwmDataValidationException) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Example 93 with PwmUnrecoverableException

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);
}
Also used : NodeInfo(password.pwm.svc.cluster.NodeInfo) ArrayList(java.util.ArrayList) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 94 with PwmUnrecoverableException

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;
}
Also used : Locale(java.util.Locale) ChangePasswordBean(password.pwm.http.bean.ChangePasswordBean) MacroMachine(password.pwm.util.macro.MacroMachine) TimeDuration(password.pwm.util.java.TimeDuration) PasswordChangeProgressChecker(password.pwm.ldap.PasswordChangeProgressChecker) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmDataValidationException(password.pwm.error.PwmDataValidationException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) IOException(java.io.IOException)

Example 95 with PwmUnrecoverableException

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);
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException)

Aggregations

PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)282 ErrorInformation (password.pwm.error.ErrorInformation)201 PwmOperationalException (password.pwm.error.PwmOperationalException)85 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)75 IOException (java.io.IOException)72 PwmException (password.pwm.error.PwmException)69 PwmApplication (password.pwm.PwmApplication)48 UserIdentity (password.pwm.bean.UserIdentity)48 Configuration (password.pwm.config.Configuration)43 ServletException (javax.servlet.ServletException)38 LinkedHashMap (java.util.LinkedHashMap)37 Instant (java.time.Instant)35 ArrayList (java.util.ArrayList)31 PwmSession (password.pwm.http.PwmSession)30 Map (java.util.Map)28 ChaiUser (com.novell.ldapchai.ChaiUser)26 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 FormConfiguration (password.pwm.config.value.data.FormConfiguration)24 HashMap (java.util.HashMap)23 ChaiException (com.novell.ldapchai.exception.ChaiException)22