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.PropagatedContextwithAuthentication(@NonNull Authentication authentication) Creates a propagated context with a mutable security context that overrides the current authentication.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.static <T> @Nullable TwithSecurityContext(@NonNull io.micronaut.core.propagation.PropagatedContext propagatedContext, @NonNull Supplier<T> supplier) Executes the supplier with the supplied propagated context.static @NonNull io.micronaut.core.propagation.PropagatedContextwithSecurityContext(@NonNull SecurityContext securityContext) Creates a propagated context with the supplied security context.
-
Constructor Details
-
ServerRequestContextSecurityContextSupplier
public ServerRequestContextSecurityContextSupplier()
-
-
Method Details
-
get
-
getSecurityContext
Description copied from interface:SecurityContextSupplierReturns theSecurityContextassociated with the current execution.- Specified by:
getSecurityContextin interfaceSecurityContextSupplier- Returns:
- the current
SecurityContext
-
getSecurityContext
public static @NonNull SecurityContext getSecurityContext(@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
-
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
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:
- 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 contextsupplier- The supplier- Returns:
- The supplier result
-