@Before public void init() throws Exception { tokenServices.setClientDetailsService( new InMemoryClientDetailsServiceBuilder() .withClient("client") .authorizedGrantTypes("authorization_code") .scopes("read") .secret("secret") .and() .build()); enhancer.setTokenEnhancers(Arrays.<TokenEnhancer>asList(jwtTokenEnhancer)); jwtTokenEnhancer.afterPropertiesSet(); tokenServices.setTokenStore(new JwtTokenStore(jwtTokenEnhancer)); tokenServices.setTokenEnhancer(enhancer); }
@Test public void additionalInfoPreservedWhenTokenDecoded() { TokenEnhancer info = new TokenEnhancer() { @Override public OAuth2AccessToken enhance( OAuth2AccessToken accessToken, OAuth2Authentication authentication) { DefaultOAuth2AccessToken result = new DefaultOAuth2AccessToken(accessToken); result.getAdditionalInformation().put("foo", "bar"); return result; } }; enhancer.setTokenEnhancers(Arrays.<TokenEnhancer>asList(info, jwtTokenEnhancer)); OAuth2AccessToken token = tokenServices.createAccessToken(authentication); assertEquals("bar", token.getAdditionalInformation().get("foo")); assertEquals( "bar", tokenServices.readAccessToken(token.getValue()).getAdditionalInformation().get("foo")); }