use of org.apereo.cas.util.http.HttpMessage in project cas by apereo.
the class YubiKeyMultifactorAuthenticationProvider method isAvailable.
@Override
protected boolean isAvailable() {
try {
final String[] endpoints = client.getWsapiUrls();
for (final String endpoint : endpoints) {
LOGGER.debug("Pinging YubiKey API endpoint at [{}]", endpoint);
final HttpMessage msg = this.httpClient.sendMessageToEndPoint(new URL(endpoint));
final String message = msg != null ? msg.getMessage() : null;
if (StringUtils.isNotBlank(message)) {
final String response = EncodingUtils.urlDecode(message);
LOGGER.debug("Received YubiKey ping response [{}]", response);
return true;
}
}
} catch (final Exception e) {
LOGGER.warn(e.getMessage(), e);
}
return false;
}
use of org.apereo.cas.util.http.HttpMessage in project cas by apereo.
the class BaseDuoSecurityAuthenticationService method ping.
@Override
public boolean ping() {
try {
final String url = buildUrlHttpScheme(getApiHost().concat("/rest/v1/ping"));
LOGGER.debug("Contacting Duo @ [{}]", url);
final HttpMessage msg = this.httpClient.sendMessageToEndPoint(new URL(url));
if (msg != null) {
final String response = URLDecoder.decode(msg.getMessage(), StandardCharsets.UTF_8.name());
LOGGER.debug("Received Duo ping response [{}]", response);
final JsonNode result = MAPPER.readTree(response);
if (result.has(RESULT_KEY_RESPONSE) && result.has(RESULT_KEY_STAT) && result.get(RESULT_KEY_RESPONSE).asText().equalsIgnoreCase("pong") && result.get(RESULT_KEY_STAT).asText().equalsIgnoreCase("OK")) {
return true;
}
LOGGER.warn("Could not reach/ping Duo. Response returned is [{}]", result);
}
} catch (final Exception e) {
LOGGER.warn("Pinging Duo has failed with error: [{}]", e.getMessage(), e);
}
return false;
}
use of org.apereo.cas.util.http.HttpMessage in project cas by apereo.
the class YubiKeyMultifactorAuthenticationProviderTests method verifyFails.
@Test
public void verifyFails() throws Exception {
val client = mock(YubicoClient.class);
when(client.getWsapiUrls()).thenThrow(new RuntimeException());
val http = mock(HttpClient.class);
when(http.sendMessageToEndPoint(any(URL.class))).thenReturn(new HttpMessage(new URL("http://localhost:1234"), "message"));
val provider = new YubiKeyMultifactorAuthenticationProvider(client, http);
val service = MultifactorAuthenticationTestUtils.getRegisteredService();
assertFalse(provider.isAvailable(service));
}
use of org.apereo.cas.util.http.HttpMessage in project cas by apereo.
the class BaseDuoAuthenticationService method ping.
@Override
public boolean ping() {
try {
final String url = buildUrlHttpScheme(getApiHost().concat("/rest/v1/ping"));
LOGGER.debug("Contacting Duo @ [{}]", url);
final HttpMessage msg = this.httpClient.sendMessageToEndPoint(new URL(url));
if (msg != null) {
final String response = URLDecoder.decode(msg.getMessage(), StandardCharsets.UTF_8.name());
LOGGER.debug("Received Duo ping response [{}]", response);
final JsonNode result = MAPPER.readTree(response);
if (result.has(RESULT_KEY_RESPONSE) && result.has(RESULT_KEY_STAT) && result.get(RESULT_KEY_RESPONSE).asText().equalsIgnoreCase("pong") && result.get(RESULT_KEY_STAT).asText().equalsIgnoreCase("OK")) {
return true;
}
LOGGER.warn("Could not reach/ping Duo. Response returned is [{}]", result);
}
} catch (final Exception e) {
LOGGER.warn("Pinging Duo has failed with error: [{}]", e.getMessage(), e);
}
return false;
}
use of org.apereo.cas.util.http.HttpMessage in project cas by apereo.
the class YubiKeyMultifactorAuthenticationProviderTests method getMultifactorAuthenticationProvider.
@Override
@SneakyThrows
public AbstractMultifactorAuthenticationProvider getMultifactorAuthenticationProvider() {
val client = mock(YubicoClient.class);
when(client.getWsapiUrls()).thenReturn(new String[] { "http://localhost:1234" });
val http = mock(HttpClient.class);
when(http.sendMessageToEndPoint(any(URL.class))).thenReturn(new HttpMessage(new URL("http://localhost:1234"), "message"));
return new YubiKeyMultifactorAuthenticationProvider(client, http);
}
Aggregations