authsession.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2011-2015 Canonical Ltd.
00006  *
00007  * Contact: Aurel Popirtac <ext-aurel.popirtac@nokia.com>
00008  * Contact: Alberto Mardegan <alberto.mardegan@canonical.com>
00009  *
00010  * This library is free software; you can redistribute it and/or
00011  * modify it under the terms of the GNU Lesser General Public License
00012  * version 2.1 as published by the Free Software Foundation.
00013  *
00014  * This library is distributed in the hope that it will be useful, but
00015  * WITHOUT ANY WARRANTY; without even the implied warranty of
00016  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
00017  * Lesser General Public License for more details.
00018  *
00019  * You should have received a copy of the GNU Lesser General Public
00020  * License along with this library; if not, write to the Free Software
00021  * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
00022  * 02110-1301 USA
00023  */
00029 #ifndef AUTHSESSION_H
00030 #define AUTHSESSION_H
00031 
00032 #include <QObject>
00033 #include <QString>
00034 #include <QStringList>
00035 #include <QByteArray>
00036 #include <QVariant>
00037 
00038 #include "libsignoncommon.h"
00039 #include "sessiondata.h"
00040 #include "signonerror.h"
00041 
00042 namespace SignOnTests {
00043     class AccessControlTest;
00044 }
00045 
00046 namespace SignOn {
00047 
00055 class SIGNON_EXPORT AuthSession: public QObject
00056 {
00057     Q_OBJECT
00058     Q_DISABLE_COPY(AuthSession)
00059 
00060     friend class IdentityImpl;
00061     friend class AuthSessionImpl;
00062     friend class SignOnTests::AccessControlTest;
00063 
00064 public:
00070     enum AuthSessionError {
00071         UnknownError = 1,               
00072         InternalServerError = 2,        
00073         InternalCommunicationError = 3, 
00074         PermissionDeniedError = 4,      
00075         AuthSessionErr = 300,           /* placeholder to rearrange enumeration */
00076         MechanismNotAvailableError,     
00077         MissingDataError,               
00078         InvalidCredentialsError,        
00079         WrongStateError,                
00080         OperationNotSupportedError,     
00081         NoConnectionError,              
00082         NetworkError,                   
00083         SslError,                       
00084         RuntimeError,                   
00085         CanceledError,                  
00086         TimedOutError,                  
00087         UserInteractionError            
00088     };
00089 
00096     enum AuthSessionState {
00097         SessionNotStarted = 0,          
00098         HostResolving,                  
00099         ServerConnecting,               
00100         DataSending,                    
00101         ReplyWaiting,                   
00102         UserPending,                    
00103         UiRefreshing,                   
00104         ProcessPending,                 
00105         SessionStarted,                 
00106         ProcessCanceling,               
00107         ProcessDone,                    
00108         CustomState,                    
00109         MaxState,
00110     };
00111 
00112 protected:
00116     AuthSession(quint32 id, const QString &methodName, QObject *parent = 0);
00117     ~AuthSession();
00118 
00119 public:
00125     const QString name() const;
00126 
00137      void queryAvailableMechanisms(const QStringList &wantedMechanisms = QStringList());
00138 
00168     void process(const SessionData &sessionData,
00169                  const QString &mechanism = QString());
00170 
00184     void challenge(const SessionData& sessionData,
00185                    const QString &mechanism = QString()) {
00186         process(sessionData, mechanism);
00187     }
00188 
00202     void request(const SessionData &sessionData,
00203                  const QString &mechanism = QString()) {
00204         process(sessionData, mechanism);
00205     }
00206 
00215     void cancel();
00216 
00225     void signMessage(const SessionData &params,
00226                      const QString &mechanism = QString()) {
00227         process(params, mechanism);
00228     }
00229 
00230 Q_SIGNALS:
00241     void error(const SignOn::Error &err);
00242 
00249     void mechanismsAvailable(const QStringList &mechanisms);
00250 
00263     void response(const SignOn::SessionData &sessionData);
00264 
00271     void stateChanged(AuthSession::AuthSessionState state,
00272                       const QString &message);
00273 
00274 private:
00275     class AuthSessionImpl *impl;
00276 };
00277 
00278 }  // namespace SignOn
00279 
00280 Q_DECLARE_METATYPE(SignOn::AuthSession::AuthSessionState)
00281 
00282 #endif // AUTHSESSION_H