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