Search in sources :

Example 1 with PwmRequest

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);
    }
}
Also used : ServletException(javax.servlet.ServletException) ErrorInformation(password.pwm.error.ErrorInformation) PwmRequest(password.pwm.http.PwmRequest) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmSession(password.pwm.http.PwmSession) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) PwmOperationalException(password.pwm.error.PwmOperationalException) IOException(java.io.IOException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmOperationalException(password.pwm.error.PwmOperationalException)

Example 2 with 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;
}
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)

Example 3 with PwmRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmRequest(password.pwm.http.PwmRequest) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmSession(password.pwm.http.PwmSession)

Example 4 with PwmRequest

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;
}
Also used : PwmRequest(password.pwm.http.PwmRequest) IOException(java.io.IOException) IOException(java.io.IOException)

Example 5 with PwmRequest

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;
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmRequest(password.pwm.http.PwmRequest) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) IOException(java.io.IOException)

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