Search in sources :

Example 51 with PwmException

use of password.pwm.error.PwmException 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 52 with PwmException

use of password.pwm.error.PwmException 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 53 with PwmException

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

Example 54 with PwmException

use of password.pwm.error.PwmException in project pwm by pwm-project.

the class AbstractPwmServlet method convertToPwmUnrecoverableException.

private PwmUnrecoverableException convertToPwmUnrecoverableException(final Throwable e, final PwmRequest pwmRequest) {
    if (e instanceof PwmUnrecoverableException) {
        return (PwmUnrecoverableException) e;
    }
    if (e instanceof PwmException) {
        return new PwmUnrecoverableException(((PwmException) e).getErrorInformation());
    }
    if (e instanceof ChaiUnavailableException) {
        final String errorMsg = "unable to contact ldap directory: " + e.getMessage();
        return new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_DIRECTORY_UNAVAILABLE, errorMsg));
    }
    final String stackTraceText;
    {
        final StringWriter errorStack = new StringWriter();
        e.printStackTrace(new PrintWriter(errorStack));
        stackTraceText = errorStack.toString();
    }
    String stackTraceHash = "hash";
    try {
        stackTraceHash = SecureEngine.hash(stackTraceText, PwmHashAlgorithm.SHA1);
    } catch (PwmUnrecoverableException e1) {
    /* */
    }
    final String errorMsg = "unexpected error processing request: " + JavaHelper.readHostileExceptionMessage(e) + " [" + stackTraceHash + "]";
    LOGGER.error(pwmRequest, errorMsg, e);
    return new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg));
}
Also used : PwmException(password.pwm.error.PwmException) ErrorInformation(password.pwm.error.ErrorInformation) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) StringWriter(java.io.StringWriter) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PrintWriter(java.io.PrintWriter)

Example 55 with PwmException

use of password.pwm.error.PwmException in project pwm by pwm-project.

the class ConfigGuideServlet method restViewAdminMatches.

@ActionHandler(action = "viewAdminMatches")
private ProcessStatus restViewAdminMatches(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
    final ConfigGuideBean configGuideBean = getBean(pwmRequest);
    try {
        final UserMatchViewerFunction userMatchViewerFunction = new UserMatchViewerFunction();
        final StoredConfigurationImpl storedConfiguration = ConfigGuideForm.generateStoredConfig(configGuideBean);
        final Serializable output = userMatchViewerFunction.provideFunction(pwmRequest, storedConfiguration, PwmSetting.QUERY_MATCH_PWM_ADMIN, null, null);
        pwmRequest.outputJsonResult(RestResultBean.withData(output));
    } catch (PwmException e) {
        LOGGER.error(pwmRequest, e.getErrorInformation());
        pwmRequest.respondWithError(e.getErrorInformation(), false);
    } catch (Exception e) {
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, "error while testing matches = " + e.getMessage());
        LOGGER.error(pwmRequest, errorInformation);
        pwmRequest.respondWithError(errorInformation);
    }
    return ProcessStatus.Halt;
}
Also used : PwmException(password.pwm.error.PwmException) ConfigGuideBean(password.pwm.http.bean.ConfigGuideBean) ErrorInformation(password.pwm.error.ErrorInformation) StoredConfigurationImpl(password.pwm.config.stored.StoredConfigurationImpl) Serializable(java.io.Serializable) UserMatchViewerFunction(password.pwm.config.function.UserMatchViewerFunction) ServletException(javax.servlet.ServletException) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmOperationalException(password.pwm.error.PwmOperationalException) ChaiUnavailableException(com.novell.ldapchai.exception.ChaiUnavailableException) PwmException(password.pwm.error.PwmException) IOException(java.io.IOException)

Aggregations

PwmException (password.pwm.error.PwmException)63 ErrorInformation (password.pwm.error.ErrorInformation)42 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)38 IOException (java.io.IOException)19 PwmOperationalException (password.pwm.error.PwmOperationalException)19 PwmApplication (password.pwm.PwmApplication)16 ChaiUnavailableException (com.novell.ldapchai.exception.ChaiUnavailableException)13 UserIdentity (password.pwm.bean.UserIdentity)13 RestResultBean (password.pwm.ws.server.RestResultBean)13 ServletException (javax.servlet.ServletException)12 LinkedHashMap (java.util.LinkedHashMap)9 PwmSession (password.pwm.http.PwmSession)9 Instant (java.time.Instant)8 TimeDuration (password.pwm.util.java.TimeDuration)8 MacroMachine (password.pwm.util.macro.MacroMachine)8 Configuration (password.pwm.config.Configuration)7 PwmRequest (password.pwm.http.PwmRequest)7 UserInfo (password.pwm.ldap.UserInfo)7 PasswordData (password.pwm.util.PasswordData)7 ArrayList (java.util.ArrayList)6