signon  8.58
signonidentityinfo.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: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
7  * Contact: 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 #include "signond-common.h"
24 #include "signonidentityinfo.h"
25 
26 #include <QBuffer>
27 #include <QDBusArgument>
28 #include <QDataStream>
29 #include <QDebug>
30 
31 namespace SignonDaemonNS {
32 
34 {
35 }
36 
38 {
39  /* We need to expand any QDBusArguments which might be present, since
40  * the map is likely to be coming from QDBus. */
41  QVariantMap::const_iterator i;
42  for (i = info.constBegin(); i != info.constEnd(); i++) {
43  if (qstrcmp(i.value().typeName(), "QDBusArgument") == 0) {
44  QDBusArgument container = i.value().value<QDBusArgument>();
45 
46  if (i.key() == SIGNOND_IDENTITY_INFO_AUTHMETHODS) {
47  MethodMap methodMap = qdbus_cast<MethodMap>(container);
48  setMethods(methodMap);
49  } else {
50  BLAME() << "Found unsupported QDBusArgument in key" << i.key();
51  }
52  } else {
53  insert(i.key(), i.value());
54  }
55  }
56 }
57 
58 const QVariantMap SignonIdentityInfo::toMap() const
59 {
60  return *this;
61 }
62 
64 {
65  QMapIterator<QString, QVariant> it(info);
66  while (it.hasNext()) {
67  it.next();
68  // We don't allow updating the ID
69  if (it.key() == SIGNOND_IDENTITY_INFO_ID) continue;
70 
71  insert(it.key(), it.value());
72  }
73 }
74 
76  const QString &mechanism,
77  QString &allowedMechanism)
78 {
79  MethodMap methodMap = methods();
80 
81  // If no methods have been specified for an identity assume anything goes
82  if (methodMap.isEmpty())
83  return true;
84 
85  if (!methodMap.contains(method))
86  return false;
87 
88  MechanismsList mechs = methodMap[method];
89  // If no mechanisms have been specified for a method, assume anything goes
90  if (mechs.isEmpty())
91  return true;
92 
93  if (mechs.contains(mechanism)) {
94  allowedMechanism = mechanism;
95  return true;
96  }
97 
98  /* in the case of SASL authentication (and possibly others),
99  * mechanism can be a list of strings, separated by a space;
100  * therefore, let's split the list first, and see if any of the
101  * mechanisms is allowed.
102  */
103  QStringList mechanisms =
104  mechanism.split(QLatin1Char(' '), QString::SkipEmptyParts);
105 
106  /* if the list is empty of it has only one element, then we already know
107  * that it didn't pass the previous checks */
108  if (mechanisms.size() <= 1)
109  return false;
110 
111  QStringList allowedMechanisms;
112  foreach (const QString &mech, mechanisms) {
113  if (mechs.contains(mech))
114  allowedMechanisms.append(mech);
115  }
116  if (allowedMechanisms.isEmpty())
117  return false;
118 
119  allowedMechanism = allowedMechanisms.join(QLatin1String(" "));
120  return true;
121 }
122 
123 } //namespace SignonDaemonNS
QStringList MechanismsList
#define BLAME()
Definition: debug.h:32
void setMethods(const MethodMap &methods)
bool checkMethodAndMechanism(const QString &method, const QString &mechanism, QString &allowedMechanism)
Daemon side representation of identity information.
const QVariantMap toMap() const
void update(const SignonIdentityInfo &info)