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 
33 namespace 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 
57 IdentityInfo::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 
73 void IdentityInfo::setId(const quint32 id)
74 {
75  impl->setId(id);
76 }
77 
78 quint32 IdentityInfo::id() const
79 {
80  return impl->id();
81 }
82 
83 void IdentityInfo::setUserName(const QString &userName)
84 {
85  impl->setUserName(userName);
86 }
87 
88 const QString IdentityInfo::userName() const
89 {
90  return impl->userName();
91 }
92 
93 void IdentityInfo::setCaption(const QString &caption)
94 {
95  impl->setCaption(caption);
96 }
97 
98 const QString IdentityInfo::caption() const
99 {
100  return impl->caption();
101 }
102 
103 void IdentityInfo::setRealms(const QStringList &realms)
104 {
105  impl->setRealms(realms);
106 }
107 
108 QStringList IdentityInfo::realms() const
109 {
110  return impl->realms();
111 }
112 
113 void IdentityInfo::setOwner(const QString &ownerToken)
114 {
115  impl->setOwners(QStringList() << ownerToken);
116 }
117 
118 QString IdentityInfo::owner() const
119 {
120  return impl->owners().value(0);
121 }
122 
123 void IdentityInfo::setAccessControlList(const QStringList &accessControlList)
124 {
125  SecurityContextList list;
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 
154 QString IdentityInfo::secret() const
155 {
156  return impl->secret();
157 }
158 
159 void 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 
170 void 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 
196 QList<MethodName> IdentityInfo::methods() const
197 {
198  return impl->methods().keys();
199 }
200 
202 {
203  return impl->methods().value(method, QStringList());
204 }
205 
206 void 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
SignOn::IdentityInfo::caption
const QString caption() const
Returns a human-readable representation of the identity.
Definition: identityinfo.cpp:98
SignOn::IdentityInfo::userName
const QString userName() const
Returns the username.
Definition: identityinfo.cpp:88
SignOn::IdentityInfo::CredentialsType
CredentialsType
Definition: identityinfo.h:76
SignOn::IdentityInfo::setRefCount
void setRefCount(qint32 refCount)
Sets the refcount into identity info.
Definition: identityinfo.cpp:206
SignOn::IdentityInfo::IdentityInfo
IdentityInfo()
Creates a new empty IdentityInfo object.
Definition: identityinfo.cpp:35
SignOn::IdentityInfo::setOwner
void setOwner(const QString &ownerToken)
Sets application token that owns identity, therefore defining the applications that will be able to m...
Definition: identityinfo.cpp:113
SignOn::IdentityInfo::type
CredentialsType type() const
Retrieves the identity type from identity info.
Definition: identityinfo.cpp:191
SignOn::IdentityInfo::~IdentityInfo
~IdentityInfo()
Destructor.
Definition: identityinfo.cpp:67
SignOn::IdentityInfo::setId
void setId(const quint32 id)
Sets the numeric identifier for the credentials record.
Definition: identityinfo.cpp:73
SignOn::IdentityInfo::secret
QString secret() const
Gets the secret.
Definition: identityinfo.cpp:154
SignOn::IdentityInfo::setRealms
void setRealms(const QStringList &realms)
Sets the realms, e.g.
Definition: identityinfo.cpp:103
SignOn::IdentityInfo::removeMethod
void removeMethod(const MethodName &method)
Removes a method from identity info.
Definition: identityinfo.cpp:181
SignOn::IdentityInfo
Definition: identityinfo.h:64
SignOn::MechanismsList
QStringList MechanismsList
Definition: identityinfo.h:49
SignOn::SecurityContext
Definition: securitycontext.h:40
SignOn::IdentityInfo::realms
QStringList realms() const
Gets the realms, e.g.
Definition: identityinfo.cpp:108
SignOn::IdentityInfo::setCaption
void setCaption(const QString &caption)
Sets a human readable caption of the identity.
Definition: identityinfo.cpp:93
SignOn::IdentityInfo::refCount
qint32 refCount() const
Retrieves the refcount from identity info.
Definition: identityinfo.cpp:213
SignOn::IdentityInfo::setStoreSecret
void setStoreSecret(const bool storeSecret)
Sets whether the secret is stored or not.
Definition: identityinfo.cpp:170
SignOn::SecurityContextList
QList< SecurityContext > SecurityContextList
Definition: identityinfo.h:55
SignOn::IdentityInfo::id
quint32 id() const
Returns the identity identifier.
Definition: identityinfo.cpp:78
SignOn::MethodName
QString MethodName
Definition: identityinfo.h:43
SignOn
Definition: async-dbus-proxy.cpp:41
SignOn::IdentityInfo::accessControlListFull
SecurityContextList accessControlListFull() const
Gets the list of access control application tokens defining the applications that are able to access ...
Definition: identityinfo.cpp:149
SignOn::IdentityInfo::mechanisms
MechanismsList mechanisms(const MethodName &method) const
Lists the all mechanisms for certain method in identity info.
Definition: identityinfo.cpp:201
SignOn::IdentityInfo::setUserName
void setUserName(const QString &userName)
Sets the username.
Definition: identityinfo.cpp:83
SignOn::IdentityInfo::isStoringSecret
bool isStoringSecret() const
Returns whether secret is to be stored.
Definition: identityinfo.cpp:165
SignOn::IdentityInfo::owner
QString owner() const
Gets the owner application token that is defining the applications that are able to modify this speci...
Definition: identityinfo.cpp:118
SignOn::IdentityInfo::accessControlList
QStringList accessControlList() const
Gets the list of access control system tokens defining the applications that are able to access this ...
Definition: identityinfo.cpp:133
SignOn::IdentityInfo::setMethod
void setMethod(const MethodName &method, const MechanismsList &mechanismsList)
Sets the method into identity info.
Definition: identityinfo.cpp:175
SignOn::IdentityInfo::setSecret
void setSecret(const QString &secret, const bool storeSecret=true)
Sets the secret.
Definition: identityinfo.cpp:159
SignOn::IdentityInfo::operator=
IdentityInfo & operator=(const IdentityInfo &other)
Assignment operator.
Definition: identityinfo.cpp:51
SignOn::IdentityInfo::setType
void setType(CredentialsType type)
Sets the type into identity info.
Definition: identityinfo.cpp:186
SignOn::IdentityInfo::methods
QList< MethodName > methods() const
Lists all methods in identity info.
Definition: identityinfo.cpp:196
SignOn::IdentityInfo::setAccessControlList
void setAccessControlList(const QStringList &accessControlList)
Sets the list of access control system tokens, therefore defining the applications that will be able ...
Definition: identityinfo.cpp:123