identity.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 "debug.h"
25 #include "identityimpl.h"
26 #include "identity.h"
27 
28 namespace SignOn {
29 
30 Identity::Identity(const quint32 id, QObject *parent):
31  QObject(parent)
32 {
33  initDebug();
34 
35  qRegisterMetaType<Error>("SignOn::Error");
36  qRegisterMetaType<Error>("Error");
37 
38  if (qMetaTypeId<Error>() < QMetaType::User)
39  BLAME() << "Identity::Identity() - "
40  "SignOn::Error meta type not registered.";
41 
42  impl = new IdentityImpl(this, id);
43 }
44 
46 {
47  Identity *identity = new Identity(SSO_NEW_IDENTITY, parent);
48  identity->impl->copyInfo(info);
49  return identity;
50 }
51 
52 Identity *Identity::existingIdentity(const quint32 id, QObject *parent)
53 {
54  if (id == 0)
55  return NULL;
56  return new Identity(id, parent);
57 }
58 
60 {
61 }
62 
63 quint32 Identity::id() const
64 {
65  return impl->id();
66 }
67 
69 {
70  impl->queryAvailableMethods();
71 }
72 
73 AuthSessionP Identity::createSession(const QString &methodName)
74 {
75  if (methodName.isEmpty())
76  return NULL;
77 
78  return AuthSessionP(impl->createSession(methodName, this));
79 }
80 
81 void Identity::destroySession(const AuthSessionP &session)
82 {
83  if (session.isNull())
84  return;
85 
86  impl->destroySession(session.data());
87 }
88 
89 void Identity::requestCredentialsUpdate(const QString &message)
90 {
91  impl->requestCredentialsUpdate(message);
92 }
93 
95 {
96  impl->storeCredentials(info);
97 }
98 
100 {
101  impl->remove();
102 }
103 
104 void Identity::addReference(const QString &reference)
105 {
106  impl->addReference(reference);
107 }
108 
109 void Identity::removeReference(const QString &reference)
110 {
111  impl->removeReference(reference);
112 }
113 
115 {
116  impl->queryInfo();
117 }
118 
119 void Identity::verifyUser(const QString &message)
120 {
121  impl->verifyUser(message);
122 }
123 
124 void Identity::verifyUser(const QVariantMap &params)
125 {
126  impl->verifyUser(params);
127 }
128 
129 void Identity::verifySecret(const QString &secret)
130 {
131  impl->verifySecret(secret);
132 }
133 
135 {
136  impl->signOut();
137 }
138 
139 } //namespace SignOn
void remove()
Removes this identity from database.
Definition: identity.cpp:99
Identity(const quint32 id=SSO_NEW_IDENTITY, QObject *parent=0)
Definition: identity.cpp:30
void verifyUser(const QString &message=QString())
Gets a secret verification from the user and compares it to the stored secret.
Definition: identity.cpp:119
virtual ~Identity()
Destructor.
Definition: identity.cpp:59
void destroySession(const AuthSessionP &session)
Destroys an authentication session.
Definition: identity.cpp:81
void queryInfo()
Query stored credential parameters for this authentication identity.
Definition: identity.cpp:114
void queryAvailableMethods()
Query list of available authentication methods for given identity.
Definition: identity.cpp:68
void verifySecret(const QString &secret)
Verifies if the given secret match the stored secret.
Definition: identity.cpp:129
void storeCredentials(const IdentityInfo &info=IdentityInfo())
Stores credential parameters for this authentication identity.
Definition: identity.cpp:94
void requestCredentialsUpdate(const QString &message=QString())
Requests the user to give a new secret into database.
Definition: identity.cpp:89
void signOut()
Signs out Identity from all services.
Definition: identity.cpp:134
AuthSessionP createSession(const QString &methodName)
Creates a new session for authentication.
Definition: identity.cpp:73
void addReference(const QString &reference=QString())
Adds the named reference to identity into the database.
Definition: identity.cpp:104
Contains identity information.
Definition: identityinfo.h:57
void removeReference(const QString &reference=QString())
Removes a named reference to identity from the database.
Definition: identity.cpp:109
static Identity * existingIdentity(const quint32 id, QObject *parent=0)
Constructs an identity object associated with an existing identity record.
Definition: identity.cpp:52
void info(const SignOn::IdentityInfo &info)
Emitted when credentials passed by queryInfo() method.
quint32 id() const
Unique id of given identity.
Definition: identity.cpp:63
Represents a database entry for a single identity.
Definition: identity.h:57
static Identity * newIdentity(const IdentityInfo &info=IdentityInfo(), QObject *parent=0)
Constructs a new identity object.
Definition: identity.cpp:45