Search in sources :

Example 26 with PwmException

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;
}
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)

Example 27 with PwmException

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;
}
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 28 with PwmException

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;
}
Also used : PwmException(password.pwm.error.PwmException) PwmSecurityKey(password.pwm.util.secure.PwmSecurityKey) PwmSessionBean(password.pwm.http.bean.PwmSessionBean)

Example 29 with PwmException

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;
}
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 30 with PwmException

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;
}
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)

Aggregations

PwmException (password.pwm.error.PwmException)63 ErrorInformation (password.pwm.error.ErrorInformation)42 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)38 IOException (java.io.IOException)19 PwmOperationalException (password.pwm.error.PwmOperationalException)19 PwmApplication (password.pwm.PwmApplication)16 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)13 UserIdentity (password.pwm.bean.UserIdentity)13 RestResultBean (password.pwm.ws.server.RestResultBean)13 ServletException (javax.servlet.ServletException)12 LinkedHashMap (java.util.LinkedHashMap)9 PwmSession (password.pwm.http.PwmSession)9 Instant (java.time.Instant)8 TimeDuration (password.pwm.util.java.TimeDuration)8 MacroMachine (password.pwm.util.macro.MacroMachine)8 Configuration (password.pwm.config.Configuration)7 PwmRequest (password.pwm.http.PwmRequest)7 UserInfo (password.pwm.ldap.UserInfo)7 PasswordData (password.pwm.util.PasswordData)7 ArrayList (java.util.ArrayList)6