- java.lang.Object
-
- com.gluonhq.cloudlink.client.user.UserClient
-
public class UserClient extends Object
The UserClient handles user authentication for a Gluon Mobile application. It loads the list of login methods that are available for the configured Gluon CloudLink application. When authentication is started through the
authenticate
method, it will load an available implementation ofAuthenticationView
that provides a way to let the user login using one of the login methods. The view is loaded by callingAuthenticationView.authenticate(Authenticator)
and passing a proper implementation of theauthenticator
. During the authentication process, proper methods on the authenticator should be called by theAuthenticationView
.Note: authenticated user information will be stored in the private storage location for the application on the device. This information lets the user sign in automatically, the next time the application is opened. As a result, the UserClient depends on the
StorageService
, so make sure that the storage plugin has been enabled in your Gluon Mobile application configuration:<dependency> <groupId>com.gluonhq.attach</groupId> <artifactId>storage</artifactId> <version>${attach.version}</version> </dependency> ... <plugin> <groupId>com.gluonhq</groupId> <artifactId>client-maven-plugin</artifactId> <version>${client.plugin.version}</version> <configuration> <attachList> <list>storage</list> </attachList> </configuration> </plugin>
- See Also:
Authenticator
,AuthenticationView
-
-
Property Summary
Properties Type Property Description ReadOnlyObjectProperty<User>
authenticatedUser
A property that holds the currently authenticated user.
-
Constructor Summary
Constructors Constructor Description UserClient()
Create an instance of a UserClient.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
authenticate(Consumer<User> successConsumer)
Start the authentication flow.void
authenticate(Consumer<User> successConsumer, Consumer<String> failureConsumer)
Start the authentication flow.ReadOnlyObjectProperty<User>
authenticatedUserProperty()
A property that holds the currently authenticated user.User
getAuthenticatedUser()
Gets the value of the property authenticatedUser.boolean
isAuthenticated()
Check whether the application is successfully authenticated with a user.void
signOut()
Sign out the currently logged in user.
-
-
-
Property Detail
-
authenticatedUser
public ReadOnlyObjectProperty<User> authenticatedUserProperty
A property that holds the currently authenticated user. The property can contain anull
value if no user is currently authenticated.- See Also:
getAuthenticatedUser()
-
-
Constructor Detail
-
UserClient
public UserClient()
Create an instance of a UserClient. It retrieves the currently authenticated user information from the private storage for the application on the device. It also tries to load an implementation ofAuthenticationView
. If a valid implementation is found, it creates an instance ofAuthenticationProvider
and sets it on the view. When no valid implementation could be constructed, authentication will not be enabled for this UserClient instance.
-
-
Method Detail
-
isAuthenticated
public boolean isAuthenticated()
Check whether the application is successfully authenticated with a user.- Returns:
true
when an authenticated user is available,false
otherwise.
-
getAuthenticatedUser
public User getAuthenticatedUser()
Gets the value of the property authenticatedUser. The returned value can benull
when no user is currently authenticated.- Returns:
- The current authenticated user or
null
if no user is authenticated.
-
authenticatedUserProperty
public ReadOnlyObjectProperty<User> authenticatedUserProperty()
A property that holds the currently authenticated user. The property can contain anull
value if no user is currently authenticated.- See Also:
getAuthenticatedUser()
-
authenticate
public void authenticate(Consumer<User> successConsumer)
Start the authentication flow. When authentication has completed successfully, the provided consumer will be called, providing the authenticated user as the input argument. If a user was already authenticated when making this call, the consumer will be called immediately.- Parameters:
successConsumer
- a consumer that will be called when authentication has completed successfully
-
authenticate
public void authenticate(Consumer<User> successConsumer, Consumer<String> failureConsumer)
Start the authentication flow. When authentication has completed successfully, the provided successConsumer will be called, providing the authenticated user as the input argument. If a user was already authenticated when making this call, the consumer will be called immediately. If authentication has completed with a failure or was aborted by the user, the provided failureConsumer will be called instead, providing an informational message string as the input argument.Both the
successConsumer
and thefailureConsumer
can benull
. If a consumer isnull
no notification will be available on the caller of this method.- Parameters:
successConsumer
- a consumer that will be called when authentication has completed successfullyfailureConsumer
- a consumer that will be called when authentication has failed or was aborted by the user
-
signOut
public void signOut()
Sign out the currently logged in user. Calling this method when no user is authenticated, will do nothing.
-
-