use of password.pwm.http.PwmRequest 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.http.PwmRequest in project pwm by pwm-project.
the class SuccessMessageTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
final HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
final PwmRequest pwmRequest = PwmRequest.forRequest(req, (HttpServletResponse) pageContext.getResponse());
final String successMsg = (String) pwmRequest.getAttribute(PwmRequestAttribute.SuccessMessage);
final String outputMsg;
if (successMsg == null || successMsg.isEmpty()) {
outputMsg = Message.getLocalizedMessage(pwmRequest.getLocale(), Message.Success_Unknown, pwmRequest.getConfig());
} else {
if (pwmRequest.isAuthenticated()) {
final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
outputMsg = macroMachine.expandMacros(successMsg);
} else {
outputMsg = successMsg;
}
}
pageContext.getOut().write(outputMsg);
} catch (Exception e) {
throw new JspTagException(e.getMessage());
}
return EVAL_PAGE;
}
use of password.pwm.http.PwmRequest 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.http.PwmRequest 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;
}
use of password.pwm.http.PwmRequest in project pwm by pwm-project.
the class PwmScriptTag method doAfterBody.
public int doAfterBody() {
try {
final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
final BodyContent bc = getBodyContent();
if (bc != null) {
final String tagBody = bc.getString();
final String strippedTagBody = stripHtmlScriptTags(tagBody);
final String output = "<script type=\"text/javascript\" nonce=\"" + pwmRequest.getCspNonce() + "\">" + strippedTagBody + "</script><noscript></noscript>";
getPreviousOut().write(output);
}
} catch (IOException e) {
LOGGER.error("IO error while processing PwmScriptTag: " + e.getMessage());
} catch (PwmUnrecoverableException e) {
LOGGER.error("error while processing PwmScriptTag: " + e.getMessage());
}
return SKIP_BODY;
}
Aggregations