use of com.yubico.webauthn.AssertionResult in project java-webauthn-server by Yubico.
the class WebAuthnServer method finishAuthentication.
public Either<List<String>, SuccessfulAuthenticationResult> finishAuthentication(String responseJson) {
logger.trace("finishAuthentication responseJson: {}", responseJson);
final AssertionResponse response;
try {
response = jsonMapper.readValue(responseJson, AssertionResponse.class);
} catch (IOException e) {
logger.debug("Failed to decode response object", e);
return Either.left(Arrays.asList("Assertion failed!", "Failed to decode response object.", e.getMessage()));
}
AssertionRequestWrapper request = assertRequestStorage.getIfPresent(response.getRequestId());
assertRequestStorage.invalidate(response.getRequestId());
if (request == null) {
return Either.left(Arrays.asList("Assertion failed!", "No such assertion in progress."));
} else {
try {
AssertionResult result = rp.finishAssertion(FinishAssertionOptions.builder().request(request.getRequest()).response(response.getCredential()).build());
if (result.isSuccess()) {
try {
userStorage.updateSignatureCount(result);
} catch (Exception e) {
logger.error("Failed to update signature count for user \"{}\", credential \"{}\"", result.getUsername(), response.getCredential().getId(), e);
}
return Either.right(new SuccessfulAuthenticationResult(request, response, userStorage.getRegistrationsByUsername(result.getUsername()), result.getUsername(), sessions.createSession(result.getUserHandle())));
} else {
return Either.left(Collections.singletonList("Assertion failed: Invalid assertion."));
}
} catch (AssertionFailedException e) {
logger.debug("Assertion failed", e);
return Either.left(Arrays.asList("Assertion failed!", e.getMessage()));
} catch (Exception e) {
logger.error("Assertion failed", e);
return Either.left(Arrays.asList("Assertion failed unexpectedly; this is likely a bug.", e.getMessage()));
}
}
}
Aggregations