protected boolean updateUserResource(final User user,
                                         final Principal principal,
                                         final Credential credential,
                                         final Optional<RegisteredService> registeredService) {
        mapper.forUpdate(user, principal, credential);
        LOGGER.trace("Updating user resource [{}]", user);

        val scimService = getScimRequestBuilder(registeredService);
        val updatedResult = updateUser(scimService, user);
        if (updatedResult.isPresent()) {
            val updatedUser = updatedResult.get();
            val groupsToCreateOrUpdate = mapper.forGroups(principal, updatedUser);
            val currentGroups = findUserGroups(scimService, updatedUser.getId().orElseThrow()).getResource().getListedResources();
            groupsToCreateOrUpdate.stream().parallel().forEach(group -> createOrUpdateGroups(scimService, group));
            currentGroups
                .stream()
                .parallel()
                .filter(group -> groupsToCreateOrUpdate.stream().noneMatch(g -> g.getDisplayName().equals(group.getDisplayName())))
                .forEach(group -> removeUserFromGroup(scimService, group, updatedUser));
        }
        return updatedResult.isPresent();
    }
This is {@link ScimPrincipalProvisioner}.

@author Misagh Moayyed
@since 5.1.0
support/cas-server-support-scim-core/src/main/java/org/apereo/cas/scim/v2/provisioning/ScimPrincipalProvisioner.java