use of password.pwm.http.ProcessStatus in project pwm by pwm-project.
the class ControlledPwmServlet method dispatchMethod.
private ProcessStatus dispatchMethod(final PwmRequest pwmRequest) throws PwmUnrecoverableException {
final ProcessAction action = readProcessAction(pwmRequest);
if (action == null) {
return ProcessStatus.Continue;
}
try {
final Method interestedMethod = discoverMethodForAction(this.getClass(), action);
if (interestedMethod != null) {
interestedMethod.setAccessible(true);
return (ProcessStatus) interestedMethod.invoke(this, pwmRequest);
}
} catch (InvocationTargetException e) {
final Throwable cause = e.getCause();
if (cause != null) {
if (cause instanceof PwmUnrecoverableException) {
throw (PwmUnrecoverableException) cause;
}
final String msg = "unexpected error during action handler for '" + this.getClass().getName() + ":" + action + "', error: " + cause.getMessage();
LOGGER.error(pwmRequest, msg, e.getCause());
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
}
LOGGER.error("uncased invocation error: " + e.getMessage(), e);
} catch (Throwable e) {
final String msg = "unexpected error invoking action handler for '" + action + "', error: " + e.getMessage();
LOGGER.error(msg, e);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
}
final String msg = "missing action handler for '" + action + "'";
LOGGER.error(msg);
throw new PwmUnrecoverableException(new ErrorInformation(PwmError.ERROR_UNKNOWN, msg));
}
use of password.pwm.http.ProcessStatus in project pwm by pwm-project.
the class ControlledPwmServlet method processAction.
protected void processAction(final PwmRequest pwmRequest) throws ServletException, IOException, ChaiUnavailableException, PwmUnrecoverableException {
preProcessCheck(pwmRequest);
final ProcessAction action = readProcessAction(pwmRequest);
if (action != null) {
final ProcessStatus status = dispatchMethod(pwmRequest);
if (status == ProcessStatus.Halt) {
if (!pwmRequest.getPwmResponse().isCommitted()) {
if (pwmRequest.getConfig().isDevDebugMode()) {
final String msg = "processing complete, handler returned halt but response is not committed";
LOGGER.error(pwmRequest, msg, new IllegalStateException(msg));
}
}
return;
}
final boolean enablePostRedirectGet = Boolean.parseBoolean(pwmRequest.getConfig().readAppProperty(AppProperty.HTTP_SERVLET_ENABLE_POST_REDIRECT_GET));
if (enablePostRedirectGet) {
final String servletUrl = pwmRequest.getURL().determinePwmServletPath();
LOGGER.debug(pwmRequest, "this request is not idempotent, redirecting to self with no action");
sendOtherRedirect(pwmRequest, servletUrl);
return;
}
}
examineLastError(pwmRequest);
if (!pwmRequest.getPwmResponse().isCommitted()) {
nextStep(pwmRequest);
}
}
use of password.pwm.http.ProcessStatus in project pwm by pwm-project.
the class AuthenticationFilter method processUnAuthenticatedSession.
private void processUnAuthenticatedSession(final PwmRequest pwmRequest, final PwmFilterChain chain) throws IOException, ServletException, PwmUnrecoverableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final HttpServletRequest req = pwmRequest.getHttpServletRequest();
final boolean bypassSso = pwmRequest.getPwmSession().getLoginInfoBean().isLoginFlag(LoginInfoBean.LoginFlag.noSso);
if (!bypassSso && pwmRequest.getPwmApplication().getApplicationMode() == PwmApplicationMode.RUNNING) {
final ProcessStatus authenticationProcessStatus = attemptAuthenticationMethods(pwmRequest);
if (authenticationProcessStatus == ProcessStatus.Halt) {
return;
}
}
final String originalRequestedUrl = pwmRequest.getURLwithQueryString();
if (pwmRequest.isAuthenticated()) {
// redirect back to self so request starts over as authenticated.
LOGGER.trace(pwmRequest, "inline authentication occurred during this request, redirecting to current url to restart request");
pwmRequest.getPwmResponse().sendRedirect(originalRequestedUrl);
return;
}
// handle if authenticated during filter process.
if (pwmSession.isAuthenticated()) {
pwmSession.getSessionStateBean().setSessionIdRecycleNeeded(true);
LOGGER.debug(pwmSession, "session authenticated during request, issuing redirect to originally requested url: " + originalRequestedUrl);
pwmRequest.sendRedirect(originalRequestedUrl);
return;
}
if (pwmApplication.getConfig().readSettingAsBoolean(PwmSetting.BASIC_AUTH_FORCE)) {
final String displayMessage = LocaleHelper.getLocalizedMessage(Display.Title_Application, pwmRequest);
pwmRequest.getPwmResponse().setHeader(HttpHeader.WWW_Authenticate, "Basic realm=\"" + displayMessage + "\"");
pwmRequest.getPwmResponse().setStatus(401);
return;
}
if (pwmRequest.getURL().isLoginServlet()) {
chain.doFilter();
return;
}
// user is not authenticated so forward to LoginPage.
LOGGER.trace(pwmSession.getLabel(), "user requested resource requiring authentication (" + req.getRequestURI() + "), but is not authenticated; redirecting to LoginServlet");
LoginServlet.redirectToLoginServlet(pwmRequest);
}
use of password.pwm.http.ProcessStatus in project pwm by pwm-project.
the class ConfigEditorServlet method restSearchSettings.
@ActionHandler(action = "search")
private ProcessStatus restSearchSettings(final PwmRequest pwmRequest) throws IOException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
final ConfigManagerBean configManagerBean = getBean(pwmRequest);
final String bodyData = pwmRequest.readRequestBodyAsString();
final Map<String, String> valueMap = JsonUtil.deserializeStringMap(bodyData);
final Locale locale = pwmRequest.getLocale();
final RestResultBean restResultBean;
final String searchTerm = valueMap.get("search");
final StoredConfigurationImpl storedConfiguration = configManagerBean.getStoredConfiguration();
if (searchTerm != null && !searchTerm.isEmpty()) {
final ArrayList<StoredConfigurationImpl.ConfigRecordID> searchResults = new ArrayList<>(configManagerBean.getStoredConfiguration().search(searchTerm, locale));
final ConcurrentHashMap<String, Map<String, SearchResultItem>> returnData = new ConcurrentHashMap<>();
searchResults.parallelStream().filter(recordID -> recordID.getRecordType() == StoredConfigurationImpl.ConfigRecordID.RecordType.SETTING).forEach(recordID -> {
final PwmSetting setting = (PwmSetting) recordID.getRecordID();
final SearchResultItem item = new SearchResultItem(setting.getCategory().toString(), storedConfiguration.readSetting(setting, recordID.getProfileID()).toDebugString(locale), setting.getCategory().toMenuLocationDebug(recordID.getProfileID(), locale), storedConfiguration.isDefaultValue(setting, recordID.getProfileID()), recordID.getProfileID());
final String returnCategory = item.getNavigation();
returnData.putIfAbsent(returnCategory, new ConcurrentHashMap<>());
returnData.get(returnCategory).put(setting.getKey(), item);
});
final TreeMap<String, Map<String, SearchResultItem>> outputMap = new TreeMap<>();
for (final String key : returnData.keySet()) {
outputMap.put(key, new TreeMap<>(returnData.get(key)));
}
restResultBean = RestResultBean.withData(outputMap);
LOGGER.trace(pwmRequest, "finished search operation with " + returnData.size() + " results in " + TimeDuration.fromCurrent(startTime).asCompactString());
} else {
restResultBean = RestResultBean.withData(new ArrayList<StoredConfigurationImpl.ConfigRecordID>());
}
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
Aggregations