1 /* vi: set et sw=4 ts=4 cino=t0,(0: */
2 /* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
4 * This file is part of gsignond
6 * Copyright (C) 2012 Intel Corporation.
8 * Contact: Alexander Kanavin <alex.kanavin@gmail.com>
10 * This library is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU Lesser General Public
12 * License as published by the Free Software Foundation; either
13 * version 2.1 of the License, or (at your option) any later version.
15 * This library is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 * Lesser General Public License for more details.
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with this library; if not, write to the Free Software
22 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
26 #include <gsignond/gsignond-plugin-interface.h>
27 #include "gsignond-password-plugin.h"
28 #include <gsignond/gsignond-error.h>
30 static void gsignond_plugin_interface_init (GSignondPluginInterface *iface);
32 G_DEFINE_TYPE_WITH_CODE (GSignondPasswordPlugin, gsignond_password_plugin,
34 G_IMPLEMENT_INTERFACE (GSIGNOND_TYPE_PLUGIN,
35 gsignond_plugin_interface_init));
37 static void gsignond_password_plugin_cancel (GSignondPlugin *self)
39 GError* error = g_error_new(GSIGNOND_ERROR,
40 GSIGNOND_ERROR_SESSION_CANCELED,
42 gsignond_plugin_error (self, error);
46 static void gsignond_password_plugin_request (
47 GSignondPlugin *self, GSignondSessionData *session_data)
52 static void gsignond_password_plugin_request_initial (
53 GSignondPlugin *self, GSignondSessionData *session_data,
54 const gchar *mechanism)
56 const gchar* username = gsignond_session_data_get_username(session_data);
57 const gchar* secret = gsignond_session_data_get_secret(session_data);
60 GSignondSessionData *response = gsignond_dictionary_new();
62 gsignond_session_data_set_username(response, username);
63 gsignond_session_data_set_secret(response, secret);
64 gsignond_plugin_response_final(self, response);
65 gsignond_dictionary_unref(response);
69 GSignondSignonuiData *user_action_data = gsignond_signonui_data_new();
71 gsignond_signonui_data_set_query_username(user_action_data, TRUE);
73 gsignond_signonui_data_set_query_username(user_action_data, FALSE);
74 gsignond_signonui_data_set_username(user_action_data, username);
76 gsignond_signonui_data_set_query_password(user_action_data, TRUE);
77 gsignond_plugin_user_action_required(self, user_action_data);
78 gsignond_dictionary_unref(user_action_data);
81 static void gsignond_password_plugin_user_action_finished (
83 GSignondSignonuiData *session_data)
85 GSignondSignonuiError query_error;
86 gboolean res = gsignond_signonui_data_get_query_error(session_data,
89 GError* error = g_error_new(GSIGNOND_ERROR,
90 GSIGNOND_ERROR_USER_INTERACTION,
91 "userActionFinished did not return an error value");
92 gsignond_plugin_error (self, error);
96 const gchar* username = gsignond_signonui_data_get_username(session_data);
97 const gchar* secret = gsignond_signonui_data_get_password(session_data);
99 if (query_error == SIGNONUI_ERROR_NONE &&
102 GSignondSessionData *response = gsignond_dictionary_new();
103 gsignond_session_data_set_username(response, username);
104 gsignond_session_data_set_secret(response, secret);
105 gsignond_plugin_response_final(self, response);
106 gsignond_dictionary_unref(response);
108 } else if (query_error == SIGNONUI_ERROR_CANCELED) {
109 GError* error = g_error_new(GSIGNOND_ERROR,
110 GSIGNOND_ERROR_SESSION_CANCELED,
112 gsignond_plugin_error (self, error);
115 GError* error = g_error_new(GSIGNOND_ERROR,
116 GSIGNOND_ERROR_USER_INTERACTION,
117 "userActionFinished error: %d",
119 gsignond_plugin_error (self, error);
124 static void gsignond_password_plugin_refresh (
125 GSignondPlugin *self,
126 GSignondSignonuiData *session_data)
128 gsignond_plugin_refreshed(self, session_data);
132 gsignond_plugin_interface_init (GSignondPluginInterface *iface)
134 iface->cancel = gsignond_password_plugin_cancel;
135 iface->request_initial = gsignond_password_plugin_request_initial;
136 iface->request = gsignond_password_plugin_request;
137 iface->user_action_finished = gsignond_password_plugin_user_action_finished;
138 iface->refresh = gsignond_password_plugin_refresh;
142 gsignond_password_plugin_init (GSignondPasswordPlugin *self)
157 gsignond_password_plugin_set_property (GObject *object,
165 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
171 gsignond_password_plugin_get_property (GObject *object,
176 GSignondPasswordPlugin *password_plugin = GSIGNOND_PASSWORD_PLUGIN (object);
177 (void) password_plugin;
178 gchar *mechanisms[] = { "password", NULL };
183 g_value_set_string (value, "password");
185 case PROP_MECHANISMS:
186 g_value_set_boxed (value, mechanisms);
190 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
196 gsignond_password_plugin_class_init (GSignondPasswordPluginClass *klass)
198 GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
200 gobject_class->set_property = gsignond_password_plugin_set_property;
201 gobject_class->get_property = gsignond_password_plugin_get_property;
203 g_object_class_override_property (gobject_class, PROP_TYPE, "type");
204 g_object_class_override_property (gobject_class, PROP_MECHANISMS,