Package org.bremersee.security.core
Class UserContextCaller
- java.lang.Object
-
- org.bremersee.security.core.UserContextCaller
-
@Validated public class UserContextCaller extends Object
The user context caller.- Author:
- Christian Bremer
-
-
Field Summary
Fields Modifier and Type Field Description static Supplier<Set<String>>
EMPTY_GROUPS_SUPPLIER
The constant EMPTY_GROUPS_SUPPLIER.static Supplier<ServiceException>
FORBIDDEN_SUPPLIER
The constant FORBIDDEN_SUPPLIER.
-
Constructor Summary
Constructors Constructor Description UserContextCaller()
Instantiates a new user context caller.UserContextCaller(Function<org.springframework.security.core.Authentication,Set<String>> groupsFn)
Instantiates a new user context caller.UserContextCaller(Function<org.springframework.security.core.Authentication,Set<String>> groupsFn, Supplier<ServiceException> unauthenticatedExceptionSupplier)
Instantiates a new user context caller.UserContextCaller(Supplier<Set<String>> groupsSupplier)
Instantiates a new user context caller.UserContextCaller(Supplier<Set<String>> groupsSupplier, Supplier<ServiceException> unauthenticatedExceptionSupplier)
Instantiates a new user context caller.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <R> R
callWithOptionalUserContext(@NotNull Function<UserContext,R> function)
Call with optional user context.<R> R
callWithRequiredUserContext(@NotNull Function<UserContext,R> function)
Call with required user context.<R,E>
org.springframework.http.ResponseEntity<E>responseWithOptionalUserContext(@NotNull Function<UserContext,R> function)
Response with optional user context response entity.<R,E>
org.springframework.http.ResponseEntity<E>responseWithRequiredUserContext(@NotNull Function<UserContext,R> function)
Response with required user context response entity.protected <R,E>
org.springframework.http.ResponseEntity<E>toResponseEntity(R result)
To response entity response entity.
-
-
-
Field Detail
-
EMPTY_GROUPS_SUPPLIER
public static final Supplier<Set<String>> EMPTY_GROUPS_SUPPLIER
The constant EMPTY_GROUPS_SUPPLIER.
-
FORBIDDEN_SUPPLIER
public static final Supplier<ServiceException> FORBIDDEN_SUPPLIER
The constant FORBIDDEN_SUPPLIER.
-
-
Constructor Detail
-
UserContextCaller
public UserContextCaller()
Instantiates a new user context caller.
-
UserContextCaller
public UserContextCaller(@Nullable Supplier<Set<String>> groupsSupplier)
Instantiates a new user context caller.- Parameters:
groupsSupplier
- the groups supplier
-
UserContextCaller
public UserContextCaller(@Nullable Function<org.springframework.security.core.Authentication,Set<String>> groupsFn)
Instantiates a new user context caller.- Parameters:
groupsFn
- the groups fn
-
UserContextCaller
public UserContextCaller(@Nullable Supplier<Set<String>> groupsSupplier, @Nullable Supplier<ServiceException> unauthenticatedExceptionSupplier)
Instantiates a new user context caller.- Parameters:
groupsSupplier
- the groups supplierunauthenticatedExceptionSupplier
- the unauthenticated exception supplier
-
UserContextCaller
public UserContextCaller(@Nullable Function<org.springframework.security.core.Authentication,Set<String>> groupsFn, @Nullable Supplier<ServiceException> unauthenticatedExceptionSupplier)
Instantiates a new user context caller.- Parameters:
groupsFn
- the groups fnunauthenticatedExceptionSupplier
- the unauthenticated exception supplier
-
-
Method Detail
-
callWithRequiredUserContext
public <R> R callWithRequiredUserContext(@NotNull @NotNull Function<UserContext,R> function)
Call with required user context.- Type Parameters:
R
- the type parameter- Parameters:
function
- the function- Returns:
- the response
-
callWithOptionalUserContext
public <R> R callWithOptionalUserContext(@NotNull @NotNull Function<UserContext,R> function)
Call with optional user context.- Type Parameters:
R
- the type parameter- Parameters:
function
- the function- Returns:
- the response
-
responseWithRequiredUserContext
public <R,E> org.springframework.http.ResponseEntity<E> responseWithRequiredUserContext(@NotNull @NotNull Function<UserContext,R> function)
Response with required user context response entity.- Type Parameters:
R
- the type parameterE
- the type parameter- Parameters:
function
- the function- Returns:
- the response entity
-
responseWithOptionalUserContext
public <R,E> org.springframework.http.ResponseEntity<E> responseWithOptionalUserContext(@NotNull @NotNull Function<UserContext,R> function)
Response with optional user context response entity.- Type Parameters:
R
- the type parameterE
- the type parameter- Parameters:
function
- the function- Returns:
- the response entity
-
toResponseEntity
protected <R,E> org.springframework.http.ResponseEntity<E> toResponseEntity(R result)
To response entity response entity.- Type Parameters:
R
- the type parameterE
- the type parameter- Parameters:
result
- the result- Returns:
- the response entity
-
-