KD SOAP API Documentation: KDSoapServerAuthInterface.cpp Source File

| 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
11#include "KDSoapServerAuthInterface.h"
12#include <KDSoapClient/KDSoapAuthentication.h>
13
14KDSoapServerAuthInterface::KDSoapServerAuthInterface()
15 : d(nullptr)
16{
17}
18
19KDSoapServerAuthInterface::~KDSoapServerAuthInterface()
20{
21}
22
23 enum Method
24{
25 None,
26 Basic,
27 Plain,
28 Login,
29 Ntlm,
30 CramMd5,
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
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
90 bool KDSoapServerAuthInterface::validateAuthentication(const KDSoapAuthentication &auth, const QString &path)
91{
92 Q_UNUSED(auth);
93 Q_UNUSED(path);
94 return false;
95}
KDSoapAuthentication.h
Method
Method
Definition KDSoapServerAuthInterface.cpp:24
Login
@ Login
Definition KDSoapServerAuthInterface.cpp:28
DigestMd5
@ DigestMd5
Definition KDSoapServerAuthInterface.cpp:31
Plain
@ Plain
Definition KDSoapServerAuthInterface.cpp:27
CramMd5
@ CramMd5
Definition KDSoapServerAuthInterface.cpp:30
Ntlm
@ Ntlm
Definition KDSoapServerAuthInterface.cpp:29
None
@ None
Definition KDSoapServerAuthInterface.cpp:25
Basic
@ Basic
Definition KDSoapServerAuthInterface.cpp:26
parseAuthLine
static void parseAuthLine(const QString &str, Method *method, QString *headerVal)
Definition KDSoapServerAuthInterface.cpp:33
KDSoapServerAuthInterface.h
KDSoapAuthentication
Definition KDSoapAuthentication.h:31
KDSoapAuthentication::setPassword
void setPassword(const QString &password)
Definition KDSoapAuthentication.cpp:61
KDSoapAuthentication::setUser
void setUser(const QString &user)
Definition KDSoapAuthentication.cpp:56
KDSoapServerAuthInterface::KDSoapServerAuthInterface
KDSoapServerAuthInterface()
Definition KDSoapServerAuthInterface.cpp:14
KDSoapServerAuthInterface::validateAuthentication
virtual bool validateAuthentication(const KDSoapAuthentication &auth, const QString &path)
Definition KDSoapServerAuthInterface.cpp:90
KDSoapServerAuthInterface::~KDSoapServerAuthInterface
virtual ~KDSoapServerAuthInterface()
Definition KDSoapServerAuthInterface.cpp:19
QByteArray
QByteArray::constData
const char * constData() const const
QByteArray::fromBase64
QByteArray fromBase64(const QByteArray &base64, QByteArray::Base64Options options)
QByteArray::indexOf
int indexOf(char ch, int from) const const
QByteArray::isEmpty
bool isEmpty() const const
QByteArray::left
QByteArray left(int len) const const
QByteArray::mid
QByteArray mid(int pos, int len) const const
QByteArray::size
int size() const const
QLatin1String
QString
QString::fromLatin1
QString fromLatin1(const char *str, int size)
QString::fromUtf8
QString fromUtf8(const char *str, int size)
QString::mid
QString mid(int position, int n) const const
QString::startsWith
bool startsWith(const QString &s, Qt::CaseSensitivity cs) const const
QString::toLatin1
QByteArray toLatin1() const const
Qt::CaseInsensitive
CaseInsensitive

© 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 on Sun Jan 7 2024 11:47:36 for KD SOAP API Documentation by doxygen 1.9.8