Search in sources :

Example 11 with PwmURL

use of password.pwm.http.PwmURL in project pwm by pwm-project.

the class ApplicationModeFilter method processFilter.

@Override
public void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain chain) throws IOException, ServletException {
    // ignore if resource request
    final PwmURL pwmURL = pwmRequest.getURL();
    if (!pwmURL.isResourceURL() && !pwmURL.isRestService() && !pwmURL.isReferenceURL() && !pwmURL.isClientApiServlet()) {
        // check for valid config
        try {
            if (checkConfigModes(pwmRequest) == ProcessStatus.Halt) {
                return;
            }
        } catch (PwmUnrecoverableException e) {
            if (e.getError() == PwmError.ERROR_UNKNOWN) {
                try {
                    LOGGER.error(e.getMessage());
                } catch (Exception ignore) {
                /* noop */
                }
            }
            pwmRequest.respondWithError(e.getErrorInformation(), true);
            return;
        }
    }
    chain.doFilter();
}
Also used : PwmURL(password.pwm.http.PwmURL) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) ServletException(javax.servlet.ServletException) IOException(java.io.IOException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Example 12 with PwmURL

use of password.pwm.http.PwmURL in project pwm by pwm-project.

the class RequestInitializationFilter method handleRequestInitialization.

public static void handleRequestInitialization(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
    final LocalSessionStateBean ssBean = pwmRequest.getPwmSession().getSessionStateBean();
    final PwmURL pwmURL = pwmRequest.getURL();
    // mark if first request
    if (ssBean.getSessionCreationTime() == null) {
        ssBean.setSessionCreationTime(Instant.now());
        ssBean.setSessionLastAccessedTime(Instant.now());
    }
    // mark session ip address
    if (ssBean.getSrcAddress() == null) {
        ssBean.setSrcAddress(readUserIPAddress(pwmRequest.getHttpServletRequest(), pwmRequest.getConfig()));
    }
    // mark the user's hostname in the session bean
    if (ssBean.getSrcHostname() == null) {
        ssBean.setSrcHostname(readUserHostname(pwmRequest.getHttpServletRequest(), pwmRequest.getConfig()));
    }
    // update the privateUrlAccessed flag
    if (pwmURL.isPrivateUrl()) {
        ssBean.setPrivateUrlAccessed(true);
    }
    // initialize the session's locale
    if (ssBean.getLocale() == null) {
        initializeLocaleAndTheme(pwmRequest);
    }
    // set idle timeout
    PwmSessionWrapper.setHttpSessionIdleTimeout(pwmRequest.getPwmApplication(), pwmRequest.getPwmSession(), pwmRequest.getHttpServletRequest().getSession());
}
Also used : LocalSessionStateBean(password.pwm.bean.LocalSessionStateBean) PwmURL(password.pwm.http.PwmURL)

Example 13 with PwmURL

use of password.pwm.http.PwmURL in project pwm by pwm-project.

the class RequestInitializationFilter method doFilter.

public void doFilter(final ServletRequest servletRequest, final ServletResponse servletResponse, final FilterChain filterChain) throws IOException, ServletException {
    final HttpServletRequest req = (HttpServletRequest) servletRequest;
    final HttpServletResponse resp = (HttpServletResponse) servletResponse;
    final PwmApplicationMode mode = PwmApplicationMode.determineMode(req);
    final PwmURL pwmURL = new PwmURL(req);
    PwmApplication testPwmApplicationLoad = null;
    try {
        testPwmApplicationLoad = ContextManager.getPwmApplication(req);
    } catch (PwmException e) {
    }
    if (testPwmApplicationLoad != null && mode == PwmApplicationMode.RUNNING) {
        if (testPwmApplicationLoad.getStatisticsManager() != null) {
            testPwmApplicationLoad.getStatisticsManager().updateEps(EpsStatistic.REQUESTS, 1);
        }
    }
    if (testPwmApplicationLoad == null && pwmURL.isResourceURL()) {
        filterChain.doFilter(req, resp);
    } else if (pwmURL.isRestService()) {
        filterChain.doFilter(req, resp);
    } else {
        if (mode == PwmApplicationMode.ERROR) {
            try {
                final ContextManager contextManager = ContextManager.getContextManager(req.getServletContext());
                if (contextManager != null) {
                    final ErrorInformation startupError = contextManager.getStartupErrorInformation();
                    servletRequest.setAttribute(PwmRequestAttribute.PwmErrorInfo.toString(), startupError);
                }
            } catch (Exception e) {
                if (pwmURL.isResourceURL()) {
                    filterChain.doFilter(servletRequest, servletResponse);
                    return;
                }
                LOGGER.error("error while trying to detect application status: " + e.getMessage());
            }
            LOGGER.error("unable to satisfy incoming request, application is not available");
            resp.setStatus(500);
            final String url = JspUrl.APP_UNAVAILABLE.getPath();
            servletRequest.getServletContext().getRequestDispatcher(url).forward(servletRequest, servletResponse);
        } else {
            initializeServletRequest(req, resp, filterChain);
        }
    }
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) PwmApplication(password.pwm.PwmApplication) ContextManager(password.pwm.http.ContextManager) HttpServletResponse(javax.servlet.http.HttpServletResponse) PwmURL(password.pwm.http.PwmURL) PwmApplicationMode(password.pwm.PwmApplicationMode) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException) UnknownHostException(java.net.UnknownHostException)

Example 14 with PwmURL

use of password.pwm.http.PwmURL in project pwm by pwm-project.

the class RequestInitializationFilter method initializeServletRequest.

private void initializeServletRequest(final HttpServletRequest req, final HttpServletResponse resp, final FilterChain filterChain) throws IOException, ServletException {
    try {
        checkAndInitSessionState(req);
        PwmRequest.forRequest(req, resp);
    } catch (Throwable e) {
        LOGGER.error("can't load application: " + e.getMessage(), e);
        if (!(new PwmURL(req).isResourceURL())) {
            respondWithUnavailableError(req, resp);
            return;
        }
        return;
    }
    try {
        final PwmRequest pwmRequest = PwmRequest.forRequest(req, resp);
        checkIfSessionRecycleNeeded(pwmRequest);
        handleRequestInitialization(pwmRequest);
        addPwmResponseHeaders(pwmRequest);
        checkIdleTimeout(pwmRequest);
        try {
            handleRequestSecurityChecks(pwmRequest);
        } catch (PwmUnrecoverableException e) {
            LOGGER.error(pwmRequest, e.getErrorInformation());
            pwmRequest.respondWithError(e.getErrorInformation());
            if (PwmError.ERROR_INTRUDER_SESSION != e.getError()) {
                pwmRequest.invalidateSession();
            }
            return;
        }
    } catch (Throwable e) {
        final String logMsg = "can't init request: " + e.getMessage();
        if (e instanceof PwmException && ((PwmException) e).getError() != PwmError.ERROR_UNKNOWN) {
            LOGGER.error(logMsg);
        } else {
            LOGGER.error(logMsg, e);
        }
        if (!(new PwmURL(req).isResourceURL())) {
            respondWithUnavailableError(req, resp);
            return;
        }
        return;
    }
    filterChain.doFilter(req, resp);
}
Also used : PwmException(password.pwm.error.PwmException) PwmRequest(password.pwm.http.PwmRequest) PwmURL(password.pwm.http.PwmURL) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException)

Aggregations

PwmURL (password.pwm.http.PwmURL)14 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 PwmApplication (password.pwm.PwmApplication)4 PwmException (password.pwm.error.PwmException)4 PwmApplicationMode (password.pwm.PwmApplicationMode)3 PwmSession (password.pwm.http.PwmSession)3 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 LocalSessionStateBean (password.pwm.bean.LocalSessionStateBean)2 Configuration (password.pwm.config.Configuration)2 ErrorInformation (password.pwm.error.ErrorInformation)2 PwmRequest (password.pwm.http.PwmRequest)2 TimeDuration (password.pwm.util.java.TimeDuration)2 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)1 URI (java.net.URI)1 UnknownHostException (java.net.UnknownHostException)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1