@Test public void tokenNotAvailableInDifferentThread() throws ExecutionException, InterruptedException { setToken(token, NO_SCOPES); Future<Token> tokenInOtherThread = executorService.submit(() -> SpringSecurityContext.getToken()); assertThat(tokenInOtherThread.get()).isNull(); }
@Nullable public static Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.nonNull(authentication) && authentication.isAuthenticated() && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication.getDetails(); String tokenValue = authDetails.getTokenValue(); return new XsuaaTokenWithGrantedAuthorities(tokenValue, authentication.getAuthorities()); } return null; }
SpringSecurityContext { @Nullable public static Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.nonNull(authentication) && authentication.isAuthenticated() && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication.getDetails(); String tokenValue = authDetails.getTokenValue(); return new XsuaaTokenWithGrantedAuthorities(tokenValue, authentication.getAuthorities()); } return null; } }
SpringSecurityContext { @Nullable public static Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.nonNull(authentication) && authentication.isAuthenticated() && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication.getDetails(); String tokenValue = authDetails.getTokenValue(); return new XsuaaTokenWithGrantedAuthorities(tokenValue, authentication.getAuthorities()); } return null; } private  SpringSecurityContext(); }
SpringSecurityContext { @Nullable public static Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.nonNull(authentication) && authentication.isAuthenticated() && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication.getDetails(); String tokenValue = authDetails.getTokenValue(); return new XsuaaTokenWithGrantedAuthorities(tokenValue, authentication.getAuthorities()); } return null; } private  SpringSecurityContext(); @Nullable static Token getToken(); @Nullable static AccessToken getAccessToken(); static void clear(); }
SpringSecurityContext { @Nullable public static Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (Objects.nonNull(authentication) && authentication.isAuthenticated() && authentication.getDetails() instanceof OAuth2AuthenticationDetails) { OAuth2AuthenticationDetails authDetails = (OAuth2AuthenticationDetails) authentication.getDetails(); String tokenValue = authDetails.getTokenValue(); return new XsuaaTokenWithGrantedAuthorities(tokenValue, authentication.getAuthorities()); } return null; } private  SpringSecurityContext(); @Nullable static Token getToken(); @Nullable static AccessToken getAccessToken(); static void clear();  }