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 Details

    • getAuthentication

      @Nullable @Nullable Authentication getAuthentication()
      Returns the authentication associated with the current user.
      Returns:
      the current Authentication, or null if no user is authenticated
    • getToken

      @Nullable @Nullable String getToken()
      Returns the token associated with the current security context.
      Returns:
      the token used to authenticate the current user, or null if 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, or null to clear it
      Returns:
      this security context instance, for method chaining
    • withToken

      @NonNull @NonNull SecurityContext withToken(@Nullable @Nullable String token)
      Sets the token associated with the current security context.
      Parameters:
      token - the token to associate, or null to clear it
      Returns:
      this security context instance, for method chaining
    • withRejectionStatus

      @NonNull @NonNull SecurityContext withRejectionStatus(@Nullable @Nullable Integer statusCode)
      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

      @Nullable @Nullable Integer 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.