[evolution-groupwise] Adapt to Camel's new authentication API.
- From: Matthew Barnes <mbarnes src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-groupwise] Adapt to Camel's new authentication API.
- Date: Sat, 15 Oct 2011 15:04:17 +0000 (UTC)
commit 7b4841b15efc9dc95e7036a562f8b0f6041dfedc
Author: Matthew Barnes <mbarnes redhat com>
Date: Sat Oct 15 09:54:09 2011 -0400
Adapt to Camel's new authentication API.
src/camel/camel-groupwise-store.c | 171 ++++++++++++++++---------------------
1 files changed, 74 insertions(+), 97 deletions(-)
---
diff --git a/src/camel/camel-groupwise-store.c b/src/camel/camel-groupwise-store.c
index 405607a..34cfb96 100644
--- a/src/camel/camel-groupwise-store.c
+++ b/src/camel/camel-groupwise-store.c
@@ -97,102 +97,6 @@ groupwise_compare_folder_name (gconstpointer a,
}
static gboolean
-groupwise_auth_loop (CamelService *service,
- GCancellable *cancellable,
- GError **error)
-{
- CamelSession *session = camel_service_get_session (service);
- CamelStore *store = CAMEL_STORE (service);
- CamelSettings *settings;
- CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
- CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
- CamelNetworkSecurityMethod security_method;
- CamelURL *url;
- gboolean authenticated = FALSE;
- gchar *uri;
- guint32 prompt_flags = CAMEL_SESSION_PASSWORD_SECRET;
- const gchar *scheme;
- const gchar *password;
- EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL};
- const gchar *soap_port;
-
- url = camel_service_get_camel_url (service);
- settings = camel_service_get_settings (service);
-
- security_method = camel_network_settings_get_security_method (
- CAMEL_NETWORK_SETTINGS (settings));
-
- soap_port = camel_groupwise_settings_get_soap_port (
- CAMEL_GROUPWISE_SETTINGS (settings));
-
- if (security_method == CAMEL_NETWORK_SECURITY_METHOD_NONE)
- scheme = "http";
- else
- scheme = "https";
-
- uri = g_strdup_printf (
- "%s://%s:%s/soap", scheme, priv->server_name, soap_port);
-
- camel_service_set_password (service, NULL);
- password = camel_service_get_password (service);
-
- while (!authenticated) {
-
- if (password == NULL && !(store->flags & CAMEL_STORE_PROXY)) {
- gchar *prompt;
- gchar *new_passwd;
-
- prompt = camel_session_build_password_prompt (
- "GroupWise", url->user, url->host);
-
- /* XXX This is a tad awkward. Maybe define a
- * camel_service_ask_password() that calls
- * camel_session_get_password() and caches
- * the password itself? */
- new_passwd = camel_session_get_password (
- session, service, prompt,
- "password", prompt_flags, error);
- camel_service_set_password (service, new_passwd);
- password = camel_service_get_password (service);
- g_free (new_passwd);
-
- g_free (prompt);
-
- if (password == NULL) {
- g_set_error (
- error, G_IO_ERROR,
- G_IO_ERROR_CANCELLED,
- _("You did not enter a password."));
- return FALSE;
- }
- }
-
- priv->cnc = e_gw_connection_new_with_error_handler (uri, priv->user, password, &errors);
-
- if (!E_IS_GW_CONNECTION (priv->cnc)) {
- if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) {
- /* We need to un-cache the password before prompting again */
- prompt_flags |= CAMEL_SESSION_PASSWORD_REPROMPT;
- camel_service_set_password (service, NULL);
- password = camel_service_get_password (service);
- } else {
- g_set_error (
- error, CAMEL_SERVICE_ERROR,
- CAMEL_SERVICE_ERROR_UNAVAILABLE,
- "%s", errors.description ?
- errors.description :
- _("You must be working online to complete this operation"));
- return FALSE;
- }
- } else
- authenticated = TRUE;
-
- }
-
- return TRUE;
-}
-
-static gboolean
check_for_connection (CamelService *service,
GCancellable *cancellable,
GError **error)
@@ -283,7 +187,13 @@ groupwise_connect_sync (CamelService *service,
return TRUE;
}
- if (!check_for_connection (service, cancellable, error) || !groupwise_auth_loop (service, cancellable, error)) {
+ if (!check_for_connection (service, cancellable, error)) {
+ camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
+ camel_service_disconnect_sync (service, TRUE, NULL);
+ return FALSE;
+ }
+
+ if (!camel_session_authenticate_sync (session, service, NULL, cancellable, error)) {
camel_service_unlock (service, CAMEL_SERVICE_REC_CONNECT_LOCK);
camel_service_disconnect_sync (service, TRUE, NULL);
return FALSE;
@@ -1528,6 +1438,72 @@ groupwise_store_finalize (GObject *object)
G_OBJECT_CLASS (camel_groupwise_store_parent_class)->finalize (object);
}
+static CamelAuthenticationResult
+groupwise_store_authenticate_sync (CamelService *service,
+ const gchar *mechanism,
+ GCancellable *cancellable,
+ GError **error)
+{
+ CamelStore *store = CAMEL_STORE (service);
+ CamelSettings *settings;
+ CamelGroupwiseStore *groupwise_store = CAMEL_GROUPWISE_STORE (store);
+ CamelGroupwiseStorePrivate *priv = groupwise_store->priv;
+ CamelNetworkSecurityMethod security_method;
+ CamelAuthenticationResult result;
+ gchar *uri;
+ const gchar *scheme;
+ const gchar *password;
+ EGwConnectionErrors errors = {E_GW_CONNECTION_STATUS_INVALID_OBJECT, NULL};
+ const gchar *soap_port;
+
+ password = camel_service_get_password (service);
+ settings = camel_service_get_settings (service);
+
+ if (password == NULL) {
+ g_set_error_literal (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_CANT_AUTHENTICATE,
+ _("Authentication password not available"));
+ return CAMEL_AUTHENTICATION_ERROR;
+ }
+
+ security_method = camel_network_settings_get_security_method (
+ CAMEL_NETWORK_SETTINGS (settings));
+
+ soap_port = camel_groupwise_settings_get_soap_port (
+ CAMEL_GROUPWISE_SETTINGS (settings));
+
+ if (security_method == CAMEL_NETWORK_SECURITY_METHOD_NONE)
+ scheme = "http";
+ else
+ scheme = "https";
+
+ uri = g_strdup_printf (
+ "%s://%s:%s/soap", scheme, priv->server_name, soap_port);
+
+ priv->cnc = e_gw_connection_new_with_error_handler (
+ uri, priv->user, password, &errors);
+
+ g_free (uri);
+
+ if (E_IS_GW_CONNECTION (priv->cnc)) {
+ result = CAMEL_AUTHENTICATION_ACCEPTED;
+ } else if (errors.status == E_GW_CONNECTION_STATUS_INVALID_PASSWORD) {
+ result = CAMEL_AUTHENTICATION_REJECTED;
+ } else {
+ g_set_error (
+ error, CAMEL_SERVICE_ERROR,
+ CAMEL_SERVICE_ERROR_UNAVAILABLE,
+ "%s", errors.description ?
+ errors.description :
+ _("You must be working online "
+ "to complete this operation"));
+ result = CAMEL_AUTHENTICATION_ERROR;
+ }
+
+ return result;
+}
+
static gboolean
groupwise_store_initable_init (GInitable *initable,
GCancellable *cancellable,
@@ -1624,6 +1600,7 @@ camel_groupwise_store_class_init (CamelGroupwiseStoreClass *class)
service_class->get_name = groupwise_get_name;
service_class->connect_sync = groupwise_connect_sync;
service_class->disconnect_sync = groupwise_disconnect_sync;
+ service_class->authenticate_sync = groupwise_store_authenticate_sync;
service_class->query_auth_types_sync = groupwise_store_query_auth_types_sync;
store_class = CAMEL_STORE_CLASS (class);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]