• Skip to content
  • Skip to link menu
KDE 4.7 API Reference
  • KDE API Reference
  • kdelibs
  • KDE Home
  • Contact Us
 

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;
00153     virtual QByteArray authDataToCache() const { return QByteArray(); }
00154     void generateResponseCommon(const QString &user, const QString &password);
00155 
00156     KConfigGroup *m_config;
00157     QByteArray m_scheme;    
00158     QByteArray m_challengeText;
00159     QList<QByteArray> m_challenge;
00160     KUrl m_resource;
00161     QByteArray m_httpMethod;
00162 
00163     bool m_isError;
00164     bool m_needCredentials;
00165     bool m_forceKeepAlive;
00166     bool m_forceDisconnect;
00167     bool m_finalAuthStage;
00168     bool m_keepPassword;
00169     QByteArray m_headerFragment;
00170 
00171     QString m_username;
00172     QString m_password;
00173 };
00174 
00175 
00176 class KHttpBasicAuthentication : public KAbstractHttpAuthentication
00177 {
00178 public:
00179     virtual QByteArray scheme() const;
00180     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00181     virtual void generateResponse(const QString &user, const QString &password);
00182     virtual bool supportsPathMatching() const { return true; }
00183 protected:
00184     virtual QByteArray authDataToCache() const { return m_challengeText; }
00185 private:
00186     friend class KAbstractHttpAuthentication;
00187     KHttpBasicAuthentication(KConfigGroup *config = 0)
00188      : KAbstractHttpAuthentication(config) {}
00189 };
00190 
00191 
00192 class KHttpDigestAuthentication : public KAbstractHttpAuthentication
00193 {
00194 public:
00195     virtual QByteArray scheme() const;
00196     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00197     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00198     virtual void generateResponse(const QString &user, const QString &password);
00199     virtual bool supportsPathMatching() const { return true; }
00200 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER
00201     virtual void setDigestNonceValue(const QByteArray&);
00202 #endif
00203 
00204 protected:
00205     virtual QByteArray authDataToCache() const { return m_challengeText; }
00206 private:
00207     friend class KAbstractHttpAuthentication;
00208     KHttpDigestAuthentication(KConfigGroup *config = 0)
00209      : KAbstractHttpAuthentication(config) {}
00210 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER
00211      QByteArray m_nonce;
00212 #endif
00213 };
00214 
00215 
00216 class KHttpNtlmAuthentication : public KAbstractHttpAuthentication
00217 {
00218 public:
00219     virtual QByteArray scheme() const;
00220     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00221     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00222     virtual void generateResponse(const QString &user, const QString &password);
00223 private:
00224     friend class KAbstractHttpAuthentication;
00225     KHttpNtlmAuthentication(KConfigGroup *config = 0)
00226      : KAbstractHttpAuthentication(config) {}
00227 };
00228 
00229 
00230 #ifdef HAVE_LIBGSSAPI
00231 class KHttpNegotiateAuthentication : public KAbstractHttpAuthentication
00232 {
00233 public:
00234     virtual QByteArray scheme() const;
00235     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00236     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00237     virtual void generateResponse(const QString &user, const QString &password);
00238 private:
00239     friend class KAbstractHttpAuthentication;
00240     KHttpNegotiateAuthentication(KConfigGroup *config = 0)
00241      : KAbstractHttpAuthentication(config) {}
00242 };
00243 #endif // HAVE_LIBGSSAPI
00244 
00245 #endif // HTTPAUTHENTICATION_H

KIOSlave

Skip menu "KIOSlave"
  • Main Page
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.7.5
This website is maintained by Adriaan de Groot and Allen Winter.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal