Package io.micronaut.security.context
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 Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription@NonNull SecurityContextget(@Nullable io.micronaut.http.HttpRequest<?> request) @NonNull SecurityContextReturns theSecurityContextassociated with the current execution.static @NonNull SecurityContextgetSecurityContext(@Nullable io.micronaut.http.HttpRequest<?> httpRequest) Convenience method to get aSecurityContextwithout the need of invokingServerRequestContext.currentRequest()when you already have the HTTP Request available.static @NonNull io.micronaut.core.propagation.PropagatedContextwithRequestAndAuthentication(@NonNull io.micronaut.http.HttpRequest<?> request, @Nullable Authentication authentication) Creates a propagated context bound to the supplied request and authentication.
-
Constructor Details
-
ServerRequestContextSecurityContextSupplier
public ServerRequestContextSecurityContextSupplier()
-
-
Method Details
-
get
@NonNull public @NonNull SecurityContext get(@Nullable @Nullable io.micronaut.http.HttpRequest<?> request) -
getSecurityContext
Description copied from interface:SecurityContextSupplierReturns theSecurityContextassociated with the current execution.- Specified by:
getSecurityContextin interfaceSecurityContextSupplier- Returns:
- the current
SecurityContext
-
getSecurityContext
@NonNull public static @NonNull SecurityContext getSecurityContext(@Nullable @Nullable io.micronaut.http.HttpRequest<?> httpRequest) Convenience method to get aSecurityContextwithout the need of invokingServerRequestContext.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
SecurityContextthroughSecurityContextHolder, or the request throughServerRequestContext, 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 processedauthentication- The authentication of the request, ornullfor an anonymous request- Returns:
- The propagated context
- Since:
- 4.18.2
-