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

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

      @NonNull 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

      @NonNull public static @NonNull SecurityContext getSecurityContext(@Nullable @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
    • withRequestAndAuthentication

      @Internal @NonNull public static @NonNull io.micronaut.core.propagation.PropagatedContext withRequestAndAuthentication(@NonNull @NonNull io.micronaut.http.HttpRequest<?> request, @Nullable @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:
      4.18.2