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

KIOSlave

  • 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
This file is part of the KDE documentation.
Documentation copyright © 1996-2013 The KDE developers.
Generated on Fri Jul 12 2013 08:55:29 by doxygen 1.8.3.1 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-4.10.5 API Reference

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