Search in sources :

Example 1 with RemoteVerificationRequestBean

use of password.pwm.bean.RemoteVerificationRequestBean in project pwm by pwm-project.

the class RemoteVerificationMethod method sendRemoteRequest.

private void sendRemoteRequest(final Map<String, String> userResponses) throws PwmUnrecoverableException {
    lastResponse = null;
    final Map<String, String> headers = new LinkedHashMap<>();
    headers.put(HttpHeader.Content_Type.getHttpName(), HttpContentType.json.getHeaderValue());
    headers.put(HttpHeader.Accept_Language.getHttpName(), locale.toLanguageTag());
    final RemoteVerificationRequestBean remoteVerificationRequestBean = new RemoteVerificationRequestBean();
    remoteVerificationRequestBean.setResponseSessionID(this.remoteSessionID);
    final MacroMachine macroMachine = MacroMachine.forUser(pwmApplication, PwmConstants.DEFAULT_LOCALE, SessionLabel.SYSTEM_LABEL, userInfo.getUserIdentity());
    remoteVerificationRequestBean.setUserInfo(PublicUserInfoBean.fromUserInfoBean(userInfo, pwmApplication.getConfig(), locale, macroMachine));
    remoteVerificationRequestBean.setUserResponses(userResponses);
    final PwmHttpClientRequest pwmHttpClientRequest = new PwmHttpClientRequest(HttpMethod.POST, url, JsonUtil.serialize(remoteVerificationRequestBean), headers);
    try {
        final PwmHttpClientResponse response = pwmHttpClient.makeRequest(pwmHttpClientRequest);
        final String responseBodyStr = response.getBody();
        this.lastResponse = JsonUtil.deserialize(responseBodyStr, RemoteVerificationResponseBean.class);
    } catch (PwmException e) {
        LOGGER.error(sessionLabel, e.getErrorInformation());
        throw new PwmUnrecoverableException(e.getErrorInformation());
    } catch (Exception e) {
        final String errorMsg = "error reading remote responses web service response: " + e.getMessage();
        final ErrorInformation errorInformation = new ErrorInformation(PwmError.ERROR_SERVICE_NOT_AVAILABLE, errorMsg);
        LOGGER.error(sessionLabel, errorInformation);
        throw new PwmUnrecoverableException(errorInformation);
    }
}
Also used : RemoteVerificationRequestBean(password.pwm.bean.RemoteVerificationRequestBean) PwmException(password.pwm.error.PwmException) RemoteVerificationResponseBean(password.pwm.bean.RemoteVerificationResponseBean) ErrorInformation(password.pwm.error.ErrorInformation) PwmHttpClientRequest(password.pwm.http.client.PwmHttpClientRequest) MacroMachine(password.pwm.util.macro.MacroMachine) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmHttpClientResponse(password.pwm.http.client.PwmHttpClientResponse) PwmUnrecoverableException(password.pwm.error.PwmUnrecoverableException) PwmException(password.pwm.error.PwmException) LinkedHashMap(java.util.LinkedHashMap)

Aggregations

LinkedHashMap (java.util.LinkedHashMap)1 RemoteVerificationRequestBean (password.pwm.bean.RemoteVerificationRequestBean)1 RemoteVerificationResponseBean (password.pwm.bean.RemoteVerificationResponseBean)1 ErrorInformation (password.pwm.error.ErrorInformation)1 PwmException (password.pwm.error.PwmException)1 PwmUnrecoverableException (password.pwm.error.PwmUnrecoverableException)1 PwmHttpClientRequest (password.pwm.http.client.PwmHttpClientRequest)1 PwmHttpClientResponse (password.pwm.http.client.PwmHttpClientResponse)1 MacroMachine (password.pwm.util.macro.MacroMachine)1