Package io.micronaut.security.context
Interface SecurityContext
public interface SecurityContext
Represents the security state associated with the current execution.
A SecurityContext provides access to the resolved Authentication and,
when applicable, the token that produced it.
- Since:
- 4.18.0
-
Method Summary
Modifier and TypeMethodDescriptionvoidclear()Clears the current authentication, token, and rejection status.@Nullable AuthenticationReturns the authentication associated with the current user.@Nullable IntegerReturns the rejection status associated with the current security context.@Nullable StringgetToken()Returns the token associated with the current security context.@NonNull SecurityContextwithAuthentication(@Nullable Authentication authentication) Sets the authentication associated with the current security context.@NonNull SecurityContextwithRejectionStatus(@Nullable Integer statusCode) Sets the rejection code associated with the current security context.@NonNull SecurityContextSets the token associated with the current security context.
-
Method Details
-
getAuthentication
Returns the authentication associated with the current user.- Returns:
- the current
Authentication, ornullif no user is authenticated
-
getToken
Returns the token associated with the current security context.- Returns:
- the token used to authenticate the current user, or
nullif authentication was not token-based or if no user is authenticated
-
withAuthentication
@NonNull @NonNull SecurityContext withAuthentication(@Nullable @Nullable Authentication authentication) Sets the authentication associated with the current security context.- Parameters:
authentication- the authentication to associate, ornullto clear it- Returns:
- this security context instance, for method chaining
-
withToken
Sets the token associated with the current security context.- Parameters:
token- the token to associate, ornullto clear it- Returns:
- this security context instance, for method chaining
-
withRejectionStatus
Sets the rejection code associated with the current security context.- Parameters:
statusCode- a code associated with the current rejection. For example, in an HTTP context it can be an HTTP status code.- Returns:
- this security context instance, for method chaining
-
getRejectionStatus
Returns the rejection status associated with the current security context.- Returns:
- the HTTP status code associated with the current rejection, or
null
-
clear
void clear()Clears the current authentication, token, and rejection status.
-