public abstract class AbstractUserFacade extends Object implements UserFacade
UserFacade
s which allows to use a mocked User
if the environment variable
"USE_MOCKED_USER" is set to "true".Constructor and Description |
---|
AbstractUserFacade() |
Modifier and Type | Method and Description |
---|---|
User |
getCurrentUser()
Returns the current
User . |
Optional<User> |
getCurrentUserIfAuthenticated()
Returns the current
User , if authenticated. |
Optional<User> |
getMockedUser()
Returns a mocked
User , if the environment variable "USE_MOCKED_USER" is set to "true". |
protected abstract User |
newMockedUser()
Instantiates a mocked
User . |
io.vavr.control.Try<User> |
tryGetCurrentUser()
Returns a
Try for the current User . |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getUserByName, getUserClass, resolveCurrentUser
@Nonnull protected abstract User newMockedUser()
User
.User
.@Nonnull public Optional<User> getMockedUser()
User
, if the environment variable "USE_MOCKED_USER" is set to "true".User
, if present.@Nonnull public User getCurrentUser() throws UserNotAuthenticatedException, UserAccessException
User
.getCurrentUser
in interface UserFacade
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
UserFacade.getCurrentUserIfAuthenticated()
.UserAccessException
- If there is an issue while accessing the User
.@Nonnull public 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. |
getCurrentUserIfAuthenticated
in interface UserFacade
Optional
of the current User
.UserAccessException
- If there is an issue while accessing the User
.@Nonnull public io.vavr.control.Try<User> tryGetCurrentUser()
Try
for the current User
.tryGetCurrentUser
in interface UserFacade
Try
for the current User
.Copyright © 2019 SAP SE. All rights reserved.