/** * signon_auth_session_query_available_mechanisms: * @self: the #SignonAuthSession. * @wanted_mechanisms: a %NULL-terminated list of mechanisms supported by the client. * @cb: (scope async): a callback which will be called with the result. * @user_data: user data to be passed to the callback. * * Queries the mechanisms available for this authentication session. the result * will be the intersection between @wanted_mechanisms and the mechanisms * supported by the authentication plugin. */ void signon_auth_session_query_available_mechanisms (SignonAuthSession *self, const gchar **wanted_mechanisms, SignonAuthSessionQueryAvailableMechanismsCb cb, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); SignonAuthSessionPrivate* priv = self->priv; g_return_if_fail (priv != NULL); AuthSessionQueryAvailableMechanismsCbData *cb_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsCbData); cb_data->self = self; cb_data->cb = cb; cb_data->user_data = user_data; AuthSessionQueryAvailableMechanismsData *operation_data = g_slice_new0 (AuthSessionQueryAvailableMechanismsData); operation_data->wanted_mechanisms = g_strdupv ((gchar **)wanted_mechanisms); operation_data->cb_data = cb_data; auth_session_check_remote_object(self); _signon_object_call_when_ready (self, auth_session_object_quark(), auth_session_query_available_mechanisms_ready_cb, operation_data); }
/** * signon_auth_session_process: * @self: the #SignonAuthSession. * @session_data: (transfer none) (element-type utf8 GValue): a dictionary of parameters. * @mechanism: the authentication mechanism to be used. * @cb: (scope async): a callback which will be called with the result. * @user_data: user data to be passed to the callback. * * Performs one step of the authentication process. If the #SignonAuthSession * object is bound to an existing identity, the identity properties such as * username and password will be also passed to the authentication plugin, so * there's no need to fill them into @session_data. * @session_data can be used to add additional authentication parameters to the * session, or to override the parameters otherwise taken from the identity. */ void signon_auth_session_process (SignonAuthSession *self, const GHashTable *session_data, const gchar* mechanism, SignonAuthSessionProcessCb cb, gpointer user_data) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); g_return_if_fail (session_data != NULL); AuthSessionProcessCbData *cb_data = g_slice_new0 (AuthSessionProcessCbData); cb_data->self = self; cb_data->cb = cb; cb_data->user_data = user_data; AuthSessionProcessData *operation_data = g_slice_new0 (AuthSessionProcessData); operation_data->session_data = signon_hash_table_to_variant (session_data); operation_data->mechanism = g_strdup (mechanism); operation_data->cb_data = cb_data; priv->busy = TRUE; auth_session_check_remote_object(self); _signon_object_call_when_ready (self, auth_session_object_quark(), auth_session_process_ready_cb, operation_data); }
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_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_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); }
/** * signon_auth_session_get_method: * @self: the #SignonAuthSession. * * Get the current authentication method. * * Returns: the authentication method being used, or %NULL on failure. */ const gchar * signon_auth_session_get_method (SignonAuthSession *self) { g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), NULL); SignonAuthSessionPrivate *priv = self->priv; g_return_val_if_fail (priv != NULL, NULL); return priv->method_name; }
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 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); }
void signon_auth_session_set_id(SignonAuthSession* self, gint id) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); g_return_if_fail (id >= 0); auth_session_check_remote_object(self); _signon_object_call_when_ready (self, auth_session_object_quark(), auth_session_set_id_ready_cb, GINT_TO_POINTER(id)); }
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_cancel: * @self: the #SignonAuthSession. * * Cancel the authentication session. */ void signon_auth_session_cancel (SignonAuthSession *self) { g_return_if_fail (SIGNON_IS_AUTH_SESSION (self)); SignonAuthSessionPrivate *priv = self->priv; g_return_if_fail (priv != NULL); auth_session_check_remote_object(self); if (!priv->busy) return; priv->canceled = TRUE; _signon_object_call_when_ready (self, auth_session_object_quark(), auth_session_cancel_ready_cb, NULL); }
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 gboolean auth_session_priv_init (SignonAuthSession *self, guint id, const gchar *method_name, GError **err) { g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), FALSE); SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); g_return_val_if_fail (priv, FALSE); priv->id = id; priv->method_name = g_strdup (method_name); priv->pending_call_get_path = SSO_AuthService_get_auth_session_object_path_async ( DBUS_G_PROXY (priv->signon_proxy), (const guint)id, method_name, auth_session_get_object_path_reply, self); priv->busy = FALSE; priv->canceled = FALSE; return 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 gboolean auth_session_priv_init (SignonAuthSession *self, guint id, const gchar *method_name, GError **err) { g_return_val_if_fail (SIGNON_IS_AUTH_SESSION (self), FALSE); SignonAuthSessionPrivate *priv = SIGNON_AUTH_SESSION_PRIV (self); g_return_val_if_fail (priv, FALSE); priv->id = id; priv->method_name = g_strdup (method_name); priv->registering = TRUE; sso_auth_service_call_get_auth_session_object_path ( priv->auth_service_proxy, id, method_name, priv->cancellable, auth_session_get_object_path_reply, self); priv->busy = FALSE; priv->canceled = FALSE; return TRUE; }
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); }
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); }