public class UserInfo
extends sirius.kernel.di.transformers.Composable
A user is authenticated using a UserManager
. To obtain or modify the current user, use UserContext.getCurrentUser()
or UserContext.setCurrentUser(UserInfo)
.
Modifier and Type | Class and Description |
---|---|
static class |
UserInfo.Builder
Builder pattern to create a new
UserInfo . |
Modifier and Type | Field and Description |
---|---|
protected String |
lang |
static UserInfo |
NOBODY
Fallback user if no user is currently available.
|
static String |
PERMISSION_LOGGED_IN
This permission represents a user which was successfully authenticated by its user manager.
|
protected Set<String> |
permissions |
protected Function<UserInfo,UserSettings> |
settingsSupplier |
protected String |
tenantId |
protected String |
tenantName |
protected String |
userId |
protected String |
username |
protected Function<UserInfo,Object> |
userSupplier |
Modifier | Constructor and Description |
---|---|
protected |
UserInfo() |
Modifier and Type | Method and Description |
---|---|
void |
assertPermission(String permission)
Asserts that the user has the given permission.
|
String |
getLang()
The language code of the user.
|
Set<String> |
getPermissions()
Returns a set of all permissions granted to the user.
|
UserSettings |
getSettings()
Obtains the user specific config.
|
String |
getTenantId()
The unique ID of the tenant.
|
String |
getTenantName()
The name of the tenant.
|
String |
getUserId()
Returns the unique ID of the user.
|
String |
getUserName()
Returns the login or descriptive name of the user.
|
<T> T |
getUserObject(Class<T> clazz)
Fetches the underlying user object of the given type.
|
boolean |
hasPermission(String permission)
Determines if the user has the given permission.
|
boolean |
hasPermissions(String... permissions)
Determines if the user has the requested permissions
|
boolean |
is(Class<?> type) |
boolean |
isLoggedIn()
Determines if the user is logged in.
|
protected boolean |
permissionFullfilled(String permission) |
protected boolean |
permissionsFullfilled(String permissions) |
<A> Optional<A> |
tryAs(Class<A> adapterType) |
public static final String PERMISSION_LOGGED_IN
public static final UserInfo NOBODY
protected String tenantId
protected String tenantName
protected String userId
protected String username
protected String lang
protected Function<UserInfo,UserSettings> settingsSupplier
public String getUserId()
public String getUserName()
@Nullable public String getTenantId()
@Nullable public String getTenantName()
public String getLang()
public boolean hasPermissions(String... permissions)
permissions
- the permissions to checkpublic boolean hasPermission(String permission)
Next to plain permission names, permissions can also negated using !permission and on top of that, whole logical expressions in DNF (disjuctive normal form)can be passed in.
Such a formula is a set of expressions where a , represents an or and a + represents an and. An example would be "logged-in,important-customer+!locked". This would translate to "the user has to be logged in or it has to be an important customer and not be locked".
permission
- the permission to checkprotected boolean permissionsFullfilled(String permissions)
protected boolean permissionFullfilled(String permission)
public void assertPermission(String permission)
If the user does not have the given permission, an exception is thrown.
permission
- the permission to checkpublic boolean isLoggedIn()
PERMISSION_LOGGED_IN
, false otherwise@Nullable public <T> T getUserObject(Class<T> clazz)
T
- the excepted type of the user objectclazz
- the excepted type of the user objectpublic boolean is(@Nonnull Class<?> type)
is
in interface sirius.kernel.di.transformers.Transformable
is
in class sirius.kernel.di.transformers.Composable
public <A> Optional<A> tryAs(@Nonnull Class<A> adapterType)
tryAs
in interface sirius.kernel.di.transformers.Transformable
tryAs
in class sirius.kernel.di.transformers.Composable
public Set<String> getPermissions()
public UserSettings getSettings()
This can be used to make parts of the system behave specific to the current scope, current tenant and user.
Copyright © 2018. All rights reserved.