signon
8.58
|
00001 /* 00002 * This file is part of signon 00003 * 00004 * Copyright (C) 2009-2010 Nokia Corporation. 00005 * 00006 * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com> 00007 * Contact: Alberto Mardegan <alberto.mardegan@canonical.com> 00008 * 00009 * This library is free software; you can redistribute it and/or 00010 * modify it under the terms of the GNU Lesser General Public License 00011 * version 2.1 as published by the Free Software Foundation. 00012 * 00013 * This library is distributed in the hope that it will be useful, but 00014 * WITHOUT ANY WARRANTY; without even the implied warranty of 00015 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00016 * Lesser General Public License for more details. 00017 * 00018 * You should have received a copy of the GNU Lesser General Public 00019 * License along with this library; if not, write to the Free Software 00020 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 00021 * 02110-1301 USA 00022 */ 00023 #include "signond-common.h" 00024 #include "signonidentityinfo.h" 00025 00026 #include <QBuffer> 00027 #include <QDBusArgument> 00028 #include <QDataStream> 00029 #include <QDebug> 00030 00031 namespace SignonDaemonNS { 00032 00033 SignonIdentityInfo::SignonIdentityInfo() 00034 { 00035 } 00036 00037 SignonIdentityInfo::SignonIdentityInfo(const QVariantMap &info) 00038 { 00039 /* We need to expand any QDBusArguments which might be present, since 00040 * the map is likely to be coming from QDBus. */ 00041 QVariantMap::const_iterator i; 00042 for (i = info.constBegin(); i != info.constEnd(); i++) { 00043 if (qstrcmp(i.value().typeName(), "QDBusArgument") == 0) { 00044 QDBusArgument container = i.value().value<QDBusArgument>(); 00045 00046 if (i.key() == SIGNOND_IDENTITY_INFO_AUTHMETHODS) { 00047 MethodMap methodMap = qdbus_cast<MethodMap>(container); 00048 setMethods(methodMap); 00049 } else { 00050 BLAME() << "Found unsupported QDBusArgument in key" << i.key(); 00051 } 00052 } else { 00053 insert(i.key(), i.value()); 00054 } 00055 } 00056 } 00057 00058 const QVariantMap SignonIdentityInfo::toMap() const 00059 { 00060 return *this; 00061 } 00062 00063 void SignonIdentityInfo::update(const SignonIdentityInfo &info) 00064 { 00065 QMapIterator<QString, QVariant> it(info); 00066 while (it.hasNext()) { 00067 it.next(); 00068 // We don't allow updating the ID 00069 if (it.key() == SIGNOND_IDENTITY_INFO_ID) continue; 00070 00071 insert(it.key(), it.value()); 00072 } 00073 } 00074 00075 bool SignonIdentityInfo::checkMethodAndMechanism(const QString &method, 00076 const QString &mechanism, 00077 QString &allowedMechanism) 00078 { 00079 MethodMap methodMap = methods(); 00080 00081 // If no methods have been specified for an identity assume anything goes 00082 if (methodMap.isEmpty()) 00083 return true; 00084 00085 if (!methodMap.contains(method)) 00086 return false; 00087 00088 MechanismsList mechs = methodMap[method]; 00089 // If no mechanisms have been specified for a method, assume anything goes 00090 if (mechs.isEmpty()) 00091 return true; 00092 00093 if (mechs.contains(mechanism)) { 00094 allowedMechanism = mechanism; 00095 return true; 00096 } 00097 00098 /* in the case of SASL authentication (and possibly others), 00099 * mechanism can be a list of strings, separated by a space; 00100 * therefore, let's split the list first, and see if any of the 00101 * mechanisms is allowed. 00102 */ 00103 QStringList mechanisms = 00104 mechanism.split(QLatin1Char(' '), QString::SkipEmptyParts); 00105 00106 /* if the list is empty of it has only one element, then we already know 00107 * that it didn't pass the previous checks */ 00108 if (mechanisms.size() <= 1) 00109 return false; 00110 00111 QStringList allowedMechanisms; 00112 foreach (const QString &mech, mechanisms) { 00113 if (mechs.contains(mech)) 00114 allowedMechanisms.append(mech); 00115 } 00116 if (allowedMechanisms.isEmpty()) 00117 return false; 00118 00119 allowedMechanism = allowedMechanisms.join(QLatin1String(" ")); 00120 return true; 00121 } 00122 00123 } //namespace SignonDaemonNS