Class SpringSecurityContext

java.lang.Object
com.sap.cloud.security.adapter.spring.SpringSecurityContext

public class SpringSecurityContext extends Object
This is an alternative way of accessing jwt tokens of type Token or AccessToken in context of an application using spring-security-oauth2.

It uses the SecurityContextHolder to access Spring's SecurityContext and can therefore used also in context of asynchronous threads.

Use this class in case your application sets Spring's security context via one of these libraries:

  1. @code{org.springframework.security.oauth:spring-security-oauth2} or
  2. @code{com.sap.cloud.security.xsuaa:spring-xsuaa} client library.
  • Method Details

    • getToken

      @Nullable public static Token getToken()
      Returns the token using SecurityContextHolder.
      Returns:
      the token or null if SecurityContext is empty or does not contain a token of this type.
    • getAccessToken

      @Nullable public static AccessToken getAccessToken()
      Returns the token using SecurityContextHolder.
      Returns:
      the token or null if SecurityContext is empty or does not contain a token of this type.
    • clear

      public static void clear()
      Clears the context value from the current thread.