signon  8.58
passwordplugin.cpp
Go to the documentation of this file.
1 /*
2  * This file is part of signon
3  *
4  * Copyright (C) 2009-2010 Nokia Corporation.
5  *
6  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
7  *
8  * This library is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public License
10  * version 2.1 as published by the Free Software Foundation.
11  *
12  * This library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  * Lesser General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public
18  * License along with this library; if not, write to the Free Software
19  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20  * 02110-1301 USA
21  */
22 
23 #include "passwordplugin.h"
24 #include "SignOn/signonplugincommon.h"
25 
26 using namespace SignOn;
27 
28 namespace PasswordPluginNS {
29 
30 PasswordPlugin::PasswordPlugin(QObject *parent):
31  AuthPluginInterface(parent)
32 {
33  TRACE();
34 }
35 
37 {
38  TRACE();
39 }
40 
41 QString PasswordPlugin::type() const
42 {
43  return QLatin1String("password");
44 }
45 
46 QStringList PasswordPlugin::mechanisms() const
47 {
48  QStringList res = QStringList(QLatin1String("password"));
49 
50  return res;
51 }
52 
54 {
55  emit error(Error(Error::SessionCanceled));
56 }
57 
58 /*
59  * Password plugin is used for returning password
60  * */
61 void PasswordPlugin::process(const SignOn::SessionData &inData,
62  const QString &mechanism )
63 {
64  TRACE();
65  Q_UNUSED(mechanism);
66  SignOn::SessionData response;
67 
68  if (!inData.UserName().isEmpty())
69  response.setUserName(inData.UserName());
70 
71  if (!inData.Secret().isEmpty()) {
72  response.setSecret(inData.Secret());
73  emit result(response);
74  return;
75  }
76 
77  //we didn't receive password from signond, so ask from user
78  SignOn::UiSessionData data;
79  if (inData.UserName().isEmpty())
80  data.setQueryUserName(true);
81  else
82  data.setUserName(inData.UserName());
83 
84  data.setQueryPassword(true);
85  emit userActionRequired(data);
86 
87  return;
88 }
89 
90 void PasswordPlugin::userActionFinished(const SignOn::UiSessionData &data)
91 {
92  TRACE();
93 
94  if (data.QueryErrorCode() == QUERY_ERROR_NONE) {
95  SignOn::SessionData response;
96  response.setUserName(data.UserName());
97  response.setSecret(data.Secret());
98  emit result(response);
99  return;
100  }
101 
102  if (data.QueryErrorCode() == QUERY_ERROR_CANCELED)
103  emit error(Error::SessionCanceled);
104  else
105  emit error(Error(Error::UserInteraction,
106  QLatin1String("userActionFinished error: ")
107  + QString::number(data.QueryErrorCode())));
108 
109  return;
110 }
111 
112 SIGNON_DECL_AUTH_PLUGIN(PasswordPlugin)
113 
114 } //namespace PasswordPluginNS
Password plugin for Sign-On.
void userActionFinished(const SignOn::UiSessionData &data)
void process(const SignOn::SessionData &inData, const QString &mechanism=0)
#define TRACE()
Definition: debug.h:28