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

KIOSlave

  • sources
  • kde-4.12
  • kdelibs
  • kioslave
  • http
httpauthentication.h
Go to the documentation of this file.
1 /* This file is part of the KDE libraries
2  Copyright (C) 2008, 2009 Andreas Hartmetz <ahartmetz@gmail.com>
3 
4  This library is free software; you can redistribute it and/or
5  modify it under the terms of the GNU Library General Public
6  License as published by the Free Software Foundation; either
7  version 2 of the License, or (at your option) any later version.
8 
9  This library is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  Library General Public License for more details.
13 
14  You should have received a copy of the GNU Library General Public License
15  along with this library; see the file COPYING.LIB. If not, write to
16  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
17  Boston, MA 02110-1301, USA.
18 */
19 
20 #ifndef HTTPAUTHENTICATION_H
21 #define HTTPAUTHENTICATION_H
22 
23 #include <config-gssapi.h>
24 
25 #include <kurl.h>
26 
27 #include <QtCore/QByteArray>
28 #include <QtCore/QString>
29 #include <QtCore/QList>
30 
31 namespace KIO {
32 class AuthInfo;
33 }
34 
35 class KConfigGroup;
36 
37 class KAbstractHttpAuthentication
38 {
39 public:
40  KAbstractHttpAuthentication(KConfigGroup *config = 0);
41  virtual ~KAbstractHttpAuthentication();
42 
49  static QByteArray bestOffer(const QList<QByteArray> &offers);
50 
57  static KAbstractHttpAuthentication *newAuth(const QByteArray &offer, KConfigGroup *config = 0);
58 
65  static QList<QByteArray> splitOffers(const QList<QByteArray> &offers);
66 
70  void reset();
74  virtual QByteArray scheme() const = 0;
78  virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
85  bool needCredentials() const { return m_needCredentials; }
91  virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const = 0;
95  virtual void generateResponse(const QString &user,
96  const QString &password) = 0;
97 
104  bool wasFinalStage() const { return m_finalAuthStage; }
111  virtual bool supportsPathMatching() const { return false; }
112 
113  // the following accessors return useful data after generateResponse() has been called.
114  // clients process the following fields top to bottom: highest priority is on top
115 
116  // malformed challenge and similar problems - it is advisable to reconnect
117  bool isError() const { return m_isError; }
121  bool forceKeepAlive() const { return m_forceKeepAlive; }
125  bool forceDisconnect() const { return m_forceDisconnect; }
126 
131  QByteArray headerFragment() const { return m_headerFragment; }
139  QString realm() const;
140 
144  void setCachePasswordEnabled(bool enable) { m_keepPassword = enable; }
145 
146 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER
147  // NOTE: FOR USE in unit testing ONLY.
148  virtual void setDigestNonceValue(const QByteArray&) {}
149 #endif
150 
151 protected:
152  void authInfoBoilerplate(KIO::AuthInfo *a) const;
159  virtual QByteArray authDataToCache() const { return QByteArray(); }
160  void generateResponseCommon(const QString &user, const QString &password);
161 
162  KConfigGroup *m_config;
163  QByteArray m_scheme;
164  QByteArray m_challengeText;
165  QList<QByteArray> m_challenge;
166  KUrl m_resource;
167  QByteArray m_httpMethod;
168 
169  bool m_isError;
170  bool m_needCredentials;
171  bool m_forceKeepAlive;
172  bool m_forceDisconnect;
173  bool m_finalAuthStage;
174  bool m_keepPassword;
175  QByteArray m_headerFragment;
176 
177  QString m_username;
178  QString m_password;
179 };
180 
181 
182 class KHttpBasicAuthentication : public KAbstractHttpAuthentication
183 {
184 public:
185  virtual QByteArray scheme() const;
186  virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
187  virtual void generateResponse(const QString &user, const QString &password);
188  virtual bool supportsPathMatching() const { return true; }
189 protected:
190  virtual QByteArray authDataToCache() const { return m_challengeText; }
191 private:
192  friend class KAbstractHttpAuthentication;
193  KHttpBasicAuthentication(KConfigGroup *config = 0)
194  : KAbstractHttpAuthentication(config) {}
195 };
196 
197 
198 class KHttpDigestAuthentication : public KAbstractHttpAuthentication
199 {
200 public:
201  virtual QByteArray scheme() const;
202  virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
203  virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
204  virtual void generateResponse(const QString &user, const QString &password);
205  virtual bool supportsPathMatching() const { return true; }
206 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER
207  virtual void setDigestNonceValue(const QByteArray&);
208 #endif
209 
210 protected:
211  virtual QByteArray authDataToCache() const { return m_challengeText; }
212 private:
213  friend class KAbstractHttpAuthentication;
214  KHttpDigestAuthentication(KConfigGroup *config = 0)
215  : KAbstractHttpAuthentication(config) {}
216 #ifdef ENABLE_HTTP_AUTH_NONCE_SETTER
217  QByteArray m_nonce;
218 #endif
219 };
220 
221 
222 class KHttpNtlmAuthentication : public KAbstractHttpAuthentication
223 {
224 public:
225  virtual QByteArray scheme() const;
226  virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
227  virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
228  virtual void generateResponse(const QString &user, const QString &password);
229 private:
230  friend class KAbstractHttpAuthentication;
231  KHttpNtlmAuthentication(KConfigGroup *config = 0)
232  : KAbstractHttpAuthentication(config) {}
233 };
234 
235 
236 #ifdef HAVE_LIBGSSAPI
237 class KHttpNegotiateAuthentication : public KAbstractHttpAuthentication
238 {
239 public:
240  virtual QByteArray scheme() const;
241  virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod);
242  virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const;
243  virtual void generateResponse(const QString &user, const QString &password);
244 private:
245  friend class KAbstractHttpAuthentication;
246  KHttpNegotiateAuthentication(KConfigGroup *config = 0)
247  : KAbstractHttpAuthentication(config) {}
248 };
249 #endif // HAVE_LIBGSSAPI
250 
251 #endif // HTTPAUTHENTICATION_H
KAbstractHttpAuthentication::newAuth
static KAbstractHttpAuthentication * newAuth(const QByteArray &offer, KConfigGroup *config=0)
Returns authentication object instance appropriate for offer.
Definition: httpauthentication.cpp:266
KAbstractHttpAuthentication::~KAbstractHttpAuthentication
virtual ~KAbstractHttpAuthentication()
Definition: httpauthentication.cpp:223
KHttpDigestAuthentication::generateResponse
virtual void generateResponse(const QString &user, const QString &password)
what to do in response to challenge
Definition: httpauthentication.cpp:519
KAbstractHttpAuthentication::isError
bool isError() const
Definition: httpauthentication.h:117
KHttpDigestAuthentication::scheme
virtual QByteArray scheme() const
the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
Definition: httpauthentication.cpp:400
KHttpBasicAuthentication::supportsPathMatching
virtual bool supportsPathMatching() const
Returns true if the authentication scheme supports path matching to identify resources that belong to...
Definition: httpauthentication.h:188
KHttpNtlmAuthentication::scheme
virtual QByteArray scheme() const
the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
Definition: httpauthentication.cpp:697
KAbstractHttpAuthentication::KAbstractHttpAuthentication
KAbstractHttpAuthentication(KConfigGroup *config=0)
Definition: httpauthentication.cpp:217
KAbstractHttpAuthentication::m_resource
KUrl m_resource
Definition: httpauthentication.h:166
kurl.h
KHttpDigestAuthentication::fillKioAuthInfo
virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const
KIO compatible data to find cached credentials.
Definition: httpauthentication.cpp:427
KAbstractHttpAuthentication::m_httpMethod
QByteArray m_httpMethod
Definition: httpauthentication.h:167
KAbstractHttpAuthentication::m_password
QString m_password
Definition: httpauthentication.h:178
KAbstractHttpAuthentication::generateResponseCommon
void generateResponseCommon(const QString &user, const QString &password)
Definition: httpauthentication.cpp:357
KIO::AuthInfo
KHttpDigestAuthentication
Definition: httpauthentication.h:198
QString
KAbstractHttpAuthentication::scheme
virtual QByteArray scheme() const =0
the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
KUrl
KHttpBasicAuthentication
Definition: httpauthentication.h:182
config
KSharedConfigPtr config()
KAbstractHttpAuthentication::splitOffers
static QList< QByteArray > splitOffers(const QList< QByteArray > &offers)
Split all headers containing multiple authentication offers.
Definition: httpauthentication.cpp:284
KAbstractHttpAuthentication::fillKioAuthInfo
virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const =0
KIO compatible data to find cached credentials.
KHttpNtlmAuthentication::generateResponse
virtual void generateResponse(const QString &user, const QString &password)
what to do in response to challenge
Definition: httpauthentication.cpp:732
KAbstractHttpAuthentication::m_forceDisconnect
bool m_forceDisconnect
Definition: httpauthentication.h:172
KHttpBasicAuthentication::scheme
virtual QByteArray scheme() const
the authentication scheme: "Negotiate", "Digest", "Basic", "NTLM"
Definition: httpauthentication.cpp:376
KAbstractHttpAuthentication::needCredentials
bool needCredentials() const
return value updated by setChallenge()
Definition: httpauthentication.h:85
KAbstractHttpAuthentication::forceDisconnect
bool forceDisconnect() const
force disconnection because the authentication method requires it
Definition: httpauthentication.h:125
KAbstractHttpAuthentication::m_forceKeepAlive
bool m_forceKeepAlive
Definition: httpauthentication.h:171
KHttpNtlmAuthentication::setChallenge
virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod)
initiate authentication with challenge string (from HTTP header)
Definition: httpauthentication.cpp:703
KHttpDigestAuthentication::setChallenge
virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod)
initiate authentication with challenge string (from HTTP header)
Definition: httpauthentication.cpp:406
KAbstractHttpAuthentication::bestOffer
static QByteArray bestOffer(const QList< QByteArray > &offers)
Choose the best authentication mechanism from the offered ones.
Definition: httpauthentication.cpp:227
KAbstractHttpAuthentication::m_isError
bool m_isError
Definition: httpauthentication.h:169
KAbstractHttpAuthentication::authInfoBoilerplate
void authInfoBoilerplate(KIO::AuthInfo *a) const
Definition: httpauthentication.cpp:345
KAbstractHttpAuthentication::headerFragment
QByteArray headerFragment() const
insert this into the next request header after "Authorization: " or "Proxy-Authorization: " ...
Definition: httpauthentication.h:131
KHttpBasicAuthentication::generateResponse
virtual void generateResponse(const QString &user, const QString &password)
what to do in response to challenge
Definition: httpauthentication.cpp:387
KAbstractHttpAuthentication
Definition: httpauthentication.h:37
KAbstractHttpAuthentication::generateResponse
virtual void generateResponse(const QString &user, const QString &password)=0
what to do in response to challenge
KAbstractHttpAuthentication::m_headerFragment
QByteArray m_headerFragment
Definition: httpauthentication.h:175
KHttpDigestAuthentication::supportsPathMatching
virtual bool supportsPathMatching() const
Returns true if the authentication scheme supports path matching to identify resources that belong to...
Definition: httpauthentication.h:205
KAbstractHttpAuthentication::m_finalAuthStage
bool m_finalAuthStage
Definition: httpauthentication.h:173
KAbstractHttpAuthentication::reset
void reset()
reset to state after default construction.
Definition: httpauthentication.cpp:305
KAbstractHttpAuthentication::m_username
QString m_username
Definition: httpauthentication.h:177
KAbstractHttpAuthentication::setChallenge
virtual void setChallenge(const QByteArray &c, const KUrl &resource, const QByteArray &httpMethod)
initiate authentication with challenge string (from HTTP header)
Definition: httpauthentication.cpp:322
KHttpNtlmAuthentication::fillKioAuthInfo
virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const
KIO compatible data to find cached credentials.
Definition: httpauthentication.cpp:722
KAbstractHttpAuthentication::m_scheme
QByteArray m_scheme
this is parsed from the header and not necessarily == scheme().
Definition: httpauthentication.h:163
KAbstractHttpAuthentication::wasFinalStage
bool wasFinalStage() const
returns true when the final stage of authentication is reached.
Definition: httpauthentication.h:104
KConfigGroup
KAbstractHttpAuthentication::authDataToCache
virtual QByteArray authDataToCache() const
Returns any authentication data that should be cached for future use.
Definition: httpauthentication.h:159
KAbstractHttpAuthentication::m_needCredentials
bool m_needCredentials
Definition: httpauthentication.h:170
KAbstractHttpAuthentication::forceKeepAlive
bool forceKeepAlive() const
force keep-alive connection because the authentication method requires it
Definition: httpauthentication.h:121
KHttpBasicAuthentication::authDataToCache
virtual QByteArray authDataToCache() const
Returns any authentication data that should be cached for future use.
Definition: httpauthentication.h:190
KAbstractHttpAuthentication::setCachePasswordEnabled
void setCachePasswordEnabled(bool enable)
Sets the cache password flag to enable.
Definition: httpauthentication.h:144
KHttpBasicAuthentication::fillKioAuthInfo
virtual void fillKioAuthInfo(KIO::AuthInfo *ai) const
KIO compatible data to find cached credentials.
Definition: httpauthentication.cpp:382
KAbstractHttpAuthentication::m_config
KConfigGroup * m_config
Definition: httpauthentication.h:162
KAbstractHttpAuthentication::supportsPathMatching
virtual bool supportsPathMatching() const
Returns true if the authentication scheme supports path matching to identify resources that belong to...
Definition: httpauthentication.h:111
KAbstractHttpAuthentication::m_challenge
QList< QByteArray > m_challenge
Definition: httpauthentication.h:165
KAbstractHttpAuthentication::m_keepPassword
bool m_keepPassword
Definition: httpauthentication.h:174
KHttpNtlmAuthentication
Definition: httpauthentication.h:222
KAbstractHttpAuthentication::realm
QString realm() const
Returns the realm sent by the server.
Definition: httpauthentication.cpp:334
KAbstractHttpAuthentication::m_challengeText
QByteArray m_challengeText
Definition: httpauthentication.h:164
QList< QByteArray >
KHttpDigestAuthentication::authDataToCache
virtual QByteArray authDataToCache() const
Returns any authentication data that should be cached for future use.
Definition: httpauthentication.h:211
This file is part of the KDE documentation.
Documentation copyright © 1996-2014 The KDE developers.
Generated on Tue Oct 14 2014 22:50:58 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KIOSlave

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

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • 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
  • kjsembed
  •   WTF
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Nepomuk-Core
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal