JBStrap user handling

The following section will discuss the login, logout and user identification processes. The Framework provides the basic classes for this. These classes must be used to allow the framework to handle user data. These classes are the CurrentUser and Role classes.

CurrentUser

This class represents a user in the framework. This is where you should store the user data, such as:

  • uuid : The user’s unique ID. This is a textual value, that must be specified. It can be any text, but it must be unique.
  • userName : The user’s username. This is a textual value, that must be specified. This is name is used during the login, and this is the name that is stored in the logs.
  • name : The user’s full name. Not mandatory.
  • telephoneNumber : The user’s telephone number. Not mandatory.
  • email : The user’s E-mail address. Not mandatory.
  • roles : The user’s roles. This information must be specified in a list that contains Role objects. A user can have multiple roles.
  • currentRole : The user’s current role. This must be specified as a Role Object. This Role must also be listed in the user’s roles (see above). The Role specified here will be used when the user logs in, which is used to determine the user’s access rights.

If these are not sufficient for you, you can create a custom user class, in which you can store additional information. This custom user class has only one requirement, it must extend the CurrentUser class.

Example for creating a custom user class, that adds user age as an additional information:

This MyUser class can be used the same way as the CurrentUser class, only you can use the user’s age as well.

Retrieving a logged in user

You may need to retrieve a user in the application and the framework provides multiple solutions for this. You can query the user on the client object, and through the UI object. You will receive the currently logged in user’s object. By default, this is the CurrentUser class, but if you made a custom user class, you will receive that class. This allows you to have the additional information that you have specified in the custom user class.

If there is no logged in user, it will return with null.

Retrieving the user through the client class:
Retrieving the user through the UI class:
Retrieving the user in a page, after the page has been displayed:
Retrieving the user in an event handler method:
Retrieving the custom user class, using the client class: