### Question:
SpringSecurityTokenStore implements AdapterTokenStore { @Override public void saveAccountInfo(OidcKeycloakAccount account) { Authentication authentication = SecurityContextHolder.getContext().getAuthentication(); if (authentication != null) { throw new IllegalStateException(String.format("Went to save Keycloak account %s, but already have %s", account, authentication)); } logger.debug("Saving account info {}", account); SecurityContext context = SecurityContextHolder.createEmptyContext(); context.setAuthentication(new KeycloakAuthenticationToken(account, true)); SecurityContextHolder.setContext(context); } SpringSecurityTokenStore(KeycloakDeployment deployment, HttpServletRequest request); @Override void checkCurrentToken(); @Override boolean isCached(RequestAuthenticator authenticator); @Override void saveAccountInfo(OidcKeycloakAccount account); @Override void logout(); @Override void refreshCallback(RefreshableKeycloakSecurityContext securityContext); @Override void saveRequest(); @Override boolean restoreRequest();  }### Answer:
@Test public void testSaveAccountInfo() throws Exception { OidcKeycloakAccount account = new SimpleKeycloakAccount(principal, Collections.singleton("FOO"), keycloakSecurityContext); Authentication authentication; store.saveAccountInfo(account); authentication = SecurityContextHolder.getContext().getAuthentication(); assertNotNull(authentication); assertTrue(authentication instanceof KeycloakAuthenticationToken); }
@Test(expected = IllegalStateException.class) public void testSaveAccountInfoInvalidAuthenticationType() throws Exception { OidcKeycloakAccount account = new SimpleKeycloakAccount(principal, Collections.singleton("FOO"), keycloakSecurityContext); Authentication authentication = new PreAuthenticatedAuthenticationToken("foo", "bar", Collections.singleton(new KeycloakRole("ROLE_FOO"))); SecurityContextHolder.getContext().setAuthentication(authentication); store.saveAccountInfo(account); }