use of password.pwm.error.PwmException in project pwm by pwm-project.
the class ErrorMessageTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
PwmApplication pwmApplication = null;
try {
pwmApplication = ContextManager.getPwmApplication(pageContext.getSession());
} catch (PwmException e) {
/* noop */
}
if (pwmRequest == null || pwmApplication == null) {
return EVAL_PAGE;
}
final ErrorInformation error = (ErrorInformation) pwmRequest.getAttribute(PwmRequestAttribute.PwmErrorInfo);
if (error != null) {
final boolean allowHtml = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_ERRORS_ALLOW_HTML));
final boolean showErrorDetail = pwmApplication.determineIfDetailErrorMsgShown();
String outputMsg = error.toUserStr(pwmRequest.getPwmSession(), pwmApplication);
if (!allowHtml) {
outputMsg = StringUtil.escapeHtml(outputMsg);
}
if (showErrorDetail) {
final String errorDetail = error.toDebugStr() == null ? "" : " { " + error.toDebugStr() + " }";
// detail should always be escaped - it may contain untrusted data
outputMsg += "<span class='errorDetail'>" + StringUtil.escapeHtml(errorDetail) + "</span>";
}
outputMsg = outputMsg.replace("\n", "<br/>");
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmApplication);
outputMsg = macroMachine.expandMacros(outputMsg);
pageContext.getOut().write(outputMsg);
}
} catch (PwmUnrecoverableException e) {
/* app not running */
} catch (Exception e) {
LOGGER.error("error executing error message tag: " + e.getMessage(), e);
throw new JspTagException(e.getMessage());
}
return EVAL_PAGE;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class PasswordRequirementsTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final Configuration config = pwmApplication.getConfig();
final Locale locale = pwmSession.getSessionStateBean().getLocale();
pwmSession.getSessionManager().getMacroMachine(pwmApplication);
final PwmPasswordPolicy passwordPolicy;
if (getForm() != null && getForm().equalsIgnoreCase("newuser")) {
final NewUserProfile newUserProfile = NewUserServlet.getNewUserProfile(pwmRequest);
passwordPolicy = newUserProfile.getNewUserPasswordPolicy(pwmApplication, locale);
} else {
passwordPolicy = pwmSession.getUserInfo().getPasswordPolicy();
}
final String configuredRuleText = passwordPolicy.getRuleText();
if (configuredRuleText != null && configuredRuleText.length() > 0) {
pageContext.getOut().write(configuredRuleText);
} else {
final MacroMachine macroMachine = pwmSession.getSessionManager().getMacroMachine(pwmApplication);
final String pre = prepend != null && prepend.length() > 0 ? prepend : "";
final String sep = separator != null && separator.length() > 0 ? separator : "<br/>";
final List<String> requirementsList = getPasswordRequirementsStrings(passwordPolicy, config, locale, macroMachine);
final StringBuilder requirementsText = new StringBuilder();
for (final String requirementStatement : requirementsList) {
requirementsText.append(pre);
requirementsText.append(requirementStatement);
requirementsText.append(sep);
}
pageContext.getOut().write(requirementsText.toString());
}
} catch (IOException | PwmException e) {
LOGGER.error("unexpected error during password requirements generation: " + e.getMessage(), e);
throw new JspTagException(e.getMessage());
}
return EVAL_PAGE;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class CryptoCookieBeanImpl method getSessionBean.
@Override
public <E extends PwmSessionBean> E getSessionBean(final PwmRequest pwmRequest, final Class<E> theClass) throws PwmUnrecoverableException {
final Map<Class<? extends PwmSessionBean>, PwmSessionBean> sessionBeans = getRequestBeanMap(pwmRequest);
if (sessionBeans.containsKey(theClass) && sessionBeans.get(theClass) != null) {
return (E) sessionBeans.get(theClass);
}
final String sessionGuid = pwmRequest.getPwmSession().getLoginInfoBean().getGuid();
final String cookieName = nameForClass(theClass);
try {
final String rawValue = pwmRequest.readCookie(cookieName);
final PwmSecurityKey key = keyForSession(pwmRequest);
final E cookieBean = pwmRequest.getPwmApplication().getSecureService().decryptObject(rawValue, key, theClass);
if (validateCookie(pwmRequest, cookieName, cookieBean)) {
sessionBeans.put(theClass, cookieBean);
return cookieBean;
}
} catch (PwmException e) {
LOGGER.debug(pwmRequest, "ignoring existing existing " + cookieName + " cookie bean due to error: " + e.getMessage());
}
final E newBean = SessionStateService.newBean(sessionGuid, theClass);
sessionBeans.put(theClass, newBean);
return newBean;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class PwmUrlTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
final String url = convertUrl(this.url);
String outputURL = url;
PwmRequest pwmRequest = null;
try {
pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
} catch (PwmException e) {
/* noop */
}
String workingUrl = url;
for (final PwmThemeURL themeUrl : PwmThemeURL.values()) {
if (themeUrl.token().equals(url)) {
workingUrl = figureThemeURL(pwmRequest, themeUrl);
workingUrl = insertContext(pageContext, workingUrl);
}
}
if (addContext) {
workingUrl = insertContext(pageContext, workingUrl);
}
if (pwmRequest != null) {
workingUrl = insertResourceNonce(pwmRequest.getPwmApplication(), workingUrl);
}
outputURL = workingUrl;
try {
pageContext.getOut().write(outputURL);
} catch (Exception e) {
throw new JspTagException(e.getMessage());
}
return EVAL_PAGE;
}
use of password.pwm.error.PwmException in project pwm by pwm-project.
the class DisplayTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
PwmRequest pwmRequest = null;
try {
pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
} catch (PwmException e) {
/* noop */
}
final Locale locale = pwmRequest == null ? PwmConstants.DEFAULT_LOCALE : pwmRequest.getLocale();
final Class bundle = readBundle();
String displayMessage = figureDisplayMessage(locale, pwmRequest == null ? null : pwmRequest.getConfig(), bundle);
if (pwmRequest != null) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
displayMessage = macroMachine.expandMacros(displayMessage);
}
pageContext.getOut().write(displayMessage);
} catch (PwmUnrecoverableException e) {
{
LOGGER.debug("error while executing jsp display tag: " + e.getMessage());
return EVAL_PAGE;
}
} catch (Exception e) {
LOGGER.debug("error while executing jsp display tag: " + e.getMessage(), e);
throw new JspTagException(e.getMessage(), e);
}
return EVAL_PAGE;
}
Aggregations