KD SOAP API Documentation 2.2
Loading...
Searching...
No Matches
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
18
22
33static 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
53bool 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)
const char * constData() const const
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
int indexOf(char ch, int from) const const
bool isEmpty() const const
QByteArray left(int len) const const
QByteArray mid(int pos, int len) const const
int size() const const
QString fromLatin1(const char *str, int size)
QString fromUtf8(const char *str, int size)
QString mid(int position, int n) const const
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QByteArray toLatin1() const const
CaseInsensitive

© 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 on Sat Apr 20 2024 00:04:25 for KD SOAP API Documentation by doxygen 1.9.8