Class ServerRequestContextSecurityContextSupplier

java.lang.Object
io.micronaut.security.context.ServerRequestContextSecurityContextSupplier
All Implemented Interfaces:
SecurityContextSupplier

@Internal public final class ServerRequestContextSecurityContextSupplier extends Object implements SecurityContextSupplier
Default SecurityContextSupplier implementation backed by the current ServerRequestContext.
Since:
4.18.0
  • Constructor Details

    • ServerRequestContextSecurityContextSupplier

      public ServerRequestContextSecurityContextSupplier()
  • Method Details

    • get

      public @NonNull SecurityContext get(@Nullable io.micronaut.http.HttpRequest<?> request)
    • getSecurityContext

      public @NonNull SecurityContext getSecurityContext()
      Description copied from interface: SecurityContextSupplier
      Returns the SecurityContext associated with the current execution.
      Specified by:
      getSecurityContext in interface SecurityContextSupplier
      Returns:
      the current SecurityContext
    • getSecurityContext

      public static @NonNull SecurityContext getSecurityContext(@Nullable io.micronaut.http.HttpRequest<?> httpRequest)
      Convenience method to get a SecurityContext without the need of invoking ServerRequestContext.currentRequest() when you already have the HTTP Request available.
      Parameters:
      httpRequest - HTTP Request
      Returns:
      The current Security Context
    • withSecurityContext

      @Internal public static @NonNull io.micronaut.core.propagation.PropagatedContext withSecurityContext(@NonNull SecurityContext securityContext)
      Creates a propagated context with the supplied security context.
      Parameters:
      securityContext - The security context to propagate
      Returns:
      The propagated context
    • withAuthentication

      @Internal public static @NonNull io.micronaut.core.propagation.PropagatedContext withAuthentication(@NonNull Authentication authentication)
      Creates a propagated context with a mutable security context that overrides the current authentication.
      Parameters:
      authentication - The authentication to propagate
      Returns:
      The propagated context
    • withRequestAndAuthentication

      @Internal public static @NonNull io.micronaut.core.propagation.PropagatedContext withRequestAndAuthentication(@NonNull io.micronaut.http.HttpRequest<?> request, @Nullable Authentication authentication)
      Creates a propagated context bound to the supplied request and authentication.

      While the returned context is propagated, code resolving the SecurityContext through SecurityContextHolder, or the request through ServerRequestContext, sees the supplied request and authentication regardless of the context currently bound to the thread. Reactive security processing may resume on a thread bound to another request's context, for example when several requests wait for the same asynchronous token validation result.

      Parameters:
      request - The request being processed
      authentication - The authentication of the request, or null for an anonymous request
      Returns:
      The propagated context
      Since:
      5.5.2
    • withSecurityContext

      @Internal public static <T> @Nullable T withSecurityContext(@NonNull io.micronaut.core.propagation.PropagatedContext propagatedContext, @NonNull Supplier<T> supplier)
      Executes the supplier with the supplied propagated context.
      Type Parameters:
      T - The result type
      Parameters:
      propagatedContext - The propagated context
      supplier - The supplier
      Returns:
      The supplier result