= UserMemento
: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
----
class 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)     // <.>
  List<RoleMemento> getRoles()     // <.>
  UserMemento withRoleAdded(String role)
  boolean isCurrentUser(String userName)     // <.>
  Stream<String> streamRoleNames()
  boolean hasRoleName(String roleName)
  boolean isSystem()     // <.>
  UserMementoBuilder asBuilder()
  UserLocale asUserLocale()
}
----

<.> 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:#getRoles_[getRoles()]
+
--
The roles associated with this user.
--
<.> xref:#isCurrentUser_String[isCurrentUser(String)]
+
--
Determine if the specified name is this user.
--
<.> xref:#isSystem_[isSystem()]
+
--
Whether this xref:refguide:applib:index/services/user/UserMemento.adoc[UserMemento] represent the _system user_ .
--

== 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.

[#getRoles_]
=== getRoles()

The roles associated with this user.

[#isCurrentUser_String]
=== isCurrentUser(String)

Determine if the specified name is this user.

[#isSystem_]
=== isSystem()

Whether this xref:refguide:applib:index/services/user/UserMemento.adoc[UserMemento] represent the _system user_ .
