[gnome-online-accounts/wip/kerberos: 5/5] wip: stuff that should be split and squashed



commit bd07d2272710b7541e1fdfa87a353a7acd5c0848
Author: Ray Strode <rstrode redhat com>
Date:   Mon Aug 13 22:00:29 2012 -0400

    wip: stuff that should be split and squashed

 src/daemon/goadaemon.c                             |   12 +-
 src/goabackend/goakerberosprovider.c               |   48 +-
 src/goaidentity/Makefile.am                        |    4 +-
 src/goaidentity/goaidentitylibrary.h               |   59 --
 .../{goaidentitylibrary.c => goaidentityservice.c} |  959 ++++++++++++++------
 src/goaidentity/goaidentityservice.h               |   61 ++
 6 files changed, 817 insertions(+), 326 deletions(-)
---
diff --git a/src/daemon/goadaemon.c b/src/daemon/goadaemon.c
index daf1a2e..ecef6d8 100644
--- a/src/daemon/goadaemon.c
+++ b/src/daemon/goadaemon.c
@@ -30,7 +30,7 @@
 #include "goadaemon.h"
 #include "goabackend/goabackend.h"
 #include "goabackend/goautils.h"
-#include "goaidentity/goaidentitylibrary.h"
+#include "goaidentity/goaidentityservice.h"
 
 struct _GoaDaemon
 {
@@ -46,7 +46,7 @@ struct _GoaDaemon
 
   GoaManager *manager;
 
-  GoaIdentityLibrary *identity_library;
+  GoaIdentityService *identity_service;
   NotifyNotification *notification;
 
   guint config_timeout_id;
@@ -132,7 +132,7 @@ goa_daemon_finalize (GObject *object)
   g_object_unref (daemon->object_manager);
   g_object_unref (daemon->connection);
 
-  g_clear_object (&daemon->identity_library);
+  g_clear_object (&daemon->identity_service);
 
   G_OBJECT_CLASS (goa_daemon_parent_class)->finalize (object);
 }
@@ -245,13 +245,13 @@ goa_daemon_init (GoaDaemon *daemon)
   /* Export objects */
   g_dbus_object_manager_server_set_connection (daemon->object_manager, daemon->connection);
 
-  daemon->identity_library = goa_identity_library_new ();
-  if (!goa_identity_library_activate (daemon->identity_library,
+  daemon->identity_service = goa_identity_service_new ();
+  if (!goa_identity_service_activate (daemon->identity_service,
                                       &error))
     {
       goa_warning ("Error activating identity service: %s", error->message);
       g_error_free (error);
-      g_clear_object (&daemon->identity_library);
+      g_clear_object (&daemon->identity_service);
     }
 }
 
diff --git a/src/goabackend/goakerberosprovider.c b/src/goabackend/goakerberosprovider.c
index 36eab82..f7b8a06 100644
--- a/src/goabackend/goakerberosprovider.c
+++ b/src/goabackend/goakerberosprovider.c
@@ -400,7 +400,6 @@ on_identity_manager_ensured_for_sign_in (GoaKerberosProvider *self,
 
 static void
 sign_in_identity (GoaKerberosProvider  *self,
-                  GoaClient            *client,
                   const char           *identity,
                   GCancellable         *cancellable,
                   GAsyncReadyCallback   callback,
@@ -439,7 +438,8 @@ on_account_signed_in (GoaProvider   *provider,
       return;
     }
 
-  g_main_loop_quit (request->loop);}
+  g_main_loop_quit (request->loop);
+}
 
 static gboolean
 refresh_account (GoaProvider    *provider,
@@ -468,7 +468,6 @@ refresh_account (GoaProvider    *provider,
 
   error = NULL;
   sign_in_identity (self,
-                    client,
                     identity,
                     NULL,
                     (GAsyncReadyCallback)
@@ -583,7 +582,6 @@ start_over:
   /* After the account is created, try to sign it in
    */
   sign_in_identity (self,
-                    client,
                     principal,
                     NULL,
                     (GAsyncReadyCallback)
@@ -658,6 +656,47 @@ show_account (GoaProvider         *provider,
                                                    _("Network Resources"));
 }
 
+static gboolean
+ensure_credentials_sync (GoaProvider         *provider,
+                         GoaObject           *object,
+                         gint                *out_expires_in,
+                         GCancellable        *cancellable,
+                         GError             **error)
+{
+  GoaKerberosProvider *self = GOA_KERBEROS_PROVIDER (provider);
+  GoaAccount          *account;
+  const char          *identity;
+  SignInRequest        request;
+
+  account = goa_object_peek_account (object);
+  identity = goa_account_get_identity (account);
+
+  memset (&request, 0, sizeof (SignInRequest));
+  request.loop = g_main_loop_new (NULL, FALSE);
+  request.error = NULL;
+
+  error = NULL;
+  sign_in_identity (self,
+                    identity,
+                    NULL,
+                    (GAsyncReadyCallback)
+                    on_account_signed_in,
+                    &request);
+
+  g_main_loop_run (request.loop);
+  g_main_loop_unref (request.loop);
+
+  if (request.error != NULL)
+    {
+      g_propagate_error (error, request.error);
+      return FALSE;
+    }
+
+  *out_expires_in = -1;
+
+  return TRUE;
+}
+
 static void
 goa_kerberos_provider_init (GoaKerberosProvider *provider)
 {
@@ -675,4 +714,5 @@ goa_kerberos_provider_class_init (GoaKerberosProviderClass *klass)
   provider_class->add_account                = add_account;
   provider_class->refresh_account            = refresh_account;
   provider_class->show_account               = show_account;
+  provider_class->ensure_credentials_sync    = ensure_credentials_sync;
 }
diff --git a/src/goaidentity/Makefile.am b/src/goaidentity/Makefile.am
index 3306571..8fa4ad3 100644
--- a/src/goaidentity/Makefile.am
+++ b/src/goaidentity/Makefile.am
@@ -23,7 +23,7 @@ identity_headers =						\
 	goaalarm.h						\
 	goaidentity.h						\
 	goaidentityinquiry.h					\
-	goaidentitylibrary.h					\
+	goaidentityservice.h					\
 	goaidentitymanagerprivate.h				\
 	goaidentitymanager.h					\
 	goaidentityutils.h					\
@@ -37,7 +37,7 @@ identity_sources =						\
 				goaalarm.c			\
 				goaidentity.c			\
 				goaidentityinquiry.c		\
-				goaidentitylibrary.c		\
+				goaidentityservice.c		\
 				goaidentitymanager.c		\
 				goaidentityutils.c		\
 				goakerberosidentity.c		\
diff --git a/src/goaidentity/goaidentitylibrary.c b/src/goaidentity/goaidentityservice.c
similarity index 50%
rename from src/goaidentity/goaidentitylibrary.c
rename to src/goaidentity/goaidentityservice.c
index 4777b40..28fd668 100644
--- a/src/goaidentity/goaidentitylibrary.c
+++ b/src/goaidentity/goaidentityservice.c
@@ -19,7 +19,7 @@
  */
 
 #include "config.h"
-#include "goaidentitylibrary.h"
+#include "goaidentityservice.h"
 
 #include <glib/gi18n-lib.h>
 #include <gmodule.h>
@@ -32,139 +32,387 @@
 #include <gcr/gcr.h>
 
 #include "goakerberosprovider.h"
+#include "goaidentityutils.h"
 
 #include "goakerberosidentitymanager.h"
 #include "goalogging.h"
 
-struct _GoaIdentityLibraryPrivate
+struct _GoaIdentityServicePrivate
 {
-  GoaIdentityManager *identity_manager;
-  GDBusConnection    *connection;
+  GDBusObjectManagerServer *identity_object_manager_server;
+  GoaIdentityManager       *identity_manager;
+  GDBusConnection          *connection;
+  guint                     bus_id;
 
-  GoaClient          *client;
-  GoaManager         *accounts_manager;
-  GDBusObjectManager *object_manager;
-  guint bus_id;
+  GoaClient                *client;
+  GoaManager               *accounts_manager;
 };
 
-G_DEFINE_TYPE (GoaIdentityLibrary, goa_identity_library, G_TYPE_OBJECT);
+static void identity_service_manager_interface_init (GoaIdentityServiceManagerIface *interface);
+static void ask_to_sign_in (GoaIdentityService *self,
+                            GoaIdentity        *identity,
+                            GCancellable       *cancellable,
+                            GAsyncReadyCallback callback,
+                            gpointer            user_data);
+
+G_DEFINE_TYPE_WITH_CODE (GoaIdentityService,
+                         goa_identity_service,
+                         GOA_IDENTITY_SERVICE_TYPE_MANAGER_SKELETON,
+                         G_IMPLEMENT_INTERFACE (GOA_IDENTITY_SERVICE_TYPE_MANAGER,
+                                                identity_service_manager_interface_init));
+
+static char *
+get_object_path_for_identity (GoaIdentityService *self,
+                              GoaIdentity        *identity)
+{
+  char **components;
+  GString *object_path;
+  int i;
+
+  components = goa_identity_get_identifier_components (identity);
+  object_path = g_string_new ("/org/gnome/Identity/Manager");
 
-static void
-goa_identity_library_init (GoaIdentityLibrary *self)
+  for (i = 0; components[i] != NULL; i++)
+    {
+      char *escaped_component;
+
+      g_string_append_c (object_path, '/');
+      escaped_component = goa_identity_utils_escape_object_path_component (components[i],
+                                                                           (gsize)
+                                                                           strlen (components[i]));
+
+      g_string_append (object_path, escaped_component);
+
+      g_free (escaped_component);
+    }
+  g_strfreev (components);
+
+  return g_string_free (object_path, FALSE);
+}
+
+static char *
+export_identity (GoaIdentityService *self,
+                 GoaIdentity        *identity)
 {
-  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
-                                            GOA_TYPE_IDENTITY_LIBRARY,
-                                            GoaIdentityLibraryPrivate);
+  char *object_path;
+  GDBusObjectSkeleton *object;
+  GDBusInterfaceSkeleton *interface;
 
-  goa_debug ("GoaIdentityLibrary: initializing");
+  object_path = get_object_path_for_identity (self, identity);
+  object = G_DBUS_OBJECT_SKELETON (goa_identity_service_object_skeleton_new (object_path));
+  interface = G_DBUS_INTERFACE_SKELETON (goa_identity_service_org_gnome_identity_skeleton_new ());
+
+  g_object_bind_property (G_OBJECT (identity),
+                          "identifier",
+                          G_OBJECT (interface),
+                          "identifier",
+                          G_BINDING_DEFAULT);
+
+  g_object_bind_property (G_OBJECT (identity),
+                          "expiration-timestamp",
+                          G_OBJECT (interface),
+                          "expiration-timestamp",
+                          G_BINDING_DEFAULT);
+
+  g_dbus_object_skeleton_add_interface (object, interface);
+  g_object_unref (interface);
+
+  g_dbus_object_manager_server_export (self->priv->identity_object_manager_server, object);
+  g_object_unref (object);
+
+  return object_path;
 }
 
 static void
-goa_identity_library_finalize (GObject *object)
+unexport_identity (GoaIdentityService *self,
+                   GoaIdentity        *identity)
 {
-  GoaIdentityLibrary *self;
+  char *object_path;
 
-  g_return_if_fail (object != NULL);
-  g_return_if_fail (GOA_IS_IDENTITY_LIBRARY (object));
+  object_path = get_object_path_for_identity (self, identity);
+  g_dbus_object_manager_server_unexport (self->priv->identity_object_manager_server,
+                                         object_path);
+  g_free (object_path);
+}
 
-  goa_debug ("GoaIdentityLibrary: finalizing");
+static void
+on_sign_in_done (GoaIdentityService *self,
+                 GAsyncResult       *result,
+                 GSimpleAsyncResult *operation_result)
+{
+  GError *error;
 
-  self = GOA_IDENTITY_LIBRARY (object);
+  error = NULL;
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), &error))
+    {
+      g_simple_async_result_take_error (operation_result, error);
+    }
+  else
+    {
+      GoaIdentity *identity;
+      char        *object_path;
 
-  goa_identity_library_deactivate (self);
+      identity = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
+      object_path = export_identity (self, identity);
 
-  g_clear_object (&self->priv->identity_manager);
+      g_simple_async_result_set_op_res_gpointer (operation_result,
+                                                 object_path,
+                                                 (GDestroyNotify)
+                                                 g_free);
+    }
+
+  g_simple_async_result_complete_in_idle (operation_result);
 
-  G_OBJECT_CLASS (goa_identity_library_parent_class)->finalize (object);
 }
 
 static void
-on_identity_renewed (GoaIdentityManager *manager,
-                     GAsyncResult       *result,
-                     GoaIdentityLibrary *self)
+on_got_identity_for_sign_in (GoaIdentityManager *manager,
+                             GAsyncResult       *result,
+                             GSimpleAsyncResult *operation_result)
 {
-  GError *error;
+  GoaIdentityService *self;
+  GError             *error;
+  GoaIdentity        *identity;
 
   error = NULL;
-  goa_identity_manager_renew_identity_finish (manager, result, &error);
+  identity = goa_identity_manager_get_identity_finish (manager, result, &error);
 
   if (error != NULL)
     {
-      goa_debug ("GoaIdentityLibrary: could not renew identity: %s",
-               error->message);
-      g_error_free (error);
+      goa_debug ("GoaIdentityService: Identity could not be signed in: %s",
+                 error->message);
       return;
     }
 
-  goa_debug ("GoaIdentityLibrary: identity renewed");
+  self = GOA_IDENTITY_SERVICE (g_async_result_get_source_object (G_ASYNC_RESULT (operation_result)));
+
+  ask_to_sign_in (self,
+                  identity,
+                  NULL,
+                  (GAsyncReadyCallback)
+                  on_sign_in_done,
+                  operation_result);
 }
 
 static void
-on_identity_needs_renewal (GoaIdentityManager *identity_manager,
-                           GoaIdentity        *identity,
-                           GoaIdentityLibrary *self)
+on_sign_in_handled (GoaIdentityService    *self,
+                    GAsyncResult          *result,
+                    GDBusMethodInvocation *invocation)
 {
-  const char *principal;
+  GError *error = NULL;
 
-  principal = goa_identity_get_identifier (identity);
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), &error))
+    {
+      g_dbus_method_invocation_take_error (invocation, error);
+    }
+  else
+    {
+      const char *object_path;
 
-  goa_debug ("GoaIdentityLibrary: identity %s needs renewal", principal);
+      object_path = g_simple_async_result_get_op_res_gpointer (G_SIMPLE_ASYNC_RESULT (result));
+      goa_identity_service_manager_complete_sign_in (GOA_IDENTITY_SERVICE_MANAGER (self),
+                                                     invocation,
+                                                     object_path);
+    }
+}
 
-  object = find_object_with_principal (self, principal);
+static gboolean
+goa_identity_service_handle_sign_in (GoaIdentityServiceManager *manager,
+                                     GDBusMethodInvocation     *invocation,
+                                     const char                *identifier,
+                                     GVariant                  *details)
+{
+  GoaIdentityService *self = GOA_IDENTITY_SERVICE (manager);
 
-  if (object != NULL)
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+                                      (GAsyncReadyCallback)
+                                      on_sign_in_handled,
+                                      g_object_ref (invocation),
+                                      goa_identity_service_handle_sign_in);
+  goa_identity_manager_get_identity (self->priv->identity_manager,
+                                     identifier,
+                                     NULL,
+                                     (GAsyncReadyCallback)
+                                     on_got_identity_for_sign_in,
+                                     result);
+  return TRUE;
+}
+
+static void
+on_sign_out_handled (GoaIdentityService    *self,
+                     GAsyncResult          *result,
+                     GDBusMethodInvocation *invocation)
+{
+  GError *error = NULL;
+
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), &error))
+    g_dbus_method_invocation_take_error (invocation, error);
+  else
+    goa_identity_service_manager_complete_sign_out (GOA_IDENTITY_SERVICE_MANAGER (self),
+                                                    invocation);
+}
+
+static void
+on_identity_signed_out (GoaIdentityManager *manager,
+                        GAsyncResult       *result,
+                        GSimpleAsyncResult *operation_result)
+{
+  GError *error;
+
+  error = NULL;
+  goa_identity_manager_sign_identity_out_finish (manager, result, &error);
+
+  if (error != NULL)
     {
-      GoaAccount *account;
+      goa_debug ("GoaIdentityService: Identity could not be signed out: %s",
+                 error->message);
+      g_simple_async_result_take_error (operation_result, error);
+    }
+  else
 
-      account = goa_object_peek_account (object);
+  g_simple_async_result_complete_in_idle (operation_result);
+  g_object_unref (operation_result);
+}
+
+static void
+on_got_identity_for_sign_out (GoaIdentityManager *manager,
+                              GAsyncResult       *result,
+                              GSimpleAsyncResult *operation_result)
+{
+  GError *error;
+  GoaIdentity *identity;
 
+  error = NULL;
+  identity = goa_identity_manager_get_identity_finish (manager, result, &error);
+
+  if (error != NULL)
+    {
+      goa_debug ("GoaIdentityService: Identity could not be signed out: %s",
+                 error->message);
+      return;
     }
 
-  goa_identity_manager_renew_identity (GOA_IDENTITY_MANAGER
-                                       (self->priv->identity_manager),
-                                       identity,
-                                       NULL,
-                                       (GAsyncReadyCallback)
-                                       on_identity_renewed,
-                                       self);
+  goa_identity_manager_sign_identity_out (manager,
+                                          identity,
+                                          NULL,
+                                          (GAsyncReadyCallback)
+                                          on_identity_signed_out,
+                                          operation_result);
+}
+
+static gboolean
+goa_identity_service_handle_sign_out (GoaIdentityServiceManager *manager,
+                                      GDBusMethodInvocation     *invocation,
+                                      const char                *identifier)
+{
+  GoaIdentityService *self = GOA_IDENTITY_SERVICE (manager);
+  GSimpleAsyncResult *result;
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+                                      (GAsyncReadyCallback)
+                                      on_sign_out_handled,
+                                      g_object_ref (invocation),
+                                      goa_identity_service_handle_sign_out);
+
+  goa_identity_manager_get_identity (self->priv->identity_manager,
+                                     identifier,
+                                     NULL,
+                                     (GAsyncReadyCallback)
+                                     on_got_identity_for_sign_out,
+                                     result);
+  return TRUE;
 }
 
 static void
-on_identity_signed_in (GoaIdentityManager *manager,
-                       GAsyncResult       *result,
-                       GoaIdentityLibrary *self)
+identity_service_manager_interface_init (GoaIdentityServiceManagerIface *interface)
+{
+  interface->handle_sign_in = goa_identity_service_handle_sign_in;
+  interface->handle_sign_out = goa_identity_service_handle_sign_out;
+}
+
+static void
+goa_identity_service_init (GoaIdentityService *self)
+{
+  self->priv = G_TYPE_INSTANCE_GET_PRIVATE (self,
+                                            GOA_TYPE_IDENTITY_SERVICE,
+                                            GoaIdentityServicePrivate);
+
+  goa_debug ("GoaIdentityService: initializing");
+}
+
+static void
+goa_identity_service_finalize (GObject *object)
+{
+  GoaIdentityService *self;
+
+  g_return_if_fail (object != NULL);
+  g_return_if_fail (GOA_IS_IDENTITY_SERVICE (object));
+
+  goa_debug ("GoaIdentityService: finalizing");
+
+  self = GOA_IDENTITY_SERVICE (object);
+
+  goa_identity_service_deactivate (self);
+
+  g_clear_object (&self->priv->identity_manager);
+  g_clear_object (&self->priv->identity_object_manager_server);
+
+  G_OBJECT_CLASS (goa_identity_service_parent_class)->finalize (object);
+}
+
+static void
+on_identity_renewed (GoaIdentityManager *manager,
+                     GAsyncResult       *result,
+                     GoaIdentityService *self)
 {
   GError *error;
 
   error = NULL;
-  goa_identity_manager_sign_identity_in_finish (manager, result, &error);
+  goa_identity_manager_renew_identity_finish (manager, result, &error);
 
   if (error != NULL)
     {
-      goa_debug ("GoaIdentityLibrary: could not sign in identity: %s",
+      goa_debug ("GoaIdentityService: could not renew identity: %s",
                error->message);
       g_error_free (error);
       return;
     }
 
-  goa_debug ("GoaIdentityLibrary: identity signed in");
+  goa_debug ("GoaIdentityService: identity renewed");
+}
+
+static gboolean
+should_ignore_object (GoaIdentityService *self,
+                      GoaObject          *object)
+{
+  GoaAccount *account;
+
+  account = goa_object_peek_account (object);
+
+  if (goa_account_get_ticketing_disabled (account))
+    return TRUE;
+
+  return FALSE;
 }
 
 static GoaObject *
-find_object_with_principal (GoaIdentityLibrary *self,
+find_object_with_principal (GoaIdentityService *self,
                             const char         *principal)
 {
   GList      *objects;
   GList      *node;
   GoaObject  *found_object;
 
-  objects = g_dbus_object_manager_get_objects (self->priv->object_manager);
+  objects = goa_client_get_accounts (self->priv->client);
 
   found_object = NULL;
   for (node = objects; node != NULL; node = node->next)
     {
       GoaObject *object = GOA_OBJECT (node->data);
       GoaAccount *account;
+      GoaTicketing *ticketing;
       const char *provider_type;
       const char *account_identity;
 
@@ -178,6 +426,11 @@ find_object_with_principal (GoaIdentityLibrary *self,
       if (g_strcmp0 (provider_type, "kerberos") != 0)
         continue;
 
+      ticketing = goa_object_peek_ticketing (object);
+
+      if (ticketing == NULL)
+        continue;
+
       account_identity = goa_account_get_identity (account);
 
       if (g_strcmp0 (account_identity, principal) == 0)
@@ -191,10 +444,119 @@ find_object_with_principal (GoaIdentityLibrary *self,
   return found_object;
 }
 
+
+static void
+on_identity_needs_renewal (GoaIdentityManager *identity_manager,
+                           GoaIdentity        *identity,
+                           GoaIdentityService *self)
+{
+  const char *principal;
+  GoaObject  *object;
+
+  principal = goa_identity_get_identifier (identity);
+
+  goa_debug ("GoaIdentityService: identity %s needs renewal", principal);
+
+  object = find_object_with_principal (self, principal);
+
+  if (object != NULL)
+    {
+      should_ignore_object (self, object);
+      return;
+    }
+
+  goa_identity_manager_renew_identity (GOA_IDENTITY_MANAGER
+                                       (self->priv->identity_manager),
+                                       identity,
+                                       NULL,
+                                       (GAsyncReadyCallback)
+                                       on_identity_renewed,
+                                       self);
+}
+
+typedef struct
+{
+  GoaIdentityService *service;
+  GoaIdentity        *identity;
+  NotifyNotification *notification;
+  GSimpleAsyncResult *result;
+  GCancellable       *cancellable;
+  gulong              refreshed_signal_id;
+} SignInRequest;
+
+static SignInRequest *
+sign_in_request_new (GoaIdentityService *service,
+                     GoaIdentity        *identity,
+                     NotifyNotification *notification,
+                     GSimpleAsyncResult *result,
+                     GCancellable       *cancellable)
+{
+  SignInRequest *request;
+
+  request = g_slice_new0 (SignInRequest);
+
+  request->service = service;
+  request->identity = g_object_ref (identity);
+  request->notification = notification;
+  request->result = result;
+  request->cancellable = g_object_ref (cancellable);
+
+  return request;
+}
+
+static void
+sign_in_request_free (SignInRequest *data)
+{
+  GoaIdentityService *service = data->service;
+
+  g_signal_handler_disconnect (service->priv->identity_manager,
+                               data->refreshed_signal_id);
+  g_object_set_data (G_OBJECT (data->identity),
+                     "sign-in-request",
+                     NULL);
+  g_clear_object (&data->identity);
+  g_clear_object (&data->cancellable);
+  g_clear_object (&data->result);
+  g_slice_free (SignInRequest, data);
+}
+
+static void
+on_identity_signed_in (GoaIdentityManager *manager,
+                       GAsyncResult       *result,
+                       SignInRequest      *request)
+{
+  GError *error;
+  GoaIdentity *identity;
+
+  error = NULL;
+  identity = goa_identity_manager_sign_identity_in_finish (manager, result, &error);
+
+  if (error != NULL)
+    {
+      goa_debug ("GoaIdentityService: could not sign in identity: %s",
+               error->message);
+      g_simple_async_result_take_error (request->result, error);
+      g_simple_async_result_complete_in_idle (request->result);
+      g_clear_object (&request->result);
+      g_clear_object (&request->cancellable);
+      return;
+    }
+
+  g_simple_async_result_set_op_res_gpointer (request->result,
+                                             g_object_ref (identity),
+                                             (GDestroyNotify)
+                                             g_object_unref);
+  g_simple_async_result_complete_in_idle (request->result);
+  g_clear_object (&request->result);
+  g_clear_object (&request->cancellable);
+
+  goa_debug ("GoaIdentityService: identity signed in");
+}
+
 static void
 on_account_created_for_identity (GoaManager         *manager,
                                  GAsyncResult       *result,
-                                 GoaIdentityLibrary *self)
+                                 GoaIdentityService *self)
 {
   char *object_path;
   GError *error;
@@ -220,7 +582,7 @@ on_account_created_for_identity (GoaManager         *manager,
 }
 
 static void
-add_temporary_account_if_necessary (GoaIdentityLibrary *self,
+add_temporary_account_if_necessary (GoaIdentityService *self,
                                     GoaIdentity        *identity)
 {
   char            *realm;
@@ -239,7 +601,7 @@ add_temporary_account_if_necessary (GoaIdentityLibrary *self,
       return;
     }
 
-  goa_debug ("GoaIdentityLibrary: adding temporary identity %s", principal);
+  goa_debug ("GoaIdentityService: adding temporary identity %s", principal);
 
   /* If there's no account for this identity then create a temporary one.
    */
@@ -270,64 +632,31 @@ add_temporary_account_if_necessary (GoaIdentityLibrary *self,
 static void
 on_identity_added (GoaIdentityManager *identity_manager,
                    GoaIdentity        *identity,
-                   GoaIdentityLibrary *self)
+                   GoaIdentityService *self)
 {
+  export_identity (self, identity);
   add_temporary_account_if_necessary (self, identity);
 }
 
 static void
-on_identity_refreshed (GoaIdentityManager *identity_manager,
-                       GoaIdentity        *identity,
-                       GoaIdentityLibrary *self)
-{
-  add_temporary_account_if_necessary (self, identity);
-}
-
-typedef struct
-{
-  GoaIdentityLibrary *library;
-  GoaIdentity        *identity;
-  NotifyNotification *notification;
-  GCancellable       *cancellable;
-  gulong              refreshed_signal_id;
-} SignInRequest;
-
-static SignInRequest *
-sign_in_request_new (GoaIdentityLibrary *library,
+on_identity_removed (GoaIdentityManager *identity_manager,
                      GoaIdentity        *identity,
-                     NotifyNotification *notification,
-                     GCancellable       *cancellable)
+                     GoaIdentityService *self)
 {
-  SignInRequest *request;
-
-  request = g_slice_new0 (SignInRequest);
-
-  request->library = library;
-  request->identity = g_object_ref (identity);
-  request->notification = notification;
-  request->cancellable = g_object_ref (cancellable);
-
-  return request;
+  unexport_identity (self, identity);
 }
 
 static void
-sign_in_request_free (SignInRequest *data)
+on_identity_refreshed (GoaIdentityManager *identity_manager,
+                       GoaIdentity        *identity,
+                       GoaIdentityService *self)
 {
-  GoaIdentityLibrary *library = data->library;
-
-  g_signal_handler_disconnect (library->priv->identity_manager,
-                               data->refreshed_signal_id);
-  g_object_set_data (G_OBJECT (data->identity),
-                     "sign-in-request",
-                     NULL);
-  g_clear_object (&data->identity);
-  g_clear_object (&data->cancellable);
-  g_slice_free (SignInRequest, data);
+  add_temporary_account_if_necessary (self, identity);
 }
 
 typedef struct
 {
-  GoaIdentityLibrary *library;
+  GoaIdentityService *service;
   GoaIdentity        *identity;
   GoaIdentityInquiry *inquiry;
   GoaIdentityQuery   *query;
@@ -336,7 +665,7 @@ typedef struct
 } SystemPromptRequest;
 
 static SystemPromptRequest *
-system_prompt_request_new (GoaIdentityLibrary *library,
+system_prompt_request_new (GoaIdentityService *service,
                            GcrSystemPrompt    *prompt,
                            GoaIdentity        *identity,
                            GoaIdentityInquiry *inquiry,
@@ -347,7 +676,7 @@ system_prompt_request_new (GoaIdentityLibrary *library,
 
   data = g_slice_new0 (SystemPromptRequest);
 
-  data->library = library;
+  data->service = service;
   data->prompt = prompt;
   data->identity = g_object_ref (identity);
   data->inquiry = g_object_ref (inquiry);
@@ -387,7 +716,7 @@ close_system_prompt (GoaIdentityManager  *manager,
     {
       if (error != NULL)
         {
-          goa_debug ("GoaIdentityLibrary: could not close system prompt: %s",
+          goa_debug ("GoaIdentityService: could not close system prompt: %s",
                    error->message);
           g_error_free (error);
         }
@@ -399,7 +728,7 @@ on_password_system_prompt_answered (GcrPrompt           *prompt,
                                     GAsyncResult        *result,
                                     SystemPromptRequest *request)
 {
-  GoaIdentityLibrary *self = request->library;
+  GoaIdentityService *self = request->service;
   GoaIdentityInquiry *inquiry = request->inquiry;
   GoaIdentity *identity = request->identity;
   GoaIdentityQuery *query = request->query;
@@ -414,7 +743,7 @@ on_password_system_prompt_answered (GcrPrompt           *prompt,
     {
       if (error != NULL)
         {
-          goa_debug ("GoaIdentityLibrary: could not get password from user: %s",
+          goa_debug ("GoaIdentityService: could not get password from user: %s",
                    error->message);
           g_error_free (error);
         }
@@ -433,7 +762,7 @@ on_password_system_prompt_answered (GcrPrompt           *prompt,
 }
 
 static void
-query_user (GoaIdentityLibrary *self,
+query_user (GoaIdentityService *self,
             GoaIdentity        *identity,
             GoaIdentityInquiry *inquiry,
             GoaIdentityQuery   *query,
@@ -500,13 +829,13 @@ query_user (GoaIdentityLibrary *self,
 
 typedef struct
 {
-  GoaIdentityLibrary *library;
+  GoaIdentityService *service;
   GoaIdentityInquiry *inquiry;
   GCancellable *cancellable;
 } SystemPromptOpenRequest;
 
 static SystemPromptOpenRequest *
-system_prompt_open_request_new (GoaIdentityLibrary *library,
+system_prompt_open_request_new (GoaIdentityService *service,
                                 GoaIdentityInquiry *inquiry,
                                 GCancellable       *cancellable)
 {
@@ -514,7 +843,7 @@ system_prompt_open_request_new (GoaIdentityLibrary *library,
 
   data = g_slice_new0 (SystemPromptOpenRequest);
 
-  data->library = library;
+  data->service = service;
   data->inquiry = g_object_ref (inquiry);
   data->cancellable = g_object_ref (cancellable);
 
@@ -534,7 +863,7 @@ on_system_prompt_open (GcrSystemPrompt         *system_prompt,
                        GAsyncResult            *result,
                        SystemPromptOpenRequest *request)
 {
-  GoaIdentityLibrary *self = request->library;
+  GoaIdentityService *self = request->service;
   GoaIdentityInquiry *inquiry = request->inquiry;
   GCancellable *cancellable = request->cancellable;
   GoaIdentity *identity;
@@ -550,7 +879,7 @@ on_system_prompt_open (GcrSystemPrompt         *system_prompt,
     {
       if (error != NULL)
         {
-          goa_debug ("GoaIdentityLibrary: could not open system prompt: %s",
+          goa_debug ("GoaIdentityService: could not open system prompt: %s",
                    error->message);
           g_error_free (error);
         }
@@ -568,7 +897,7 @@ on_system_prompt_open (GcrSystemPrompt         *system_prompt,
 static void
 on_identity_inquiry (GoaIdentityInquiry *inquiry,
                      GCancellable       *cancellable,
-                     GoaIdentityLibrary *self)
+                     GoaIdentityService *self)
 {
   SystemPromptOpenRequest *request;
 
@@ -584,7 +913,7 @@ on_sign_in_clicked (NotifyNotification *notification,
                     const char         *action_id,
                     SignInRequest      *request)
 {
-  GoaIdentityLibrary *self = request->library;
+  GoaIdentityService *self = request->service;
   GoaIdentity *identity = request->identity;
   const char *identifier;
 
@@ -596,7 +925,8 @@ on_sign_in_clicked (NotifyNotification *notification,
                                          self,
                                          request->cancellable,
                                          (GAsyncReadyCallback)
-                                         on_identity_signed_in, self);
+                                         on_identity_signed_in,
+                                         request);
 }
 
 static void
@@ -616,21 +946,33 @@ cancel_sign_in (GoaIdentityManager *identity_manager,
 }
 
 static void
-ask_to_sign_in (GoaIdentityLibrary *self,
-                GoaIdentity    *identity)
+ask_to_sign_in (GoaIdentityService *self,
+                GoaIdentity        *identity,
+                GCancellable       *cancellable,
+                GAsyncReadyCallback callback,
+                gpointer            user_data)
 {
   NotifyNotification *notification;
   char *name;
   char *description;
+  GSimpleAsyncResult *result;
   SignInRequest *request;
-  GCancellable *cancellable;
+
+  if (cancellable == NULL)
+    cancellable = g_cancellable_new ();
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+                                      callback,
+                                      user_data,
+                                      ask_to_sign_in);
+  g_simple_async_result_set_check_cancellable (result, cancellable);
 
   request = g_object_get_data (G_OBJECT (identity), "sign-in-request");
 
   if (request != NULL)
     g_cancellable_cancel (request->cancellable);
 
-  goa_debug ("GoaIdentityLibrary: asking to sign back in");
+  goa_debug ("GoaIdentityService: asking to sign back in");
 
   name = goa_identity_manager_name_identity (self->priv->identity_manager, identity);
   if (goa_identity_is_signed_in (identity))
@@ -652,9 +994,7 @@ ask_to_sign_in (GoaIdentityLibrary *self,
   g_free (description);
   notify_notification_set_app_name (notification, _("Network Realm"));
 
-  cancellable = g_cancellable_new ();
-
-  request = sign_in_request_new (self, identity, notification, cancellable);
+  request = sign_in_request_new (self, identity, notification, result, cancellable);
 
   g_object_set_data (G_OBJECT (identity),
                      "sign-in-request",
@@ -664,10 +1004,6 @@ ask_to_sign_in (GoaIdentityLibrary *self,
                          G_CALLBACK (close_notification),
                          notification,
                          NULL);
-  g_signal_connect_swapped (G_OBJECT (notification),
-                            "closed",
-                            G_CALLBACK (sign_in_request_free),
-                            request);
 
   request->refreshed_signal_id =
     g_signal_connect (G_OBJECT (self->priv->identity_manager),
@@ -681,181 +1017,270 @@ ask_to_sign_in (GoaIdentityLibrary *self,
                                   (NotifyActionCallback)
                                   on_sign_in_clicked,
                                   request,
-                                  NULL);
+                                  (GFreeFunc)
+                                  sign_in_request_free);
 
   notify_notification_show (notification, NULL);
 }
 
 static void
+on_credentials_ensured (GoaAccount         *account,
+                        GAsyncResult       *result,
+                        GoaIdentityService *self)
+{
+  GError     *error;
+  const char *account_identity;
+  int         expires_in;
+
+  account_identity = goa_account_get_identity (account);
+
+  error = NULL;
+  if (!goa_account_call_ensure_credentials_finish (account,
+                                                   &expires_in,
+                                                   result,
+                                                   &error))
+    {
+      goa_debug ("GoaIdentityService: could not ensure credentials for account %s: %s",
+                 account_identity,
+                 error->message);
+      g_error_free (error);
+      return;
+    }
+
+  goa_debug ("GoaIdentityService: credentials for account %s ensured for %d seconds",
+             account_identity,
+             expires_in);
+}
+
+static void
 on_identity_expiring (GoaIdentityManager *identity_manager,
                       GoaIdentity        *identity,
-                      GoaIdentityLibrary *self)
+                      GoaIdentityService *self)
 {
-  goa_debug ("GoaIdentityLibrary: identity expiring");
-  ask_to_sign_in (self, identity);
+  const char *principal;
+  GoaObject  *object;
+  GoaAccount *account;
+
+  principal = goa_identity_get_identifier (identity);
+
+  goa_debug ("GoaIdentityService: identity %s expiring", principal);
+
+  object = find_object_with_principal (self, principal);
+
+  if (object == NULL)
+    return;
+
+  if (should_ignore_object (self, object))
+    return;
+
+  account = goa_object_peek_account (object);
+  goa_account_call_ensure_credentials (account,
+                                       NULL,
+                                       (GAsyncReadyCallback)
+                                       on_credentials_ensured,
+                                       self);
 }
 
 static void
 on_identity_expired (GoaIdentityManager *identity_manager,
                      GoaIdentity        *identity,
-                     GoaIdentityLibrary *self)
+                     GoaIdentityService *self)
 {
-  goa_debug ("GoaIdentityLibrary: identity expired");
-  ask_to_sign_in (self, identity);
+  const char *principal;
+  GoaObject  *object;
+  GoaAccount *account;
+
+  principal = goa_identity_get_identifier (identity);
+
+  goa_debug ("GoaIdentityService: identity %s expired", principal);
+
+  object = find_object_with_principal (self, principal);
+
+  if (object == NULL)
+    return;
+
+  if (should_ignore_object (self, object))
+    return;
+
+  account = goa_object_peek_account (object);
+
+  goa_account_call_ensure_credentials (account,
+                                       NULL,
+                                       (GAsyncReadyCallback)
+                                       on_credentials_ensured,
+                                       self);
 }
 
 static void
-on_identity_signed_in_for_service (GoaIdentityManager *manager,
-                                   GAsyncResult       *result,
-                                   GSimpleAsyncResult *service_result)
+on_sign_out_for_account_change_done (GoaIdentityService *self,
+                                     GAsyncResult       *result)
 {
-  GError *error;
-  GoaIdentity *identity;
-
-  error = NULL;
-  identity = goa_identity_manager_sign_identity_in_finish (manager,
-                                                           result,
-                                                           &error);
+  GError *error = NULL;
 
-  if (error != NULL)
+  if (g_simple_async_result_propagate_error (G_SIMPLE_ASYNC_RESULT (result), &error))
     {
-      goa_debug ("GoaIdentityLibrary: Identity could not be signed in: %s",
-               error->message);
-      g_simple_async_result_take_error (service_result, error);
-
+      goa_debug ("Sign out failed: %s", error->message);
+      g_error_free (error);
     }
   else
     {
-      goa_debug ("GoaIdentityLibrary: Identity %s signed in",
-               goa_identity_get_identifier (identity));
-      g_simple_async_result_set_op_res_gpointer (service_result,
-                                                 g_object_ref (identity),
-                                                 (GDestroyNotify)
-                                                 g_object_unref);
+      goa_debug ("Sign out complete");
     }
-  g_simple_async_result_complete (service_result);
-
 }
 
 static void
-on_got_identity_for_service (GoaIdentityManager *manager,
-                             GAsyncResult       *result,
-                             GSimpleAsyncResult *service_result)
+on_account_interface_added (GDBusObjectManager *manager,
+                            GoaObject          *object,
+                            GDBusInterface     *interface,
+                            GoaIdentityService *self)
 {
-  GError *error;
-  GoaIdentity *identity;
+  GoaAccount         *account;
+  GoaTicketing       *ticketing;
+  GDBusInterfaceInfo *info;
+  const char         *provider_type;
 
-  error = NULL;
-  identity = goa_identity_manager_get_identity_finish (manager, result, &error);
+  account = goa_object_peek_account (object);
 
-  if (error != NULL)
-    {
-      goa_debug ("GoaIdentityLibrary: Identity could not be signed in: %s",
-                 error->message);
-      g_simple_async_result_take_error (service_result, error);
-      g_simple_async_result_complete (service_result);
-      return;
-    }
+  if (account == NULL)
+    return;
 
-  goa_identity_manager_sign_identity_out (manager,
-                                          identity,
-                                          NULL,
-                                          (GAsyncReadyCallback)
-                                          on_identity_signed_out_for_service,
-                                          service_result);
-}
+  provider_type = goa_account_get_provider_type (account);
 
-static void
-on_identity_signed_out_for_removal (GoaIdentityManager *manager,
-                                    GAsyncResult       *result,
-                                    GoaIdentityLibrary *self)
-{
-  GError *error;
+  if (g_strcmp0 (provider_type, "kerberos") != 0)
+    return;
 
-  error = NULL;
-  goa_identity_manager_sign_identity_out_finish (manager, result, &error);
+  info = g_dbus_interface_get_info (interface);
 
-  if (error != NULL)
+  if (g_strcmp0 (info->name, "org.gnome.OnlineAccounts.Ticketing") != 0)
+    return;
+
+  ticketing = goa_object_peek_ticketing (object);
+
+  if (ticketing != NULL)
     {
-      goa_debug ("GoaIdentityLibrary: Identity could not be signed out: %s",
-               error->message);
+      /* Ticketing interface is present, sign in if not already
+       * signed in.
+       */
+      goa_account_call_ensure_credentials (account,
+                                           NULL,
+                                           (GAsyncReadyCallback)
+                                           on_credentials_ensured,
+                                           self);
+      return;
     }
 }
 
 static void
-on_got_identity_for_removal (GoaIdentityManager *manager,
-                             GAsyncResult       *result,
-                             GoaIdentityLibrary *self)
+on_account_interface_removed (GDBusObjectManager *manager,
+                              GoaObject          *object,
+                              GDBusInterface     *interface,
+                              GoaIdentityService *self)
 {
-  GError *error;
-  GoaIdentity *identity;
+  GoaAccount         *account;
+  GoaTicketing       *ticketing;
+  GDBusInterfaceInfo *info;
+  const char         *provider_type;
+  const char         *account_identity;
+  GSimpleAsyncResult *result;
 
-  error = NULL;
-  identity = goa_identity_manager_get_identity_finish (manager, result, &error);
+  account = goa_object_peek_account (object);
 
-  if (error != NULL)
-    {
-      goa_debug ("GoaIdentityLibrary: Identity could not be signed out: %s",
-                 error->message);
-      return;
-    }
+  if (account == NULL)
+    return;
 
-  goa_identity_manager_sign_identity_out (manager,
-                                          identity,
-                                          NULL,
-                                          (GAsyncReadyCallback)
-                                          on_identity_signed_out_for_removal,
-                                          self);
+  provider_type = goa_account_get_provider_type (account);
+
+  if (g_strcmp0 (provider_type, "kerberos") != 0)
+    return;
+
+  info = g_dbus_interface_get_info (interface);
+
+  if (g_strcmp0 (info->name, "org.gnome.OnlineAccounts.Ticketing") != 0)
+    return;
+
+  ticketing = goa_object_peek_ticketing (object);
+
+  if (ticketing != NULL)
+    return;
+
+  /* Ticketing interface is gone, sign out if not already
+   * signed out.
+   */
+
+  account_identity = goa_account_get_identity (account);
+
+  goa_debug ("Kerberos account %s was disabled and should now be signed out", account_identity);
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+                                      (GAsyncReadyCallback)
+                                      on_sign_out_for_account_change_done,
+                                      NULL,
+                                      on_account_interface_removed);
+
+  goa_identity_manager_get_identity (self->priv->identity_manager,
+                                     account_identity,
+                                     NULL,
+                                     (GAsyncReadyCallback)
+                                     on_got_identity_for_sign_out,
+                                     result);
 }
 
 static void
-on_account_object_removed (GoaManager         *manager,
-                           GoaObject          *object,
-                           GoaIdentityLibrary *self)
+on_account_removed (GoaClient          *client,
+                    GoaObject          *object,
+                    GoaIdentityService *self)
 {
-  GoaAccount *account;
-  const char *provider_type;
-  const char *account_identity;
-
-  goa_debug ("Object removed");
+  GSimpleAsyncResult *result;
+  GoaAccount         *account;
+  const char         *provider_type;
+  const char         *account_identity;
 
   account = goa_object_peek_account (object);
 
   if (account == NULL)
     return;
 
-  goa_debug ("Object has account");
-
   provider_type = goa_account_get_provider_type (account);
 
   if (g_strcmp0 (provider_type, "kerberos") != 0)
     return;
 
-  goa_debug ("Object is kerberos object");
-
   account_identity = goa_account_get_identity (account);
 
+  goa_debug ("Kerberos account %s removed and should now be signed out", account_identity);
+
+  result = g_simple_async_result_new (G_OBJECT (self),
+                                      (GAsyncReadyCallback)
+                                      on_sign_out_for_account_change_done,
+                                      NULL,
+                                      on_account_removed);
+
   goa_identity_manager_get_identity (self->priv->identity_manager,
                                      account_identity,
                                      NULL,
                                      (GAsyncReadyCallback)
-                                     on_got_identity_for_removal,
-                                     self);
+                                     on_got_identity_for_sign_out,
+                                     result);
 }
 
 static void
 on_identities_listed (GoaIdentityManager *manager,
                       GAsyncResult       *result,
-                      GoaIdentityLibrary *self)
+                      GoaIdentityService *self)
 {
   GError *error = NULL;
   GList *identities, *node;
+  GDBusObjectManager *object_manager;
 
   g_signal_connect (G_OBJECT (self->priv->identity_manager),
                     "identity-added",
                     G_CALLBACK (on_identity_added),
                     self);
   g_signal_connect (G_OBJECT (self->priv->identity_manager),
+                    "identity-removed",
+                    G_CALLBACK (on_identity_removed),
+                    self);
+  g_signal_connect (G_OBJECT (self->priv->identity_manager),
                     "identity-refreshed",
                     G_CALLBACK (on_identity_refreshed),
                     self);
@@ -872,6 +1297,22 @@ on_identities_listed (GoaIdentityManager *manager,
                     G_CALLBACK (on_identity_expired),
                     self);
 
+  g_signal_connect (G_OBJECT (self->priv->client),
+                    "account-removed",
+                    G_CALLBACK (on_account_removed),
+                    self);
+
+  object_manager = goa_client_get_object_manager (self->priv->client);
+
+  g_signal_connect (G_OBJECT (object_manager),
+                    "interface-added",
+                    G_CALLBACK (on_account_interface_added),
+                    self);
+  g_signal_connect (G_OBJECT (object_manager),
+                    "interface-removed",
+                    G_CALLBACK (on_account_interface_removed),
+                    self);
+
   identities = goa_identity_manager_list_identities_finish (manager, result, &error);
 
   if (identities == NULL)
@@ -891,20 +1332,12 @@ on_identities_listed (GoaIdentityManager *manager,
       add_temporary_account_if_necessary (self, identity);
     }
 
-  g_signal_connect (G_OBJECT (self->priv->object_manager),
-                    "interface-removed",
-                    G_CALLBACK (on_account_object_removed),
-                    self);
-  g_signal_connect (G_OBJECT (self->priv->object_manager),
-                    "object-removed",
-                    G_CALLBACK (on_account_object_removed),
-                    self);
 }
 
 static void
 on_got_client (GoaClient          *client,
                GAsyncResult       *result,
-               GoaIdentityLibrary *self)
+               GoaIdentityService *self)
 {
   GError *error;
 
@@ -918,7 +1351,6 @@ on_got_client (GoaClient          *client,
       return;
     }
 
-  self->priv->object_manager = goa_client_get_object_manager (client);
   self->priv->accounts_manager = goa_client_get_manager (client);
 
   self->priv->identity_manager = goa_kerberos_identity_manager_new (NULL, &error);
@@ -939,14 +1371,17 @@ on_got_client (GoaClient          *client,
 static void
 on_bus_acquired (GDBusConnection    *connection,
                  const char         *unique_name,
-                 GoaIdentityLibrary *self)
+                 GoaIdentityService *self)
 {
-  goa_debug ("GoaIdentityLibrary: Connected to session bus");
+  goa_debug ("GoaIdentityService: Connected to session bus");
 
   if (self->priv->connection == NULL)
   {
     self->priv->connection = g_object_ref (connection);
 
+    g_dbus_object_manager_server_set_connection (self->priv->identity_object_manager_server,
+                                                 self->priv->connection);
+
     goa_client_new (NULL,
                     (GAsyncReadyCallback)
                     on_got_client,
@@ -957,28 +1392,41 @@ on_bus_acquired (GDBusConnection    *connection,
 static void
 on_name_acquired (GDBusConnection    *connection,
                   const char         *name,
-                  GoaIdentityLibrary *self)
+                  GoaIdentityService *self)
 {
   if (g_strcmp0 (name, "org.gnome.Identity") == 0)
-    goa_debug ("GoaIdentityLibrary: Acquired name org.gnome.Identity");
+    goa_debug ("GoaIdentityService: Acquired name org.gnome.Identity");
 }
 
 static void
 on_name_lost (GDBusConnection    *connection,
               const char         *name,
-              GoaIdentityLibrary *self)
+              GoaIdentityService *self)
 {
   if (g_strcmp0 (name, "org.gnome.Identity") == 0)
-    goa_debug ("GoaIdentityLibrary: Lost name org.gnome.Identity");
+    goa_debug ("GoaIdentityService: Lost name org.gnome.Identity");
 }
 
 gboolean
-goa_identity_library_activate (GoaIdentityLibrary   *self,
+goa_identity_service_activate (GoaIdentityService   *self,
                                GError              **error)
 {
-  g_return_val_if_fail (GOA_IS_IDENTITY_LIBRARY (self), FALSE);
+  GoaIdentityServiceObjectSkeleton *object;
+
+  g_return_val_if_fail (GOA_IS_IDENTITY_SERVICE (self), FALSE);
+
+  goa_debug ("GoaIdentityService: Activating identity service");
+
+  self->priv->identity_object_manager_server =
+    g_dbus_object_manager_server_new ("/org/gnome/Identity");
+
+  object = goa_identity_service_object_skeleton_new ("/org/gnome/Identity/Manager");
+  goa_identity_service_object_skeleton_set_manager (object,
+                                                    GOA_IDENTITY_SERVICE_MANAGER (self));
 
-  goa_debug ("GoaIdentityLibrary: Activating identity library");
+  g_dbus_object_manager_server_export (self->priv->identity_object_manager_server,
+                                       G_DBUS_OBJECT_SKELETON (object));
+  g_object_unref (object);
 
   self->priv->bus_id = g_bus_own_name (G_BUS_TYPE_SESSION,
                                        "org.gnome.Identity",
@@ -994,9 +1442,9 @@ goa_identity_library_activate (GoaIdentityLibrary   *self,
 }
 
 void
-goa_identity_library_deactivate (GoaIdentityLibrary *self)
+goa_identity_service_deactivate (GoaIdentityService *self)
 {
-  goa_debug ("GoaIdentityLibrary: Deactivating identity library");
+  goa_debug ("GoaIdentityService: Deactivating identity service");
 
   if (self->priv->identity_manager != NULL)
     {
@@ -1006,27 +1454,28 @@ goa_identity_library_deactivate (GoaIdentityLibrary *self)
       g_clear_object (&self->priv->identity_manager);
     }
 
+  g_clear_object (&self->priv->identity_object_manager_server);
   g_clear_object (&self->priv->connection);
   g_clear_object (&self->priv->client);
 }
 
 static void
-goa_identity_library_class_init (GoaIdentityLibraryClass *library_class)
+goa_identity_service_class_init (GoaIdentityServiceClass *service_class)
 {
-  GObjectClass *object_class = G_OBJECT_CLASS (library_class);
+  GObjectClass *object_class = G_OBJECT_CLASS (service_class);
 
-  object_class->finalize = goa_identity_library_finalize;
+  object_class->finalize = goa_identity_service_finalize;
 
-  g_type_class_add_private (library_class, sizeof (GoaIdentityLibraryPrivate));
+  g_type_class_add_private (service_class, sizeof (GoaIdentityServicePrivate));
 }
 
-GoaIdentityLibrary *
-goa_identity_library_new (void)
+GoaIdentityService *
+goa_identity_service_new (void)
 {
   GObject *object;
 
-  object = g_object_new (GOA_TYPE_IDENTITY_LIBRARY,
+  object = g_object_new (GOA_TYPE_IDENTITY_SERVICE,
                          NULL);
 
-  return GOA_IDENTITY_LIBRARY (object);
+  return GOA_IDENTITY_SERVICE (object);
 }
diff --git a/src/goaidentity/goaidentityservice.h b/src/goaidentity/goaidentityservice.h
new file mode 100644
index 0000000..5bbe5f5
--- /dev/null
+++ b/src/goaidentity/goaidentityservice.h
@@ -0,0 +1,61 @@
+/* -*- Mode: C; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 8 -*-
+ *
+ * Copyright (C) 2012 Red Hat, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
+ * 02111-1307, USA.
+ *
+ * Authors: Ray Strode
+ */
+
+#ifndef __GOA_IDENTITY_SERVICE_H__
+#define __GOA_IDENTITY_SERVICE_H__
+
+#include <glib.h>
+#include <glib-object.h>
+#include <gio/gio.h>
+
+#include "org.gnome.Identity.h"
+
+G_BEGIN_DECLS
+#define GOA_TYPE_IDENTITY_SERVICE           (goa_identity_service_get_type ())
+#define GOA_IDENTITY_SERVICE(obj)           (G_TYPE_CHECK_INSTANCE_CAST (obj, GOA_TYPE_IDENTITY_SERVICE, GoaIdentityService))
+#define GOA_IDENTITY_SERVICE_CLASS(cls)     (G_TYPE_CHECK_CLASS_CAST (cls, GOA_TYPE_IDENTITY_SERVICE, GoaIdentityServiceClass))
+#define GOA_IS_IDENTITY_SERVICE(obj)        (G_TYPE_CHECK_INSTANCE_TYPE (obj, GOA_TYPE_IDENTITY_SERVICE))
+#define GOA_IS_IDENTITY_SERVICE_CLASS(obj)  (G_TYPE_CHECK_CLASS_TYPE (obj, GOA_TYPE_IDENTITY_SERVICE))
+#define GOA_IDENTITY_SERVICE_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GOA_TYPE_IDENTITY_SERVICE, GoaIdentityServiceClass))
+typedef struct _GoaIdentityService GoaIdentityService;
+typedef struct _GoaIdentityServiceClass GoaIdentityServiceClass;
+typedef struct _GoaIdentityServicePrivate GoaIdentityServicePrivate;
+
+struct _GoaIdentityService
+{
+  GoaIdentityServiceManagerSkeleton  parent_instance;
+  GoaIdentityServicePrivate         *priv;
+};
+
+struct _GoaIdentityServiceClass
+{
+  GoaIdentityServiceManagerSkeletonClass  parent_class;
+};
+
+GType goa_identity_service_get_type (void);
+GoaIdentityService *goa_identity_service_new (void);
+gboolean goa_identity_service_activate   (GoaIdentityService  *service,
+                                          GError             **error);
+void     goa_identity_service_deactivate (GoaIdentityService  *service);
+
+G_END_DECLS
+#endif /* __GOA_IDENTITY_SERVICE_H__ */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]