use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class RestStatisticsServer method doPwmStatisticJsonGet.
@RestMethodHandler(method = HttpMethod.GET, consumes = HttpContentType.form, produces = HttpContentType.json)
public RestResultBean doPwmStatisticJsonGet(final RestRequest restRequest) throws PwmUnrecoverableException {
final String statKey = restRequest.readParameterAsString("statKey", PwmHttpRequestWrapper.Flag.BypassValidation);
final String statName = restRequest.readParameterAsString("statName", PwmHttpRequestWrapper.Flag.BypassValidation);
final String days = restRequest.readParameterAsString("days", PwmHttpRequestWrapper.Flag.BypassValidation);
try {
final StatisticsManager statisticsManager = restRequest.getPwmApplication().getStatisticsManager();
final JsonOutput jsonOutput = new JsonOutput();
jsonOutput.EPS = addEpsStats(statisticsManager);
if (statName != null && statName.length() > 0) {
jsonOutput.nameData = doNameStat(statisticsManager, statName, days);
} else {
jsonOutput.keyData = doKeyStat(statisticsManager, statKey);
}
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_STATISTICS);
final RestResultBean resultBean = RestResultBean.withData(jsonOutput);
return resultBean;
} catch (Exception e) {
final String errorMsg = "unexpected error building json response: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class RestVerifyResponsesServer method doSetChallengeDataJson.
@RestMethodHandler(method = HttpMethod.POST, consumes = HttpContentType.json, produces = HttpContentType.json)
public RestResultBean doSetChallengeDataJson(final RestRequest restRequest) throws IOException, PwmUnrecoverableException {
final Instant startTime = Instant.now();
final JsonPutChallengesInput jsonInput = RestUtility.deserializeJsonBody(restRequest, JsonPutChallengesInput.class);
final String username = RestUtility.readValueFromJsonAndParam(jsonInput.getUsername(), restRequest.readParameterAsString("username", PwmHttpRequestWrapper.Flag.BypassValidation), "username");
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
LOGGER.debug(restRequest.getSessionLabel(), "beginning /verifyresponses REST service against " + (targetUserIdentity.isSelf() ? "self" : targetUserIdentity.getUserIdentity().toDisplayString()));
try {
final ResponseSet responseSet = restRequest.getPwmApplication().getCrService().readUserResponseSet(restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiUser());
final boolean verified = responseSet.test(jsonInput.toCrMap());
final RestResultBean restResultBean = RestResultBean.forSuccessMessage(verified, restRequest, Message.Success_Unknown);
LOGGER.debug(restRequest.getSessionLabel(), "completed /verifyresponses REST service in " + TimeDuration.fromCurrent(startTime).asCompactString() + ", response: " + JsonUtil.serialize(restResultBean));
return restResultBean;
} catch (ChaiUnavailableException e) {
throw PwmUnrecoverableException.fromChaiException(e);
}
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class ClientApiServlet method restHealthProcessor.
@ActionHandler(action = "health")
public ProcessStatus restHealthProcessor(final PwmRequest pwmRequest) throws IOException, ServletException, PwmUnrecoverableException {
if (pwmRequest.getPwmApplication().getApplicationMode() == PwmApplicationMode.RUNNING) {
if (!pwmRequest.isAuthenticated()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_AUTHENTICATION_REQUIRED);
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
return ProcessStatus.Halt;
}
if (!pwmRequest.getPwmSession().getSessionManager().checkPermission(pwmRequest.getPwmApplication(), Permission.PWMADMIN)) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNAUTHORIZED, "admin privileges required");
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
return ProcessStatus.Halt;
}
}
try {
final HealthData jsonOutput = RestHealthServer.processGetHealthCheckData(pwmRequest.getPwmApplication(), pwmRequest.getLocale(), false);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
pwmRequest.outputJsonResult(restResultBean);
} catch (PwmException e) {
final ErrorInformation errorInformation = e.getErrorInformation();
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
LOGGER.debug(pwmRequest, errorInformation);
pwmRequest.respondWithError(errorInformation);
}
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class LoginServlet method processRestLogin.
@ActionHandler(action = "restLogin")
private ProcessStatus processRestLogin(final PwmRequest pwmRequest) throws PwmUnrecoverableException, ServletException, IOException, ChaiUnavailableException {
final boolean passwordOnly = passwordOnly(pwmRequest);
final Map<String, String> valueMap = pwmRequest.readBodyAsJsonStringMap();
if (valueMap == null || valueMap.isEmpty()) {
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_MISSING_PARAMETER, "missing json request body");
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
return ProcessStatus.Halt;
}
try {
handleLoginRequest(pwmRequest, valueMap, passwordOnly);
} catch (PwmOperationalException e) {
final ErrorInformation errorInformation = e.getErrorInformation();
LOGGER.trace(pwmRequest, "returning rest login error to client: " + errorInformation.toDebugStr());
pwmRequest.outputJsonResult(RestResultBean.fromError(errorInformation, pwmRequest));
return ProcessStatus.Halt;
}
pwmRequest.readParametersAsMap();
// login has succeeded
final String nextLoginUrl = determinePostLoginUrl(pwmRequest);
final HashMap<String, String> resultMap = new HashMap<>(Collections.singletonMap("nextURL", nextLoginUrl));
final RestResultBean restResultBean = RestResultBean.withData(resultMap);
LOGGER.debug(pwmRequest, "rest login succeeded");
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class SetupOtpServlet method handleRestValidateCode.
@ActionHandler(action = "restValidateCode")
private ProcessStatus handleRestValidateCode(final PwmRequest pwmRequest) throws PwmUnrecoverableException, IOException, ServletException, ChaiUnavailableException {
final PwmApplication pwmApplication = pwmRequest.getPwmApplication();
final PwmSession pwmSession = pwmRequest.getPwmSession();
final OTPUserRecord otpUserRecord = pwmSession.getUserInfo().getOtpUserRecord();
final OtpService otpService = pwmApplication.getOtpService();
final String bodyString = pwmRequest.readRequestBodyAsString();
final Map<String, String> clientValues = JsonUtil.deserializeStringMap(bodyString);
final String code = Validator.sanitizeInputValue(pwmApplication.getConfig(), clientValues.get("code"), 1024);
try {
final boolean passed = otpService.validateToken(pwmRequest.getSessionLabel(), pwmSession.getUserInfo().getUserIdentity(), otpUserRecord, code, false);
final RestResultBean restResultBean = RestResultBean.withData(passed);
LOGGER.trace(pwmSession, "returning result for restValidateCode: " + JsonUtil.serialize(restResultBean));
pwmRequest.outputJsonResult(restResultBean);
} catch (PwmOperationalException e) {
final String errorMsg = "error during otp code validation: " + e.getMessage();
LOGGER.error(pwmSession, errorMsg);
pwmRequest.outputJsonResult(RestResultBean.fromError(new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMsg), pwmRequest));
}
return ProcessStatus.Continue;
}
Aggregations