Interface UserInfo

All Known Subinterfaces:
ModifiableUserInfo

public interface UserInfo
Interface to fetch user and authorization information.

The current user refers to the authenticated user for whom the request context has been opened. All user information like ids, names, roles, tenant and user attributes are assumed to be verified, i.e. they are secured by adequate means like JWT verification.

  • Method Details

    • create

      static ModifiableUserInfo create()
      Creates a ModifiableUserInfo based on default values of a clear UserInfo.
      Returns:
      The created ModifiableUserInfo instance.
    • getId

      default String getId()
      Returns the verified user id of the request's authenticated user.
      Returns:
      The user id.
    • getName

      String getName()
      Returns the verified user name of the request's authenticated user.
      Returns:
      The user name.
    • getTenant

      default String getTenant()
      Returns the verified tenant of the request's authenticated user.
      Returns:
      The tenant of the user.
    • isSystemUser

      default boolean isSystemUser()
      Returns true if the user is a system user and not a named user.
      Returns:
      true if the user is a system user and not a named user.
    • isInternalUser

      default boolean isInternalUser()
      Returns true if the user is the internal user.
      Returns:
      true if the user is the internal user.
    • isAuthenticated

      boolean isAuthenticated()
      Returns true if UserInfo is filled with data of an authenticated user.
      Returns:
      true if UserInfo is filled with data of an authenticated user.
    • isPrivileged

      default boolean isPrivileged()
      Returns true if UserInfo is a privileged user, i.e. passes all authorization checks. Privileged users can only be used internally.
      Returns:
      true if UserInfo is a privileged user.
    • hasRole

      default boolean hasRole(String role)
      Checks if the current user is associated with the specified user role.
      Parameters:
      role - The name of the role.
      Returns:
      true if role is present, false otherwise.
    • getRoles

      default Set<String> getRoles()
      Returns the List of granted user roles.
      Returns:
      the List of roles.
    • getAttributeValues

      default List<String> getAttributeValues(String attribute)
      Returns a List of values of the specified attribute as presented in the request.
      Parameters:
      attribute - The name of the attribute.
      Returns:
      The value of the attribute or an empty list if no values are present.
    • getAttributes

      default Map<String,List<String>> getAttributes()
      Returns all user attributes as a Map.
      Returns:
      The user attributes.
    • isUnrestrictedAttribute

      @Deprecated default boolean isUnrestrictedAttribute(String attribute)
      Deprecated.
      Returns true if the passed attribute is unrestricted, i.e. the current user has no restrictions with respect to this attribute.
      Parameters:
      attribute - The name of the attribute.
      Returns:
      true if unrestricted, false otherwise.
    • getUnrestrictedAttributes

      @Deprecated default Set<String> getUnrestrictedAttributes()
      Deprecated.
      Returns the Set of unrestricted attributes of the user.
      Returns:
      the Set of unrestricted attributes.
    • getAdditionalAttribute

      default Object getAdditionalAttribute(String name)
      Returns additional attribute with given name if existing.
      Parameters:
      name - The name of the attribute.
      Returns:
      The attribute value as Object.
    • getAdditionalAttributes

      default Map<String,Object> getAdditionalAttributes()
      Returns all additional attributes as Map.
      Returns:
      The additional attributes,
    • as

      default <T extends UserInfo> T as(Class<T> concreteUserInfoClazz)
      Provides type-safe access to UserInfo and additional attributes. Creates a concrete proxy instance implementing UserInfo and a sub interface concreteUserInfoClazz which has a concrete API for the additional attributes according to the chosen authentication.

      Example:

      XsuaaUserInfo xsuaaUser = eventContext.getUserInfo().as(XsuaaUserInfo.class);
      Type Parameters:
      T - the type of the concrete UserInfo interface.
      Parameters:
      concreteUserInfoClazz - The sub interface providing the concrete API of additional attributes.
      Returns:
      A concrete proxy instance implementing UserInfo and concreteUserInfoClazz.
    • copy

      default ModifiableUserInfo copy()
      Creates a ModifiableUserInfo based on this UserInfo.
      Returns:
      The created ModifiableUserInfo instance.