Blame SOURCES/0070-ovirt-Use-sso-token-when-set-in-.vv-file.patch

099e20
From 193ab5abdd2807d94e49c7333afc740cf2496e99 Mon Sep 17 00:00:00 2001
099e20
From: Christophe Fergeau <cfergeau@redhat.com>
099e20
Date: Fri, 15 Jan 2016 16:35:52 +0100
099e20
Subject: [PATCH] ovirt: Use sso-token when set in .vv file
099e20
099e20
Starting with oVirt 4.0, this replaces the jsessionid field for
099e20
automatic authentication with oVirt instances for REST communication.
099e20
099e20
(cherry picked from commit 4f3733294028d9b1f7c7135eb299436509845bb4)
099e20
---
099e20
 man/remote-viewer.pod    | 11 +++++++++--
099e20
 src/ovirt-foreign-menu.c | 25 ++++++++++++++++++++++---
099e20
 2 files changed, 31 insertions(+), 5 deletions(-)
099e20
099e20
diff --git a/man/remote-viewer.pod b/man/remote-viewer.pod
099e20
index 1358f1b..6b69aa3 100644
099e20
--- a/man/remote-viewer.pod
099e20
+++ b/man/remote-viewer.pod
099e20
@@ -309,8 +309,15 @@ GUID of the oVirt virtual machine to connect to.
099e20
 
099e20
 =item C<jsessionid> (string)
099e20
 
099e20
-Value to set the 'jsessionid' cookie to. Setting this authentication cookie to a valid value
099e20
-will allow to interact with the oVirt REST API without being asked for credentials.
099e20
+Value to set the 'jsessionid' cookie to. With oVirt 3.6, setting this
099e20
+authentication cookie to a valid value will allow to interact with the oVirt
099e20
+REST API without being asked for credentials.
099e20
+
099e20
+=item C<sso-token> (string)
099e20
+
099e20
+Value to set the 'Authorization' header to. With oVirt 4.0 or newer, setting
099e20
+this authentication header to a valid value will allow to interact with the
099e20
+oVirt REST API without being asked for credentials.
099e20
 
099e20
 =item C<ca> (string)
099e20
 
099e20
diff --git a/src/ovirt-foreign-menu.c b/src/ovirt-foreign-menu.c
099e20
index b170054..2f96ad8 100644
099e20
--- a/src/ovirt-foreign-menu.c
099e20
+++ b/src/ovirt-foreign-menu.c
099e20
@@ -830,6 +830,7 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
099e20
     gboolean admin;
099e20
     char *ca_str = NULL;
099e20
     char *jsessionid = NULL;
099e20
+    char *sso_token = NULL;
099e20
     char *url = NULL;
099e20
     char *vm_guid = NULL;
099e20
     GByteArray *ca = NULL;
099e20
@@ -837,15 +838,22 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
099e20
     url = virt_viewer_file_get_ovirt_host(file);
099e20
     vm_guid = virt_viewer_file_get_ovirt_vm_guid(file);
099e20
     jsessionid = virt_viewer_file_get_ovirt_jsessionid(file);
099e20
+    sso_token = virt_viewer_file_get_ovirt_sso_token(file);
099e20
     ca_str = virt_viewer_file_get_ovirt_ca(file);
099e20
     admin = virt_viewer_file_get_ovirt_admin(file);
099e20
 
099e20
-    if ((url == NULL) || (vm_guid == NULL) || (jsessionid == NULL)) {
099e20
-        g_debug("ignoring [ovirt] section content as URL, VM GUID or jsessionid"
099e20
+    if ((url == NULL) || (vm_guid == NULL)) {
099e20
+        g_debug("ignoring [ovirt] section content as URL, VM GUID"
099e20
                 " are missing from the .vv file");
099e20
         goto end;
099e20
     }
099e20
 
099e20
+    if ((jsessionid == NULL) && (sso_token == NULL)) {
099e20
+        g_debug("ignoring [ovirt] section content as jsessionid and sso-token"
099e20
+                " are both missing from the .vv file");
099e20
+        goto end;
099e20
+    }
099e20
+
099e20
     proxy = ovirt_proxy_new(url);
099e20
     if (proxy == NULL)
099e20
         goto end;
099e20
@@ -857,9 +865,19 @@ OvirtForeignMenu *ovirt_foreign_menu_new_from_file(VirtViewerFile *file)
099e20
 
099e20
     g_object_set(G_OBJECT(proxy),
099e20
                  "admin", admin,
099e20
-                 "session-id", jsessionid,
099e20
                  "ca-cert", ca,
099e20
                  NULL);
099e20
+    if (jsessionid != NULL) {
099e20
+        g_object_set(G_OBJECT(proxy),
099e20
+                     "session-id", jsessionid,
099e20
+                     NULL);
099e20
+    }
099e20
+    if (sso_token != NULL) {
099e20
+        g_object_set(G_OBJECT(proxy),
099e20
+                     "sso-token", sso_token,
099e20
+                     NULL);
099e20
+    }
099e20
+
099e20
     menu = g_object_new(OVIRT_TYPE_FOREIGN_MENU,
099e20
                         "proxy", proxy,
099e20
                         "vm-guid", vm_guid,
099e20
@@ -869,6 +887,7 @@ end:
099e20
     g_free(url);
099e20
     g_free(vm_guid);
099e20
     g_free(jsessionid);
099e20
+    g_free(sso_token);
099e20
     g_free(ca_str);
099e20
     if (ca != NULL) {
099e20
         g_byte_array_unref(ca);