Class User

  • All Implemented Interfaces:
    Serializable

    public final class User
    extends Object
    implements Serializable
    Identifies the user on whose behalf an operation is performed.

    This is a shared-kernel type: a user means the same thing in every bounded context, so contexts should accept this model in their service signatures instead of declaring a user model of their own. It carries nothing but the identity of the user — no permissions, no roles, no context-specific state. Authorization decisions are made by the authorization context (see fc-user-access) based on this identity, never by inspecting this model.

    Since:
    8.5.6
    Author:
    Norman Lorenz
    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      User​(@NonNull org.pac4j.core.profile.UserProfile pac4jProfile)
      Creates a new User instance.
    • Constructor Detail

      • User

        public User​(@NonNull
                    @NonNull org.pac4j.core.profile.UserProfile pac4jProfile)
        Creates a new User instance.
        Parameters:
        pac4jProfile - The pac4j user profile which was returned by the authentication client for this user. Never null.
    • Method Detail

      • system

        public static User system()
        The user the system itself acts as, for an operation it performs on its own behalf rather than for a signed-in user, such as a reaction to an event or a scheduled job.

        A new instance each time, because a pac4j profile is mutable and a shared one could be changed by any caller. Instances are still equal to one another, so a caller can test for the system user.

        Returns:
        the system user. Never null.
        Since:
        8.5.6
      • getDisplayName

        public String getDisplayName()
        Determines a name for this user that is suitable for displaying it to other humans, e.g. in the GUI or in log messages. Derived from the pac4j profile: the display name if the profile has one, otherwise the first and family name, otherwise whichever of the two is present.
        Returns:
        a human-readable name for this user, or null if none could be determined from the profile.
        Since:
        8.5.6
      • equals

        public boolean equals​(Object other)

        Two users are equal when they refer to the same principal, i.e. when the client name and ID of their pac4j profiles match.

        Overrides:
        equals in class Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object
      • getPac4jProfile

        @NonNull
        public @NonNull org.pac4j.core.profile.UserProfile getPac4jProfile()
        The pac4j user profile which was returned by the authentication client for this user. Never null.