ResourceServerResource extends AbstractResource { @SuppressWarnings("unchecked") protected void pruneClientScopes(final List<String> newScopes, List<String> oldScopes, Set<Client> clients) { if (!newScopes.containsAll(oldScopes)) { subtract(oldScopes, newScopes); Collection<String> outdatedScopes = subtract(oldScopes, newScopes); LOG.info("Resource server has updated scopes. Will remove all outdated scopes from clients: {}", outdatedScopes); for (Client c : clients) { final List<String> clientScopes = c.getScopes(); if (CollectionUtils.containsAny(clientScopes, outdatedScopes)) { ArrayList<String> prunedScopes = new ArrayList<String>(subtract(clientScopes, outdatedScopes)); LOG.info("Client scopes of client {} were: {}. After pruning (because resourceServer has new scopes): {}", new Object[]{c.getClientId(), c.getScopes(), prunedScopes}); c.setScopes(prunedScopes); } } } }  @GET Response getAll(@Context
                         HttpServletRequest request); @GET @Path("/{resourceServerId}") Response getById(@Context
                          HttpServletRequest request, @PathParam("resourceServerId")
                          Long id); @GET @Path("/stats") Response stats(@Context
                        HttpServletRequest request); @GET @Path("/principal") Response principal(@Context
                        HttpServletRequest request); @PUT Response put(@Context
                      HttpServletRequest request, @Valid
                      ResourceServer newOne); @DELETE @Path("/{resourceServerId}") Response delete(@Context
                         HttpServletRequest request, @PathParam("resourceServerId")
                         Long id); @POST @Path("/{resourceServerId}") Response post(@Valid
                       final ResourceServer resourceServer, @Context
                       HttpServletRequest request, @PathParam("resourceServerId")
                       Long id);  }
@Test public void pruneScopes() { Client client1 = new Client(); client1.setScopes(Arrays.asList("scope1")); Client client2 = new Client(); client2.setScopes(Arrays.asList("scope1", "scope2")); Set<Client> clients = new HashSet(Arrays.asList(client1, client2)); List<String> oldScopes = Arrays.asList("scope1"); List<String> newScopes = Arrays.asList("scope2"); resourceServerResource.pruneClientScopes(newScopes, oldScopes, clients); assertEquals(0, client1.getScopes().size()); assertEquals(1, client2.getScopes().size()); assertEquals("scope2", client2.getScopes().get(0)); }