Package com.sap.cds.services.request
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 Summary
Modifier and TypeMethodDescriptiondefault <T extends UserInfo>
TProvides type-safe access toUserInfoand additional attributes.default ModifiableUserInfocopy()Creates aModifiableUserInfobased on thisUserInfo.static ModifiableUserInfocreate()Creates aModifiableUserInfobased on default values of a clearUserInfo.default ObjectgetAdditionalAttribute(String name) Returns additional attribute with given name if existing.Returns all additional attributes asMap.Returns all user attributes as aMap.getAttributeValues(String attribute) Returns aListof values of the specified attribute as presented in the request.default StringgetId()Returns the verified user id of the request's authenticated user.getName()Returns the verified user name of the request's authenticated user.getRoles()Returns theListof granted user roles.default StringReturns the verified tenant of the request's authenticated user.Deprecated.default booleanChecks if the current user is associated with the specified user role.booleanReturnstrueifUserInfois filled with data of an authenticated user.default booleanReturnstrueif the user is the internal user.default booleanReturnstrueifUserInfois a privileged user, i.e. passes all authorization checks.default booleanReturnstrueif the user is a system user and not a named user.default booleanisUnrestrictedAttribute(String attribute) Deprecated.
-
Method Details
-
create
Creates aModifiableUserInfobased on default values of a clearUserInfo.- Returns:
- The created
ModifiableUserInfoinstance.
-
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
Returns the verified tenant of the request's authenticated user.- Returns:
- The tenant of the user.
-
isSystemUser
default boolean isSystemUser()Returnstrueif the user is a system user and not a named user.- Returns:
trueif the user is a system user and not a named user.
-
isInternalUser
default boolean isInternalUser()Returnstrueif the user is the internal user.- Returns:
trueif the user is the internal user.
-
isAuthenticated
boolean isAuthenticated()ReturnstrueifUserInfois filled with data of an authenticated user.- Returns:
trueifUserInfois filled with data of an authenticated user.
-
isPrivileged
default boolean isPrivileged()ReturnstrueifUserInfois a privileged user, i.e. passes all authorization checks. Privileged users can only be used internally.- Returns:
trueifUserInfois a privileged user.
-
hasRole
Checks if the current user is associated with the specified user role.- Parameters:
role- The name of the role.- Returns:
trueif role is present,falseotherwise.
-
getRoles
Returns theListof granted user roles.- Returns:
- the
Listof roles.
-
getAttributeValues
Returns aListof 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
Returns all user attributes as aMap.- Returns:
- The user attributes.
-
isUnrestrictedAttribute
Deprecated.Returnstrueif 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:
trueif unrestricted,falseotherwise.
-
getUnrestrictedAttributes
Deprecated.Returns theSetof unrestricted attributes of the user.- Returns:
- the
Setof unrestricted attributes.
-
getAdditionalAttribute
Returns additional attribute with given name if existing.- Parameters:
name- The name of the attribute.- Returns:
- The attribute value as
Object.
-
getAdditionalAttributes
Returns all additional attributes asMap.- Returns:
- The additional attributes,
-
as
Provides type-safe access toUserInfoand additional attributes. Creates a concrete proxy instance implementingUserInfoand a sub interfaceconcreteUserInfoClazzwhich 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 concreteUserInfointerface.- Parameters:
concreteUserInfoClazz- The sub interface providing the concrete API of additional attributes.- Returns:
- A concrete proxy instance implementing
UserInfoandconcreteUserInfoClazz.
-
copy
Creates aModifiableUserInfobased on thisUserInfo.- Returns:
- The created
ModifiableUserInfoinstance.
-