public boolean createOrUpdateGroups(final ScimRequestBuilder scimService, final Group group) {
        val response = findGroup(scimService, group.getDisplayName().orElseThrow());
        if (response.isSuccess()) {
            if (response.getResource().getTotalResults() > 0) {
                val existingGroup = response.getResource().getListedResources().getFirst();
                group.getDisplayName().ifPresent(existingGroup::setDisplayName);
                group.getExternalId().ifPresent(existingGroup::setExternalId);

                val currentMembers = new ArrayList<>(existingGroup.getMembers());
                currentMembers.removeIf(member -> group.getMembers().contains(member));
                currentMembers.addAll(group.getMembers());
                existingGroup.setMembers(currentMembers);

                val groupServerResponse = scimService.update(Group.class, EndpointPaths.GROUPS, existingGroup.getId().orElseThrow())
                    .setResource(existingGroup)
                    .sendRequest();
                return groupServerResponse.isSuccess();
            }
            return scimService.create(Group.class, EndpointPaths.GROUPS)
                .setResource(group)
                .sendRequest()
                .isSuccess();
        }
        return false;
    }
Create or update groups.

@param scimService the scim service
@param group       the group
@return true or false
support/cas-server-support-scim-core/src/main/java/org/apereo/cas/scim/v2/BaseScimService.java