KIOSlave
httpauthentication.h
Go to the documentation of this file.
00001 /* This file is part of the KDE libraries 00002 Copyright (C) 2008, 2009 Andreas Hartmetz <ahartmetz@gmail.com> 00003 00004 This library is free software; you can redistribute it and/or 00005 modify it under the terms of the GNU Library General Public 00006 License as published by the Free Software Foundation; either 00007 version 2 of the License, or (at your option) any later version. 00008 00009 This library is distributed in the hope that it will be useful, 00010 but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00012 Library General Public License for more details. 00013 00014 You should have received a copy of the GNU Library General Public License 00015 along with this library; see the file COPYING.LIB. If not, write to 00016 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, 00017 Boston, MA 02110-1301, USA. 00018 */ 00019 00020 #ifndef HTTPAUTHENTICATION_H 00021 #define HTTPAUTHENTICATION_H 00022 00023 #include <config-gssapi.h> 00024 00025 #include <kurl.h> 00026 00027 #include <QtCore/QByteArray> 00028 #include <QtCore/QString> 00029 #include <QtCore/QList> 00030 00031 namespace KIO { 00032 class AuthInfo; 00033 } 00034 00035 class KConfigGroup; 00036 00037 class KAbstractHttpAuthentication 00038 { 00039 public: 00040 KAbstractHttpAuthentication(KConfigGroup *config = 0); 00041 virtual ~KAbstractHttpAuthentication(); 00042 00049 static QByteArray bestOffer(const QList<QByteArray> &offers); 00050 00057 static KAbstractHttpAuthentication *newAuth(const QByteArray &offer, KConfigGroup *config = 0); 00058 00065 static QList<QByteArray> splitOffers(const QList<QByteArray> &offers); 00066 00070 void reset(); 00074 virtual QByteArray scheme() const = 0; 00078 virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod); 00085 bool needCredentials() const { return m_needCredentials; } 00091 virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const = 0; 00095 virtual void generateResponse(const QString &user, 00096 const QString &password) = 0; 00097 00104 bool wasFinalStage() const { return m_finalAuthStage; } 00111 virtual bool supportsPathMatching() const { return false; } 00112 00113 // the following accessors return useful data after generateResponse() has been called. 00114 // clients process the following fields top to bottom: highest priority is on top 00115 00116 // malformed challenge and similar problems - it is advisable to reconnect 00117 bool isError() const { return m_isError; } 00121 bool forceKeepAlive() const { return m_forceKeepAlive; } 00125 bool forceDisconnect() const { return m_forceDisconnect; } 00126 00131 QByteArray headerFragment() const { return m_headerFragment; } 00139 QString realm() const; 00140 00144 void setCachePasswordEnabled(bool enable) { m_keepPassword = enable; } 00145 00146 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER 00147 // NOTE: FOR USE in unit testing ONLY. 00148 virtual void setDigestNonceValue(const QByteArray&) {} 00149 #endif 00150 00151 protected: 00152 void authInfoBoilerplate(KIO::AuthInfo *a) const; 00159 virtual QByteArray authDataToCache() const { return QByteArray(); } 00160 void generateResponseCommon(const QString &user, const QString &password); 00161 00162 KConfigGroup *m_config; 00163 QByteArray m_scheme; 00164 QByteArray m_challengeText; 00165 QList<QByteArray> m_challenge; 00166 KUrl m_resource; 00167 QByteArray m_httpMethod; 00168 00169 bool m_isError; 00170 bool m_needCredentials; 00171 bool m_forceKeepAlive; 00172 bool m_forceDisconnect; 00173 bool m_finalAuthStage; 00174 bool m_keepPassword; 00175 QByteArray m_headerFragment; 00176 00177 QString m_username; 00178 QString m_password; 00179 }; 00180 00181 00182 class KHttpBasicAuthentication : public KAbstractHttpAuthentication 00183 { 00184 public: 00185 virtual QByteArray scheme() const; 00186 virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const; 00187 virtual void generateResponse(const QString &user, const QString &password); 00188 virtual bool supportsPathMatching() const { return true; } 00189 protected: 00190 virtual QByteArray authDataToCache() const { return m_challengeText; } 00191 private: 00192 friend class KAbstractHttpAuthentication; 00193 KHttpBasicAuthentication(KConfigGroup *config = 0) 00194 : KAbstractHttpAuthentication(config) {} 00195 }; 00196 00197 00198 class KHttpDigestAuthentication : public KAbstractHttpAuthentication 00199 { 00200 public: 00201 virtual QByteArray scheme() const; 00202 virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod); 00203 virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const; 00204 virtual void generateResponse(const QString &user, const QString &password); 00205 virtual bool supportsPathMatching() const { return true; } 00206 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER 00207 virtual void setDigestNonceValue(const QByteArray&); 00208 #endif 00209 00210 protected: 00211 virtual QByteArray authDataToCache() const { return m_challengeText; } 00212 private: 00213 friend class KAbstractHttpAuthentication; 00214 KHttpDigestAuthentication(KConfigGroup *config = 0) 00215 : KAbstractHttpAuthentication(config) {} 00216 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER 00217 QByteArray m_nonce; 00218 #endif 00219 }; 00220 00221 00222 class KHttpNtlmAuthentication : public KAbstractHttpAuthentication 00223 { 00224 public: 00225 virtual QByteArray scheme() const; 00226 virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod); 00227 virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const; 00228 virtual void generateResponse(const QString &user, const QString &password); 00229 private: 00230 friend class KAbstractHttpAuthentication; 00231 KHttpNtlmAuthentication(KConfigGroup *config = 0) 00232 : KAbstractHttpAuthentication(config) {} 00233 }; 00234 00235 00236 #ifdef HAVE_LIBGSSAPI 00237 class KHttpNegotiateAuthentication : public KAbstractHttpAuthentication 00238 { 00239 public: 00240 virtual QByteArray scheme() const; 00241 virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod); 00242 virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const; 00243 virtual void generateResponse(const QString &user, const QString &password); 00244 private: 00245 friend class KAbstractHttpAuthentication; 00246 KHttpNegotiateAuthentication(KConfigGroup *config = 0) 00247 : KAbstractHttpAuthentication(config) {} 00248 }; 00249 #endif // HAVE_LIBGSSAPI 00250 00251 #endif // HTTPAUTHENTICATION_H
This file is part of the KDE documentation.
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed May 2 2012 18:44:25 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
Documentation copyright © 1996-2012 The KDE developers.
Generated on Wed May 2 2012 18:44:25 by doxygen 1.8.0 written by Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.