@Test public void customUserPreservedWhenTokenDecoded() { DefaultAccessTokenConverter tokenConverter = new DefaultAccessTokenConverter(); tokenConverter.setUserTokenConverter( new UserAuthenticationConverter() { @Override public Authentication extractAuthentication(Map<String, ?> map) { return new FooAuthentication((String) map.get("user")); } @Override public Map<String, ?> convertUserAuthentication(Authentication userAuthentication) { Map<String, Object> map = new HashMap<String, Object>(); map.put("user", userAuthentication.getName()); map.put("foo", "bar"); return map; } }); jwtTokenEnhancer.setAccessTokenConverter(tokenConverter); OAuth2AccessToken token = tokenServices.createAccessToken(authentication); assertEquals( "bob", tokenServices.loadAuthentication(token.getValue()).getUserAuthentication().getName()); }
@Test public void scopePreservedWhenTokenDecoded() { OAuth2AccessToken token = tokenServices.createAccessToken(authentication); assertEquals( "[read]", tokenServices .loadAuthentication(token.getValue()) .getOAuth2Request() .getScope() .toString()); }