authsession.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 AUTHSESSION_H
00029 #define AUTHSESSION_H
00030 
00031 #include <QObject>
00032 #include <QString>
00033 #include <QStringList>
00034 #include <QByteArray>
00035 #include <QVariant>
00036 
00037 #include "libsignoncommon.h"
00038 #include "sessiondata.h"
00039 #include "signonerror.h"
00040 
00041 
00042 namespace SignOn {
00043 
00051 class SIGNON_EXPORT AuthSession: public QObject
00052 {
00053     Q_OBJECT
00054     Q_DISABLE_COPY(AuthSession)
00055 
00056     friend class IdentityImpl;
00057     friend class AuthSessionImpl;
00058 
00059 public:
00065     enum AuthSessionError {
00066         UnknownError = 1,               
00067         InternalServerError = 2,        
00068         InternalCommunicationError = 3, 
00069         PermissionDeniedError = 4,      
00070         AuthSessionErr = 300,           /* placeholder to rearrange enumeration */
00071         MechanismNotAvailableError,     
00072         MissingDataError,               
00073         InvalidCredentialsError,        
00074         WrongStateError,                
00075         OperationNotSupportedError,     
00076         NoConnectionError,              
00077         NetworkError,                   
00078         SslError,                       
00079         RuntimeError,                   
00080         CanceledError,                  
00081         TimedOutError,                  
00082         UserInteractionError            
00083     };
00084 
00091     enum AuthSessionState {
00092         SessionNotStarted = 0,          
00093         HostResolving,                  
00094         ServerConnecting,               
00095         DataSending,                    
00096         ReplyWaiting,                   
00097         UserPending,                    
00098         UiRefreshing,                   
00099         ProcessPending,                 
00100         SessionStarted,                 
00101         ProcessCanceling,               
00102         ProcessDone,                    
00103         CustomState,                    
00104         MaxState,
00105     };
00106 
00107 protected:
00111     AuthSession(quint32 id, const QString &methodName, QObject *parent = 0);
00112     ~AuthSession();
00113 
00114 public:
00120     const QString name() const;
00121 
00132      void queryAvailableMechanisms(const QStringList &wantedMechanisms = QStringList());
00133 
00163     void process(const SessionData &sessionData,
00164                  const QString &mechanism = QString());
00165 
00179     void challenge(const SessionData& sessionData,
00180                    const QString &mechanism = QString()) {
00181         process(sessionData, mechanism);
00182     }
00183 
00197     void request(const SessionData &sessionData,
00198                  const QString &mechanism = QString()) {
00199         process(sessionData, mechanism);
00200     }
00201 
00210     void cancel();
00211 
00220     void signMessage(const SessionData &params,
00221                      const QString &mechanism = QString()) {
00222         process(params, mechanism);
00223     }
00224 
00225 Q_SIGNALS:
00236     void error(const SignOn::Error &err);
00237 
00244     void mechanismsAvailable(const QStringList &mechanisms);
00245 
00258     void response(const SignOn::SessionData &sessionData);
00259 
00266     void stateChanged(AuthSession::AuthSessionState state,
00267                       const QString &message);
00268 
00269 private:
00270     class AuthSessionImpl *impl;
00271 };
00272 
00273 }  // namespace SignOn
00274 
00275 Q_DECLARE_METATYPE(SignOn::AuthSession::AuthSessionState)
00276 
00277 #endif // AUTHSESSION_H