authsession.h
00001 /*
00002  * This file is part of signon
00003  *
00004  * Copyright (C) 2009-2010 Nokia Corporation.
00005  * Copyright (C) 2011-2016 Canonical Ltd.
00006  *
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 namespace SignOnTests {
00042     class AccessControlTest;
00043 }
00044 
00045 namespace SignOn {
00046 
00054 class SIGNON_EXPORT AuthSession: public QObject
00055 {
00056     Q_OBJECT
00057     Q_DISABLE_COPY(AuthSession)
00058 
00059     friend class IdentityImpl;
00060     friend class AuthSessionImpl;
00061     friend class SignOnTests::AccessControlTest;
00062 
00063 public:
00069     enum AuthSessionError {
00070         UnknownError = 1,               
00071         InternalServerError = 2,        
00072         InternalCommunicationError = 3, 
00073         PermissionDeniedError = 4,      
00074         AuthSessionErr = 300,           /* placeholder to rearrange enumeration */
00075         MechanismNotAvailableError,     
00076         MissingDataError,               
00077         InvalidCredentialsError,        
00078         WrongStateError,                
00079         OperationNotSupportedError,     
00080         NoConnectionError,              
00081         NetworkError,                   
00082         SslError,                       
00083         RuntimeError,                   
00084         CanceledError,                  
00085         TimedOutError,                  
00086         UserInteractionError            
00087     };
00088 
00095     enum AuthSessionState {
00096         SessionNotStarted = 0,          
00097         HostResolving,                  
00098         ServerConnecting,               
00099         DataSending,                    
00100         ReplyWaiting,                   
00101         UserPending,                    
00102         UiRefreshing,                   
00103         ProcessPending,                 
00104         SessionStarted,                 
00105         ProcessCanceling,               
00106         ProcessDone,                    
00107         CustomState,                    
00108         MaxState,
00109     };
00110 
00111 protected:
00115     AuthSession(quint32 id, const QString &methodName, QObject *parent = 0);
00116     ~AuthSession();
00117 
00118 public:
00124     const QString name() const;
00125 
00136      void queryAvailableMechanisms(const QStringList &wantedMechanisms = QStringList());
00137 
00167     void process(const SessionData &sessionData,
00168                  const QString &mechanism = QString());
00169 
00183     void challenge(const SessionData& sessionData,
00184                    const QString &mechanism = QString()) {
00185         process(sessionData, mechanism);
00186     }
00187 
00201     void request(const SessionData &sessionData,
00202                  const QString &mechanism = QString()) {
00203         process(sessionData, mechanism);
00204     }
00205 
00214     void cancel();
00215 
00224     void signMessage(const SessionData &params,
00225                      const QString &mechanism = QString()) {
00226         process(params, mechanism);
00227     }
00228 
00229 Q_SIGNALS:
00240     void error(const SignOn::Error &err);
00241 
00248     void mechanismsAvailable(const QStringList &mechanisms);
00249 
00262     void response(const SignOn::SessionData &sessionData);
00263 
00270     void stateChanged(AuthSession::AuthSessionState state,
00271                       const QString &message);
00272 
00273 private:
00274     class AuthSessionImpl *impl;
00275 };
00276 
00277 }  // namespace SignOn
00278 
00279 Q_DECLARE_METATYPE(SignOn::AuthSession::AuthSessionState)
00280 
00281 #endif // AUTHSESSION_H