Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class InMemoryTotpRepository
- Object
- InMemoryTotpRepository
ImplementsTotpRepository
Secrets kept in this process: gone when it stops. For development and
tests; see
JdbcTotpRepository otherwise.Constructors
public InMemoryTotpRepository() |
Methods
public synchronized void save(String username, byte[] secret) | Stores a new, unconfirmed secret for username, replacing any other. |
public synchronized TotpCredential find(String username) | The credential of username, or null. |
public synchronized boolean confirm(String username) | Marks the credential confirmed, if it is there and was not. |
public synchronized boolean advance(String username, long step) | Records that a code of time step step was accepted, if no code of that step or a later one has been. |
public synchronized boolean confirm(String username, byte[] expectedSecret, long step) | Confirms and consumes a code only if the current, unconfirmed credential still has the secret that was verified. |
public synchronized boolean advance(String username, byte[] expectedSecret, long step) | Consumes a sign-in code only if the confirmed credential still has the verified secret and its last accepted step is lower. |
public synchronized boolean delete(String username) | Forgets the credential. |
Inherited methods
Constructor details
InMemoryTotpRepository
public InMemoryTotpRepository()Method details
save
public synchronized void save(String username, byte[] secret)Stores a new, unconfirmed secret for
username, replacing any other.find
public synchronized TotpCredential find(String username)The credential of
username, or null.confirm
public synchronized boolean confirm(String username)Marks the credential confirmed, if it is there and was not.
Returns
whether this call confirmed it
advance
public synchronized boolean advance(String username, long step)Records that a code of time step step was accepted, if no code of
that step or a later one has been.
The test and the change are one step, which is what makes a code good once: of two requests presenting the same code at the same moment, on one server or two, exactly one is told true.
Returns
whether this call recorded it
confirm
public synchronized boolean confirm(String username, byte[] expectedSecret, long step)Confirms and consumes a code only if the current, unconfirmed credential
still has the secret that was verified. The comparison and both changes
must be atomic, including across servers sharing a database.
advance
public synchronized boolean advance(String username, byte[] expectedSecret, long step)Consumes a sign-in code only if the confirmed credential still has the
verified secret and its last accepted step is lower. This is one atomic change.
delete
public synchronized boolean delete(String username)Forgets the credential.
Returns
whether there was one