use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class ShortcutServlet method handleUserSelection.
private void handleUserSelection(final PwmRequest pwmRequest, final ShortcutsBean shortcutsBean) throws PwmUnrecoverableException, ChaiUnavailableException, IOException, ServletException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final String link = pwmRequest.readParameterAsString("link");
final Map<String, ShortcutItem> visibleItems = shortcutsBean.getVisibleItems();
if (link != null && visibleItems.keySet().contains(link)) {
final ShortcutItem item = visibleItems.get(link);
pwmApplication.getStatisticsManager().incrementValue(Statistic.SHORTCUTS_SELECTED);
LOGGER.trace(pwmSession, "shortcut link selected: " + link + ", setting link for 'forwardURL' to " + item.getShortcutURI());
pwmSession.getSessionStateBean().setForwardURL(item.getShortcutURI().toString());
pwmRequest.sendRedirectToContinue();
return;
}
LOGGER.error(pwmSession, "unknown/unexpected link requested to " + link);
pwmRequest.forwardToJsp(JspUrl.SHORTCUT);
}
use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class ActivateUserUtils method validateParamsAgainstLDAP.
static void validateParamsAgainstLDAP(final PwmRequest pwmRequest, final Map<FormConfiguration, String> formValues, final UserIdentity userIdentity) throws ChaiUnavailableException, PwmDataValidationException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final String searchFilter = figureLdapSearchFilter(pwmRequest);
final ChaiProvider chaiProvider = pwmApplication.getProxyChaiProvider(userIdentity.getLdapProfileID());
final ChaiUser chaiUser = chaiProvider.getEntryFactory().newChaiUser(userIdentity.getUserDN());
for (final Map.Entry<FormConfiguration, String> entry : formValues.entrySet()) {
final FormConfiguration formItem = entry.getKey();
final String attrName = formItem.getName();
final String tokenizedAttrName = "%" + attrName + "%";
if (searchFilter.contains(tokenizedAttrName)) {
LOGGER.trace(pwmSession, "skipping validation of ldap value for '" + attrName + "' because it is in search filter");
} else {
final String value = entry.getValue();
try {
if (!chaiUser.compareStringAttribute(attrName, value)) {
final String errorMsg = "incorrect value for '" + attrName + "'";
final ErrorInformation errorInfo = new ErrorInformation(PwmError.ERROR_ACTIVATION_VALIDATIONFAIL, errorMsg, new String[] { attrName });
LOGGER.debug(pwmSession.getLabel(), errorInfo.toDebugStr());
throw new PwmDataValidationException(errorInfo);
}
LOGGER.trace(pwmSession.getLabel(), "successful validation of ldap value for '" + attrName + "'");
} catch (ChaiOperationException e) {
LOGGER.error(pwmSession.getLabel(), "error during param validation of '" + attrName + "', error: " + e.getMessage());
throw new PwmDataValidationException(new ErrorInformation(PwmError.ERROR_ACTIVATION_VALIDATIONFAIL, "ldap error testing value for '" + attrName + "'", new String[] { attrName }));
}
}
}
}
use of password.pwm.http.PwmSession 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.http.PwmSession in project pwm by pwm-project.
the class ChangePasswordServlet method nextStep.
public void nextStep(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException, ServletException {
final ChangePasswordBean changePasswordBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ChangePasswordBean.class);
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final Configuration config = pwmApplication.getConfig();
if (changePasswordBean.getChangeProgressTracker() != null) {
forwardToWaitPage(pwmRequest);
return;
}
if (ChangePasswordServletUtil.warnPageShouldBeShown(pwmRequest, changePasswordBean)) {
LOGGER.trace(pwmRequest, "password expiration is within password warn period, forwarding user to warning page");
pwmRequest.forwardToJsp(JspUrl.PASSWORD_WARN);
return;
}
final String agreementMsg = pwmApplication.getConfig().readSettingAsLocalizedString(PwmSetting.PASSWORD_CHANGE_AGREEMENT_MESSAGE, pwmRequest.getLocale());
if (agreementMsg != null && agreementMsg.length() > 0 && !changePasswordBean.isAgreementPassed()) {
final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
final String expandedText = macroMachine.expandMacros(agreementMsg);
pwmRequest.setAttribute(PwmRequestAttribute.AgreementText, expandedText);
pwmRequest.forwardToJsp(JspUrl.PASSWORD_AGREEMENT);
return;
}
if (ChangePasswordServletUtil.determineIfCurrentPasswordRequired(pwmApplication, pwmSession) && !changePasswordBean.isCurrentPasswordPassed()) {
forwardToFormPage(pwmRequest);
return;
}
if (!config.readSettingAsForm(PwmSetting.PASSWORD_REQUIRE_FORM).isEmpty() && !changePasswordBean.isFormPassed()) {
forwardToFormPage(pwmRequest);
return;
}
changePasswordBean.setAllChecksPassed(true);
forwardToChangePage(pwmRequest);
}
use of password.pwm.http.PwmSession in project pwm by pwm-project.
the class CommandServlet method processPageLeaveNotice.
@ActionHandler(action = "pageLeaveNotice")
private ProcessStatus processPageLeaveNotice(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ChaiUnavailableException, ServletException {
final PwmSession pwmSession = pwmRequest.getPwmSession();
final String referrer = pwmRequest.getHttpServletRequest().getHeader("Referer");
final Instant pageLeaveNoticeTime = Instant.now();
pwmSession.getSessionStateBean().setPageLeaveNoticeTime(pageLeaveNoticeTime);
LOGGER.debug("pageLeaveNotice indicated at " + pageLeaveNoticeTime.toString() + ", referer=" + referrer);
if (!pwmRequest.getPwmResponse().isCommitted()) {
pwmRequest.getPwmResponse().setHeader(HttpHeader.Cache_Control, "no-cache, no-store, must-revalidate");
pwmRequest.getPwmResponse().setContentType(HttpContentType.plain);
}
return ProcessStatus.Halt;
}
Aggregations