= UserMemento _(record)_
:Notice: Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file distributed with this work for additional information regarding copyright ownership. The ASF licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at. http://www.apache.org/licenses/LICENSE-2.0 . Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR  CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Immutable serializable value holding details about a user and its roles.

== API

[source,java]
.UserMemento.java
----
record UserMemento {
  public static final String LOGICAL_TYPE_NAME;
  public static final String AUTHORIZED_USER_ROLE;     // <.>
  UserMemento system()     // <.>
  UserMemento ofName(String name)     // <.>
  UserMemento ofNameAndRoles(String name, RoleMemento... roles)     // <.>
  UserMemento ofNameAndRoleNames(String name, String... roleNames)     // <.>
  UserMemento ofNameAndRoleNames(String name, List<String> roleNames)     // <.>
  UserMemento ofNameAndRoleNames(String name, Stream<String> roleNames)     // <.>
  String nameFormatted()
  UserMemento withRoleAdded(String role)
  boolean isCurrentUser(String userName)     // <.>
  Stream<String> streamRoleNames()
  boolean hasRoleName(String roleName)
  boolean hasSudoAccessAllRole()     // <.>
  UserMementoBuilder asBuilder()
  UserLocale asUserLocale()
  UserMementoBuilder builder(String name)
  UserMemento withRealName(String realName)
  UserMemento withAvatarUrl(URL avatarUrl)
  UserMemento withImpersonating(boolean impersonating)
  UserMemento withAuthenticationCode(String authenticationCode)
  UserMemento withAuthenticationSource(AuthenticationSource authenticationSource)
  UserMemento withMultiTenancyToken(String multiTenancyToken)
  UserMemento withLanguageLocale(Locale languageLocale)
  UserMemento withNumberFormatLocale(Locale numberFormatLocale)
  UserMemento withTimeFormatLocale(Locale timeFormatLocale)
  boolean equals(Object obj)
  int hashCode()
  String getName()     // <.>
  String getAuthenticationCode()     // <.>
  AuthenticationSource getAuthenticationSource()     // <.>
  URL getAvatarUrl()     // <.>
  String getRealName()     // <.>
  Locale getLanguageLocale()     // <.>
  Locale getnumberFormatLocale()     // <.>
  Locale getTimeFormatLocale()     // <.>
  String getMultiTenancyToken()     // <.>
  List<RoleMemento> getRoles()     // <.>
}
----

<.> xref:#AUTHORIZED_USER_ROLE[AUTHORIZED_USER_ROLE]
+
--
Also used by the wicket-viewer and its AuthorizeInstantiation(...) annotations; the actual value is arbitrary; however, we use namespace style to clarify the origin
--
<.> xref:#system_[system()]
+
--
The framework's internal user with unrestricted privileges.
--
<.> xref:#ofName_String[ofName(String)]
+
--
Creates a new user with the specified name and no roles.
--
<.> xref:#ofNameAndRoles_String_RoleMemento[ofNameAndRoles(String, RoleMemento)]
+
--
Creates a new user with the specified name and assigned roles.
--
<.> xref:#ofNameAndRoleNames_String_String[ofNameAndRoleNames(String, String)]
+
--
Creates a new user with the specified name and assigned role names.
--
<.> xref:#ofNameAndRoleNames_String_List[ofNameAndRoleNames(String, List)]
+
--
Creates a new user with the specified name and assigned role names.
--
<.> xref:#ofNameAndRoleNames_String_Stream[ofNameAndRoleNames(String, Stream)]
+
--
Creates a new user with the specified name and assigned role names.
--
<.> xref:#isCurrentUser_String[isCurrentUser(String)]
+
--
Determine if the specified name is this user.
--
<.> xref:#hasSudoAccessAllRole_[hasSudoAccessAllRole()]
+
--
Whether this xref:refguide:applib:index/services/user/UserMemento.adoc[UserMemento] 's _UserMemento#roles() roles_ contains the xref:refguide:applib:index/services/sudo/SudoService.adoc[SudoService] 's _SudoService#ACCESS_ALL_ROLE ACCESS_ALL_ROLE_ role (meaning that security checks are disabled).
--
<.> xref:#getName_[getName()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#name()_ instead
====
--
<.> xref:#getAuthenticationCode_[getAuthenticationCode()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#authenticationCode()_ instead
====
--
<.> xref:#getAuthenticationSource_[getAuthenticationSource()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#authenticationSource()_ instead
====
--
<.> xref:#getAvatarUrl_[getAvatarUrl()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#avatarUrl()_ instead
====
--
<.> xref:#getRealName_[getRealName()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#realName()_ instead
====
--
<.> xref:#getLanguageLocale_[getLanguageLocale()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#languageLocale()_ instead
====
--
<.> xref:#getnumberFormatLocale_[getnumberFormatLocale()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#numberFormatLocale()_ instead
====
--
<.> xref:#getTimeFormatLocale_[getTimeFormatLocale()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#timeFormatLocale()_ instead
====
--
<.> xref:#getMultiTenancyToken_[getMultiTenancyToken()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#multiTenancyToken()_ instead
====
--
<.> xref:#getRoles_[getRoles()]
+
--
[WARNING]
====
[red]#_deprecated:_#

use _#roles()_ instead
====
--

== Members

[#AUTHORIZED_USER_ROLE]
=== AUTHORIZED_USER_ROLE

Also used by the wicket-viewer and its AuthorizeInstantiation(...) annotations; the actual value is arbitrary; however, we use namespace style to clarify the origin

[#system_]
=== system()

The framework's internal user with unrestricted privileges.

[#ofName_String]
=== ofName(String)

Creates a new user with the specified name and no roles.

[#ofNameAndRoles_String_RoleMemento]
=== ofNameAndRoles(String, RoleMemento)

Creates a new user with the specified name and assigned roles.

[#ofNameAndRoleNames_String_String]
=== ofNameAndRoleNames(String, String)

Creates a new user with the specified name and assigned role names.

[#ofNameAndRoleNames_String_List]
=== ofNameAndRoleNames(String, List)

Creates a new user with the specified name and assigned role names.

[#ofNameAndRoleNames_String_Stream]
=== ofNameAndRoleNames(String, Stream)

Creates a new user with the specified name and assigned role names.

[#isCurrentUser_String]
=== isCurrentUser(String)

Determine if the specified name is this user.

[#hasSudoAccessAllRole_]
=== hasSudoAccessAllRole()

Whether this xref:refguide:applib:index/services/user/UserMemento.adoc[UserMemento] 's _UserMemento#roles() roles_ contains the xref:refguide:applib:index/services/sudo/SudoService.adoc[SudoService] 's _SudoService#ACCESS_ALL_ROLE ACCESS_ALL_ROLE_ role (meaning that security checks are disabled).

[#getName_]
=== getName()

[WARNING]
====
[red]#_deprecated:_#

use _#name()_ instead
====

[#getAuthenticationCode_]
=== getAuthenticationCode()

[WARNING]
====
[red]#_deprecated:_#

use _#authenticationCode()_ instead
====

[#getAuthenticationSource_]
=== getAuthenticationSource()

[WARNING]
====
[red]#_deprecated:_#

use _#authenticationSource()_ instead
====

[#getAvatarUrl_]
=== getAvatarUrl()

[WARNING]
====
[red]#_deprecated:_#

use _#avatarUrl()_ instead
====

[#getRealName_]
=== getRealName()

[WARNING]
====
[red]#_deprecated:_#

use _#realName()_ instead
====

[#getLanguageLocale_]
=== getLanguageLocale()

[WARNING]
====
[red]#_deprecated:_#

use _#languageLocale()_ instead
====

[#getnumberFormatLocale_]
=== getnumberFormatLocale()

[WARNING]
====
[red]#_deprecated:_#

use _#numberFormatLocale()_ instead
====

[#getTimeFormatLocale_]
=== getTimeFormatLocale()

[WARNING]
====
[red]#_deprecated:_#

use _#timeFormatLocale()_ instead
====

[#getMultiTenancyToken_]
=== getMultiTenancyToken()

[WARNING]
====
[red]#_deprecated:_#

use _#multiTenancyToken()_ instead
====

[#getRoles_]
=== getRoles()

[WARNING]
====
[red]#_deprecated:_#

use _#roles()_ instead
====
