Backend API. Server-side code: this runs in a Codename One backend, not in the app on the device.
public final class JdbcTokenRepository
- Object
- JdbcTokenRepository
ImplementsPersistentTokenRepository
Remembered sign-ins kept in the server’s database, in the
cn1_persistent_logins table of SecuritySchema, so that any process of a
deployment recognizes a cookie any other issued.
http.rememberMe(remember -> remember.tokenRepository(new JdbcTokenRepository(dataSource)));
A token is replaced by one UPDATE that names the hash it expects to find,
and counted as replaced only when that changed exactly one row.
Constructors
public JdbcTokenRepository(DataSource dataSource) |
Methods
public void createNewToken(PersistentRememberMeToken token) | Stores a new series. |
public boolean updateToken(String series, String expectedTokenHash, String newTokenHash, long lastUsed) | Replaces the token of series, if it is still expectedTokenHash. |
public PersistentRememberMeToken getTokenForSeries(String series) | The stored token of series, or null. |
public void removeToken(String series) | Forgets one series: one browser. |
public void removeUserTokens(String username) | Forgets every series of a user: every browser they were remembered in. |
public List<PersistentRememberMeToken> getTokensForUser(String username) | Every series of a user, most recently used first. |
public boolean removeUserToken(String username, String series) | Removes the series in one statement that names its owner, so it cannot remove another user’s. |
public int deleteExpired(long now, long olderThanSeconds)
throws IOException |
Inherited methods
Constructor details
JdbcTokenRepository
public JdbcTokenRepository(DataSource dataSource)Method details
createNewToken
public void createNewToken(PersistentRememberMeToken token)updateToken
public 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
getTokenForSeries
public PersistentRememberMeToken getTokenForSeries(String series)series, or null.removeToken
public void removeToken(String series)removeUserTokens
public void removeUserTokens(String username)getTokensForUser
public List<PersistentRememberMeToken> getTokensForUser(String username)Parameters
usernameString- the user, matched ignoring case as sign-in does
removeUserToken
public boolean removeUserToken(String username, String series)Returns
deleteExpired
public int deleteExpired(long now, long olderThanSeconds)
throws IOException