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;
}
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);
}
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;
}
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;
}
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;
}
Aggregations