signon  8.56
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  const QString &mechanism,
65  QString &allowedMechanism)
66 {
67  MethodMap methodMap = methods();
68 
69  // If no methods have been specified for an identity assume anything goes
70  if (methodMap.isEmpty())
71  return true;
72 
73  if (!methodMap.contains(method))
74  return false;
75 
76  MechanismsList mechs = methodMap[method];
77  // If no mechanisms have been specified for a method, assume anything goes
78  if (mechs.isEmpty())
79  return true;
80 
81  if (mechs.contains(mechanism)) {
82  allowedMechanism = mechanism;
83  return true;
84  }
85 
86  /* in the case of SASL authentication (and possibly others),
87  * mechanism can be a list of strings, separated by a space;
88  * therefore, let's split the list first, and see if any of the
89  * mechanisms is allowed.
90  */
91  QStringList mechanisms =
92  mechanism.split(QLatin1Char(' '), QString::SkipEmptyParts);
93 
94  /* if the list is empty of it has only one element, then we already know
95  * that it didn't pass the previous checks */
96  if (mechanisms.size() <= 1)
97  return false;
98 
99  QStringList allowedMechanisms;
100  foreach (const QString &mech, mechanisms) {
101  if (mechs.contains(mech))
102  allowedMechanisms.append(mech);
103  }
104  if (allowedMechanisms.isEmpty())
105  return false;
106 
107  allowedMechanism = allowedMechanisms.join(QLatin1String(" "));
108  return true;
109 }
110 
111 } //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)
const QVariantMap toMap() const