@Test public void setSecurityContext() throws InterruptedException, ExecutionException { ExecutorService executor = Executors.newFixedThreadPool(2); Future<Token> future_1 = executor.submit(() -> { initSecurityContextWithToken(token_1); return SpringSecurityContext.getToken(); }); Future<Token> future_2 = executor.submit(() -> { initSecurityContextWithToken(token_2); return SpringSecurityContext.getToken(); }); assertEquals(SUBDOMAIN_1, future_1.get().getSubdomain()); assertEquals(SUBDOMAIN_1 + "-id", future_1.get().getZoneId()); assertEquals(SUBDOMAIN_2, future_2.get().getSubdomain()); assertEquals(SUBDOMAIN_2 + "-id", future_2.get().getZoneId()); }
static public Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new AccessDeniedException("Access forbidden: not authenticated"); } Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof Token) { return (Token) principal; } throw new AccessDeniedException( "Access forbidden: SecurityContextHolder does not contain a principal of type 'Token' " + principal); }
SpringSecurityContext { static public Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new AccessDeniedException("Access forbidden: not authenticated"); } Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof Token) { return (Token) principal; } throw new AccessDeniedException( "Access forbidden: SecurityContextHolder does not contain a principal of type 'Token' " + principal); } }
SpringSecurityContext { static public Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new AccessDeniedException("Access forbidden: not authenticated"); } Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof Token) { return (Token) principal; } throw new AccessDeniedException( "Access forbidden: SecurityContextHolder does not contain a principal of type 'Token' " + principal); } private  SpringSecurityContext(); }
SpringSecurityContext { static public Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new AccessDeniedException("Access forbidden: not authenticated"); } Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof Token) { return (Token) principal; } throw new AccessDeniedException( "Access forbidden: SecurityContextHolder does not contain a principal of type 'Token' " + principal); } private  SpringSecurityContext(); static Token getToken(); static void init(String encodedJwtToken, JwtDecoder xsuaaJwtDecoder,
			AuthoritiesExtractor authoritiesExtractor); static void clear(); }
SpringSecurityContext { static public Token getToken() { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication == null) { throw new AccessDeniedException("Access forbidden: not authenticated"); } Object principal = SecurityContextHolder.getContext().getAuthentication().getPrincipal(); if (principal instanceof Token) { return (Token) principal; } throw new AccessDeniedException( "Access forbidden: SecurityContextHolder does not contain a principal of type 'Token' " + principal); } private  SpringSecurityContext(); static Token getToken(); static void init(String encodedJwtToken, JwtDecoder xsuaaJwtDecoder,
			AuthoritiesExtractor authoritiesExtractor); static void clear();  }