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();
}
}
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);
}
}
}
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);
}
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));
}
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;
}
Aggregations