Skip to content

Commit

Permalink
Move implementation to cpp file
Browse files Browse the repository at this point in the history
  • Loading branch information
domi4484 authored and nyalldawson committed Dec 11, 2024
1 parent a803be7 commit 02a4e55
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 29 deletions.
1 change: 1 addition & 0 deletions src/core/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ set(QGIS_CORE_SRCS
auth/qgsauthmethod.cpp
auth/qgsauthmethodmetadata.cpp
auth/qgsauthmethodregistry.cpp
auth/qgsauthorizationsettings.cpp

auth/qgsauthconfigurationstoragesqlite.cpp
auth/qgsauthconfigurationstoragedb.cpp
Expand Down
48 changes: 48 additions & 0 deletions src/core/auth/qgsauthorizationsettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/***************************************************************************
qgsauthorizationsettings.cpp
---------------------
begin : December 2024
copyright : (C) 2024 by Damiano Lombardi
email : damiano at opengis.ch
***************************************************************************
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation; either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/

#include "qgsauthorizationsettings.h"

QgsAuthorizationSettings::QgsAuthorizationSettings(const QString &userName, const QString &password, const QgsHttpHeaders &httpHeaders, const QString &authcfg)
: mUserName( userName )
, mPassword( password )
, mHttpHeaders( httpHeaders )
, mAuthCfg( authcfg )
{}

bool QgsAuthorizationSettings::setAuthorization(QNetworkRequest &request) const
{
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
{
return QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg );
}
else if ( !mUserName.isEmpty() || !mPassword.isEmpty() )
{
request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( mUserName, mPassword ).toUtf8().toBase64() );
}

mHttpHeaders.updateNetworkRequest( request );

return true;
}

bool QgsAuthorizationSettings::setAuthorizationReply(QNetworkReply *reply) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsApplication::authManager()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}
32 changes: 3 additions & 29 deletions src/core/auth/qgsauthorizationsettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,39 +37,13 @@ class CORE_EXPORT QgsAuthorizationSettings
public:

//! Constructor for QgsAuthorizationSettings.
QgsAuthorizationSettings( const QString &userName = QString(), const QString &password = QString(), const QgsHttpHeaders &httpHeaders = QgsHttpHeaders(), const QString &authcfg = QString() )
: mUserName( userName )
, mPassword( password )
, mHttpHeaders( httpHeaders )
, mAuthCfg( authcfg )
{}
QgsAuthorizationSettings( const QString &userName = QString(), const QString &password = QString(), const QgsHttpHeaders &httpHeaders = QgsHttpHeaders(), const QString &authcfg = QString() );

//! Update authorization for request
bool setAuthorization( QNetworkRequest &request ) const
{
if ( !mAuthCfg.isEmpty() ) // must be non-empty value
{
return QgsApplication::authManager()->updateNetworkRequest( request, mAuthCfg );
}
else if ( !mUserName.isEmpty() || !mPassword.isEmpty() )
{
request.setRawHeader( "Authorization", "Basic " + QStringLiteral( "%1:%2" ).arg( mUserName, mPassword ).toUtf8().toBase64() );
}

mHttpHeaders.updateNetworkRequest( request );

return true;
}
bool setAuthorization( QNetworkRequest &request ) const;

//! Update authorization for reply
bool setAuthorizationReply( QNetworkReply *reply ) const
{
if ( !mAuthCfg.isEmpty() )
{
return QgsApplication::authManager()->updateNetworkReply( reply, mAuthCfg );
}
return true;
}
bool setAuthorizationReply( QNetworkReply *reply ) const;

//! Username for basic http authentication
QString mUserName;
Expand Down

0 comments on commit 02a4e55

Please sign in to comment.