use of com.yubico.u2f.data.messages.SignResponse in project cas by apereo.
the class U2FAuthenticationHandler method doAuthentication.
@Override
@SneakyThrows
protected AuthenticationHandlerExecutionResult doAuthentication(final Credential credential) {
final U2FTokenCredential tokenCredential = (U2FTokenCredential) credential;
final Authentication authentication = WebUtils.getInProgressAuthentication();
if (authentication == null) {
throw new IllegalArgumentException("CAS has no reference to an authentication event to locate a principal");
}
final Principal p = authentication.getPrincipal();
final SignResponse authenticateResponse = SignResponse.fromJson(tokenCredential.getToken());
final String authJson = u2FDeviceRepository.getDeviceAuthenticationRequest(authenticateResponse.getRequestId(), p.getId());
final SignRequestData authenticateRequest = SignRequestData.fromJson(authJson);
DeviceRegistration registration = null;
try {
registration = u2f.finishSignature(authenticateRequest, authenticateResponse, u2FDeviceRepository.getRegisteredDevices(p.getId()));
return createHandlerResult(tokenCredential, p);
} catch (final DeviceCompromisedException e) {
registration = e.getDeviceRegistration();
throw new PreventedException("Device possibly compromised and therefore blocked: " + e.getMessage(), e);
} finally {
u2FDeviceRepository.authenticateDevice(p.getId(), registration);
}
}
Aggregations