signon  8.58
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  * Copyright (C) 2013 Canonical Ltd.
6  *
7  * Conta Alberto Mardegan <alberto.mardegan@canonical.com>
8  *
9  * This library is free software; you can redistribute it and/or
10  * modify it under the terms of the GNU Lesser General Public License
11  * version 2.1 as published by the Free Software Foundation.
12  *
13  * This library is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this library; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
21  * 02110-1301 USA
22  */
23 
24 #include "signond-common.h"
25 #include "signonauthsession.h"
27 
28 using namespace SignonDaemonNS;
29 
31  const QString &method,
32  pid_t ownerPid):
33  m_id(id),
34  m_method(method),
35  m_ownerPid(ownerPid)
36 {
37  TRACE();
38 
39  (void)new SignonAuthSessionAdaptor(this);
40 
41  static quint32 incr = 0;
42  QString objectName = SIGNOND_DAEMON_OBJECTPATH +
43  QLatin1String("/AuthSession_") + QString::number(incr++, 16);
44  TRACE() << objectName;
45 
46  setObjectName(objectName);
47 }
48 
50 {
51  Q_EMIT unregistered();
52  TRACE();
53 }
54 
56  const QString &method,
58  pid_t ownerPid)
59 {
60  TRACE();
61  SignonAuthSession *sas = new SignonAuthSession(id, method, ownerPid);
62 
63  SignonSessionCore *core = SignonSessionCore::sessionCore(id, method, parent);
64  if (!core) {
65  TRACE() << "Cannot retrieve proper tasks queue";
66  delete sas;
67  return NULL;
68  }
69 
70  sas->setParent(core);
71 
72  connect(core, SIGNAL(stateChanged(const QString&, int, const QString&)),
73  sas, SLOT(stateChangedSlot(const QString&, int, const QString&)));
74 
75  TRACE() << "SignonAuthSession created successfully:" << sas->objectName();
76  return sas;
77 }
78 
80 {
82 }
83 
84 quint32 SignonAuthSession::id() const
85 {
86  return m_id;
87 }
88 
90 {
91  return m_method;
92 }
93 
95 {
96  return m_ownerPid;
97 }
98 
99 QStringList
100 SignonAuthSession::queryAvailableMechanisms(const QStringList &wantedMechanisms)
101 {
102  return parent()->queryAvailableMechanisms(wantedMechanisms);
103 }
104 
105 QVariantMap SignonAuthSession::process(const QVariantMap &sessionDataVa,
106  const QString &mechanism)
107 {
108  setDelayedReply(true);
109  parent()->process(connection(),
110  message(),
111  sessionDataVa,
112  mechanism,
113  objectName());
114  return QVariantMap();
115 }
116 
118 {
119  TRACE();
120  parent()->cancel(objectName());
121 }
122 
123 void SignonAuthSession::setId(quint32 id)
124 {
125  m_id = id;
126  parent()->setId(id);
127 }
128 
130 {
131  //TODO - remove the `objectUnref` functionality from the DBus API
132  TRACE();
133  cancel();
134 
135  deleteLater();
136 }
137 
138 void SignonAuthSession::stateChangedSlot(const QString &sessionKey,
139  int state,
140  const QString &message)
141 {
142  TRACE();
143 
144  if (sessionKey == objectName())
145  emit stateChanged(state, message);
146 }
void process(const QDBusConnection &connection, const QDBusMessage &message, const QVariantMap &sessionDataVa, const QString &mechanism, const QString &cancelKey)
Daemon side representation of authentication session.
Daemon side representation of authentication session.
QStringList queryAvailableMechanisms(const QStringList &wantedMechanisms)
SignonSessionCore * parent() const
static SignonSessionCore * sessionCore(const quint32 id, const QString &method, SignonDaemon *parent)
SignonAuthSession(quint32 id, const QString &method, pid_t ownerPid)
#define TRACE()
Definition: debug.h:28
QStringList queryAvailableMechanisms(const QStringList &wantedMechanisms)
QVariantMap process(const QVariantMap &sessionDataVa, const QString &mechanism)
void stateChanged(int state, const QString &message)
static SignonAuthSession * createAuthSession(const quint32 id, const QString &method, SignonDaemon *parent, pid_t ownerPid)
void cancel(const QString &cancelKey)