identity.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  *
00006  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00007  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00008  *
00009  * This library is free software; you can redistribute it and/or
00010  * modify it under the terms of the GNU Lesser General Public License
00011  * version 2.1 as published by the Free Software Foundation.
00012  *
00013  * This library is distributed in the hope that it will be useful, but
00014  * WITHOUT ANY WARRANTY; without even the implied warranty of
00015  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00016  * Lesser General Public License for more details.
00017  *
00018  * You should have received a copy of the GNU Lesser General Public
00019  * License along with this library; if not, write to the Free Software
00020  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00021  * 02110-1301 USA
00022  */
00028 #ifndef IDENTITY_H
00029 #define IDENTITY_H
00030 
00031 #include <QObject>
00032 #include <QByteArray>
00033 #include <QMap>
00034 #include <QString>
00035 #include <QStringList>
00036 #include <QVariant>
00037 #include <QPointer>
00038 
00039 #include "libsignoncommon.h"
00040 #include "authsession.h"
00041 #include "identityinfo.h"
00042 #include "signonerror.h"
00043 
00044 #define SSO_NEW_IDENTITY 0
00045 
00046 namespace SignOn {
00047 
00048 typedef QPointer<AuthSession> AuthSessionP;
00049 
00057 class SIGNON_EXPORT Identity: public QObject
00058 {
00059     Q_OBJECT
00060     Q_DISABLE_COPY(Identity)
00061 
00062     friend class IdentityImpl;
00063 
00064 public:
00070     enum IdentityError {
00071         UnknownError = 1,               
00073         InternalServerError = 2,        
00074         InternalCommunicationError = 3, 
00076         PermissionDeniedError = 4,      
00079         IdentityErr = 200,              /* placeholder to rearrange
00080                                           enumeration. */
00081         MethodNotAvailableError,        
00083         NotFoundError,                  
00086         StoreFailedError,               
00087         RemoveFailedError,              
00088         SignOutFailedError,             
00089         CanceledError,                  
00090         CredentialsNotAvailableError    
00091     };
00092 
00093 protected:
00097     Identity(const quint32 id = SSO_NEW_IDENTITY,
00098              QObject *parent = 0);
00099 
00100 public:
00110     static Identity *newIdentity(const IdentityInfo &info = IdentityInfo(),
00111                                  QObject *parent = 0);
00112 
00122     static Identity *existingIdentity(const quint32 id, QObject *parent = 0);
00123 
00127     virtual ~Identity();
00128 
00135     quint32 id() const;
00136 
00147     void queryAvailableMethods();
00148 
00157     AuthSessionP createSession(const QString &methodName);
00158 
00164     void destroySession(const AuthSessionP &session);
00165 
00181     void requestCredentialsUpdate(const QString &message = QString());
00182 
00203     void storeCredentials(const IdentityInfo &info = IdentityInfo());
00204 
00217     void remove();
00218 
00231     void addReference(const QString &reference = QString());
00232 
00245     void removeReference(const QString &reference = QString());
00246 
00260     void queryInfo();
00261 
00275     void verifyUser(const QString &message = QString());
00276 
00290     void verifyUser(const QVariantMap &params);
00291 
00303     void verifySecret(const QString &secret);
00304 
00317     void signOut();
00318 
00319 Q_SIGNALS:
00320 
00331     void error(const SignOn::Error &err);
00332 
00339     void methodsAvailable(const QStringList &methods);
00340 
00346     void credentialsStored(const quint32 id);
00347 
00353     void referenceAdded();
00354 
00360     void referenceRemoved();
00361 
00366     void info(const SignOn::IdentityInfo &info);
00367 
00372     void userVerified(const bool valid);
00373 
00378     void secretVerified(const bool valid);
00379 
00383     void signedOut();
00384 
00388     void removed();
00389 
00390 private:
00391     class IdentityImpl *impl;
00392 };
00393 
00394 }  // namespace SignOn
00395 
00396 #endif /* IDENTITY_H */