Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.

public interface UserCredentialRepository

Known subtypesInMemoryUserCredentialRepository, JdbcUserCredentialRepository

Where the passkeys users have registered are kept.

InMemoryUserCredentialRepository keeps them in this process, for a test or a demonstration; JdbcUserCredentialRepository keeps them in the server’s database. Both do the two things the ceremonies depend on as one step each, so that two requests at once cannot both pass:

  • save stores a credential only when no credential has its id, whoever it belongs to;
  • advance moves the signature counter forward and never back.

Methods

public abstract boolean save(CredentialRecord record)Stores a new credential.
public abstract CredentialRecord findByCredentialId(byte[] credentialId)The credential with this id, or null.
public abstract List<CredentialRecord> findByUserId(byte[] userEntityUserId)The credentials of the user with this handle, oldest first; empty when they have none.
public abstract boolean advance(byte[] credentialId, long signatureCount, boolean uvInitialized, boolean backupState, long lastUsed)Records a sign-in: the counter the authenticator sent, the flags it sent, and when.
public abstract boolean delete(byte[] credentialId)Removes a credential.

Method details

save

public abstract boolean save(CredentialRecord record)
Stores a new credential.

Returns

false, and nothing stored, when a credential with this id is there already – this user’s or another’s

findByCredentialId

public abstract CredentialRecord findByCredentialId(byte[] credentialId)
The credential with this id, or null.

findByUserId

public abstract List<CredentialRecord> findByUserId(byte[] userEntityUserId)
The credentials of the user with this handle, oldest first; empty when they have none.

advance

public abstract boolean advance(byte[] credentialId, long signatureCount, boolean uvInitialized, boolean backupState, long lastUsed)

Records a sign-in: the counter the authenticator sent, the flags it sent, and when.

The counter is taken only when it is greater than the one stored – or when both are zero, which is an authenticator that keeps no counter. One statement decides and stores, so of two requests with the same assertion one is refused.

Returns

false, and nothing changed, when the counter did not advance or the credential is gone

delete

public abstract boolean delete(byte[] credentialId)
Removes a credential.

Returns

whether there was one