/**
   * Make sure the resource set doesn't have any restricted or reserved scopes.
   *
   * @param rs
   */
  private ResourceSet validateScopes(ResourceSet rs) {
    // scopes that the client is asking for
    Set<SystemScope> requestedScopes = scopeService.fromStrings(rs.getScopes());

    // the scopes that the resource set can have must be a subset of the dynamically allowed scopes
    Set<SystemScope> allowedScopes =
        scopeService.removeRestrictedAndReservedScopes(requestedScopes);

    rs.setScopes(scopeService.toStrings(allowedScopes));

    return rs;
  }
  private ClientDetailsEntity validateScopes(ClientDetailsEntity newClient)
      throws ValidationException {
    // scopes that the client is asking for
    Set<SystemScope> requestedScopes = scopeService.fromStrings(newClient.getScope());

    // the scopes that the client can have must be a subset of the dynamically allowed scopes
    Set<SystemScope> allowedScopes =
        scopeService.removeRestrictedAndReservedScopes(requestedScopes);

    // if the client didn't ask for any, give them the defaults
    if (allowedScopes == null || allowedScopes.isEmpty()) {
      allowedScopes = scopeService.getDefaults();
    }

    newClient.setScope(scopeService.toStrings(allowedScopes));

    return newClient;
  }