[evolution-data-server/tintou/external-auth] ESourceAuthentication: Add is-external property and use it instead of checking UOA or GOA extensions



commit c0848ee7e035e4699afa180a00de7e16e3ca9a69
Author: Corentin Noël <corentin noel collabora com>
Date:   Tue Aug 20 16:04:43 2019 +0200

    ESourceAuthentication: Add is-external property and use it instead of checking UOA or GOA extensions

 .../evolution-data-server-docs.sgml.in             |  4 ++
 src/libedataserver/e-oauth2-service.c              | 14 ++--
 src/libedataserver/e-source-authentication.c       | 82 +++++++++++++++++++++-
 src/libedataserver/e-source-authentication.h       |  5 ++
 src/libedataserverui/e-trust-prompt.c              | 10 ++-
 .../module-gnome-online-accounts.c                 |  6 ++
 src/modules/google-backend/module-google-backend.c | 29 +++++---
 .../oauth2-services/module-oauth2-services.c       |  7 +-
 8 files changed, 127 insertions(+), 30 deletions(-)
---
diff --git a/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in 
b/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
index c68ad8f77..62ce0ec2b 100644
--- a/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
+++ b/docs/reference/evolution-data-server/evolution-data-server-docs.sgml.in
@@ -359,6 +359,10 @@
     <title>Index of deprecated symbols</title>
     <xi:include href="xml/api-index-deprecated.xml"><xi:fallback /></xi:include>
   </index>
+  <index id="api-index-3-36" role="3.36">
+    <title>Index of new symbols in 3.36</title>
+    <xi:include href="xml/api-index-3.36.xml"><xi:fallback /></xi:include>
+  </index>
   <index id="api-index-3-34" role="3.34">
     <title>Index of new symbols in 3.34</title>
     <xi:include href="xml/api-index-3.34.xml"><xi:fallback /></xi:include>
diff --git a/src/libedataserver/e-oauth2-service.c b/src/libedataserver/e-oauth2-service.c
index c4d295baf..979095b74 100644
--- a/src/libedataserver/e-oauth2-service.c
+++ b/src/libedataserver/e-oauth2-service.c
@@ -38,8 +38,6 @@
 #include "e-secret-store.h"
 #include "e-soup-ssl-trust.h"
 #include "e-source-authentication.h"
-#include "e-source-goa.h"
-#include "e-source-uoa.h"
 
 #include "e-oauth2-service.h"
 
@@ -49,20 +47,16 @@ static gboolean
 eos_default_can_process (EOAuth2Service *service,
                         ESource *source)
 {
-       gboolean can = FALSE;
-
        g_return_val_if_fail (E_IS_SOURCE (source), FALSE);
 
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_GOA) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_UOA)) {
-               return FALSE;
-       }
-
        if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
                ESourceAuthentication *auth_extension;
                gchar *method;
 
                auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
+               if (e_source_authentication_get_is_external (auth_extension))
+                       return FALSE;
+
                method = e_source_authentication_dup_method (auth_extension);
 
                if (g_strcmp0 (method, e_oauth2_service_get_name (service)) == 0) {
@@ -73,7 +67,7 @@ eos_default_can_process (EOAuth2Service *service,
                g_free (method);
        }
 
-       return can;
+       return FALSE;
 }
 
 static gboolean
diff --git a/src/libedataserver/e-source-authentication.c b/src/libedataserver/e-source-authentication.c
index bf2514ce2..3cbf175dc 100644
--- a/src/libedataserver/e-source-authentication.c
+++ b/src/libedataserver/e-source-authentication.c
@@ -50,6 +50,7 @@ struct _ESourceAuthenticationPrivate {
        gboolean remember_password;
        gchar *user;
        gchar *credential_name;
+       gboolean is_external;
 
        /* GNetworkAddress caches data internally, so we maintain the
         * instance to preserve the cache as opposed to just creating
@@ -66,7 +67,8 @@ enum {
        PROP_PROXY_UID,
        PROP_REMEMBER_PASSWORD,
        PROP_USER,
-       PROP_CREDENTIAL_NAME
+       PROP_CREDENTIAL_NAME,
+       PROP_IS_EXTERNAL
 };
 
 G_DEFINE_TYPE (
@@ -142,6 +144,12 @@ source_authentication_set_property (GObject *object,
                                E_SOURCE_AUTHENTICATION (object),
                                g_value_get_string (value));
                        return;
+
+               case PROP_IS_EXTERNAL:
+                       e_source_authentication_set_is_external (
+                               E_SOURCE_AUTHENTICATION (object),
+                               g_value_get_boolean (value));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -209,6 +217,13 @@ source_authentication_get_property (GObject *object,
                                e_source_authentication_dup_credential_name (
                                E_SOURCE_AUTHENTICATION (object)));
                        return;
+
+               case PROP_IS_EXTERNAL:
+                       g_value_set_boolean (
+                               value,
+                               e_source_authentication_get_is_external (
+                               E_SOURCE_AUTHENTICATION (object)));
+                       return;
        }
 
        G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
@@ -372,6 +387,20 @@ e_source_authentication_class_init (ESourceAuthenticationClass *class)
                        G_PARAM_EXPLICIT_NOTIFY |
                        G_PARAM_STATIC_STRINGS |
                        E_SOURCE_PARAM_SETTING));
+
+       g_object_class_install_property (
+               object_class,
+               PROP_IS_EXTERNAL,
+               g_param_spec_boolean (
+                       "is-external",
+                       "Is External",
+                       "Whether the authentication is done by another authentication manager (like any 
Single Sign On daemon)",
+                       FALSE,
+                       G_PARAM_READWRITE |
+                       G_PARAM_CONSTRUCT |
+                       G_PARAM_EXPLICIT_NOTIFY |
+                       G_PARAM_STATIC_STRINGS |
+                       E_SOURCE_PARAM_SETTING));
 }
 
 static void
@@ -966,3 +995,54 @@ e_source_authentication_set_credential_name (ESourceAuthentication *extension,
 
        g_object_notify (G_OBJECT (extension), "credential-name");
 }
+
+/**
+ * e_source_authentication_get_is_external:
+ * @extension: an #ESourceAuthentication
+ *
+ * Get if the authentication is done by and external application such as a
+ * Single Sign On application (e.g. GNOME Online Accounts)
+ *
+ * Returns: %TRUE if the authentication is done by an external application,
+ * %FALSE otherwise
+ *
+ * Since: 3.36
+ **/
+gboolean
+e_source_authentication_get_is_external (ESourceAuthentication *extension)
+{
+       g_return_val_if_fail (E_IS_SOURCE_AUTHENTICATION (extension), FALSE);
+
+       return extension->priv->is_external;
+}
+
+/**
+ * e_source_authentication_set_is_external:
+ * @extension: an #ESourceAuthentication
+ * @is_external: %TRUE if the authentication is done using an external
+ * application, %FALSE otherwise
+ *
+ * Set if the authentication is done by and external application such as a
+ * Single Sign On application (e.g. GNOME Online Accounts)
+ *
+ * Since: 3.36
+ **/
+void
+e_source_authentication_set_is_external (ESourceAuthentication *extension,
+                                         gboolean is_external)
+{
+       g_return_if_fail (E_IS_SOURCE_AUTHENTICATION (extension));
+
+       e_source_extension_property_lock (E_SOURCE_EXTENSION (extension));
+
+       if (extension->priv->is_external == is_external) {
+               e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
+               return;
+       }
+
+       extension->priv->is_external = is_external;
+
+       e_source_extension_property_unlock (E_SOURCE_EXTENSION (extension));
+
+       g_object_notify (G_OBJECT (extension), "is-external");
+}
diff --git a/src/libedataserver/e-source-authentication.h b/src/libedataserver/e-source-authentication.h
index ee29798c3..3c8d1204c 100644
--- a/src/libedataserver/e-source-authentication.h
+++ b/src/libedataserver/e-source-authentication.h
@@ -129,6 +129,11 @@ gchar *            e_source_authentication_dup_credential_name
 void           e_source_authentication_set_credential_name
                                        (ESourceAuthentication *extension,
                                         const gchar *credential_name);
+gboolean       e_source_authentication_get_is_external
+                                       (ESourceAuthentication *extension);
+void           e_source_authentication_set_is_external
+                                       (ESourceAuthentication *extension,
+                                        gboolean is_external);
 
 G_END_DECLS
 
diff --git a/src/libedataserverui/e-trust-prompt.c b/src/libedataserverui/e-trust-prompt.c
index af8b596d5..06e6691d6 100644
--- a/src/libedataserverui/e-trust-prompt.c
+++ b/src/libedataserverui/e-trust-prompt.c
@@ -558,15 +558,13 @@ e_trust_prompt_run_for_source (GtkWindow *parent,
        g_return_if_fail (E_IS_SOURCE (source));
        g_return_if_fail (certificate_pem != NULL);
 
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_GOA) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_UOA)) {
-               /* Make sure that GOA/UOA collection sources contain these extensions too */
-               g_warn_if_fail (e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION));
+       if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION))
+               extension_authentication = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
+
+       if (extension_authentication && e_source_authentication_get_is_external (extension_authentication)) {
                g_warn_if_fail (e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND));
        }
 
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION))
-               extension_authentication = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
        if (e_source_has_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND))
                extension_webdav = e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
 
diff --git a/src/modules/gnome-online-accounts/module-gnome-online-accounts.c 
b/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
index 1fd2a6ec8..0c1105813 100644
--- a/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
+++ b/src/modules/gnome-online-accounts/module-gnome-online-accounts.c
@@ -539,6 +539,9 @@ gnome_online_accounts_config_oauth (EGnomeOnlineAccounts *extension,
        extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
        source_extension = e_source_get_extension (source, extension_name);
 
+       e_source_authentication_set_is_external (
+               E_SOURCE_AUTHENTICATION (source_extension),
+               TRUE);
        e_source_authentication_set_method (
                E_SOURCE_AUTHENTICATION (source_extension),
                CAMEL_OAUTH_MECHANISM_NAME);
@@ -558,6 +561,9 @@ gnome_online_accounts_config_oauth2 (EGnomeOnlineAccounts *extension,
        extension_name = E_SOURCE_EXTENSION_AUTHENTICATION;
        source_extension = e_source_get_extension (source, extension_name);
 
+       e_source_authentication_set_is_external (
+               E_SOURCE_AUTHENTICATION (source_extension),
+               TRUE);
        e_source_authentication_set_method (
                E_SOURCE_AUTHENTICATION (source_extension),
                CAMEL_OAUTH2_MECHANISM_NAME);
diff --git a/src/modules/google-backend/module-google-backend.c 
b/src/modules/google-backend/module-google-backend.c
index 29586337f..34d3a818c 100644
--- a/src/modules/google-backend/module-google-backend.c
+++ b/src/modules/google-backend/module-google-backend.c
@@ -102,6 +102,7 @@ static gboolean
 google_backend_can_use_google_auth (ESource *source)
 {
        ESourceRegistryServer *registry;
+       ESourceAuthentication *auth_extension;
        gboolean res;
 
        g_return_val_if_fail (E_IS_SERVER_SIDE_SOURCE (source), FALSE);
@@ -124,8 +125,8 @@ google_backend_can_use_google_auth (ESource *source)
                }
        }
 
-       res = !e_source_has_extension (source, E_SOURCE_EXTENSION_GOA) &&
-             !e_source_has_extension (source, E_SOURCE_EXTENSION_UOA);
+       auth_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
+       res = !e_source_authentication_get_is_external (auth_extension);
 
        g_object_unref (source);
 
@@ -705,10 +706,9 @@ google_backend_populate (ECollectionBackend *backend)
           it's there before setting correct authentication method on the master source. */
        (void) e_source_get_extension (source, E_SOURCE_EXTENSION_WEBDAV_BACKEND);
 
-       /* Force OAuth2 for GOA/UOA Google accounts and do it before calling parent method,
-          thus it knows what authentication method it's supposed to use */
-       if (e_source_has_extension (source, E_SOURCE_EXTENSION_GOA) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_UOA))
+       /* Force OAuth2 for Google accounts using external auth method and do it before calling
+          parent method, thus it knows what authentication method it's supposed to use */
+       if (e_source_authentication_get_is_external (authentication_extension))
                e_source_authentication_set_method (authentication_extension, "OAuth2");
 
        /* Chain up to parent's method. */
@@ -747,6 +747,7 @@ google_backend_child_added (ECollectionBackend *backend,
        ESource *collection_source;
        const gchar *extension_name;
        gboolean is_mail = FALSE;
+       gboolean has_external_auth = FALSE;
 
        /* Chain up to parent's child_added() method. */
        E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->
@@ -782,6 +783,8 @@ google_backend_child_added (ECollectionBackend *backend,
                        child_source, extension_name);
                auth_child_user = e_source_authentication_get_user (
                        auth_child_extension);
+               has_external_auth = e_source_authentication_get_is_external (
+                       auth_child_extension);
 
                /* XXX Do not override an existing user name setting.
                 *     The IMAP or (especially) SMTP configuration may
@@ -842,8 +845,7 @@ google_backend_child_added (ECollectionBackend *backend,
                        G_CALLBACK (google_backend_contacts_update_auth_method_cb),
                        backend);
 
-               if (!e_source_has_extension (collection_source, E_SOURCE_EXTENSION_GOA) &&
-                   !e_source_has_extension (collection_source, E_SOURCE_EXTENSION_UOA)) {
+               if (!has_external_auth) {
                        /* Even the book is part of the collection it can be removed
                           separately, if not configured through GOA or UOA. */
                        e_server_side_source_set_removable (E_SERVER_SIDE_SOURCE (child_source), TRUE);
@@ -856,16 +858,23 @@ google_backend_child_removed (ECollectionBackend *backend,
                              ESource *child_source)
 {
        ESource *collection_source;
+       gboolean has_external_auth = FALSE;
 
        /* Chain up to parent's method. */
        E_COLLECTION_BACKEND_CLASS (e_google_backend_parent_class)->child_removed (backend, child_source);
 
        collection_source = e_backend_get_source (E_BACKEND (backend));
 
+       if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_AUTHENTICATION)) {
+               ESourceAuthentication *auth_child_extension;
+               auth_child_extension = e_source_get_extension (
+                       child_source, E_SOURCE_EXTENSION_AUTHENTICATION);
+               has_external_auth = e_source_authentication_get_is_external (
+                       auth_child_extension);
+       }
        if (e_source_has_extension (child_source, E_SOURCE_EXTENSION_ADDRESS_BOOK) &&
            e_source_has_extension (collection_source, E_SOURCE_EXTENSION_COLLECTION) &&
-           !e_source_has_extension (collection_source, E_SOURCE_EXTENSION_GOA) &&
-           !e_source_has_extension (collection_source, E_SOURCE_EXTENSION_UOA)) {
+           !has_external_auth) {
                ESourceCollection *collection_extension;
 
                collection_extension = e_source_get_extension (collection_source, 
E_SOURCE_EXTENSION_COLLECTION);
diff --git a/src/modules/oauth2-services/module-oauth2-services.c 
b/src/modules/oauth2-services/module-oauth2-services.c
index 31540f78d..488295438 100644
--- a/src/modules/oauth2-services/module-oauth2-services.c
+++ b/src/modules/oauth2-services/module-oauth2-services.c
@@ -124,14 +124,15 @@ oauth2_source_monitor_update_source (EOAuth2SourceMonitor *extension,
        g_return_if_fail (E_IS_SERVER_SIDE_SOURCE (source));
 
        if (!extension->oauth2_services ||
-           !e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_GOA) ||
-           e_source_has_extension (source, E_SOURCE_EXTENSION_UOA))
+           !e_source_has_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION))
                return;
 
        server_source = E_SERVER_SIDE_SOURCE (source);
        authentication_extension = e_source_get_extension (source, E_SOURCE_EXTENSION_AUTHENTICATION);
 
+       if (e_source_authentication_get_is_external (authentication_extension))
+               return;
+
        auth_method = e_source_authentication_dup_method (authentication_extension);
 
        if (e_oauth2_services_is_oauth2_alias (extension->oauth2_services, auth_method)) {


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