signon  8.42
signondaemonadaptor.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) 2011 Intel Corporation.
6  *
7  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
8  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
9  * Contact: Jussi Laako <jussi.laako@linux.intel.com>
10  *
11  * This library is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU Lesser General Public License
13  * version 2.1 as published by the Free Software Foundation.
14  *
15  * This library is distributed in the hope that it will be useful, but
16  * 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.
19  *
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
23  * 02110-1301 USA
24  */
25 
26 #include "signondaemonadaptor.h"
27 #include "signondisposable.h"
29 
30 namespace SignonDaemonNS {
31 
32 SignonDaemonAdaptor::SignonDaemonAdaptor(SignonDaemon *parent):
33  QDBusAbstractAdaptor(parent),
34  m_parent(parent)
35 {
36  setAutoRelaySignals(false);
37 }
38 
39 SignonDaemonAdaptor::~SignonDaemonAdaptor()
40 {
41 }
42 
43 void SignonDaemonAdaptor::registerNewIdentity(QDBusObjectPath &objectPath)
44 {
45  m_parent->registerNewIdentity(objectPath);
46 
48 }
49 
50 void SignonDaemonAdaptor::securityErrorReply(const char *failedMethodName)
51 {
52  QString errMsg;
53  QTextStream(&errMsg) << SIGNOND_PERMISSION_DENIED_ERR_STR
54  << "Method:"
55  << failedMethodName;
56 
57  QDBusMessage msg = parentDBusContext().message();
58  msg.setDelayedReply(true);
59  QDBusMessage errReply =
60  msg.createErrorReply(SIGNOND_PERMISSION_DENIED_ERR_NAME,
61  errMsg);
62  SIGNOND_BUS.send(errReply);
63  TRACE() << "Method FAILED Access Control check:" << failedMethodName;
64 }
65 
66 void SignonDaemonAdaptor::getIdentity(const quint32 id,
67  QDBusObjectPath &objectPath,
68  QVariantMap &identityData)
69 {
70  if (!AccessControlManagerHelper::instance()->isPeerAllowedToUseIdentity(
71  parentDBusContext().message(), id)) {
72  securityErrorReply(__func__);
73  return;
74  }
75 
76  m_parent->getIdentity(id, objectPath, identityData);
77 
79 }
80 
82 {
83  return m_parent->queryMethods();
84 }
85 
87  const QString &type)
88 {
90 
91  /* Access Control */
92  if (id != SIGNOND_NEW_IDENTITY) {
93  if (!AccessControlManagerHelper::instance()->isPeerAllowedToUseAuthSession(
94  parentDBusContext().message(), id)) {
95  securityErrorReply(__func__);
96  return QString();
97  }
98  }
99 
100  TRACE() << "ACM passed, creating AuthSession object";
101  return m_parent->getAuthSessionObjectPath(id, type);
102 }
103 
104 QStringList SignonDaemonAdaptor::queryMechanisms(const QString &method)
105 {
106  return m_parent->queryMechanisms(method);
107 }
108 
109 void SignonDaemonAdaptor::queryIdentities(const QVariantMap &filter)
110 {
111  /* Access Control */
112  if (!AccessControlManagerHelper::instance()->isPeerKeychainWidget(
113  parentDBusContext().message())) {
114  securityErrorReply(__func__);
115  return;
116  }
117 
118  QDBusMessage msg = parentDBusContext().message();
119  msg.setDelayedReply(true);
120  MapList identities = m_parent->queryIdentities(filter);
121  QDBusMessage reply = msg.createReply(QVariant::fromValue(identities));
122  SIGNOND_BUS.send(reply);
123 }
124 
126 {
127  /* Access Control */
128  if (!AccessControlManagerHelper::instance()->isPeerKeychainWidget(
129  parentDBusContext().message())) {
130  securityErrorReply(__func__);
131  return false;
132  }
133 
134  return m_parent->clear();
135 }
136 
137 } //namespace SignonDaemonNS