Search in sources :

Example 6 with PwmRequest

use of password.pwm.http.PwmRequest in project pwm by pwm-project.

the class PwmScriptRefTag method doEndTag.

public int doEndTag() throws javax.servlet.jsp.JspTagException {
    try {
        final PwmRequest pwmRequest = JspUtility.getPwmRequest(pageContext);
        final String cspNonce = pwmRequest.getCspNonce();
        String url = getUrl();
        url = PwmUrlTag.convertUrl(url);
        url = PwmUrlTag.insertContext(pageContext, url);
        url = PwmUrlTag.insertResourceNonce(pwmRequest.getPwmApplication(), url);
        final String output = "<script type=\"text/javascript\" nonce=\"" + cspNonce + "\" src=\"" + url + "\"></script><noscript></noscript>";
        pageContext.getOut().write(output);
    } catch (Exception e) {
        LOGGER.error("error during scriptRef output of pwmFormID: " + e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : PwmRequest(password.pwm.http.PwmRequest)

Example 7 with PwmRequest

use of password.pwm.http.PwmRequest in project pwm by pwm-project.

the class JspThrowableHandlerTag method jspOutput.

private String jspOutput(final String errorReference) {
    Locale userLocale = PwmConstants.DEFAULT_LOCALE;
    Configuration configuration = null;
    try {
        final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
        userLocale = pwmRequest.getLocale();
        configuration = pwmRequest.getConfig();
    } catch (Exception e) {
        LOGGER.error("error during pwmFormIDTag output of pwmFormID: " + e.getMessage());
    }
    final String[] strArgs = new String[] { errorReference };
    return LocaleHelper.getLocalizedMessage(userLocale, Display.Display_ErrorReference, configuration, strArgs);
}
Also used : Locale(java.util.Locale) PwmRequest(password.pwm.http.PwmRequest) Configuration(password.pwm.config.Configuration) IOException(java.io.IOException)

Example 8 with PwmRequest

use of password.pwm.http.PwmRequest in project pwm by pwm-project.

the class PwmMacroTag method doEndTag.

public int doEndTag() throws JspTagException {
    try {
        final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
        final MacroMachine macroMachine = pwmRequest.getPwmSession().getSessionManager().getMacroMachine(pwmRequest.getPwmApplication());
        final String outputValue = macroMachine.expandMacros(value);
        pageContext.getOut().write(outputValue);
    } catch (PwmUnrecoverableException e) {
        LOGGER.error("error while processing PwmMacroTag: " + e.getMessage());
    } catch (Exception e) {
        throw new JspTagException(e.getMessage(), e);
    }
    return EVAL_PAGE;
}
Also used : PwmRequest(password.pwm.http.PwmRequest) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException)

Example 9 with PwmRequest

use of password.pwm.http.PwmRequest in project pwm by pwm-project.

the class UserInfoTag method doEndTag.

public int doEndTag() throws JspTagException {
    try {
        final PwmRequest pwmRequest = JspUtility.getPwmRequest(pageContext);
        final PwmSession pwmSession = pwmRequest.getPwmSession();
        if (pwmSession.isAuthenticated()) {
            final String ldapValue = pwmSession.getUserInfo().readStringAttribute(attribute);
            pageContext.getOut().write(StringUtil.escapeHtml(ldapValue == null ? "" : ldapValue));
        }
    } catch (Exception e) {
        throw new JspTagException(e.getMessage());
    }
    return EVAL_PAGE;
}
Also used : PwmRequest(password.pwm.http.PwmRequest) PwmSession(password.pwm.http.PwmSession) JspTagException(javax.servlet.jsp.JspTagException) JspTagException(javax.servlet.jsp.JspTagException)

Example 10 with PwmRequest

use of password.pwm.http.PwmRequest 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;
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) PwmRequest(password.pwm.http.PwmRequest) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmException(password.pwm.error.PwmException)

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