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