Search in sources :

Example 96 with ErrorInformation

use of password.pwm.error.ErrorInformation in project pwm by pwm-project.

the class ClientApiServlet method doGetStringsData.

@ActionHandler(action = "strings")
public ProcessStatus doGetStringsData(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
    final String bundleName = pwmRequest.readParameterAsString("bundle");
    final int maxCacheAgeSeconds = 60 * 5;
    final String eTagValue = makeClientEtag(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession(), pwmRequest.getHttpServletRequest());
    pwmRequest.getPwmResponse().setHeader(HttpHeader.ETag, eTagValue);
    pwmRequest.getPwmResponse().setHeader(HttpHeader.Expires, String.valueOf(System.currentTimeMillis() + (maxCacheAgeSeconds * 1000)));
    pwmRequest.getPwmResponse().setHeader(HttpHeader.Cache_Control, "public, max-age=" + maxCacheAgeSeconds);
    try {
        final LinkedHashMap<String, String> displayData = new LinkedHashMap<>(makeDisplayData(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession(), bundleName));
        final RestResultBean restResultBean = RestResultBean.withData(displayData);
        pwmRequest.outputJsonResult(restResultBean);
    } catch (Exception e) {
        final String errorMSg = "error during rest /strings call for bundle " + bundleName + ", error: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMSg);
        LOGGER.debug(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation);
    }
    return ProcessStatus.Halt;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) LinkedHashMap(java.util.LinkedHashMap) RestResultBean(password.pwm.ws.server.RestResultBean)

Example 97 with ErrorInformation

use of password.pwm.error.ErrorInformation in project pwm by pwm-project.

the class GuestRegistrationServlet method handleUpdateRequest.

protected void handleUpdateRequest(final PwmRequest pwmRequest, final GuestRegistrationBean guestRegistrationBean) throws ServletException, ChaiUnavailableException, IOException, PwmUnrecoverableException {
    // Fetch the session state bean.
    final PwmSession pwmSession = pwmRequest.getPwmSession();
    final LocalSessionStateBean ssBean = pwmSession.getSessionStateBean();
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    final Configuration config = pwmApplication.getConfig();
    final List<FormConfiguration> formItems = pwmApplication.getConfig().readSettingAsForm(PwmSetting.GUEST_UPDATE_FORM);
    final String expirationAttribute = config.readSettingAsString(PwmSetting.GUEST_EXPIRATION_ATTRIBUTE);
    try {
        // read the values from the request
        final Map<FormConfiguration, String> formValues = FormUtility.readFormValuesFromRequest(pwmRequest, formItems, pwmRequest.getLocale());
        // see if the values meet form requirements.
        FormUtility.validateFormValues(config, formValues, ssBean.getLocale());
        // read current values from user.
        final ChaiUser theGuest = pwmSession.getSessionManager().getActor(pwmApplication, guestRegistrationBean.getUpdateUserIdentity());
        // check unique fields against ldap
        FormUtility.validateFormValueUniqueness(pwmApplication, formValues, ssBean.getLocale(), Collections.singletonList(guestRegistrationBean.getUpdateUserIdentity()));
        final Instant expirationDate = readExpirationFromRequest(pwmRequest);
        // Update user attributes
        LdapOperationsHelper.writeFormValuesToLdap(pwmApplication, pwmSession.getSessionManager().getMacroMachine(pwmApplication), theGuest, formValues, false);
        // Write expirationDate
        if (expirationDate != null) {
            theGuest.writeDateAttribute(expirationAttribute, expirationDate);
        }
        // send email.
        final UserInfo guestUserInfoBean = UserInfoFactory.newUserInfo(pwmApplication, pwmRequest.getSessionLabel(), pwmRequest.getLocale(), guestRegistrationBean.getUpdateUserIdentity(), theGuest.getChaiProvider());
        this.sendUpdateGuestEmailConfirmation(pwmRequest, guestUserInfoBean);
        pwmApplication.getStatisticsManager().incrementValue(Statistic.UPDATED_GUESTS);
        // everything good so forward to confirmation page.
        pwmRequest.getPwmResponse().forwardToSuccessPage(Message.Success_UpdateGuest);
        return;
    } catch (PwmOperationalException e) {
        LOGGER.error(pwmSession, e.getErrorInformation().toDebugStr());
        setLastError(pwmRequest, e.getErrorInformation());
    } catch (ChaiOperationException e) {
        final ErrorInformation info = new ErrorInformation(PwmError.ERROR_UNKNOWN, "unexpected error writing to ldap: " + e.getMessage());
        LOGGER.error(pwmSession, info);
        setLastError(pwmRequest, info);
    }
    this.forwardToUpdateJSP(pwmRequest, guestRegistrationBean);
}
Also used : PwmApplication(password.pwm.PwmApplication) FormConfiguration(password.pwm.config.value.data.FormConfiguration) SearchConfiguration(password.pwm.ldap.search.SearchConfiguration) ActionConfiguration(password.pwm.config.value.data.ActionConfiguration) Configuration(password.pwm.config.Configuration) Instant(java.time.Instant) UserInfo(password.pwm.ldap.UserInfo) PwmOperationalException(password.pwm.error.PwmOperationalException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUser(com.novell.ldapchai.ChaiUser) LocalSessionStateBean(password.pwm.bean.LocalSessionStateBean) FormConfiguration(password.pwm.config.value.data.FormConfiguration) ChaiOperationException(com.novell.ldapchai.exception.ChaiOperationException) PwmSession(password.pwm.http.PwmSession)

Example 98 with ErrorInformation

use of password.pwm.error.ErrorInformation in project pwm by pwm-project.

the class AdminServlet method downloadAuditLogCsv.

@ActionHandler(action = "downloadAuditLogCsv")
private ProcessStatus downloadAuditLogCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmApplication.getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_AUDIT_RECORDS_CSV));
    final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
    try {
        pwmApplication.getAuditManager().outputVaultToCsv(outputStream, pwmRequest.getLocale(), true);
    } 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) 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 99 with ErrorInformation

use of password.pwm.error.ErrorInformation in project pwm by pwm-project.

the class AdminServlet method downloadUserSummaryCsv.

@ActionHandler(action = "downloadUserSummaryCsv")
private ProcessStatus downloadUserSummaryCsv(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_SUMMARY_CSV));
    final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
    try {
        final ReportCsvUtility reportCsvUtility = new ReportCsvUtility(pwmApplication);
        reportCsvUtility.outputSummaryToCsv(outputStream, pwmRequest.getLocale());
    } 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) 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 100 with ErrorInformation

use of password.pwm.error.ErrorInformation in project pwm by pwm-project.

the class AdminServlet method downloadStatisticsLogCsv.

@ActionHandler(action = "downloadStatisticsLogCsv")
private ProcessStatus downloadStatisticsLogCsv(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
    final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
    pwmRequest.getPwmResponse().markAsDownload(HttpContentType.csv, pwmRequest.getPwmApplication().getConfig().readAppProperty(AppProperty.DOWNLOAD_FILENAME_STATISTICS_CSV));
    final OutputStream outputStream = pwmRequest.getPwmResponse().getOutputStream();
    try {
        final StatisticsManager statsManager = pwmApplication.getStatisticsManager();
        statsManager.outputStatsToCsv(outputStream, pwmRequest.getLocale(), true);
    } 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) StatisticsManager(password.pwm.svc.stats.StatisticsManager) OutputStream(java.io.OutputStream) 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)

Aggregations

ErrorInformation (password.pwm.error.ErrorInformation)325 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)216 PwmOperationalException (password.pwm.error.PwmOperationalException)125 PwmException (password.pwm.error.PwmException)67 UserIdentity (password.pwm.bean.UserIdentity)62 IOException (java.io.IOException)58 PwmApplication (password.pwm.PwmApplication)54 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)53 ChaiUser (com.novell.ldapchai.ChaiUser)38 PwmSession (password.pwm.http.PwmSession)38 LinkedHashMap (java.util.LinkedHashMap)35 Configuration (password.pwm.config.Configuration)33 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)32 Map (java.util.Map)32 Instant (java.time.Instant)30 ArrayList (java.util.ArrayList)30 FormConfiguration (password.pwm.config.value.data.FormConfiguration)29 ServletException (javax.servlet.ServletException)28 RestResultBean (password.pwm.ws.server.RestResultBean)26 UserInfo (password.pwm.ldap.UserInfo)23