My Project
identityinfo.cpp
1/*
2 * This file is part of signon
3 *
4 * Copyright (C) 2009-2010 Nokia Corporation.
5 * Copyright (C) 2011-2016 Canonical Ltd.
6 *
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
24#include <QVariant>
25#include <QString>
26
27#include "debug.h"
28#include "libsignoncommon.h"
29#include "identityinfo.h"
30#include "identityinfoimpl.h"
31#include "identity.h"
32
33namespace SignOn {
34
36 impl(new IdentityInfoImpl)
37{
38 qRegisterMetaType<IdentityInfo>("SignOn::IdentityInfo");
39
40 if (qMetaTypeId<IdentityInfo>() < QMetaType::User)
41 BLAME() << "IdentityInfo::IdentityInfo() - "
42 "IdentityInfo meta type not registered.";
43}
44
46 impl(new IdentityInfoImpl)
47{
48 *impl = *other.impl;
49}
50
52{
53 *impl = *other.impl;
54 return *this;
55}
56
57IdentityInfo::IdentityInfo(const QString &caption,
58 const QString &userName,
59 const QMap<MethodName, MechanismsList> &methods):
60 impl(new IdentityInfoImpl)
61{
62 impl->setCaption(caption);
63 impl->setUserName(userName);
64 impl->setMethods(methods);
65}
66
68{
69 if (impl) delete impl;
70 impl = 0;
71}
72
73void IdentityInfo::setId(const quint32 id)
74{
75 impl->setId(id);
76}
77
78quint32 IdentityInfo::id() const
79{
80 return impl->id();
81}
82
83void IdentityInfo::setUserName(const QString &userName)
84{
85 impl->setUserName(userName);
86}
87
88const QString IdentityInfo::userName() const
89{
90 return impl->userName();
91}
92
93void IdentityInfo::setCaption(const QString &caption)
94{
95 impl->setCaption(caption);
96}
97
98const QString IdentityInfo::caption() const
99{
100 return impl->caption();
101}
102
103void IdentityInfo::setRealms(const QStringList &realms)
104{
105 impl->setRealms(realms);
106}
107
108QStringList IdentityInfo::realms() const
109{
110 return impl->realms();
111}
112
113void IdentityInfo::setOwner(const QString &ownerToken)
114{
115 impl->setOwners(QStringList() << ownerToken);
116}
117
118QString IdentityInfo::owner() const
119{
120 return impl->owners().value(0);
121}
122
123void IdentityInfo::setAccessControlList(const QStringList &accessControlList)
124{
126 for (const QString &sysCtx: accessControlList) {
127 list.append(SecurityContext(sysCtx, QLatin1String("*")));
128 }
129
130 impl->setAccessControlList(list);
131}
132
134{
135 SecurityContextList accessControlList = impl->accessControlList();
136 QStringList list;
137 for (const SecurityContext &secCtx: accessControlList) {
138 list.append(secCtx.systemContext());
139 }
140
141 return list;
142}
143
145{
146 impl->setAccessControlList(accessControlList);
147}
148
150{
151 return impl->accessControlList();
152}
153
154QString IdentityInfo::secret() const
155{
156 return impl->secret();
157}
158
159void IdentityInfo::setSecret(const QString &secret, const bool storeSecret)
160{
161 impl->setSecret(secret);
162 impl->setStoreSecret(storeSecret);
163}
164
166{
167 return impl->storeSecret();
168}
169
170void IdentityInfo::setStoreSecret(const bool storeSecret)
171{
172 impl->setStoreSecret(storeSecret);
173}
174
176 const MechanismsList &mechanismsList)
177{
178 impl->updateMethod(method, mechanismsList);
179}
180
182{
183 impl->removeMethod(method);
184}
185
187{
188 impl->setType(type);
189}
190
192{
193 return impl->type();
194}
195
196QList<MethodName> IdentityInfo::methods() const
197{
198 return impl->methods().keys();
199}
200
202{
203 return impl->methods().value(method, QStringList());
204}
205
206void IdentityInfo::setRefCount(qint32 refCount)
207{
208 /* This method is a mistake, let's keep it for binary compatibility as a
209 * no-op. */
210 Q_UNUSED(refCount);
211}
212
214{
215 return impl->refCount();
216}
217
218} //namespace SignOn
Contains identity information.
void setCaption(const QString &caption)
Sets a human readable caption of the identity.
QStringList realms() const
Gets the realms, e.g.
~IdentityInfo()
Destructor.
CredentialsType type() const
Retrieves the identity type from identity info.
void setAccessControlList(const QStringList &accessControlList)
Sets the list of access control system tokens, therefore defining the applications that will be able ...
void setRefCount(qint32 refCount)
Sets the refcount into identity info.
void setType(CredentialsType type)
Sets the type into identity info.
void setSecret(const QString &secret, const bool storeSecret=true)
Sets the secret.
void removeMethod(const MethodName &method)
Removes a method from identity info.
QStringList accessControlList() const
Gets the list of access control system tokens defining the applications that are able to access this ...
void setId(const quint32 id)
Sets the numeric identifier for the credentials record.
QString owner() const
Gets the owner application token that is defining the applications that are able to modify this speci...
qint32 refCount() const
Retrieves the refcount from identity info.
IdentityInfo & operator=(const IdentityInfo &other)
Assignment operator.
SecurityContextList accessControlListFull() const
Gets the list of access control application tokens defining the applications that are able to access ...
void setRealms(const QStringList &realms)
Sets the realms, e.g.
void setUserName(const QString &userName)
Sets the username.
IdentityInfo()
Creates a new empty IdentityInfo object.
const QString caption() const
Returns a human-readable representation of the identity.
void setMethod(const MethodName &method, const MechanismsList &mechanismsList)
Sets the method into identity info.
QString secret() const
Gets the secret.
const QString userName() const
Returns the username.
void setStoreSecret(const bool storeSecret)
Sets whether the secret is stored or not.
quint32 id() const
Returns the identity identifier.
QList< MethodName > methods() const
Lists all methods in identity info.
MechanismsList mechanisms(const MethodName &method) const
Lists the all mechanisms for certain method in identity info.
CredentialsType
Values used to describe the type of the identity.
void setOwner(const QString &ownerToken)
Sets application token that owns identity, therefore defining the applications that will be able to m...
bool isStoringSecret() const
Returns whether secret is to be stored.
Contains access security context information.
QString MethodName
Defines a string as an authentication method.
QStringList MechanismsList
Defines a string list as a list of mechanisms.
QList< SecurityContext > SecurityContextList
Defines a list of security contexts.