SimpleGrantedAuthoritiesMapper implements GrantedAuthoritiesMapper { @Override public Collection<? extends GrantedAuthority> mapAuthorities( Collection<? extends GrantedAuthority> authorities) { if(mappings.isEmpty()) { return authorities; } List<GrantedAuthority> result = new ArrayList<GrantedAuthority>(); for(GrantedAuthority authority : authorities) { if(mappings.containsKey(authority.getAuthority())) { result.add(new GrantedAuthorityImpl(mappings.get(authority.getAuthority()))); } else { result.add(authority); } } return result; } SimpleGrantedAuthoritiesMapper(Map<String, String> mappings); @Override Collection<? extends GrantedAuthority> mapAuthorities(
            Collection<? extends GrantedAuthority> authorities);  }
@Test public void testMapping() { roleMappings.put("A", "B"); authorities.add(new GrantedAuthorityImpl("A")); Collection<? extends GrantedAuthority> mapped = mapper.mapAuthorities(authorities); assertEquals(1, mapped.size()); assertEquals("B", mapped.iterator().next().getAuthority()); }