signon  8.58
exampleplugin.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 "exampleplugin.h"
24 #include "exampledata.h"
25 #include "SignOn/signonplugincommon.h"
26 
27 using namespace SignOn;
28 
29 namespace ExamplePluginNS {
30 
31 ExamplePlugin::ExamplePlugin(QObject *parent):
32  AuthPluginInterface(parent)
33 {
34  TRACE();
35  m_showTos = false;
36 }
37 
39 {
40  TRACE();
41 }
42 
43 QString ExamplePlugin::type() const
44 {
45  return QLatin1String("example");
46 }
47 
48 QStringList ExamplePlugin::mechanisms() const
49 {
50  QStringList res = QStringList(QLatin1String("default"));
51  res << QLatin1String("example");
52 
53  return res;
54 }
55 
57 {
58 }
59 /*
60  * example plugin is used for testing purposes only
61  * */
62 void ExamplePlugin::process(const SignOn::SessionData &inData,
63  const QString &mechanism )
64 {
65  ExampleData response;
66  ExampleData input = inData.data<ExampleData>();
67 
68  if (!mechanisms().contains(mechanism) ) {
69  TRACE() << "invalid mechanism: " << mechanism;
70  // next is commented to allow invalid machanism to be used
71  /*
72  emit error(PLUGIN_ERROR_MECHANISM_NOT_SUPPORTED);
73  return;
74  */
75  }
76  TRACE() << "User: " << inData.UserName() ;
77  TRACE() << "Example" << input.Example();
78 
79  if (input.Params() == QLatin1String("Example")) {
80  qDebug() << inData.UserName();
81  response.setExample(QLatin1String("authenticated"));
82  emit result(response);
83  return;
84  }
85 
86  if (input.Params() == QLatin1String("error")) {
87  emit error(Error::NotAuthorized);
88  return;
89  }
90 
91  if (input.Params() == QLatin1String("toserror")) {
92  emit error(Error::TOSNotAccepted);
93  return;
94  }
95 
96  if (input.Params() == QLatin1String("store")) {
97  ExampleData storeData;
98  storeData.setExample(QLatin1String("store:") + input.Example());
99  emit store(storeData);
100  }
101 
102  if (input.Params() == QLatin1String("url")) {
103  SignOn::UiSessionData data;
104  data.setOpenUrl(input.Example());
105  data.setNetworkProxy(inData.NetworkProxy());
106  emit userActionRequired(data);
107 
108  return;
109  }
110 
111  if (input.Params() == QLatin1String("ui")) {
112  SignOn::UiSessionData data;
113  data.setQueryPassword(true);
114  data.setQueryUserName(true);
115  emit userActionRequired(data);
116 
117  return;
118  }
119 
120  if (input.Params() == QLatin1String("captcha")) {
121  SignOn::UiSessionData data;
122  data.setCaptchaUrl(input.Example());
123  data.setNetworkProxy(inData.NetworkProxy());
124  emit userActionRequired(data);
125 
126  return;
127  }
128 
129  if (!input.Tos().isEmpty()) {
130  SignOn::UiSessionData data;
131  //% "Click here to see TOS update"
132  /*
133  QString tos("Terms of service has changed. Click <a href=\"%1\">"
134  "here " "! </a> to see changes.");
135  */
136  QString tos = input.Tos();
137  data.setQueryMessage(tos.arg(input.Example()));
138  data.setOpenUrl(input.Example());
139  m_showTos = true;
140  emit userActionRequired(data);
141 
142  return;
143  }
144 
145  response.setExample(QLatin1String("authenticated"));
146  TRACE() << "Emitting results";
147 
148  emit store(response);
149  emit result(response);
150  return;
151 }
152 
153 
154 void ExamplePlugin::userActionFinished(const SignOn::UiSessionData &data)
155 {
156  Q_UNUSED(data);
157  ExampleData response;
158  TRACE();
159  if (m_showTos) {
160  m_showTos = false;
161  if (data.QueryErrorCode() != QUERY_ERROR_NONE) {
162  emit error(Error::TOSNotAccepted);
163  return;
164  }
165  }
166 
167  response.setExample(QLatin1String("signon-ui shown"));
168  emit result(response);
169 
170 }
171 
172 SIGNON_DECL_AUTH_PLUGIN(ExamplePlugin)
173 
174 } //namespace ExamplePluginNS
void userActionFinished(const SignOn::UiSessionData &data)
void process(const SignOn::SessionData &inData, const QString &mechanism=0)
QStringList mechanisms() const
Example plugin for Sign-On.
Definition: exampleplugin.h:37
#define TRACE()
Definition: debug.h:28
Data container to hold values for example authentication session.
Definition: exampledata.h:31