public class SqrlAutoCloseablePersistence extends Object implements SqrlPersistence, AutoCloseable
SqrlPersistence which, when auto-closed, will call
SqrlPersistence.closeRollback() unless a close method was already called; Users must still call
SqrlPersistence.closeCommit() during the happy path as the java try-with-resources semantics gives us no
way of knowing if an exception was thrown or not
While it is an unfortunate tradeoff to have deviate from the standard try-with-resources pattern, this is the only way we can ensure rollback gets called when both checked and unchecked exceptions occur
| Constructor and Description |
|---|
SqrlAutoCloseablePersistence(SqrlPersistence sqrlPersistence) |
| Modifier and Type | Method and Description |
|---|---|
void |
cleanUpExpiredEntries()
Delete any expired objects in the persistence store
|
void |
close() |
void |
closeCommit()
Commit all updates since this persistence object was created
|
void |
closeRollback()
Ignore all updates since this persistence object was created
|
void |
createAndEnableSqrlIdentity(String sqrlIdk,
Map<String,String> identityDataTable)
Create a new
SqrlIdentity and enable SQRL authentication |
SqrlCorrelator |
createCorrelator(String correlatorString,
Date expiryTime)
Create a new correlator instance in the persistence
|
void |
deleteSqrlCorrelator(SqrlCorrelator sqrlCorrelator) |
void |
deleteSqrlIdentity(String sqrlIdk)
Invoked when the user chooses to remove SQRL authentication for this site
|
boolean |
doesSqrlIdentityExistByIdk(String sqrlIdk)
Check persistence to see if a user exists with the given sqrlIdk
|
SqrlCorrelator |
fetchSqrlCorrelator(String correlator)
Fetch the correlator object for the given string value
|
SqrlCorrelator |
fetchSqrlCorrelatorRequired(String correlator)
Fetch the correlator object for the given string value, or throw an exception if it does not exist
|
Map<String,SqrlCorrelator> |
fetchSqrlCorrelatorsDetached(Set<String> correlatorStringSet) |
Map<String,SqrlAuthenticationStatus> |
fetchSqrlCorrelatorStatusUpdates(Map<String,SqrlAuthenticationStatus> correlatorToCurrentStatusTable)
Checks for correlators who's status has changed or is
SqrlAuthenticationStatus.AUTH_COMPLETE. |
Boolean |
fetchSqrlFlagForIdentity(String sqrlIdk,
SqrlFlag flagToFetch)
Invoked to determine if SQRL auth is enabled for a user
|
SqrlIdentity |
fetchSqrlIdentityByUserXref(String appUserXref)
Fetch the sqrl identity for the the given app user cross reference id
|
String |
fetchSqrlIdentityDataItem(String sqrlIdk,
String toFetch)
Request to the data store to retrieve user specific SQRL data that was previously stored via
#userAuthenticatedViaSqrl(String, String, Map) |
String |
fetchTransientAuthData(String correlator,
String transientNameServerParrot)
Fetch a short lived name/value for a given correlator and name
|
boolean |
hasTokenBeenUsed(String nutTokenString)
Check persistence to see if this token has already been used
|
boolean |
isClosed() |
void |
markTokenAsUsed(String nutTokenString,
Date expiryTime)
Mark the given token as used in persistence.
|
void |
setSqrlFlagForIdentity(String sqrlIdk,
SqrlFlag flagToSet,
boolean valueToSet)
Invoked when the user chooses to temporarily disable SQRL authentication for this site
|
void |
storeSqrlDataForSqrlIdentity(String sqrlIdk,
Map<String,String> dataToStore)
Indicates that we have received user specific data from the SQRL client that needs to be stored for the user;
NOTE this is often the first call made for a new SQRL identity, so if the identity does not currently
exist, it must be created
|
void |
updateIdkForSqrlIdentity(String previousSqrlIdk,
String newSqrlIdk)
The user has updated their SQRL ID but this application is still using the old one.
|
void |
updateNativeUserXref(long sqrlIdentityId,
String nativeUserXref)
Called to assign a native user cross reference to the given SQRL identity object so when SQRL authentication
takes place, the application knows which user has authenticated
|
void |
userAuthenticatedViaSqrl(String sqrlIdk,
String correlator)
Indicates that a user was authenticated successfully via SQRL.
|
public SqrlAutoCloseablePersistence(SqrlPersistence sqrlPersistence)
public void close()
close in interface AutoCloseablepublic void createAndEnableSqrlIdentity(String sqrlIdk, Map<String,String> identityDataTable)
SqrlPersistenceSqrlIdentity and enable SQRL authenticationcreateAndEnableSqrlIdentity in interface SqrlPersistencesqrlIdk - the idk of the SQRL identityidentityDataTable - auth data for this SQRL identitypublic boolean doesSqrlIdentityExistByIdk(String sqrlIdk)
SqrlPersistencedoesSqrlIdentityExistByIdk in interface SqrlPersistencesqrlIdk - the SQRL ID to check forpublic SqrlIdentity fetchSqrlIdentityByUserXref(String appUserXref)
SqrlPersistencefetchSqrlIdentityByUserXref in interface SqrlPersistenceappUserXref - the app user cross reference value to search bypublic void updateIdkForSqrlIdentity(String previousSqrlIdk, String newSqrlIdk)
SqrlPersistenceupdateIdkForSqrlIdentity in interface SqrlPersistencepreviousSqrlIdk - the old SQRL ID, which is present in persistencenewSqrlIdk - the new SQRL ID, which should replace previousSqrlIdk in persistencepublic void deleteSqrlIdentity(String sqrlIdk)
SqrlPersistencedeleteSqrlIdentity in interface SqrlPersistencesqrlIdk - the SQRL ID which represents the user.public void updateNativeUserXref(long sqrlIdentityId,
String nativeUserXref)
SqrlPersistenceupdateNativeUserXref in interface SqrlPersistencesqrlIdentityId - the SQRL identity to updatenativeUserXref - the applications native user id for this userpublic void userAuthenticatedViaSqrl(String sqrlIdk, String correlator)
SqrlPersistence
userAuthenticatedViaSqrl in interface SqrlPersistencesqrlIdk - the SQRL ID which the user authenticated with.correlator - The correlator ID that was generated when the login page was presented and embedded in the sqrl urlpublic Boolean fetchSqrlFlagForIdentity(String sqrlIdk, SqrlFlag flagToFetch)
SqrlPersistencefetchSqrlFlagForIdentity in interface SqrlPersistencesqrlIdk - the SQRL ID which represents the user.SqrlEaabledState#NOT_EXIST if there is nonepublic void setSqrlFlagForIdentity(String sqrlIdk, SqrlFlag flagToSet, boolean valueToSet)
SqrlPersistencesetSqrlFlagForIdentity in interface SqrlPersistencesqrlIdk - the SQRL ID which represents the user.public void storeSqrlDataForSqrlIdentity(String sqrlIdk, Map<String,String> dataToStore)
SqrlPersistencestoreSqrlDataForSqrlIdentity in interface SqrlPersistencesqrlIdk - the SQRL ID which the user authenticated with.dataToStore - SQRL related data that must be persisted for this user and be retreivable via
SqrlPersistence.fetchSqrlIdentityDataItem(String, String)public String fetchSqrlIdentityDataItem(String sqrlIdk, String toFetch)
SqrlPersistence#userAuthenticatedViaSqrl(String, String, Map)
fetchSqrlIdentityDataItem in interface SqrlPersistencesqrlIdk - the SQRL ID which the user authenticated with.toFetch - The name of the SQRL data to be fetched. Was the key in the Map whenpublic boolean hasTokenBeenUsed(String nutTokenString)
SqrlPersistencehasTokenBeenUsed in interface SqrlPersistencenutTokenString - the SqrlNutToken token in sqbase64 format as received from the client the token sent by the
SQRL client in the requestpublic void markTokenAsUsed(String nutTokenString, Date expiryTime)
SqrlPersistence#hasTokenBeenUsed(SqrlNutToken) must return true for this token until expiryTime. Once the expiryTime has
been reached, persistence cleanup can occur and this token can be deleted from persistencemarkTokenAsUsed in interface SqrlPersistencenutTokenString - the SqrlNutToken token in sqbase64 format as received from the clientexpiryTime - the time at which this token can safely be deleted from persistence since it will fail timestamp
validationpublic String fetchTransientAuthData(String correlator, String transientNameServerParrot)
SqrlPersistencefetchTransientAuthData in interface SqrlPersistencecorrelator - correlator to which this data belongspublic SqrlCorrelator createCorrelator(String correlatorString, Date expiryTime)
SqrlPersistencecreateCorrelator in interface SqrlPersistencecorrelatorString - the correlator value stringexpiryTime - the time at which this correlator expirespublic SqrlCorrelator fetchSqrlCorrelator(String correlator)
SqrlPersistencefetchSqrlCorrelator in interface SqrlPersistencecorrelator - the string value to search forpublic SqrlCorrelator fetchSqrlCorrelatorRequired(String correlator)
SqrlPersistencefetchSqrlCorrelatorRequired in interface SqrlPersistencecorrelator - the string value to search forpublic void closeCommit()
SqrlPersistencecloseCommit in interface SqrlPersistencepublic void closeRollback()
SqrlPersistencecloseRollback in interface SqrlPersistencepublic boolean isClosed()
isClosed in interface SqrlPersistencepublic void cleanUpExpiredEntries()
SqrlPersistencecleanUpExpiredEntries in interface SqrlPersistencepublic Map<String,SqrlCorrelator> fetchSqrlCorrelatorsDetached(Set<String> correlatorStringSet)
fetchSqrlCorrelatorsDetached in interface SqrlPersistencepublic Map<String,SqrlAuthenticationStatus> fetchSqrlCorrelatorStatusUpdates(Map<String,SqrlAuthenticationStatus> correlatorToCurrentStatusTable)
SqrlPersistenceSqrlAuthenticationStatus.AUTH_COMPLETE. Complete
state is always returned in case the client didn't get the update the first time it was sentfetchSqrlCorrelatorStatusUpdates in interface SqrlPersistencecorrelatorToCurrentStatusTable - table of string correlators and their current state as sent by the browserpublic void deleteSqrlCorrelator(SqrlCorrelator sqrlCorrelator)
deleteSqrlCorrelator in interface SqrlPersistenceCopyright © 2016. All rights reserved.