public class SyncUser extends Object
A user can log in to the Realm Object Server, and if access is granted, it is possible to synchronize the local and the remote Realm. Moreover, synchronization is halted when the user is logged out.
It is possible to persist a user. By retrieving a user, there is no need to log in to the 3rd party provider again. Persisting a user between sessions, the user's credentials are stored locally on the device, and should be treated as sensitive data.
Modifier and Type | Class and Description |
---|---|
static interface |
SyncUser.Callback |
Modifier and Type | Method and Description |
---|---|
static Collection<SyncUser> |
all()
Returns all valid users known by this device.
|
static SyncUser |
currentUser()
Returns the last user that has logged in and who is still valid.
|
boolean |
equals(Object o) |
static SyncUser |
fromJson(String user)
Loads a user that has previously been serialized using
toJson() . |
String |
getAccessToken()
Returns this user's access token.
|
String |
getIdentity()
Returns the identity of this user on the Realm Object Server.
|
Realm |
getManagementRealm()
Returns an instance of the Management Realm owned by the user.
|
int |
hashCode() |
boolean |
isValid()
Returns
true if the user is logged into the Realm Object Server. |
static SyncUser |
login(SyncCredentials credentials,
String authenticationUrl)
Logs in the user to the Realm Object Server.
|
static RealmAsyncTask |
loginAsync(SyncCredentials credentials,
String authenticationUrl,
SyncUser.Callback callback)
Logs in the user to the Realm Object Server.
|
void |
logout()
Logs out the user from the Realm Object Server.
|
String |
toJson()
Returns a JSON token representing this user.
|
public static SyncUser currentUser()
SyncUser
that has logged in and who is still valid. null
if no current user or user has
been invalidated.public static Collection<SyncUser> all()
public static SyncUser fromJson(String user)
toJson()
.user
- JSON string representing the user.IllegalArgumentException
- if the JSON couldn't be converted to a valid SyncUser
object.public static SyncUser login(SyncCredentials credentials, String authenticationUrl) throws ObjectServerError
SyncConfiguration
.credentials
- credentials to use.authenticationUrl
- server that can authenticate against.ObjectServerError
- if the login failed.IllegalArgumentException
- if the URL is malformed.public static RealmAsyncTask loginAsync(SyncCredentials credentials, String authenticationUrl, SyncUser.Callback callback)
SyncConfiguration
.credentials
- credentials to use.authenticationUrl
- server that the user is authenticated against.callback
- callback when login has completed or failed. The callback will always happen on the same thread
as this this method is called on.IllegalArgumentException
- if not on a Looper thread.public void logout()
AuthenticationListener
will be notified and user credentials will be deleted from this device.IllegalStateException
- if any Realms owned by this user is still open. They should be closed before
logging out.public String toJson()
Possession of this JSON token can potentially grant access to data stored on the Realm Object Server, so it should be treated as sensitive data.
fromJson(String)
.fromJson(String)
public boolean isValid()
true
if the user is logged into the Realm Object Server. If this method returns true
it
implies that the user has valid credentials that have not expired.
The user might still be have been logged out by the Realm Object Server which will not be detected before the
user tries to actively synchronize a Realm. If a logged out user tries to synchronize a Realm, an error will be
reported to the SyncSession.ErrorHandler
defined by
SyncConfiguration.Builder.errorHandler(SyncSession.ErrorHandler)
.
true
if the User is logged into the Realm Object Server, false
otherwise.public String getIdentity()
null
is returned.public String getAccessToken()
null
is returned.public Realm getManagementRealm()
This Realm can be used to control access and permissions for Realms owned by the user. This includes giving other users access to Realms.