KD SOAP API Documentation  2.2
KDSoapServerAuthInterface.cpp
Go to the documentation of this file.
1 /****************************************************************************
2 **
3 ** This file is part of the KD Soap project.
4 **
5 ** SPDX-FileCopyrightText: 2010 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.com>
6 **
7 ** SPDX-License-Identifier: MIT
8 **
9 ****************************************************************************/
10 
13 
15  : d(nullptr)
16 {
17 }
18 
20 {
21 }
22 
23 enum Method
24 {
31  DigestMd5
32 };
33 static void parseAuthLine(const QString &str, Method *method, QString *headerVal)
34 {
35  *method = None;
36  // The code below (from QAuthenticatorPrivate::parseHttpResponse)
37  // is supposed to be run in a loop, apparently
38  // (multiple WWW-Authenticate lines? multiple values in the line?)
39 
40  // qDebug() << "parseAuthLine() " << str;
41  if (*method < Basic && str.startsWith(QLatin1String("Basic"), Qt::CaseInsensitive)) {
42  *method = Basic;
43  *headerVal = str.mid(6);
44  } else if (*method < Ntlm && str.startsWith(QLatin1String("NTLM"), Qt::CaseInsensitive)) {
45  *method = Ntlm;
46  *headerVal = str.mid(5);
47  } else if (*method < DigestMd5 && str.startsWith(QLatin1String("Digest"), Qt::CaseInsensitive)) {
48  *method = DigestMd5;
49  *headerVal = str.mid(7);
50  }
51 }
52 
53 bool KDSoapServerAuthInterface::handleHttpAuth(const QByteArray &authValue, const QString &path)
54 {
55  bool authOk = false;
56  KDSoapAuthentication authSettings;
57  if (authValue.isEmpty()) {
58  // Let the implementation decide whether it accepts "no auth".
59  authOk = validateAuthentication(authSettings, path);
60  } else {
61  // qDebug() << "got authValue=" << authValue; // looks like "Basic <base64 of user:pass>"
62  Method method;
63  QString headerVal;
64  parseAuthLine(QString::fromLatin1(authValue.constData(), authValue.size()), &method, &headerVal);
65  // qDebug() << "method=" << method << "headerVal=" << headerVal;
66  switch (method) {
67  case None:
68  // Let the implementation decide whether it accepts "no auth".
69  authOk = validateAuthentication(authSettings, path);
70  break;
71  case Basic: {
72  const QByteArray userPass = QByteArray::fromBase64(headerVal.toLatin1());
73  const int separatorPos = userPass.indexOf(':');
74  if (separatorPos == -1) {
75  break;
76  }
77  authSettings.setUser(QString::fromUtf8(userPass.left(separatorPos).constData()));
78  authSettings.setPassword(QString::fromUtf8(userPass.mid(separatorPos + 1).constData()));
79  authOk = validateAuthentication(authSettings, path);
80  break;
81  }
82  default:
83  qWarning("Unsupported authentication mechanism %s", authValue.constData());
84  break;
85  }
86  }
87  return authOk;
88 }
89 
91 {
92  Q_UNUSED(auth);
93  Q_UNUSED(path);
94  return false;
95 }
static void parseAuthLine(const QString &str, Method *method, QString *headerVal)
void setPassword(const QString &password)
void setUser(const QString &user)
virtual bool validateAuthentication(const KDSoapAuthentication &auth, const QString &path)

© 2010-2024 Klarälvdalens Datakonsult AB (KDAB)
"The Qt, C++ and OpenGL Experts"
https://www.kdab.com/
https://www.kdab.com/development-resources/qt-tools/kd-soap/
Generated by doxygen 1.9.1