Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public interface PersistentTokenRepository
Known subtypesInMemoryTokenRepositoryImpl, JdbcTokenRepository
Where remembered sign-ins are kept.
Methods
public abstract void createNewToken(PersistentRememberMeToken token) | Stores a new series. |
public abstract boolean updateToken(String series, String expectedTokenHash, String newTokenHash, long lastUsed) | Replaces the token of series, if it is still expectedTokenHash. |
public abstract PersistentRememberMeToken getTokenForSeries(String series) | The stored token of series, or null. |
public abstract void removeToken(String series) | Forgets one series: one browser. |
public abstract void removeUserTokens(String username) | Forgets every series of a user: every browser they were remembered in. |
public default List<PersistentRememberMeToken> getTokensForUser(String username) | Every series a user holds, for a “signed-in devices” page: one per browser or device that signed in with remember-me and has not signed out. |
public default boolean removeUserToken(String username, String series) | Revokes one series of a user, such as a device chosen on a “signed-in devices” page. |
Method details
createNewToken
public abstract void createNewToken(PersistentRememberMeToken token)Stores a new series.
updateToken
public abstract boolean updateToken(String series, String expectedTokenHash, String newTokenHash, long lastUsed)Replaces the token of series, if it is still expectedTokenHash.
The test and the change are one step: of two requests presenting the
same cookie at the same moment, one replaces the token and the other is
told it did not.
Store expectedTokenHash as the previous hash of the replacement token,
so concurrent requests can recognize the rotation for a bounded grace period.
Returns
whether this call replaced it
getTokenForSeries
public abstract PersistentRememberMeToken getTokenForSeries(String series)The stored token of
series, or null.removeToken
public abstract void removeToken(String series)Forgets one series: one browser.
removeUserTokens
public abstract void removeUserTokens(String username)Forgets every series of a user: every browser they were remembered in.
getTokensForUser
public default List<PersistentRememberMeToken> getTokensForUser(String username)Every series a user holds, for a “signed-in devices” page: one per browser
or device that signed in with remember-me and has not signed out. A
repository that cannot list throws
UnsupportedOperationException.Parameters
usernameString- the user, matched ignoring case as sign-in does
removeUserToken
public default boolean removeUserToken(String username, String series)Revokes one series of a user, such as a device chosen on a “signed-in
devices” page. A series of another user is left alone, so a series taken
from a request cannot revoke someone else’s sign-in.
Returns
whether the series belonged to the user and was removed