• Skip to content
  • Skip to link menu
KDE 4.3 API Reference
  • KDE API Reference
  • kdelibs
  • Sitemap
  • 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 KAbstractHttpAuthentication
00037 {
00038 public:
00039     KAbstractHttpAuthentication()
00040     {
00041         reset();
00042     }
00043 
00044     static QByteArray bestOffer(const QList<QByteArray> &offers);
00045     static KAbstractHttpAuthentication *newAuth(const QByteArray &offer);
00046 
00047     virtual ~KAbstractHttpAuthentication() {}
00048 
00049     // reset to state after default construction.
00050     void reset();
00051     // the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
00052     virtual QByteArray scheme() const = 0;
00053     // initiate authentication with challenge string (from HTTP header) c
00054     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00055     // return value updated by setChallenge(); if this is false user and password passed
00056     // to generateResponse will be ignored and may be empty.
00057     bool needCredentials() const { return m_needCredentials; }
00058     // KIO compatible data to find cached credentials. Note that username and/or password
00059     // as well as UI text will NOT be filled in.
00060     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const = 0;
00061     // what to do in response to challenge
00062     virtual void generateResponse(const QString &user,
00063                                   const QString &password) = 0;
00064 
00065     // the following accessors return useful data after generateResponse() has been called.
00066     // clients process the following fields top to bottom: highest priority is on top
00067 
00068     // malformed challenge and similar problems - it is advisable to reconnect
00069     bool isError() const { return m_isError; }
00070     // force keep-alive connection because the authentication method requires it
00071     bool forceKeepAlive() const { return m_forceKeepAlive; }
00072     // force disconnection because the authentication method requires it
00073     bool forceDisconnect() const { return m_forceDisconnect; }
00074 
00075     // insert this into the next request header after "Authorization: " or "Proxy-Authorization: "
00076     QString headerFragment() const { return m_headerFragment; }
00077     // this is mainly for GUI shown to the user
00078     QString realm() const;
00079 
00080 protected:
00081     void authInfoBoilerplate(KIO::AuthInfo *a) const;
00082     void generateResponseCommon(const QString &user, const QString &password);
00083 
00084     QByteArray m_scheme;    // this is parsed from the header and not necessarily == scheme().
00085     QList<QByteArray> m_challenge;
00086     KUrl m_resource;
00087     QByteArray m_httpMethod;
00088 
00089     bool m_isError;
00090     bool m_needCredentials;
00091     bool m_forceKeepAlive;
00092     bool m_forceDisconnect;
00093     QString m_headerFragment;
00094 
00095     QString m_username;
00096     QString m_password;
00097 };
00098 
00099 
00100 class KHttpBasicAuthentication : public KAbstractHttpAuthentication
00101 {
00102 public:
00103     virtual QByteArray scheme() const;
00104     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00105     virtual void generateResponse(const QString &user, const QString &password);
00106 private:
00107     friend class KAbstractHttpAuthentication;
00108     KHttpBasicAuthentication()
00109      : KAbstractHttpAuthentication() {}
00110 };
00111 
00112 
00113 class KHttpDigestAuthentication : public KAbstractHttpAuthentication
00114 {
00115 public:
00116     virtual QByteArray scheme() const;
00117     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00118     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00119     virtual void generateResponse(const QString &user, const QString &password);
00120 private:
00121     friend class KAbstractHttpAuthentication;
00122     KHttpDigestAuthentication()
00123      : KAbstractHttpAuthentication() {}
00124 };
00125 
00126 
00127 class KHttpNtlmAuthentication : public KAbstractHttpAuthentication
00128 {
00129 public:
00130     virtual QByteArray scheme() const;
00131     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00132     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00133     virtual void generateResponse(const QString &user, const QString &password);
00134 private:
00135     friend class KAbstractHttpAuthentication;
00136     KHttpNtlmAuthentication()
00137      : KAbstractHttpAuthentication() {}
00138 };
00139 
00140 
00141 #ifdef HAVE_LIBGSSAPI
00142 class KHttpNegotiateAuthentication : public KAbstractHttpAuthentication
00143 {
00144 public:
00145     virtual QByteArray scheme() const;
00146     virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
00147     virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
00148     virtual void generateResponse(const QString &user, const QString &password);
00149 private:
00150     friend class KAbstractHttpAuthentication;
00151     KHttpNegotiateAuthentication()
00152      : KAbstractHttpAuthentication() {}
00153 };
00154 #endif // HAVE_LIBGSSAPI
00155 
00156 #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
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver
Generated for kdelibs by doxygen 1.6.1
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