signon  8.42
signonauthsession.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  * Conta 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 "signond-common.h"
24 #include "signonauthsession.h"
26 
27 using namespace SignonDaemonNS;
28 
30  const QString &method,
31  pid_t ownerPid):
32  m_id(id),
33  m_method(method),
34  m_registered(false),
35  m_ownerPid(ownerPid)
36 {
37  TRACE();
38 
39  static quint32 incr = 0;
40  QString objectName = SIGNOND_DAEMON_OBJECTPATH +
41  QLatin1String("/AuthSession_") + QString::number(incr++, 16);
42  TRACE() << objectName;
43 
44  setObjectName(objectName);
45 }
46 
48 {
49  TRACE();
50 
51  if (m_registered)
52  {
53  emit unregistered();
54  QDBusConnection connection(SIGNOND_BUS);
55  connection.unregisterObject(objectName());
56  }
57 }
58 
60  const QString &method,
61  SignonDaemon *parent,
62  bool &supportsAuthMethod,
63  pid_t ownerPid)
64 {
65  TRACE();
66  supportsAuthMethod = true;
67  SignonAuthSession* sas = new SignonAuthSession(id, method, ownerPid);
68 
69  QDBusConnection connection(SIGNOND_BUS);
70  if (!connection.isConnected()) {
71  TRACE() << "Cannot get DBUS object connected";
72  delete sas;
73  return QString();
74  }
75 
76  (void)new SignonAuthSessionAdaptor(sas);
77  QString objectName = sas->objectName();
78  if (!connection.registerObject(sas->objectName(), sas,
79  QDBusConnection::ExportAdaptors)) {
80  TRACE() << "Object cannot be registered: " << objectName;
81  delete sas;
82  return QString();
83  }
84 
85  SignonSessionCore *core = SignonSessionCore::sessionCore(id, method, parent);
86  if (!core) {
87  TRACE() << "Cannot retrieve proper tasks queue";
88  supportsAuthMethod = false;
89  delete sas;
90  return QString();
91  }
92 
93  sas->objectRegistered();
94  sas->setParent(core);
95 
96  connect(core, SIGNAL(stateChanged(const QString&, int, const QString&)),
97  sas, SLOT(stateChangedSlot(const QString&, int, const QString&)));
98 
99  TRACE() << "SignonAuthSession is created successfully: " << objectName;
100  return objectName;
101 }
102 
104 {
106 }
107 
108 quint32 SignonAuthSession::id() const
109 {
110  return m_id;
111 }
112 
114 {
115  return m_method;
116 }
117 
119 {
120  return m_ownerPid;
121 }
122 
123 QStringList
124 SignonAuthSession::queryAvailableMechanisms(const QStringList &wantedMechanisms)
125 {
126  return parent()->queryAvailableMechanisms(wantedMechanisms);
127 }
128 
129 QVariantMap SignonAuthSession::process(const QVariantMap &sessionDataVa,
130  const QString &mechanism)
131 {
132  setDelayedReply(true);
133  parent()->process(connection(),
134  message(),
135  sessionDataVa,
136  mechanism,
137  objectName());
138  return QVariantMap();
139 }
140 
142 {
143  TRACE();
144  parent()->cancel(objectName());
145 }
146 
147 void SignonAuthSession::setId(quint32 id)
148 {
149  m_id = id;
150  parent()->setId(id);
151 }
152 
154 {
155  //TODO - remove the `objectUnref` functionality from the DBus API
156  TRACE();
157  cancel();
158 
159  if (m_registered) {
160  QDBusConnection connection(SIGNOND_BUS);
161  connection.unregisterObject(objectName());
162  m_registered = false;
163  }
164 
165  deleteLater();
166 }
167 
168 void SignonAuthSession::stateChangedSlot(const QString &sessionKey,
169  int state,
170  const QString &message)
171 {
172  TRACE();
173 
174  if (sessionKey == objectName())
175  emit stateChanged(state, message);
176 }
177 
179 {
180  m_registered = true;
181 }