[virt-tools-list] [virt-viewer 19/20] Handle authentication in VirtViewerSessionOvirt
Christophe Fergeau
cfergeau at redhat.com
Wed Jun 13 12:23:27 UTC 2012
Until now, the credentials were hardcoded in the source. Use
the virt_viewer_auth_collect_credentials API to interactively ask
for authentication credentials.
---
src/ovirt-proxy.c | 5 -----
src/virt-viewer-session-ovirt.c | 29 +++++++++++++++++++++++++++++
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/src/ovirt-proxy.c b/src/ovirt-proxy.c
index 7e3a071..ca47062 100644
--- a/src/ovirt-proxy.c
+++ b/src/ovirt-proxy.c
@@ -42,9 +42,6 @@ struct _OvirtProxyPrivate {
#define OVIRT_PROXY_GET_PRIVATE(o) (G_TYPE_INSTANCE_GET_PRIVATE((o), OVIRT_TYPE_PROXY, OvirtProxyPrivate))
-
-#define ADMIN_LOGIN "admin at internal"
-#define ADMIN_PASSWORD "XXXXXXX"
#define API_ENTRY_POINT "/api/"
enum OvirtResponseStatus {
@@ -810,7 +807,5 @@ OvirtProxy *ovirt_proxy_new(const char *uri)
return g_object_new(OVIRT_TYPE_PROXY,
"url-format", uri,
"ssl-strict", FALSE,
- "username", ADMIN_LOGIN,
- "password", ADMIN_PASSWORD,
NULL);
}
diff --git a/src/virt-viewer-session-ovirt.c b/src/virt-viewer-session-ovirt.c
index f5eb9b9..ab4d3bd 100644
--- a/src/virt-viewer-session-ovirt.c
+++ b/src/virt-viewer-session-ovirt.c
@@ -29,6 +29,7 @@
#include "ovirt-proxy.h"
#include "ovirt-vm.h"
#include "ovirt-vm-display.h"
+#include "virt-viewer-auth.h"
#include "virt-viewer-session-ovirt.h"
#include "virt-viewer-session-spice.h"
#include "virt-viewer-util.h"
@@ -419,6 +420,32 @@ error:
}
static gboolean
+authenticate_cb(RestProxy *proxy, G_GNUC_UNUSED RestProxyAuth *auth,
+ G_GNUC_UNUSED gboolean retrying, gpointer user_data)
+{
+ gchar *username;
+ gchar *password;
+ VirtViewerSessionOvirt *ovirt = VIRT_VIEWER_SESSION_OVIRT(user_data);
+
+ int ret = virt_viewer_auth_collect_credentials(ovirt->priv->main_window,
+ "oVirt",
+ NULL,
+ &username, &password);
+ if (ret < 0) {
+ g_signal_emit_by_name(G_OBJECT(ovirt), "session-cancelled");
+ return FALSE;
+ } else {
+ g_object_set(G_OBJECT(proxy),
+ "username", username,
+ "password", password,
+ NULL);
+ g_free(username);
+ g_free(password);
+ return TRUE;
+ }
+}
+
+static gboolean
virt_viewer_session_ovirt_open_uri(VirtViewerSession *session,
const gchar *uri)
{
@@ -435,6 +462,8 @@ virt_viewer_session_ovirt_open_uri(VirtViewerSession *session,
proxy = ovirt_proxy_new (self->priv->rest_uri);
if (proxy == NULL)
goto error;
+ g_signal_connect(G_OBJECT(proxy), "authenticate",
+ G_CALLBACK(authenticate_cb), session);
ovirt_proxy_lookup_vm_async(proxy, self->priv->vm_name,
lookup_vm_async_cb, session,
&error);
--
1.7.10.2
More information about the virt-tools-list
mailing list