From 571766f82c6e5988b1edc2dc6a4d1c652d8a769f Mon Sep 17 00:00:00 2001 From: Alberto Mardegan Date: Fri, 31 Jan 2014 11:41:04 +0200 Subject: [PATCH] Identity: add constructors compatible with libsignon-glib Restore the constructors to the original form, in order to reduce the differences with libsignon-glib; add a "_with_context" tag to the constructors which take the additional application context parameter. --- examples/gsso-example.c | 8 ++--- libgsignon-glib/signon-identity.c | 58 ++++++++++++++++++++++++++----- libgsignon-glib/signon-identity.h | 9 +++-- tests/check_signon.c | 42 +++++++++++----------- 4 files changed, 80 insertions(+), 37 deletions(-) diff --git a/examples/gsso-example.c b/examples/gsso-example.c index 3ebb2b7..b84f546 100644 --- a/examples/gsso-example.c +++ b/examples/gsso-example.c @@ -163,7 +163,7 @@ static void create_auth_identity(GMainLoop* main_loop, const gchar* identity_cap { const gchar* all_mechanisms[] = { "*", NULL }; - SignonIdentity* identity = signon_identity_new(NULL); + SignonIdentity* identity = signon_identity_new(); SignonIdentityInfo* identity_info = signon_identity_info_new(); signon_identity_info_set_caption(identity_info, identity_caption); signon_identity_info_set_method(identity_info, identity_method, all_mechanisms); @@ -204,7 +204,7 @@ static void signon_remove_identity_cb(SignonIdentity *self, static void remove_auth_identity(GMainLoop* main_loop, gint identity_id) { - SignonIdentity* identity = signon_identity_new_from_db(identity_id, NULL); + SignonIdentity* identity = signon_identity_new_from_db(identity_id); signon_identity_remove (identity, signon_remove_identity_cb, main_loop); @@ -250,7 +250,7 @@ static void get_google_token(GMainLoop* main_loop, gint identity_id, exit(1); } - SignonIdentity* identity = signon_identity_new_from_db(identity_id, NULL); + SignonIdentity* identity = signon_identity_new_from_db(identity_id); SignonAuthSession* session = signon_identity_create_session(identity, "oauth", NULL); GVariantBuilder builder; @@ -296,7 +296,7 @@ static void get_google_token(GMainLoop* main_loop, gint identity_id, static void get_password(GMainLoop* main_loop, gint identity_id) { - SignonIdentity* identity = signon_identity_new_from_db(identity_id, NULL); + SignonIdentity* identity = signon_identity_new_from_db(identity_id); SignonAuthSession* session = signon_identity_create_session(identity, "password", NULL); GVariantBuilder builder; diff --git a/libgsignon-glib/signon-identity.c b/libgsignon-glib/signon-identity.c index 0313644..74ac7ee 100644 --- a/libgsignon-glib/signon-identity.c +++ b/libgsignon-glib/signon-identity.c @@ -42,9 +42,10 @@ * * Operations on an identity * - * - a new identity can be created with signon_identity_new(). This operation - * does not store the identity to the database, the identity is not visible - * to other applications, and accordingly it is not subject to access control. + * - a new identity can be created with signon_identity_new() or + * signon_identity_new_with_context(). This operation does not store the + * identity to the database, the identity is not visible to other applications, + * and accordingly it is not subject to access control. * * - an authentication session can be started from an identity using * signon_identity_create_session() or signon_auth_session_new(). If the identity @@ -55,9 +56,10 @@ * signon_auth_service_query_identities(). Only the identites owned by the * requesting application are returned. * - * - identities stored in a database can be retrieved using signon_identity_new_from_db(), - * subject to access control (an application performing that operation has to be - * either the identity's owner, or it has to be on the ACL list). + * - identities stored in a database can be retrieved using signon_identity_new_from_db() + * or signon_identity_new_with_context_from_db(), subject to access control (an + * application performing that operation has to be either the identity's owner, + * or it has to be on the ACL list). * * - newly created identities can be stored to the database, and identities already * in the database can be updated using signon_identity_store_credentials_with_info() @@ -94,7 +96,7 @@ * owner. Owners are allowed to perform all of the operations on the identity * specified above. By default an identity's owner is determined by gSSO daemon * using system services for the system context, and a string supplied in - * signon_identity_new() for the application context. + * signon_identity_new_with_context() for the application context. * * - ACL is a list of #SignonSecurityContext objects, that specifies applications * that can access the identity to perform authentication sessions. They're not @@ -691,6 +693,29 @@ identity_check_remote_registration (SignonIdentity *self) /** * signon_identity_new_from_db: * @id: identity ID. + * + * Construct an identity object associated with an existing identity + * record. + * This is essentially equivalent to calling + * signon_identity_new_with_context_from_db() and passing %NULL as the + * application context. + * + * Applications can determine the @id either by enumerating the identities with + * signon_auth_service_query_identities() (if they're the owner of the identity) + * or via other means (such as the system's accounts service, or an application + * configuration). + * + * Returns: an instance of a #SignonIdentity. + */ +SignonIdentity * +signon_identity_new_from_db (guint32 id) +{ + return signon_identity_new_with_context_from_db (id, NULL); +} + +/** + * signon_identity_new_with_context_from_db: + * @id: identity ID. * @application_context: application security context, can be %NULL. * * Construct an identity object associated with an existing identity @@ -707,7 +732,7 @@ identity_check_remote_registration (SignonIdentity *self) * Returns: an instance of a #SignonIdentity. */ SignonIdentity* -signon_identity_new_from_db (guint32 id, const gchar *application_context) +signon_identity_new_with_context_from_db (guint32 id, const gchar *application_context) { SignonIdentity *identity; DEBUG ("%s %d: %d\n", G_STRFUNC, __LINE__, id); @@ -731,6 +756,21 @@ signon_identity_new_from_db (guint32 id, const gchar *application_context) /** * signon_identity_new: + * + * Construct a new, empty, identity object. + * This is essentially equivalent to calling signon_identity_new_with_context() + * and passing %NULL as the application context. + * + * Returns: an instance of an #SignonIdentity. + */ +SignonIdentity * +signon_identity_new () +{ + return signon_identity_new_with_context (NULL); +} + +/** + * signon_identity_new_with_context: * @application_context: application security context, can be %NULL. * * Construct a new, empty, identity object. See #SignonSecurityContext for a @@ -741,7 +781,7 @@ signon_identity_new_from_db (guint32 id, const gchar *application_context) * Returns: an instance of an #SignonIdentity. */ SignonIdentity* -signon_identity_new (const gchar *application_context) +signon_identity_new_with_context (const gchar *application_context) { DEBUG ("%s %d", G_STRFUNC, __LINE__); SignonIdentity *identity = g_object_new ( diff --git a/libgsignon-glib/signon-identity.h b/libgsignon-glib/signon-identity.h index 98d0977..211ffb6 100644 --- a/libgsignon-glib/signon-identity.h +++ b/libgsignon-glib/signon-identity.h @@ -105,9 +105,12 @@ typedef SignonIdentityVoidCb SignonIdentityReferenceRemovedCb; GType signon_identity_get_type (void) G_GNUC_CONST; -SignonIdentity *signon_identity_new_from_db (guint32 id, - const gchar *application_context); -SignonIdentity *signon_identity_new (const gchar *application_context); +SignonIdentity *signon_identity_new_from_db (guint32 id); +SignonIdentity *signon_identity_new (); + +SignonIdentity *signon_identity_new_with_context_from_db (guint32 id, + const gchar *application_context); +SignonIdentity *signon_identity_new_with_context (const gchar *application_context); const GError *signon_identity_get_last_error (SignonIdentity *identity); diff --git a/tests/check_signon.c b/tests/check_signon.c index 264f29c..7e3457b 100644 --- a/tests/check_signon.c +++ b/tests/check_signon.c @@ -129,7 +129,7 @@ new_identity() GHashTable *methods; guint id = 0; - idty = signon_identity_new (NULL); + idty = signon_identity_new (); fail_unless (SIGNON_IS_IDENTITY (idty)); methods = g_hash_table_new (g_str_hash, g_str_equal); g_hash_table_insert (methods, "ssotest", ssotest_mechanisms); @@ -336,7 +336,7 @@ START_TEST(test_auth_session_query_mechanisms) GError *err = NULL; g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new(NULL); + SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL, "Cannot create Iddentity object"); SignonAuthSession *auth_session = signon_identity_create_session(idty, @@ -408,7 +408,7 @@ START_TEST(test_auth_session_query_mechanisms_nonexisting) GError *err = NULL; g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new(NULL); + SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL, "Cannot create Iddentity object"); SignonAuthSession *auth_session = signon_identity_create_session(idty, @@ -501,7 +501,7 @@ START_TEST(test_auth_session_creation) gboolean auth_sess_destroyed = FALSE; g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new(NULL); + SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL, "Cannot create Identity object"); SignonAuthSession *auth_session = signon_identity_create_session(idty, @@ -534,7 +534,7 @@ START_TEST(test_auth_session_process) GError *err = NULL; g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new(NULL); + SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL, "Cannot create Iddentity object"); SignonAuthSession *auth_session = signon_identity_create_session(idty, @@ -647,7 +647,7 @@ START_TEST(test_auth_session_process_failure) fail_unless (id != 0); - idty = signon_identity_new_from_db (id, NULL); + idty = signon_identity_new_from_db (id); fail_unless (idty != NULL, "Cannot create Identity object"); auth_session = signon_auth_session_new (G_OBJECT (idty), @@ -756,7 +756,7 @@ START_TEST(test_auth_session_process_after_store) g_debug("%s", G_STRFUNC); - idty = signon_identity_new (NULL); + idty = signon_identity_new (); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -812,7 +812,7 @@ START_TEST(test_get_existing_identity) fail_unless (id != 0); - identity = signon_identity_new_from_db (id, NULL); + identity = signon_identity_new_from_db (id); fail_unless (identity != NULL); fail_unless (SIGNON_IS_IDENTITY (identity), @@ -830,7 +830,7 @@ END_TEST START_TEST(test_get_nonexisting_identity) { g_debug("%s", G_STRFUNC); - identity = signon_identity_new_from_db (G_MAXINT, NULL); + identity = signon_identity_new_from_db (G_MAXINT); fail_unless (identity != NULL); fail_unless (SIGNON_IS_IDENTITY (identity), @@ -879,7 +879,7 @@ static void store_credentials_identity_cb(SignonIdentity *self, START_TEST(test_store_credentials_identity) { g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new(NULL); + SignonIdentity *idty = signon_identity_new(); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -930,7 +930,7 @@ static void identity_remove_cb(SignonIdentity *self, const GError *error, gpoint START_TEST(test_remove_identity) { g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new (NULL); + SignonIdentity *idty = signon_identity_new (); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -946,7 +946,7 @@ START_TEST(test_remove_identity) * */ gint id = new_identity(); - SignonIdentity *idty2 = signon_identity_new_from_db (id, NULL); + SignonIdentity *idty2 = signon_identity_new_from_db (id); signon_identity_remove(idty2, identity_remove_cb, NULL); _run_mainloop (); @@ -1070,7 +1070,7 @@ static SignonIdentityInfo *create_standard_info() START_TEST(test_info_identity) { g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new (NULL); + SignonIdentity *idty = signon_identity_new (); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -1120,7 +1120,7 @@ START_TEST(test_info_identity) gint id = signon_identity_info_get_id (info); fail_unless (id != 0); - SignonIdentity *idty2 = signon_identity_new_from_db (id, NULL); + SignonIdentity *idty2 = signon_identity_new_from_db (id); signon_identity_query_info (idty2, identity_info_cb, &info); _run_mainloop (); @@ -1185,7 +1185,7 @@ START_TEST(test_signout_identity) { gboolean as1_destroyed = FALSE, as2_destroyed = FALSE; g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new (NULL); + SignonIdentity *idty = signon_identity_new (); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -1201,7 +1201,7 @@ START_TEST(test_signout_identity) _run_mainloop (); gint id = signon_identity_info_get_id (info); - SignonIdentity *idty2 = signon_identity_new_from_db (id, NULL); + SignonIdentity *idty2 = signon_identity_new_from_db (id); /* wait some more time to ensure that the object gets registered */ g_timeout_add_seconds (2, test_quit_main_loop_cb, main_loop); @@ -1247,7 +1247,7 @@ END_TEST START_TEST(test_unregistered_identity) { g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new (NULL); + SignonIdentity *idty = signon_identity_new (); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -1264,7 +1264,7 @@ START_TEST(test_unregistered_identity) * give the time for identity to became idle * */ sleep(SIGNOND_IDLE_TIMEOUT); - SignonIdentity *idty2 = signon_identity_new (NULL); + SignonIdentity *idty2 = signon_identity_new (); /* * give time to handle unregistered signal @@ -1283,7 +1283,7 @@ END_TEST START_TEST(test_unregistered_auth_session) { g_debug("%s", G_STRFUNC); - SignonIdentity *idty = signon_identity_new (NULL); + SignonIdentity *idty = signon_identity_new (); fail_unless (idty != NULL); fail_unless (SIGNON_IS_IDENTITY (idty), "Failed to initialize the Identity."); @@ -1300,7 +1300,7 @@ START_TEST(test_unregistered_auth_session) * give the time for identity to became idle * */ sleep(SIGNOND_IDLE_TIMEOUT); - SignonIdentity *idty2 = signon_identity_new (NULL); + SignonIdentity *idty2 = signon_identity_new (); /* * give time to handle unregistered signal @@ -1426,7 +1426,7 @@ START_TEST(test_regression_unref) guint id = new_identity(); fail_unless (id != 0); - idty = signon_identity_new_from_db (id, NULL); + idty = signon_identity_new_from_db (id); fail_unless (idty != NULL); auth_session = signon_auth_session_new (G_OBJECT (idty), "ssotest", -- 2.34.1