Search in sources :

Example 16 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwmResponse method forwardToJsp.

// its okay to disappear the exception during logging
@SuppressFBWarnings("DE_MIGHT_IGNORE")
public void forwardToJsp(final JspUrl jspURL) throws ServletException, IOException, PwmUnrecoverableException {
    if (!pwmRequest.isFlag(PwmRequestFlag.NO_REQ_COUNTER)) {
        pwmRequest.getPwmSession().getSessionManager().incrementRequestCounterKey();
    }
    preCommitActions();
    final HttpServletRequest httpServletRequest = pwmRequest.getHttpServletRequest();
    final ServletContext servletContext = httpServletRequest.getSession().getServletContext();
    final String url = jspURL.getPath();
    try {
        LOGGER.trace(pwmRequest.getSessionLabel(), "forwarding to " + url);
    } catch (Exception e) {
    /* noop, server may not be up enough to do the log output */
    }
    servletContext.getRequestDispatcher(url).forward(httpServletRequest, this.getHttpServletResponse());
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ServletContext(javax.servlet.ServletContext) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 17 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwmSession method unauthenticateUser.

/**
 * Unauthenticate the pwmSession.
 */
public void unauthenticateUser(final PwmRequest pwmRequest) {
    final LocalSessionStateBean ssBean = getSessionStateBean();
    if (getLoginInfoBean().isAuthenticated()) {
        // try to tear out a session normally.
        getUserSessionDataCacheBean().clearPermissions();
        final StringBuilder sb = new StringBuilder();
        sb.append("unauthenticate session from ").append(ssBean.getSrcAddress());
        if (getUserInfo().getUserIdentity() != null) {
            sb.append(" (").append(getUserInfo().getUserIdentity()).append(")");
        }
        // mark the session state bean as no longer being authenticated
        this.getLoginInfoBean().setAuthenticated(false);
        // close out any outstanding connections
        getSessionManager().closeConnections();
        LOGGER.debug(this, sb.toString());
    }
    if (pwmRequest != null) {
        try {
            pwmRequest.getPwmApplication().getSessionStateService().clearLoginSession(pwmRequest);
        } catch (PwmUnrecoverableException e) {
            final String errorMsg = "unexpected error writing removing login cookie from response: " + e.getMessage();
            final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
            LOGGER.error(pwmRequest, errorInformation);
        }
        pwmRequest.getHttpServletRequest().setAttribute(PwmConstants.SESSION_ATTR_BEANS, null);
    }
    userInfo = null;
    loginInfoBean = null;
    userSessionDataCacheBean = null;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) LocalSessionStateBean(password.pwm.bean.LocalSessionStateBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 18 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwmSession method getLabel.

public SessionLabel getLabel() {
    final LocalSessionStateBean ssBean = this.getSessionStateBean();
    String userID = null;
    try {
        userID = isAuthenticated() ? this.getUserInfo().getUsername() : null;
    } catch (PwmUnrecoverableException e) {
        LOGGER.error("unexpected error reading username: " + e.getMessage(), e);
    }
    final UserIdentity userIdentity = isAuthenticated() ? this.getUserInfo().getUserIdentity() : null;
    return new SessionLabel(ssBean.getSessionID(), userIdentity, userID, ssBean.getSrcAddress(), ssBean.getSrcAddress());
}
Also used : SessionLabel(password.pwm.bean.SessionLabel) UserIdentity(password.pwm.bean.UserIdentity) LocalSessionStateBean(password.pwm.bean.LocalSessionStateBean) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 19 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwmHttpRequestWrapper method readRequestBodyAsString.

public static String readRequestBodyAsString(final HttpServletRequest httpServletRequest, final int maxChars) throws IOException, PwmUnrecoverableException {
    final StringWriter stringWriter = new StringWriter();
    final Reader readerStream = new InputStreamReader(httpServletRequest.getInputStream(), PwmConstants.DEFAULT_CHARSET);
    try {
        IOUtils.copy(readerStream, stringWriter);
    } catch (Exception e) {
        final String errorMsg = "error reading request body stream: " + e.getMessage();
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
    } finally {
        IOUtils.closeQuietly(readerStream);
    }
    final String stringValue = stringWriter.toString();
    if (stringValue.length() > maxChars) {
        throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, "input request body is to big, size=" + stringValue.length() + ", max=" + maxChars));
    }
    return stringValue;
}
Also used : ErrorInformation(password.pwm.error.ErrorInformation) StringWriter(java.io.StringWriter) InputStreamReader(java.io.InputStreamReader) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException) UnsupportedEncodingException(java.io.UnsupportedEncodingException)

Example 20 with PwmUnrecoverableException

use of password.pwm.error.PwmUnrecoverableException in project pwm by pwm-project.

the class PwmValueTag method doEndTag.

public int doEndTag() throws JspTagException {
    if (PwmApplicationMode.determineMode((HttpServletRequest) pageContext.getRequest()) == PwmApplicationMode.ERROR) {
        return EVAL_PAGE;
    }
    try {
        final HttpServletRequest req = (HttpServletRequest) pageContext.getRequest();
        final PwmRequest pwmRequest = PwmRequest.forRequest(req, (HttpServletResponse) pageContext.getResponse());
        try {
            final PwmValue value = getName();
            final String output = calcValue(pwmRequest, pageContext, value);
            final String escapedOutput = value.getFlags().contains(PwmValue.Flag.DoNotEscape) ? output : StringUtil.escapeHtml(output);
            pageContext.getOut().write(escapedOutput);
        } catch (IllegalArgumentException e) {
            LOGGER.error("can't output requested value name '" + getName() + "'");
        }
    } catch (PwmUnrecoverableException e) {
        LOGGER.error("error while processing PwmValueTag: " + e.getMessage());
    } catch (Exception e) {
        throw new JspTagException(e.getMessage(), e);
    }
    return EVAL_PAGE;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmRequest(password.pwm.http.PwmRequest) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) JspTagException(javax.servlet.jsp.JspTagException)

Aggregations

PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)282 ErrorInformation (password.pwm.error.ErrorInformation)201 PwmOperationalException (password.pwm.error.PwmOperationalException)85 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)75 IOException (java.io.IOException)72 PwmException (password.pwm.error.PwmException)69 PwmApplication (password.pwm.PwmApplication)48 UserIdentity (password.pwm.bean.UserIdentity)48 Configuration (password.pwm.config.Configuration)43 ServletException (javax.servlet.ServletException)38 LinkedHashMap (java.util.LinkedHashMap)37 Instant (java.time.Instant)35 ArrayList (java.util.ArrayList)31 PwmSession (password.pwm.http.PwmSession)30 Map (java.util.Map)28 ChaiUser (com.novell.ldapchai.ChaiUser)26 ChaiOperationException (com.novell.ldapchai.exception.ChaiOperationException)25 FormConfiguration (password.pwm.config.value.data.FormConfiguration)24 HashMap (java.util.HashMap)23 ChaiException (com.novell.ldapchai.exception.ChaiException)22