use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class RestStatusServer method doGetStatusData.
@RestMethodHandler(method = HttpMethod.GET, produces = HttpContentType.json, consumes = HttpContentType.json)
public RestResultBean doGetStatusData(final RestRequest restRequest) throws PwmUnrecoverableException {
final Instant startTime = Instant.now();
final String username = restRequest.readParameterAsString("username");
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, username);
try {
final ChaiProvider chaiProvider = targetUserIdentity.getChaiProvider();
final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), chaiProvider);
final MacroMachine macroMachine = MacroMachine.forUser(restRequest.getPwmApplication(), restRequest.getLocale(), restRequest.getSessionLabel(), targetUserIdentity.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, restRequest.getPwmApplication().getConfig(), restRequest.getLocale(), macroMachine);
StatisticsManager.incrementStat(restRequest.getPwmApplication(), Statistic.REST_STATUS);
final RestResultBean restResultBean = RestResultBean.withData(publicUserInfoBean);
LOGGER.debug(restRequest.getSessionLabel(), "completed REST status request in " + TimeDuration.compactFromCurrent(startTime) + ", result=" + JsonUtil.serialize(restResultBean));
return restResultBean;
} catch (PwmException e) {
return RestResultBean.fromError(e.getErrorInformation());
} 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 PeopleSearchServlet method restLoadClientData.
@ActionHandler(action = "clientData")
private ProcessStatus restLoadClientData(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final PeopleSearchConfiguration peopleSearchConfiguration = PeopleSearchConfiguration.fromConfiguration(pwmRequest.getPwmApplication());
final PeopleSearchClientConfigBean peopleSearchClientConfigBean = PeopleSearchClientConfigBean.fromConfig(pwmRequest.getPwmApplication(), peopleSearchConfiguration, pwmRequest.getLocale(), pwmRequest.getUserInfoIfLoggedIn(), pwmRequest.getSessionLabel());
final RestResultBean restResultBean = RestResultBean.withData(peopleSearchClientConfigBean);
LOGGER.trace(pwmRequest, "returning clientData: " + JsonUtil.serialize(restResultBean));
pwmRequest.outputJsonResult(restResultBean);
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class PeopleSearchServlet method restSearchRequest.
@ActionHandler(action = "search")
private ProcessStatus restSearchRequest(final PwmRequest pwmRequest) throws ChaiUnavailableException, PwmUnrecoverableException, IOException, ServletException {
final Map<String, Object> jsonBodyMap = pwmRequest.readBodyAsJsonMap(PwmHttpRequestWrapper.Flag.BypassValidation);
final String username = jsonBodyMap.get("username") == null ? null : jsonBodyMap.get("username").toString();
final boolean includeDisplayName = pwmRequest.readParameterAsBoolean("includeDisplayName");
final PeopleSearchDataReader peopleSearchDataReader = new PeopleSearchDataReader(pwmRequest);
final SearchResultBean searchResultBean = peopleSearchDataReader.makeSearchResultBean(username, includeDisplayName);
final RestResultBean restResultBean = RestResultBean.withData(searchResultBean);
addExpiresHeadersToResponse(pwmRequest);
pwmRequest.outputJsonResult(restResultBean);
LOGGER.trace(pwmRequest, "returning " + searchResultBean.getSearchResults().size() + " results for search request '" + username + "'");
return ProcessStatus.Halt;
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class RestCheckPasswordServer method doOperation.
public RestResultBean doOperation(final RestRequest restRequest, final JsonInput jsonInput) throws PwmUnrecoverableException {
final Instant startTime = Instant.now();
if (StringUtil.isEmpty(jsonInput.getPassword1())) {
final String errorMessage = "missing field '" + FIELD_PASSWORD_1 + "'";
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_FIELD_REQUIRED, errorMessage, new String[] { FIELD_PASSWORD_1 });
return RestResultBean.fromError(restRequest, errorInformation);
}
try {
final TargetUserIdentity targetUserIdentity = RestUtility.resolveRequestedUsername(restRequest, jsonInput.getUsername());
final UserInfo userInfo = UserInfoFactory.newUserInfo(restRequest.getPwmApplication(), restRequest.getSessionLabel(), restRequest.getLocale(), targetUserIdentity.getUserIdentity(), targetUserIdentity.getChaiProvider());
final PasswordCheckRequest checkRequest = new PasswordCheckRequest(targetUserIdentity.getUserIdentity(), StringUtil.isEmpty(jsonInput.getPassword1()) ? null : new PasswordData(jsonInput.getPassword1()), StringUtil.isEmpty(jsonInput.getPassword2()) ? null : new PasswordData(jsonInput.getPassword2()), userInfo);
restRequest.getPwmApplication().getStatisticsManager().incrementValue(Statistic.REST_CHECKPASSWORD);
final PasswordUtility.PasswordCheckInfo passwordCheckInfo = PasswordUtility.checkEnteredPassword(restRequest.getPwmApplication(), restRequest.getLocale(), targetUserIdentity.getChaiUser(), checkRequest.getUserInfo(), null, checkRequest.getPassword1(), checkRequest.getPassword2());
final JsonOutput jsonOutput = JsonOutput.fromPasswordCheckInfo(passwordCheckInfo);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
final TimeDuration timeDuration = TimeDuration.fromCurrent(startTime);
LOGGER.trace(restRequest.getSessionLabel(), "REST /checkpassword response (" + timeDuration.asCompactString() + "): " + JsonUtil.serialize(jsonOutput));
return restResultBean;
} catch (PwmException e) {
LOGGER.debug(restRequest.getSessionLabel(), "REST /checkpassword error during execution: " + e.getMessage());
return RestResultBean.fromError(restRequest, e.getErrorInformation());
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
LOGGER.error(restRequest.getSessionLabel(), errorInformation.toDebugStr(), e);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
use of password.pwm.ws.server.RestResultBean in project pwm by pwm-project.
the class RestRandomPasswordServer method doPostRandomPasswordForm.
@RestMethodHandler(method = HttpMethod.POST, consumes = HttpContentType.form, produces = HttpContentType.json)
public RestResultBean doPostRandomPasswordForm(final RestRequest restRequest) throws PwmUnrecoverableException {
final JsonInput jsonInput = new JsonInput();
jsonInput.username = restRequest.readParameterAsString("username", PwmHttpRequestWrapper.Flag.BypassValidation);
jsonInput.strength = restRequest.readParameterAsInt("strength", 0);
jsonInput.maxLength = restRequest.readParameterAsInt("maxLength", 0);
jsonInput.minLength = restRequest.readParameterAsInt("minLength", 0);
jsonInput.chars = restRequest.readParameterAsString("chars", PwmHttpRequestWrapper.Flag.BypassValidation);
jsonInput.noUser = restRequest.readParameterAsBoolean("noUser");
try {
final JsonOutput jsonOutput = doOperation(restRequest, jsonInput);
final RestResultBean restResultBean = RestResultBean.withData(jsonOutput);
return restResultBean;
} catch (PwmException e) {
LOGGER.error(restRequest.getSessionLabel(), "error executing rest-json random password request: " + e.getMessage(), e);
return RestResultBean.fromError(restRequest, e.getErrorInformation());
} catch (Exception e) {
final String errorMessage = "unexpected error executing web service: " + e.getMessage();
final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_UNKNOWN, errorMessage);
return RestResultBean.fromError(restRequest, errorInformation);
}
}
Aggregations