@Test
public void testChangeAuthoritiesAuthenticationTokenFail() throws Exception {
TestChangeAuthentication testAuthentication = new TestChangeAuthentication("test2", false,
new SimpleGrantedAuthority("USER"));
OAuth2Authentication oauth2Authentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request(
"id", false, Collections.singleton("read")), testAuthentication);
OAuth2AccessToken createAccessToken = getTokenServices().createAccessToken(oauth2Authentication);
// First time. The Authentication has 2 roles;
assertEquals(testAuthentication.getAuthorities(),
getTokenServices().loadAuthentication(createAccessToken.getValue()).getAuthorities());
// Now I change the authorities from testAuthentication
testAuthentication = new TestChangeAuthentication("test2", false, new SimpleGrantedAuthority("NONE"));
// I recreate the request
oauth2Authentication = new OAuth2Authentication(RequestTokenFactory.createOAuth2Request("id", false,
Collections.singleton("read")), testAuthentication);
// I create the authentication again
createAccessToken = getTokenServices().createAccessToken(oauth2Authentication);
assertEquals(testAuthentication.getAuthorities(),
getTokenServices().loadAuthentication(createAccessToken.getValue()).getAuthorities());