if (authenticationResponse.getStatusCode().value() == 401) {
// temporary - the idea here is to generate the not authorized exception - not by hand, but by returning wrong credentials which in turn will be refused later
return new org.springframework.security.core.userdetails.User("wrongUsername", "wrongPass", Lists.<GrantedAuthority> newArrayList());
}
final User principalFromRest = authenticationResponse.getBody();
final Set<String> privilegesFromRest = Sets.newHashSet();
final Set<Role> roles = principalFromRest.getRoles();
for (final Role role : roles) {
privilegesFromRest.addAll(Collections2.transform(role.getPrivileges(), Functions.toStringFunction()));
}
final String[] authorityStringsAsArray = privilegesFromRest.toArray(new String[privilegesFromRest.size()]);
final List<GrantedAuthority> authorities = AuthorityUtils.createAuthorityList(authorityStringsAsArray);