Search in sources :

Example 6 with PwmApplicationMode

use of password.pwm.PwmApplicationMode in project pwm by pwm-project.

the class ConfigAccessFilter method processFilter.

@Override
void processFilter(final PwmApplicationMode mode, final PwmRequest pwmRequest, final PwmFilterChain filterChain) throws PwmException, IOException, ServletException {
    final PwmApplicationMode appMode = pwmRequest.getPwmApplication().getApplicationMode();
    if (appMode == PwmApplicationMode.NEW) {
        filterChain.doFilter();
        return;
    }
    final boolean blockOldIE = Boolean.parseBoolean(pwmRequest.getPwmApplication().getConfig().readAppProperty(AppProperty.CONFIG_EDITOR_BLOCK_OLD_IE));
    if (blockOldIE) {
        try {
            UserAgentUtils.checkIfPreIE11(pwmRequest);
        } catch (PwmException e) {
            pwmRequest.respondWithError(e.getErrorInformation());
            return;
        }
    }
    final ConfigManagerBean configManagerBean = pwmRequest.getPwmApplication().getSessionStateService().getBean(pwmRequest, ConfigManagerBean.class);
    if (checkAuthentication(pwmRequest, configManagerBean) == ProcessStatus.Continue) {
        filterChain.doFilter();
    }
}
Also used : PwmException(password.pwm.error.PwmException) ConfigManagerBean(password.pwm.http.bean.ConfigManagerBean) PwmApplicationMode(password.pwm.PwmApplicationMode)

Example 7 with PwmApplicationMode

use of password.pwm.PwmApplicationMode 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)

Aggregations

PwmApplicationMode (password.pwm.PwmApplicationMode)7 PwmApplication (password.pwm.PwmApplication)5 PwmException (password.pwm.error.PwmException)4 ErrorInformation (password.pwm.error.ErrorInformation)3 PwmURL (password.pwm.http.PwmURL)3 IOException (java.io.IOException)2 HashSet (java.util.HashSet)2 ServletException (javax.servlet.ServletException)2 HttpServletRequest (javax.servlet.http.HttpServletRequest)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 PwmEnvironment (password.pwm.PwmEnvironment)2 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)2 File (java.io.File)1 UnknownHostException (java.net.UnknownHostException)1 Timer (java.util.Timer)1 Configuration (password.pwm.config.Configuration)1 ConfigurationReader (password.pwm.config.stored.ConfigurationReader)1 ContextManager (password.pwm.http.ContextManager)1 PwmRequest (password.pwm.http.PwmRequest)1 ConfigManagerBean (password.pwm.http.bean.ConfigManagerBean)1