signon 8.54

- Main Page
- Related Pages
- Namespaces
- Classes
- Files

- File List
- File Members

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 "signonidentityinfo.h"
24
25 #include <QBuffer>
26 #include <QDataStream>
27 #include <QDebug>
28
29 namespace SignonDaemonNS {
30
31 SignonIdentityInfo::SignonIdentityInfo():
32 m_id(0),
33 m_userName(QString()),
34 m_password(QString()),
35 m_storePassword(false),
36 m_caption(QString()),
37 m_methods(QMap<QString, QStringList>()),
38 m_realms(QStringList()),
39 m_accessControlList(QStringList()),
40 m_ownerList(QStringList()),
41 m_type(0),
42 m_refCount(0),
43 m_validated(false),
44 m_isUserNameSecret(false)
45 {
46 }
47
48 SignonIdentityInfo::SignonIdentityInfo(const QVariantMap &info):
49 m_id(0),
50 m_userName(QString()),
51 m_password(QString()),
52 m_storePassword(false),
53 m_caption(QString()),
54 m_methods(QMap<QString, QStringList>()),
55 m_realms(QStringList()),
56 m_accessControlList(QStringList()),
57 m_ownerList(QStringList()),
58 m_type(0),
59 m_refCount(0),
60 m_validated(false),
61 m_isUserNameSecret(false)
62 {
63 m_id = info.value(SIGNOND_IDENTITY_INFO_ID).toInt();
64 m_userName = info.value(SIGNOND_IDENTITY_INFO_USERNAME).toString();
65 m_password = info.value(SIGNOND_IDENTITY_INFO_SECRET).toString();
66 m_storePassword = info.value(SIGNOND_IDENTITY_INFO_STORESECRET).toBool();
67 m_caption = info.value(SIGNOND_IDENTITY_INFO_CAPTION).toString();
68 m_methods =
69 info.value(SIGNOND_IDENTITY_INFO_AUTHMETHODS).value<MethodMap>();
70
71 m_realms = info.value(SIGNOND_IDENTITY_INFO_REALMS).toStringList();
72 m_accessControlList = info.value(SIGNOND_IDENTITY_INFO_ACL).toStringList();
73 m_ownerList = info.value(SIGNOND_IDENTITY_INFO_OWNER).toStringList();
74 m_type = info.value(SIGNOND_IDENTITY_INFO_TYPE).toInt();
75 m_refCount = info.value(SIGNOND_IDENTITY_INFO_REFCOUNT).toInt();
76 m_validated = info.value(SIGNOND_IDENTITY_INFO_VALIDATED).toBool();
77 }
78
79 SignonIdentityInfo::SignonIdentityInfo(const quint32 id,
80 const QString &userName,
81 const QString &password,
82 const bool storePassword,
83 const QString &caption,
84 const MethodMap &methods,
85 const QStringList &realms,
86 const QStringList &accessControlList,
87 const QStringList &ownerList,
88 int type,
89 int refCount,
90 bool validated):
91 m_id(id),
92 m_userName(userName),
93 m_password(password),
94 m_storePassword(storePassword),
95 m_caption(caption),
96 m_methods(methods),
97 m_realms(realms),
98 m_accessControlList(accessControlList),
99 m_ownerList(ownerList),
100 m_type(type),
101 m_refCount(refCount),
102 m_validated(validated),
103 m_isUserNameSecret(false)
104 {
105 }
106
107 const QVariantMap SignonIdentityInfo::toMap() const
108 {
109 QVariantMap values;
110 values.insert(SIGNOND_IDENTITY_INFO_ID, m_id);
111 values.insert(SIGNOND_IDENTITY_INFO_USERNAME, m_userName);
112 values.insert(SIGNOND_IDENTITY_INFO_SECRET, m_password);
113 values.insert(SIGNOND_IDENTITY_INFO_CAPTION, m_caption);
114 values.insert(SIGNOND_IDENTITY_INFO_REALMS, m_realms);
115 values.insert(SIGNOND_IDENTITY_INFO_AUTHMETHODS,
116 QVariant::fromValue(m_methods));
117 values.insert(SIGNOND_IDENTITY_INFO_ACL, m_accessControlList);
118 values.insert(SIGNOND_IDENTITY_INFO_OWNER, m_ownerList);
119 values.insert(SIGNOND_IDENTITY_INFO_TYPE, m_type);
120 values.insert(SIGNOND_IDENTITY_INFO_REFCOUNT, m_refCount);
121 values.insert(SIGNOND_IDENTITY_INFO_VALIDATED, m_validated);
122 values.insert(SIGNOND_IDENTITY_INFO_USERNAME_IS_SECRET,
123 m_isUserNameSecret);
124 return values;
125 }
126
127 bool SignonIdentityInfo::operator==(const SignonIdentityInfo &other) const
128 {
129 //do not care about list element order
130 SignonIdentityInfo me = *this;
131 SignonIdentityInfo you = other;
132 me.m_realms.sort();
133 you.m_realms.sort();
134 me.m_accessControlList.sort();
135 you.m_accessControlList.sort();
136 QMapIterator<QString, QStringList> it(me.m_methods);
137 while (it.hasNext()) {
138 it.next();
139 QStringList list1 = it.value();
140 QStringList list2 = you.m_methods.value(it.key());
141 list1.sort();
142 list2.sort();
143 if (list1 != list2) return false;
144 }
145
146 return (m_id == other.m_id)
147 && (m_userName == other.m_userName)
148 && (m_password == other.m_password)
149 && (m_caption == other.m_caption)
150 && (me.m_realms ==you.m_realms)
151 && (me.m_accessControlList == you.m_accessControlList)
152 && (m_type == other.m_type)
153 && (m_validated == other.m_validated);
154 }
155
156 bool SignonIdentityInfo::checkMethodAndMechanism(const QString &method,
157 const QString &mechanism,
158 QString &allowedMechanism)
159 {
160 // If no methods have been specified for an identity assume anything goes
161 if (m_methods.isEmpty())
162 return true;
163
164 if (!m_methods.contains(method))
165 return false;
166
167 MechanismsList mechs = m_methods[method];
168 // If no mechanisms have been specified for a method, assume anything goes
169 if (mechs.isEmpty())
170 return true;
171
172 if (mechs.contains(mechanism)) {
173 allowedMechanism = mechanism;
174 return true;
175 }
176
177 /* in the case of SASL authentication (and possibly others),
178 * mechanism can be a list of strings, separated by a space;
179 * therefore, let's split the list first, and see if any of the
180 * mechanisms is allowed.
181 */
182 QStringList mechanisms =
183 mechanism.split(QLatin1Char(' '), QString::SkipEmptyParts);
184
185 /* if the list is empty of it has only one element, then we already know
186 * that it didn't pass the previous checks */
187 if (mechanisms.size() <= 1)
188 return false;
189
190 QStringList allowedMechanisms;
191 foreach (const QString &mech, mechanisms) {
192 if (mechs.contains(mech))
193 allowedMechanisms.append(mech);
194 }
195 if (allowedMechanisms.isEmpty())
196 return false;
197
198 allowedMechanism = allowedMechanisms.join(QLatin1String(" "));
199 return true;
200 }
201
202 SignonIdentityInfo &
203 SignonIdentityInfo::operator=(const SignonIdentityInfo &other)
204 {
205
206 m_id = other.m_id;
207 m_userName = other.m_userName;
208 m_password = other.m_password ;
209 m_storePassword = other.m_storePassword;
210 m_caption = other.m_caption;
211 m_realms = other.m_realms;
212 m_accessControlList = other.m_accessControlList;
213 m_ownerList = other.m_ownerList;
214 m_type = other.m_type;
215 m_refCount = other.m_refCount;
216 m_validated = other.m_validated;
217 m_methods = other.m_methods;
218 return *this;
219 }
220
221 } //namespace SignonDaemonNS
SignonDaemonNS::MechanismsList
QStringList MechanismsList
Definition: signonidentityinfo.h:35
SignonDaemonNS::SignonIdentityInfo::checkMethodAndMechanism
bool checkMethodAndMechanism(const QString &method, const QString &mechanism, QString &allowedMechanism)
Definition: signonidentityinfo.cpp:156
signonidentityinfo.h
SignonDaemonNS::SignonIdentityInfo::SignonIdentityInfo
SignonIdentityInfo()
Definition: signonidentityinfo.cpp:31
SignonDaemonNS::SignonIdentityInfo
Daemon side representation of identity information.
Definition: signonidentityinfo.h:43
SignonDaemonNS::SignonIdentityInfo::operator=
SignonIdentityInfo & operator=(const SignonIdentityInfo &other)
Definition: signonidentityinfo.cpp:203
SignonDaemonNS::SignonIdentityInfo::operator==
bool operator==(const SignonIdentityInfo &other) const
Definition: signonidentityinfo.cpp:127
SignonDaemonNS::SignonIdentityInfo::toMap
const QVariantMap toMap() const
Definition: signonidentityinfo.cpp:107
QMap
Definition: backupifadaptor.h:19