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