Class 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 of AuthenticationView that provides a way to let the user login using one of the login methods. The view is loaded by calling AuthenticationView.authenticate(Authenticator) and passing a proper implementation of the authenticator. During the authentication process, proper methods on the authenticator should be called by the AuthenticationView.

    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 Detail

      • authenticatedUser

        public ReadOnlyObjectProperty<User> authenticatedUserProperty
        A property that holds the currently authenticated user. The property can contain a null 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 of AuthenticationView. If a valid implementation is found, it creates an instance of AuthenticationProvider 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 be null 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 a null 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 the failureConsumer can be null. If a consumer is null no notification will be available on the caller of this method.

        Parameters:
        successConsumer - a consumer that will be called when authentication has completed successfully
        failureConsumer - 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.