static void session_authenticate (SoupSession *session, SoupMessage *msg, SoupAuth *auth, gboolean retrying, gpointer user_data) { GnomeKeyringResult result; gchar *user = NULL; gchar *password = NULL; // Get the previous user name that was used for this uri // TODO Gconf stuff // There wasn't one, so let's use the logged in user's name if (!user) user = g_strdup(getenv("USER")); if (retrying) { // Prompt the user if there were no valid credentials in the keyring GtkWidget *user_field = NULL; GtkWidget *pass_field = NULL; GtkWidget *dialog = get_credentials_dialog(user, soup_auth_get_realm(auth), soup_auth_get_host(auth), &user_field, &pass_field); gint response = gtk_dialog_run(GTK_DIALOG (dialog)); if (response == GTK_RESPONSE_REJECT) { gtk_widget_destroy(dialog); return; } g_free(user); user = g_strdup(gtk_entry_get_text(GTK_ENTRY(user_field))); password = g_strdup(gtk_entry_get_text(GTK_ENTRY(pass_field))); gtk_widget_destroy(dialog); // Store password in the keyring gchar * description = g_strdup_printf("Nautilus-Sendto-Trac:%s:%s", soup_auth_get_host(auth), soup_auth_get_realm(auth)); result = gnome_keyring_store_password_sync(HTTP_AUTH_SCHEMA, NULL, description, password, "host", soup_auth_get_host(auth), "realm", soup_auth_get_realm(auth), "user", user, NULL); g_free(description); g_free(password); } // Try and get a password for the user from the keyring result = gnome_keyring_find_password_sync(HTTP_AUTH_SCHEMA, &password, "host", soup_auth_get_host(auth), "realm", soup_auth_get_realm(auth), "user", user, NULL); if (result != GNOME_KEYRING_RESULT_OK) password = ""; // Do the authentication soup_auth_authenticate(auth, user, password); g_free(user); if (result == GNOME_KEYRING_RESULT_OK) gnome_keyring_free_password(password); return; }
static void soup_auth_get_property (GObject *object, guint prop_id, GValue *value, GParamSpec *pspec) { SoupAuth *auth = SOUP_AUTH (object); SoupAuthPrivate *priv = SOUP_AUTH_GET_PRIVATE (object); switch (prop_id) { case PROP_SCHEME_NAME: g_value_set_string (value, soup_auth_get_scheme_name (auth)); break; case PROP_REALM: if (auth->realm) g_free (auth->realm); g_value_set_string (value, soup_auth_get_realm (auth)); break; case PROP_HOST: if (priv->host) g_free (priv->host); g_value_set_string (value, soup_auth_get_host (auth)); break; case PROP_IS_FOR_PROXY: g_value_set_boolean (value, priv->proxy); break; case PROP_IS_AUTHENTICATED: g_value_set_boolean (value, soup_auth_is_authenticated (auth)); break; default: G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec); break; } }
static gchar* katze_http_auth_soup_auth_get_hash (SoupAuth* auth) { return g_strdup_printf ("%s:%s:%s", soup_auth_get_host (auth), soup_auth_get_scheme_name (auth), soup_auth_get_realm (auth)); }
JNIEXPORT jintLong JNICALL WebKitGTK_NATIVE(_1soup_1auth_1get_1host) (JNIEnv *env, jclass that, jintLong arg0) { jintLong rc = 0; WebKitGTK_NATIVE_ENTER(env, that, _1soup_1auth_1get_1host_FUNC); rc = (jintLong)soup_auth_get_host((SoupAuth *)arg0); WebKitGTK_NATIVE_EXIT(env, that, _1soup_1auth_1get_1host_FUNC); return rc; }
static gboolean soup_gss_build_response (SoupNegotiateConnectionState *conn, SoupAuth *auth, GError **err) { if (!conn->initialized) if (!soup_gss_client_init (conn, soup_auth_get_host (auth), err)) return FALSE; if (soup_gss_client_step (conn, "", err) != AUTH_GSS_CONTINUE) return FALSE; return TRUE; }
static void katze_http_auth_session_authenticate_cb (SoupSession* session, SoupMessage* msg, SoupAuth* auth, gboolean retrying, KatzeHttpAuth* http_auth) { gchar* opaque_info; KatzeHttpAuthLogin* login; GtkWidget* dialog; GtkSizeGroup* sizegroup; GtkWidget* hbox; GtkWidget* image; GtkWidget* label; GtkWidget* align; GtkWidget* entry; KatzeHttpAuthSave* save; /* We want to ask for authentication exactly once, so we enforce this with a tag. There might be a better way. */ if (!retrying && g_object_get_data (G_OBJECT (msg), "katze-session-tag")) return; if (1) { /* We use another tag to indicate whether a message is paused. There doesn't seem to be API in libSoup to find that out. */ soup_session_pause_message (session, g_object_ref (msg)); g_object_set_data (G_OBJECT (msg), "paused", (void*)1); } g_object_set_data (G_OBJECT (msg), "katze-session-tag", (void*)1); opaque_info = katze_http_auth_soup_auth_get_hash (auth); login = g_hash_table_lookup (http_auth->logins, opaque_info); g_free (opaque_info); dialog = gtk_dialog_new_with_buttons (_("Authentication Required"), NULL, GTK_DIALOG_DESTROY_WITH_PARENT | GTK_DIALOG_NO_SEPARATOR, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, GTK_STOCK_OK, GTK_RESPONSE_OK, NULL); gtk_window_set_icon_name (GTK_WINDOW (dialog), GTK_STOCK_DIALOG_AUTHENTICATION); gtk_container_set_border_width (GTK_CONTAINER (dialog), 5); gtk_container_set_border_width (GTK_CONTAINER (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 5); gtk_box_set_spacing (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), 5); hbox = gtk_hbox_new (FALSE, 6); image = gtk_image_new_from_stock (GTK_STOCK_DIALOG_AUTHENTICATION, GTK_ICON_SIZE_DIALOG); gtk_box_pack_start (GTK_BOX (hbox), image, FALSE, FALSE, 0); label = gtk_label_new (_("A username and a password are required\n" "to open this location:")); gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, FALSE, TRUE, 0); label = gtk_label_new (soup_auth_get_host (auth)); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), label, FALSE, TRUE, 0); /* If the realm is merely the host, omit the realm label */ if (g_strcmp0 (soup_auth_get_host (auth), soup_auth_get_realm (auth))) { label = gtk_label_new (soup_auth_get_realm (auth)); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), label, FALSE, TRUE, 0); } sizegroup = gtk_size_group_new (GTK_SIZE_GROUP_HORIZONTAL); hbox = gtk_hbox_new (FALSE, 6); label = gtk_label_new (_("Username")); align = gtk_alignment_new (0, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (align), label); gtk_size_group_add_widget (sizegroup, align); gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0); entry = gtk_entry_new (); if (login) gtk_entry_set_text (GTK_ENTRY (entry), login->username); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); g_object_set_data (G_OBJECT (dialog), "username", entry); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, FALSE, TRUE, 0); hbox = gtk_hbox_new (FALSE, 6); label = gtk_label_new (_("Password")); align = gtk_alignment_new (0, 0.5, 0, 0); gtk_container_add (GTK_CONTAINER (align), label); gtk_size_group_add_widget (sizegroup, align); gtk_box_pack_start (GTK_BOX (hbox), align, TRUE, TRUE, 0); entry = gtk_entry_new (); if (login) gtk_entry_set_text (GTK_ENTRY (entry), login->password); gtk_entry_set_visibility (GTK_ENTRY (entry), FALSE); gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); gtk_entry_set_activates_default (GTK_ENTRY (entry), TRUE); g_object_set_data (G_OBJECT (dialog), "password", entry); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, FALSE, TRUE, 0); hbox = gtk_hbox_new (FALSE, 6); label = gtk_check_button_new_with_mnemonic (_("_Remember password")); gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); g_object_set_data (G_OBJECT (dialog), "remember", label); gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (label), (login != NULL)); gtk_box_pack_start (GTK_BOX (gtk_dialog_get_content_area (GTK_DIALOG (dialog))), hbox, FALSE, TRUE, 0); gtk_dialog_set_default_response (GTK_DIALOG (dialog), GTK_RESPONSE_OK); gtk_widget_show_all (gtk_dialog_get_content_area (GTK_DIALOG (dialog))); g_object_set_data (G_OBJECT (dialog), "session", session); g_object_set_data (G_OBJECT (dialog), "msg", msg); save = g_slice_new0 (KatzeHttpAuthSave); save->http_auth = http_auth; save->auth = g_object_ref (auth); g_signal_connect (dialog, "response", G_CALLBACK (authentication_dialog_response_cb), save); gtk_widget_show (dialog); }