use of password.pwm.bean.pub.PublicUserInfoBean 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.bean.pub.PublicUserInfoBean in project pwm by pwm-project.
the class RestTokenDataClient method invoke.
private TokenDestinationData invoke(final SessionLabel sessionLabel, final TokenDestinationData tokenDestinationData, final UserIdentity userIdentity, final String url, final Locale locale) throws PwmOperationalException, ChaiUnavailableException, PwmUnrecoverableException {
if (tokenDestinationData == null) {
throw new NullPointerException("tokenDestinationData can not be null");
}
final Map<String, Object> sendData = new LinkedHashMap<>();
sendData.put(DATA_KEY_TOKENDATA, tokenDestinationData);
if (userIdentity != null) {
final UserInfo userInfo = UserInfoFactory.newUserInfoUsingProxy(pwmApplication, sessionLabel, userIdentity, locale);
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), PwmConstants.DEFAULT_LOCALE, macroMachine);
sendData.put(RestClient.DATA_KEY_USERINFO, publicUserInfoBean);
}
final String jsonRequestData = JsonUtil.serializeMap(sendData);
final String responseBody = RestClientHelper.makeOutboundRestWSCall(pwmApplication, locale, url, jsonRequestData);
return JsonUtil.deserialize(responseBody, TokenDestinationData.class);
}
use of password.pwm.bean.pub.PublicUserInfoBean in project pwm by pwm-project.
the class PwmPasswordRuleValidator method invokeExternalRuleMethods.
public List<ErrorInformation> invokeExternalRuleMethods(final Configuration config, final PwmPasswordPolicy pwmPasswordPolicy, final PasswordData password, final UserInfo userInfo) throws PwmUnrecoverableException {
final List<ErrorInformation> returnedErrors = new ArrayList<>();
final String restURL = config.readSettingAsString(PwmSetting.EXTERNAL_PWCHECK_REST_URLS);
final boolean haltOnError = Boolean.parseBoolean(config.readAppProperty(AppProperty.WS_REST_CLIENT_PWRULE_HALTONERROR));
final Map<String, Object> sendData = new LinkedHashMap<>();
if (restURL == null || restURL.isEmpty()) {
return Collections.emptyList();
}
{
final String passwordStr = password == null ? "" : password.getStringValue();
sendData.put("password", passwordStr);
}
if (pwmPasswordPolicy != null) {
final LinkedHashMap<String, Object> policyData = new LinkedHashMap<>();
for (final PwmPasswordRule rule : PwmPasswordRule.values()) {
policyData.put(rule.name(), pwmPasswordPolicy.getValue(rule));
}
sendData.put("policy", policyData);
}
if (userInfo != null) {
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), locale, macroMachine);
sendData.put("userInfo", publicUserInfoBean);
}
final String jsonRequestBody = JsonUtil.serializeMap(sendData);
try {
final String responseBody = RestClientHelper.makeOutboundRestWSCall(pwmApplication, locale, restURL, jsonRequestBody);
final Map<String, Object> responseMap = JsonUtil.deserialize(responseBody, new TypeToken<Map<String, Object>>() {
});
if (responseMap.containsKey(REST_RESPONSE_KEY_ERROR) && Boolean.parseBoolean(responseMap.get(REST_RESPONSE_KEY_ERROR).toString())) {
if (responseMap.containsKey(REST_RESPONSE_KEY_ERROR_MSG)) {
final String errorMessage = responseMap.get(REST_RESPONSE_KEY_ERROR_MSG).toString();
LOGGER.trace("external web service reported error: " + errorMessage);
returnedErrors.add(new ErrorInformation(PwmError.PASSWORD_CUSTOM_ERROR, errorMessage, errorMessage, null));
} else {
LOGGER.trace("external web service reported error without specifying an errorMessage");
returnedErrors.add(new ErrorInformation(PwmError.PASSWORD_CUSTOM_ERROR));
}
} else {
LOGGER.trace("external web service did not report an error");
}
} catch (PwmOperationalException e) {
final String errorMsg = "error executing external rule REST call: " + e.getMessage();
LOGGER.error(errorMsg);
if (haltOnError) {
throw new PwmUnrecoverableException(e.getErrorInformation(), e);
}
throw new IllegalStateException("http response error code: " + e.getMessage());
}
return returnedErrors;
}
use of password.pwm.bean.pub.PublicUserInfoBean in project pwm by pwm-project.
the class ExternalRestMacro method replaceValue.
public String replaceValue(final String matchValue, final MacroRequestInfo macroRequestInfo) {
final PwmApplication pwmApplication = macroRequestInfo.getPwmApplication();
final UserInfo userInfoBean = macroRequestInfo.getUserInfo();
final String inputString = matchValue.substring(11, matchValue.length() - 1);
final Map<String, Object> sendData = new HashMap<>();
try {
if (userInfoBean != null) {
final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfoBean.getUserIdentity());
final PublicUserInfoBean publicUserInfoBean = PublicUserInfoBean.fromUserInfoBean(userInfoBean, pwmApplication.getConfig(), PwmConstants.DEFAULT_LOCALE, macroMachine);
sendData.put("userInfo", publicUserInfoBean);
}
sendData.put("input", inputString);
final String requestBody = JsonUtil.serializeMap(sendData);
final String responseBody = RestClientHelper.makeOutboundRestWSCall(pwmApplication, PwmConstants.DEFAULT_LOCALE, url, requestBody);
final Map<String, Object> responseMap = JsonUtil.deserialize(responseBody, new TypeToken<Map<String, Object>>() {
});
if (responseMap.containsKey("output")) {
return responseMap.get("output").toString();
} else {
return "";
}
} catch (PwmException e) {
final String errorMsg = "error while executing external macro '" + matchValue + "', error: " + e.getMessage();
LOGGER.error(errorMsg);
throw new IllegalStateException(errorMsg);
}
}
Aggregations