Class UserContextCaller


  • @Validated
    public class UserContextCaller
    extends Object
    The user context caller.
    Author:
    Christian Bremer
    • 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<org.bremersee.exception.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<org.bremersee.exception.ServiceException> unauthenticatedExceptionSupplier)
        Instantiates a new user context caller.
        Parameters:
        groupsSupplier - the groups supplier
        unauthenticatedExceptionSupplier - the unauthenticated exception supplier
      • UserContextCaller

        public UserContextCaller​(@Nullable
                                 Function<org.springframework.security.core.Authentication,​Set<String>> groupsFn,
                                 @Nullable
                                 Supplier<org.bremersee.exception.ServiceException> unauthenticatedExceptionSupplier)
        Instantiates a new user context caller.
        Parameters:
        groupsFn - the groups fn
        unauthenticatedExceptionSupplier - 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 parameter
        E - 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 parameter
        E - 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 parameter
        E - the type parameter
        Parameters:
        result - the result
        Returns:
        the response entity