Search in sources :

Example 11 with PwmRequest

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;
}
Also used : Locale(java.util.Locale) PwmApplication(password.pwm.PwmApplication) PwmRequest(password.pwm.http.PwmRequest) Configuration(password.pwm.config.Configuration) IOException(java.io.IOException) NewUserProfile(password.pwm.config.profile.NewUserProfile) PwmException(password.pwm.error.PwmException) PwmPasswordPolicy(password.pwm.config.profile.PwmPasswordPolicy) MacroMachine(password.pwm.util.macro.MacroMachine) PwmSession(password.pwm.http.PwmSession) JspTagException(javax.servlet.jsp.JspTagException)

Example 12 with PwmRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmRequest(password.pwm.http.PwmRequest) MacroMachine(password.pwm.util.macro.MacroMachine) JspTagException(javax.servlet.jsp.JspTagException) JspTagException(javax.servlet.jsp.JspTagException)

Example 13 with PwmRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmException(password.pwm.error.PwmException) PwmRequest(password.pwm.http.PwmRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) JspTagException(javax.servlet.jsp.JspTagException) JspTagException(javax.servlet.jsp.JspTagException) PwmException(password.pwm.error.PwmException)

Example 14 with PwmRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmException(password.pwm.error.PwmException) Locale(java.util.Locale) PwmRequest(password.pwm.http.PwmRequest) HttpServletResponse(javax.servlet.http.HttpServletResponse) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) MissingResourceException(java.util.MissingResourceException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmException(password.pwm.error.PwmException)

Example 15 with PwmRequest

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;
}
Also used : BodyContent(javax.servlet.jsp.tagext.BodyContent) PwmRequest(password.pwm.http.PwmRequest) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException)

Aggregations

PwmRequest (password.pwm.http.PwmRequest)19 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)10 PwmException (password.pwm.error.PwmException)9 IOException (java.io.IOException)8 JspTagException (javax.servlet.jsp.JspTagException)8 HttpServletRequest (javax.servlet.http.HttpServletRequest)7 MacroMachine (password.pwm.util.macro.MacroMachine)6 PwmSession (password.pwm.http.PwmSession)5 Locale (java.util.Locale)4 ErrorInformation (password.pwm.error.ErrorInformation)4 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)3 ServletException (javax.servlet.ServletException)3 HttpServletResponse (javax.servlet.http.HttpServletResponse)3 PwmApplication (password.pwm.PwmApplication)3 Configuration (password.pwm.config.Configuration)3 LinkedHashMap (java.util.LinkedHashMap)2 PwmApplicationMode (password.pwm.PwmApplicationMode)2 PwmPasswordPolicy (password.pwm.config.profile.PwmPasswordPolicy)2 FileValue (password.pwm.config.value.FileValue)2 PwmURL (password.pwm.http.PwmURL)2