use of password.pwm.http.PwmRequest in project pwm by pwm-project.
the class AbstractPwmServlet method handleRequest.
private void handleRequest(final HttpServletRequest req, final HttpServletResponse resp, final HttpMethod method) throws ServletException, IOException {
try {
final PwmRequest pwmRequest = PwmRequest.forRequest(req, resp);
if (!method.isIdempotent() && !pwmRequest.getURL().isCommandServletURL()) {
Validator.validatePwmFormID(pwmRequest);
try {
Validator.validatePwmRequestCounter(pwmRequest);
} catch (PwmOperationalException e) {
if (e.getError() == PwmError.ERROR_INCORRECT_REQ_SEQUENCE) {
final ErrorInformation errorInformation = e.getErrorInformation();
final PwmSession pwmSession = PwmSessionWrapper.readPwmSession(req);
LOGGER.error(pwmSession, errorInformation.toDebugStr());
pwmRequest.respondWithError(errorInformation, false);
return;
}
throw e;
}
}
// check for incorrect method type.
final ProcessAction processAction = readProcessAction(pwmRequest);
if (processAction != null) {
if (!processAction.permittedMethods().contains(method)) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, "incorrect request method " + method.toString() + " on request to " + pwmRequest.getURLwithQueryString());
LOGGER.error(pwmRequest.getPwmSession(), errorInformation.toDebugStr());
pwmRequest.respondWithError(errorInformation, false);
return;
}
}
this.processAction(pwmRequest);
} catch (Exception e) {
final PwmRequest pwmRequest;
try {
pwmRequest = PwmRequest.forRequest(req, resp);
} catch (Exception e2) {
try {
LOGGER.fatal("exception occurred, but exception handler unable to load request instance; error=" + e.getMessage(), e);
} catch (Exception e3) {
e3.printStackTrace();
}
throw new ServletException(e);
}
final PwmUnrecoverableException pue = convertToPwmUnrecoverableException(e, pwmRequest);
if (processUnrecoverableException(req, resp, pwmRequest.getPwmApplication(), pwmRequest.getPwmSession(), pue)) {
return;
}
outputUnrecoverableException(pwmRequest, pue);
clearModuleBeans(pwmRequest);
}
}
use of password.pwm.http.PwmRequest 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;
}
use of password.pwm.http.PwmRequest in project pwm by pwm-project.
the class PwmIfTag method doStartTag.
@Override
public int doStartTag() throws JspException {
boolean showBody = false;
if (PwmApplicationMode.determineMode((HttpServletRequest) pageContext.getRequest()) != PwmApplicationMode.ERROR) {
if (test != null) {
try {
final PwmRequest pwmRequest = PwmRequest.forRequest((HttpServletRequest) pageContext.getRequest(), (HttpServletResponse) pageContext.getResponse());
final PwmSession pwmSession = pwmRequest.getPwmSession();
final PwmIfTest testEnum = test;
if (testEnum != null) {
try {
final PwmIfOptions options = new PwmIfOptions(negate, permission, setting, requestFlag);
showBody = testEnum.passed(pwmRequest, options);
} catch (ChaiUnavailableException e) {
LOGGER.error("error testing jsp if '" + testEnum.toString() + "', error: " + e.getMessage());
}
} else {
final String errorMsg = "unknown test name '" + test + "' in pwm:If jsp tag!";
LOGGER.warn(pwmSession, errorMsg);
}
} catch (PwmUnrecoverableException e) {
LOGGER.error("error executing PwmIfTag for test '" + test + "', error: " + e.getMessage());
}
}
}
if (negate) {
showBody = !showBody;
}
return showBody ? EVAL_BODY_INCLUDE : SKIP_BODY;
}
use of password.pwm.http.PwmRequest in project pwm by pwm-project.
the class CurrentUrlTag method doEndTag.
@Override
public int doEndTag() throws javax.servlet.jsp.JspTagException {
try {
final PwmRequest pwmRequest = JspUtility.getPwmRequest(pageContext);
final String currentUrl = pwmRequest.getURLwithoutQueryString();
pageContext.getOut().write(StringUtil.escapeHtml(currentUrl));
} catch (Exception e) {
try {
pageContext.getOut().write("errorGeneratingPwmFormID");
} catch (IOException e1) {
/* ignore */
}
LOGGER.error("error during pwmFormIDTag output of pwmFormID: " + e.getMessage());
}
return EVAL_PAGE;
}
use of password.pwm.http.PwmRequest in project pwm by pwm-project.
the class PwmFormIDTag method doEndTag.
public int doEndTag() throws javax.servlet.jsp.JspTagException {
if (PwmApplicationMode.determineMode((HttpServletRequest) pageContext.getRequest()) == PwmApplicationMode.ERROR) {
return EVAL_PAGE;
}
try {
final PwmRequest pwmRequest = JspUtility.getPwmRequest(pageContext);
final String pwmFormID = buildPwmFormID(pwmRequest);
pageContext.getOut().write(pwmFormID);
} catch (Exception e) {
try {
pageContext.getOut().write("errorGeneratingPwmFormID");
} catch (IOException e1) {
/* ignore */
}
LOGGER.error("error during pwmFormIDTag output of pwmFormID: " + e.getMessage(), e);
}
return EVAL_PAGE;
}
Aggregations