public final class UserAccessor extends Object
User
.
This class handles the access to a User
by delegating the calls to the underlying UserFacade
.
Constructor and Description |
---|
UserAccessor() |
Modifier and Type | Method and Description |
---|---|
static User |
getCurrentUser()
Returns the current
User . |
static Optional<User> |
getCurrentUserIfAuthenticated()
Returns the current
User , if authenticated. |
static Optional<User> |
getUserByName(String name)
Returns a
User by its name, if it exists. |
static UserFacade |
getUserFacade()
Returns the
UserFacade instance. |
static void |
setUserFacade(UserFacade userFacade)
Replaces the default
UserFacade instance. |
static io.vavr.control.Try<User> |
tryGetCurrentUser()
Returns a
Try for the current User . |
public static void setUserFacade(@Nonnull UserFacade userFacade)
UserFacade
instance. This method is for internal use only.userFacade
- The facade to replace the current/default one with.@Nonnull public static User getCurrentUser() throws UserNotAuthenticatedException, UserAccessException
User
.User
.UserNotAuthenticatedException
- If the User
is currently not authenticated. This typically occurs when trying to access the
user within code that is running outside the context of a request, e.g., within a background task.
For more details on how user authentication is defined, refer to
getCurrentUserIfAuthenticated()
.UserAccessException
- If there is an issue while accessing the User
.@Nonnull public static Optional<User> getCurrentUserIfAuthenticated() throws UserAccessException
User
, if authenticated.
The user authentication is defined as follows:
User authenticated | User not authenticated | |
---|---|---|
SAP Cloud Platform Cloud Foundry | A request is present with an "Authorization" header that contains a valid JWT bearer with field "user_name". | A request is not available, no "Authorization" header is present in the current request, or the JWT bearer does not hold a field "user_name". |
SAP Cloud Platform Neo | A request is present that holds an authenticated principal according to the UserProvider API. |
A request is not available or the user is not authenticated according to the UserProvider API. |
Optional
of the current User
.UserAccessException
- If there is an issue while accessing the User
.@Nonnull public static io.vavr.control.Try<User> tryGetCurrentUser()
Try
for the current User
.Try
for the current User
.@Nonnull public static Optional<User> getUserByName(@Nullable String name) throws UserAccessDeniedException, UserAccessException
User
by its name, if it exists.name
- The name of the User
to find.UserAccessDeniedException
- If accessing user information is denied.UserAccessException
- If there is an issue while accessing the User
.@Nullable public static UserFacade getUserFacade()
UserFacade
instance. For internal use only.Copyright © 2019 SAP SE. All rights reserved.