static void auth_session_set_id_ready_cb (gpointer object, const GError *error, gpointer user_data) { if (error) { g_warning ("%s returned error: %s", G_STRFUNC, error->message); return; } g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); gint id = GPOINTER_TO_INT(user_data); GError *err = NULL; sso_auth_session_call_set_id_sync (priv->proxy, id, priv->cancellable, &err); priv->id = id; if (err) g_warning ("%s returned error: %s", G_STRFUNC, err->message); g_clear_error(&err); }
static void auth_session_remote_object_destroyed_cb (GDBusProxy *proxy, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); DEBUG ("remote object unregistered"); if (priv->proxy) { g_object_unref (priv->proxy); priv->proxy = NULL; } /* * as remote object is destroyed only * when the session core is destroyed, * so there should not be any processes * running * */ priv->busy = FALSE; priv->canceled = FALSE; _signon_object_not_ready(self); }
static void auth_session_process_ready_cb (gpointer object, const GError *error, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); AuthSessionProcessData *operation_data = (AuthSessionProcessData *)user_data; g_return_if_fail (operation_data != NULL); AuthSessionProcessCbData *cb_data = operation_data->cb_data; g_return_if_fail (cb_data != NULL); if (error || priv->canceled) { GError *err = ( error ? (GError *)error : g_error_new(auth_session_errors_quark(), 1, SSO_AUTH_SESSION_CANCELED_PROBLEM_G) ); DEBUG ("AuthSessionError: %s", err->message); (cb_data->cb) (self, operation_data->session_data, err, cb_data->user_data); if (!error) g_clear_error (&err); g_slice_free (AuthSessionProcessCbData, cb_data); priv->busy = FALSE; priv->canceled = FALSE; } else { g_return_if_fail (priv->proxy != NULL); _SSO_AuthSession_process_async_timeout (priv->proxy, operation_data->session_data, operation_data->mechanism, auth_session_process_reply, cb_data, 0x7FFFFFFF); g_hash_table_destroy (operation_data->session_data); g_signal_emit (self, auth_session_signals[STATE_CHANGED], 0, SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, auth_session_process_pending_message); } g_free (operation_data->mechanism); g_slice_free (AuthSessionProcessData, operation_data); }
static void auth_session_process_ready_cb (gpointer object, const GError *error, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); AuthSessionProcessData *operation_data = (AuthSessionProcessData *)user_data; g_return_if_fail (operation_data != NULL); AuthSessionProcessCbData *cb_data = operation_data->cb_data; g_return_if_fail (cb_data != NULL); if (error || priv->canceled) { GError *err = (error ? (GError *)error : g_error_new (signon_error_quark (), SIGNON_ERROR_SESSION_CANCELED, "Authentication session was canceled")); DEBUG ("AuthSessionError: %s", err->message); (cb_data->cb) (self, NULL, err, cb_data->user_data); if (!error) g_clear_error (&err); g_slice_free (AuthSessionProcessCbData, cb_data); priv->busy = FALSE; priv->canceled = FALSE; } else { g_return_if_fail (priv->proxy != NULL); sso_auth_session_call_process (priv->proxy, operation_data->session_data, operation_data->mechanism, priv->cancellable, auth_session_process_reply, cb_data); g_signal_emit (self, auth_session_signals[STATE_CHANGED], 0, SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, auth_session_process_pending_message); } g_free (operation_data->mechanism); g_slice_free (AuthSessionProcessData, operation_data); }
static void signon_auth_session_finalize (GObject *object) { g_return_if_fail (SIGNON_IS_AUTH_SESSION(object)); SignonAuthSession *self = SIGNON_AUTH_SESSION(object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); g_free (priv->method_name); G_OBJECT_CLASS (signon_auth_session_parent_class)->finalize (object); }
static void identity_store_credentials_reply (GObject *object, GAsyncResult *res, gpointer userdata) { IdentityStoreCredentialsCbData *cb_data = (IdentityStoreCredentialsCbData *)userdata; SsoIdentity *proxy = SSO_IDENTITY (object); guint id; GError *error = NULL; g_return_if_fail (cb_data != NULL); g_return_if_fail (cb_data->self != NULL); g_return_if_fail (cb_data->self->priv != NULL); SignonIdentityPrivate *priv = cb_data->self->priv; sso_identity_call_store_finish (proxy, &id, res, &error); SIGNON_RETURN_IF_CANCELLED (error); if (error == NULL) { g_return_if_fail (priv->identity_info == NULL); GSList *slist = priv->sessions; while (slist) { SignonAuthSession *session = SIGNON_AUTH_SESSION (priv->sessions->data); signon_auth_session_set_id (session, id); slist = g_slist_next (slist); } g_object_set (cb_data->self, "id", id, NULL); cb_data->self->priv->id = id; /* * if the previous state was REMOVED * then we need to reset it * */ priv->removed = FALSE; } if (cb_data->cb) { (cb_data->cb) (cb_data->self, id, error, cb_data->user_data); } g_clear_error(&error); g_slice_free (IdentityStoreCredentialsCbData, cb_data); }
static void auth_session_state_changed_cb (GDBusProxy *proxy, gint state, gchar *message, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (user_data)); SignonAuthSession *self = SIGNON_AUTH_SESSION (user_data); g_signal_emit ((GObject *)self, auth_session_signals[STATE_CHANGED], 0, state, message); }
static void auth_session_query_available_mechanisms_ready_cb (gpointer object, const GError *error, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); AuthSessionQueryAvailableMechanismsData *operation_data = (AuthSessionQueryAvailableMechanismsData *)user_data; g_return_if_fail (operation_data != NULL); AuthSessionQueryAvailableMechanismsCbData *cb_data = operation_data->cb_data; g_return_if_fail (cb_data != NULL); if (error) { (cb_data->cb) (self, NULL, error, cb_data->user_data); g_slice_free (AuthSessionQueryAvailableMechanismsCbData, cb_data); } else { g_return_if_fail (priv->proxy != NULL); sso_auth_session_call_query_available_mechanisms ( priv->proxy, (const char **)operation_data->wanted_mechanisms, priv->cancellable, auth_session_query_mechanisms_reply, cb_data); g_signal_emit (self, auth_session_signals[STATE_CHANGED], 0, SIGNON_AUTH_SESSION_STATE_PROCESS_PENDING, auth_session_process_pending_message); } g_strfreev (operation_data->wanted_mechanisms); g_slice_free (AuthSessionQueryAvailableMechanismsData, operation_data); }
/** * signon_auth_session_new: * @id: the id of the #SignonIdentity to be used. Can be 0, if this session is * not bound to any stored identity. * @method_name: the name of the authentication method to be used. * @err: a pointer to a location which will contain the error, in case this * function fails. * * Creates a new #SignonAuthSession, which can be used to authenticate using * the specified method. * * Returns: a new #SignonAuthSession. */ SignonAuthSession * signon_auth_session_new (gint id, const gchar *method_name, GError **err) { SignonAuthSession *self = SIGNON_AUTH_SESSION(g_object_new (SIGNON_TYPE_AUTH_SESSION, NULL)); g_return_val_if_fail (self != NULL, NULL); if (!auth_session_priv_init(self, id, method_name, err)) { if (*err) g_warning ("%s returned error: %s", G_STRFUNC, (*err)->message); g_object_unref (self); return NULL; } return self; }
static void signon_auth_session_dispose (GObject *object) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); if (priv->dispose_has_run) return; GError *err = NULL; if (priv->proxy) { dbus_g_proxy_disconnect_signal (priv->proxy, "stateChanged", G_CALLBACK (auth_session_state_changed_cb), self); dbus_g_proxy_disconnect_signal (priv->proxy, "unregistered", G_CALLBACK (auth_session_remote_object_destroyed_cb), self); SSO_AuthSession_object_unref (priv->proxy, &err); g_object_unref (priv->proxy); priv->proxy = NULL; } if (priv->signon_proxy) { g_object_unref (priv->signon_proxy); priv->signon_proxy = NULL; } G_OBJECT_CLASS (signon_auth_session_parent_class)->dispose (object); priv->dispose_has_run = TRUE; }
static void auth_session_cancel_ready_cb (gpointer object, const GError *error, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); g_return_if_fail (user_data == NULL); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); if (error) { //TODO: in general this function does not return any values, // that is why I think it should not emit anything for this particular case DEBUG("error during initialization"); } else if (priv->proxy && priv->busy) SSO_AuthSession_cancel (priv->proxy, NULL); priv->busy = FALSE; priv->canceled = FALSE; }
static void signon_auth_session_dispose (GObject *object) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (object)); SignonAuthSession *self = SIGNON_AUTH_SESSION (object); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); if (priv->dispose_has_run) return; if (priv->cancellable) { g_cancellable_cancel (priv->cancellable); priv->cancellable = NULL; } if (priv->proxy) { g_signal_handler_disconnect (priv->proxy, priv->signal_state_changed); g_signal_handler_disconnect (priv->proxy, priv->signal_unregistered); g_object_unref (priv->proxy); priv->proxy = NULL; } if (priv->auth_service_proxy) { g_object_unref (priv->auth_service_proxy); priv->auth_service_proxy = NULL; } G_OBJECT_CLASS (signon_auth_session_parent_class)->dispose (object); priv->dispose_has_run = TRUE; }
static void auth_session_get_object_path_reply (GObject *object, GAsyncResult *res, gpointer userdata) { SsoAuthService *proxy = SSO_AUTH_SERVICE (object); gchar *object_path = NULL; GError *error = NULL; sso_auth_service_call_get_auth_session_object_path_finish (proxy, &object_path, res, &error); SIGNON_RETURN_IF_CANCELLED (error); g_return_if_fail (SIGNON_IS_AUTH_SESSION (userdata)); SignonAuthSession *self = SIGNON_AUTH_SESSION (userdata); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); priv->registering = FALSE; if (!g_strcmp0(object_path, "") || error) { if (error) DEBUG ("Error message is %s", error->message); else error = g_error_new (signon_error_quark(), SIGNON_ERROR_RUNTIME, "Cannot create remote AuthSession object"); } else { GDBusConnection *connection; const gchar *bus_name; GError *proxy_error = NULL; connection = g_dbus_proxy_get_connection ((GDBusProxy *)proxy); bus_name = g_dbus_proxy_get_name ((GDBusProxy *)proxy); priv->proxy = sso_auth_session_proxy_new_sync (connection, G_DBUS_PROXY_FLAGS_NONE, bus_name, object_path, priv->cancellable, &proxy_error); if (G_UNLIKELY (proxy_error != NULL)) { g_warning ("Failed to initialize AuthSession proxy: %s", proxy_error->message); g_clear_error (&proxy_error); } g_dbus_proxy_set_default_timeout ((GDBusProxy *)priv->proxy, G_MAXINT); priv->signal_state_changed = g_signal_connect (priv->proxy, "state-changed", G_CALLBACK (auth_session_state_changed_cb), self); priv->signal_unregistered = g_signal_connect (priv->proxy, "unregistered", G_CALLBACK (auth_session_remote_object_destroyed_cb), self); } DEBUG ("Object path received: %s", object_path); _signon_object_ready (self, auth_session_object_quark (), error); g_clear_error (&error); }
/** * signon_identity_create_session: * @self: the #SignonIdentity. * @method: method. * @error: pointer to a location which will receive the error, if any. * * Creates an authentication session for this identity. * * Returns: (transfer full): a new #SignonAuthSession. */ SignonAuthSession * signon_identity_create_session(SignonIdentity *self, const gchar *method, GError **error) { g_return_val_if_fail (SIGNON_IS_IDENTITY (self), NULL); SignonIdentityPrivate *priv = self->priv; g_return_val_if_fail (priv != NULL, NULL); DEBUG ("%s %d", G_STRFUNC, __LINE__); if (method == NULL) { DEBUG ("NULL method as input. Aborting."); g_set_error(error, signon_error_quark(), SIGNON_ERROR_UNKNOWN, "NULL input method."); return NULL; } GSList *list = priv->sessions; while (list) { SignonAuthSession *session = SIGNON_AUTH_SESSION (priv->sessions->data); const gchar *sessionMethod = signon_auth_session_get_method (session); if (g_strcmp0(sessionMethod, method) == 0) { DEBUG ("Auth Session with method `%s` already created.", method); g_set_error (error, signon_error_quark(), SIGNON_ERROR_METHOD_NOT_AVAILABLE, "Authentication session for this method already requested."); return NULL; } list = list->next; } SignonAuthSession *session = signon_auth_session_new (priv->id, method, error); if (session) { DEBUG ("%s %d", G_STRFUNC, __LINE__); priv->sessions = g_slist_append(priv->sessions, session); g_object_weak_ref (G_OBJECT(session), identity_session_object_destroyed_cb, self); /* * if you want to delete the identity * you MUST delete all authsessions * first * */ g_object_ref (self); priv->signed_out = FALSE; } return session; }
static void auth_session_get_object_path_reply (DBusGProxy *proxy, char *object_path, GError *error, gpointer userdata) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (userdata)); SignonAuthSession *self = SIGNON_AUTH_SESSION (userdata); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); priv->pending_call_get_path = NULL; if (!g_strcmp0(object_path, "") || error) { if (error) DEBUG ("Error message is %s", error->message); else { error = g_error_new (auth_session_errors_quark(), 1, SSO_AUTH_SESSION_CONNECTION_PROBLEM_G); g_free (object_path); } } else { priv->proxy = dbus_g_proxy_new_from_proxy (DBUS_G_PROXY (priv->signon_proxy), SIGNOND_AUTH_SESSION_INTERFACE, object_path); dbus_g_object_register_marshaller (_signon_marshal_VOID__INT_STRING, G_TYPE_NONE, G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->proxy, "stateChanged", G_TYPE_INT, G_TYPE_STRING, G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "stateChanged", G_CALLBACK (auth_session_state_changed_cb), self, NULL); dbus_g_object_register_marshaller (g_cclosure_marshal_VOID__VOID, G_TYPE_NONE, G_TYPE_INVALID); dbus_g_proxy_add_signal (priv->proxy, "unregistered", G_TYPE_INVALID); dbus_g_proxy_connect_signal (priv->proxy, "unregistered", G_CALLBACK (auth_session_remote_object_destroyed_cb), self, NULL); g_free (object_path); } DEBUG ("Object path received: %s", object_path); _signon_object_ready (self, auth_session_object_quark (), error); g_clear_error (&error); }