• Skip to content
  • Skip to link menu
KDE 4.6 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 #ifndef HTTP_H_ // if we're included from http.cpp all necessary headers are already included
00026 #include <QtCore/QByteArray>
00027 #include <QtCore/QString>
00028 #include <QtCore/QList>
00029 #include <kio/authinfo.h>
00030 #endif
00031 
00032 namespace KIO {
00033 class AuthInfo;
00034 }
00035 
00036 class KConfigGroup;
00037 
00038 class KAbstractHttpAuthentication
00039 {
00040 public:
00041     KAbstractHttpAuthentication(KConfigGroup *config = 0);
00042     virtual ~KAbstractHttpAuthentication();
00043 
00044     static QByteArray bestOffer(const QList<QByteArray> &offers);
00045     static KAbstractHttpAuthentication *newAuth(const QByteArray &offer, KConfigGroup *config = 0);
00046 
00047     // reset to state after default construction.
00048     void reset();
00049     // the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
00050     virtual QByteArray scheme() const = 0;
00051     // initiate authentication with challenge string (from HTTP header) c
00052     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00053     // return value updated by setChallenge(); if this is false user and password passed
00054     // to generateResponse will be ignored and may be empty.
00055     bool needCredentials() const { return m_needCredentials; }
00056     // KIO compatible data to find cached credentials. Note that username and/or password
00057     // as well as UI text will NOT be filled in.
00058     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const = 0;
00059     // what to do in response to challenge
00060     virtual void generateResponse(const QString &user,
00061                                   const QString &password) = 0;
00062 
00063     // returns true when the final stage of authentication is reached. Unless
00064     // the authentication scheme requires multiple stages like NTLM this
00065     // function will always return true.
00066     bool wasFinalStage() const { return m_finalAuthStage; }
00067     // Returns true if the authentication scheme supports path matching to identify
00068     // resources that belong to the same protection space (relam). See RFC 2617.
00069     virtual bool supportsPathMatching() const { return false; }
00070 
00071     // the following accessors return useful data after generateResponse() has been called.
00072     // clients process the following fields top to bottom: highest priority is on top
00073 
00074     // malformed challenge and similar problems - it is advisable to reconnect
00075     bool isError() const { return m_isError; }
00076     // force keep-alive connection because the authentication method requires it
00077     bool forceKeepAlive() const { return m_forceKeepAlive; }
00078     // force disconnection because the authentication method requires it
00079     bool forceDisconnect() const { return m_forceDisconnect; }
00080 
00081     // insert this into the next request header after "Authorization: " or "Proxy-Authorization: "
00082     QByteArray headerFragment() const { return m_headerFragment; }
00083     // this is mainly for GUI shown to the user
00084     QString realm() const;
00085 
00086 protected:
00087     void authInfoBoilerplate(KIO::AuthInfo *a) const;
00088     virtual QByteArray authDataToCache() const { return QByteArray(); }
00089     void generateResponseCommon(const QString &user, const QString &password);
00090 
00091     KConfigGroup *m_config;
00092     QByteArray m_scheme;    // this is parsed from the header and not necessarily == scheme().
00093     QByteArray m_challengeText;
00094     QList<QByteArray> m_challenge;
00095     KUrl m_resource;
00096     QByteArray m_httpMethod;
00097 
00098     bool m_isError;
00099     bool m_needCredentials;
00100     bool m_forceKeepAlive;
00101     bool m_forceDisconnect;
00102     bool m_finalAuthStage;
00103     QByteArray m_headerFragment;
00104 
00105     QString m_username;
00106     QString m_password;
00107 };
00108 
00109 
00110 class KHttpBasicAuthentication : public KAbstractHttpAuthentication
00111 {
00112 public:
00113     virtual QByteArray scheme() const;
00114     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00115     virtual void generateResponse(const QString &user, const QString &password);
00116     virtual bool supportsPathMatching() const { return true; }
00117 protected:
00118     virtual QByteArray authDataToCache() const { return m_challengeText; }
00119 private:
00120     friend class KAbstractHttpAuthentication;
00121     KHttpBasicAuthentication(KConfigGroup *config = 0)
00122      : KAbstractHttpAuthentication(config) {}
00123 };
00124 
00125 
00126 class KHttpDigestAuthentication : public KAbstractHttpAuthentication
00127 {
00128 public:
00129     virtual QByteArray scheme() const;
00130     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00131     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00132     virtual void generateResponse(const QString &user, const QString &password);
00133     virtual bool supportsPathMatching() const { return true; }
00134 protected:
00135     virtual QByteArray authDataToCache() const { return m_challengeText; }
00136 private:
00137     friend class KAbstractHttpAuthentication;
00138     KHttpDigestAuthentication(KConfigGroup *config = 0)
00139      : KAbstractHttpAuthentication(config) {}
00140 };
00141 
00142 
00143 class KHttpNtlmAuthentication : public KAbstractHttpAuthentication
00144 {
00145 public:
00146     virtual QByteArray scheme() const;
00147     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00148     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00149     virtual void generateResponse(const QString &user, const QString &password);
00150 private:
00151     friend class KAbstractHttpAuthentication;
00152     KHttpNtlmAuthentication(KConfigGroup *config = 0)
00153      : KAbstractHttpAuthentication(config) {}
00154 };
00155 
00156 
00157 #ifdef HAVE_LIBGSSAPI
00158 class KHttpNegotiateAuthentication : public KAbstractHttpAuthentication
00159 {
00160 public:
00161     virtual QByteArray scheme() const;
00162     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00163     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00164     virtual void generateResponse(const QString &user, const QString &password);
00165 private:
00166     friend class KAbstractHttpAuthentication;
00167     KHttpNegotiateAuthentication(KConfigGroup *config = 0)
00168      : KAbstractHttpAuthentication(config) {}
00169 };
00170 #endif // HAVE_LIBGSSAPI
00171 
00172 #endif // HTTPAUTHENTICATION_H

KIOSlave

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

kdelibs

Skip menu "kdelibs"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • Kate
  • 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.3
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