use of demo.webauthn.data.AssertionRequestWrapper 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()));
}
}
}
use of demo.webauthn.data.AssertionRequestWrapper in project java-webauthn-server by Yubico.
the class WebAuthnServer method startAuthentication.
public Either<List<String>, AssertionRequestWrapper> startAuthentication(Optional<String> username) {
logger.trace("startAuthentication username: {}", username);
if (username.isPresent() && !userStorage.userExists(username.get())) {
return Either.left(Collections.singletonList("The username \"" + username.get() + "\" is not registered."));
} else {
AssertionRequestWrapper request = new AssertionRequestWrapper(generateRandom(32), rp.startAssertion(StartAssertionOptions.builder().username(username).build()));
assertRequestStorage.put(request.getRequestId(), request);
return Either.right(request);
}
}
Aggregations