ArchitectureComponentsUser Management

User Management

The user-specific classes in the code serve to manage user data and operations in the system, including creating, updating, deleting, and retrieving users.

  1. AbstractUserController: This class sets up the HTTP endpoints for user management under /v1/users. It provides the ability to perform operations such as creating, retrieving, updating, deleting users, as well as managing session termination. It also caters to the currently authenticated user with specific endpoints.

  2. UserDto: This Data Transfer Object is responsible for carrying user-specific data between various processes. With fields like id, email, firstName, lastName, phone, mobile, password, locale, and roles, it aids in handling data during creating and updating operations.

  3. AbstractBaseUser: Serving as the model, this class extends the AbstractBaseModel and implements the UserDetails interface, providing fundamental fields and methods necessary to handle user data.

  4. AbstractUserService: This abstract class serves as the service layer, providing crucial methods for pre-processing and post-processing during creation and updating of users. The service includes methods for password sanitization, role resolution, conversion from DTO to entity, and specific operations for the currently logged-in user like self-update and password updating. It also has a method for generating a nonce, creating a default user, and converting a Principal object into a user.

Combined, these classes provide a comprehensive structure for managing users in the system - from the HTTP interface down to data handling and processing logic. This makes user management secure, efficient, and flexible to handle various user-related requirements.

Endpoints

FunctionExplanationHTTP-Method
findAll()Fetches all instances of a particular entity, with support for pagination.GET
findById(@PathVariable("id") @NotNull final ID id)Fetches an entity by its ID.GET
create(@Valid @RequestBody @NotNull final USERDTO user)Creates a new user from the provided user data.POST
updateObject(@PathVariable("id") @NotNull final ID id, @Valid @RequestBody @NotNull final USERDTO user)Updates an existing user with new user data.PUT
update(@PathVariable("id") final ID id, @NotNull @RequestBody Map<String, Object> userFields)Applies a partial update (patch) to a user.PATCH
delete(@PathVariable("id") @NotNull final ID id)Deletes a user by its ID.DELETE
terminate(@PathVariable @NotNull final ID id)Terminates all sessions of a given user.POST
getMe(@Parameter(hidden = true) @AuthenticationPrincipal final USER user)Retrieves the currently logged-in user.GET
updateMe(@Parameter(hidden = true) @AuthenticationPrincipal final USER user, @Valid @NotNull @RequestBody final USERDTO updateInformation)Updates the currently logged-in user by passing the entire update object.PUT
updateMePartial(@Parameter(hidden = true) @AuthenticationPrincipal final USER user, @NotNull @RequestBody final Map<String, Object> userFields)Updates the currently logged-in user by passing individual fields.PATCH
updatePassword(@Parameter(hidden = true) @AuthenticationPrincipal final USER user, @NotNull @Valid @RequestBody final PasswordUpdateRequest updateRequest)Changes the currently logged-in user’s password.PUT
getMyRoles(@Parameter(hidden = true) @AuthenticationPrincipal final USER user)Retrieves the currently logged-in user’s roles.GET
getMyRights(@Parameter(hidden = true) @AuthenticationPrincipal final USER user)Retrieves the currently logged-in user’s rights / permissions.GET
collectionOptions()Returns the allowed HTTP methods for the collection.OPTIONS

Model

Database Model

FieldDescriptionConstraints
idThe unique identifier for the user.
created_atThe date and time when the user was created.
created_byThe entity who created this user.
updated_atThe date and time when the user was last updated.
updated_byThe entity who last updated this user.
emailThe user’s email address.Not Empty, Email, Unique, Max length: 150
enabledIndicates if the user account is enabled or disabled.Default: true
failed_login_attemptsNumber of times the user unsuccessfully attempted to login.Default: 0
first_nameThe user’s first name.Not Empty
last_nameThe user’s last name.Not Empty
localeThe user’s locale.Not Null, Default: German
login_disabledIndicates if the user’s login is disabled.Default: false
mobileThe user’s mobile number.
nonceA random, one-time number used in authentication processes.
passwordThe user’s encrypted password.JSON Property Access: Write Only
password_reset_tokenThe token used when resetting the user’s password.
phoneThe user’s phone number.
rolesThe roles names assigned to the user.Not Null
sourceThe source from which the user was created.

Output

{
    "id": 1,
    "firstName": "Admin",
    "lastName": "User",
    "phone": null,
    "mobile": null,
    "email": "admin@frachtwerk.de",
    "locale": "de",
    "roles":
      [{
        "name": "ADMIN",
        "description": "Application Admin",
        "rights": [
            {
                "authority": "USER_DELETE",
                "description": ""
            },
            {
            "..."
            }
            {
                "authority": "TRANSLATION_UPDATE",
                "description": ""
            }
        ],
        "protected": true,
        "editable": false,
        "systemRole": true,
        "defaultRole": true
    },
    {
        "name": "USER",
        "description": "User",
         "..."
        }]
}