use of org.apereo.cas.adaptors.duo.DuoUserAccountAuthStatus in project cas by apereo.
the class BaseDuoSecurityAuthenticationService method getDuoUserAccount.
@Override
public DuoUserAccount getDuoUserAccount(final String username) {
final DuoUserAccount account = new DuoUserAccount(username);
account.setStatus(DuoUserAccountAuthStatus.AUTH);
try {
final Http userRequest = buildHttpPostUserPreAuthRequest(username);
signHttpUserPreAuthRequest(userRequest);
LOGGER.debug("Contacting Duo to inquire about username [{}]", username);
final String userResponse = userRequest.executeHttpRequest().body().string();
final String jsonResponse = URLDecoder.decode(userResponse, StandardCharsets.UTF_8.name());
LOGGER.debug("Received Duo admin response [{}]", jsonResponse);
final JsonNode result = MAPPER.readTree(jsonResponse);
if (result.has(RESULT_KEY_RESPONSE) && result.has(RESULT_KEY_STAT) && result.get(RESULT_KEY_STAT).asText().equalsIgnoreCase("OK")) {
final JsonNode response = result.get(RESULT_KEY_RESPONSE);
final String authResult = response.get(RESULT_KEY_RESULT).asText().toUpperCase();
final DuoUserAccountAuthStatus status = DuoUserAccountAuthStatus.valueOf(authResult);
account.setStatus(status);
account.setMessage(response.get(RESULT_KEY_STATUS_MESSAGE).asText());
if (status == DuoUserAccountAuthStatus.ENROLL) {
final String enrollUrl = response.get(RESULT_KEY_ENROLL_PORTAL_URL).asText();
account.setEnrollPortalUrl(enrollUrl);
}
}
} catch (final Exception e) {
LOGGER.warn("Reaching Duo has failed with error: [{}]", e.getMessage(), e);
}
return account;
}
Aggregations