check with the authorization manager whether to allow the import of a certain url (unfortunatel doesn't seem to be any way to block local absolute paths :/)

svn path=/trunk/KDE/kdebase/runtime/; revision=1188241
This commit is contained in:
Marco Martin 2010-10-21 19:02:29 +00:00
parent 155dc2d056
commit ade2a71286
4 changed files with 51 additions and 10 deletions

View File

@ -19,11 +19,38 @@
#include "packageaccessmanager.h"
#include <QNetworkReply>
#include <Plasma/Package>
PackageAccessManager::PackageAccessManager(const Plasma::Package *package, QObject *parent)
#include "plasmoid/appletauthorization.h"
class ErrorReply : public QNetworkReply
{
public:
ErrorReply(QNetworkAccessManager::Operation op, const QNetworkRequest &req)
: QNetworkReply()
{
setError(QNetworkReply::ContentOperationNotPermittedError, "The plasmoid has not been authorized to load remote content");
setOperation(op);
setRequest(req);
setUrl(req.url());
}
qint64 readData(char *data, qint64 maxSize)
{
return 0;
}
void abort()
{
}
};
PackageAccessManager::PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent)
: KIO::AccessManager(parent),
m_package(package)
m_package(package),
m_auth(auth)
{
}
@ -32,7 +59,7 @@ PackageAccessManager::~PackageAccessManager()
}
QNetworkReply *PackageAccessManager::createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
QNetworkReply *PackageAccessManager::createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData)
{
QUrl reqUrl(req.url());
@ -42,7 +69,11 @@ QNetworkReply *PackageAccessManager::createRequest(Operation op, const QNetworkR
reqUrl.setPath(m_package->path()+"/contents/"+reqUrl.path());
request.setUrl(reqUrl);
return KIO::AccessManager::createRequest(op, request, outgoingData);
} else {
} else if ((reqUrl.scheme() == "http" && !m_auth->authorizeRequiredExtension("http")) ||
((reqUrl.scheme() == "file" || reqUrl.scheme() == "desktop") && !m_auth->authorizeRequiredExtension("localio")) ||
(!m_auth->authorizeRequiredExtension("networkio"))) {
return new ErrorReply(op, req);
}else {
return KIO::AccessManager::createRequest(op, req, outgoingData);
}
}

View File

@ -22,22 +22,26 @@
#include <kio/accessmanager.h>
namespace Plasma
{
class Package;
}
class AppletAuthorization;
class PackageAccessManager : public KIO::AccessManager
{
public:
PackageAccessManager(const Plasma::Package *package, QObject *parent = 0);
PackageAccessManager(const Plasma::Package *package, AppletAuthorization *auth, QObject *parent = 0);
~PackageAccessManager();
protected:
QNetworkReply *createRequest(Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0);
QNetworkReply *createRequest(QNetworkAccessManager::Operation op, const QNetworkRequest &req, QIODevice *outgoingData = 0);
private:
const Plasma::Package *m_package;
AppletAuthorization *m_auth;
};
#endif

View File

@ -22,10 +22,12 @@
#include <Plasma/Package>
#include "packageaccessmanager.h"
#include "plasmoid/appletauthorization.h"
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package *package)
PackageAccessManagerFactory::PackageAccessManagerFactory(const Plasma::Package *package, AppletAuthorization *auth)
: QDeclarativeNetworkAccessManagerFactory(),
m_package(package)
m_package(package),
m_auth(auth)
{
}
@ -35,7 +37,7 @@ PackageAccessManagerFactory::~PackageAccessManagerFactory()
QNetworkAccessManager *PackageAccessManagerFactory::create(QObject *parent)
{
return new PackageAccessManager(m_package, parent);
return new PackageAccessManager(m_package, m_auth, parent);
}

View File

@ -22,20 +22,24 @@
#include <QDeclarativeNetworkAccessManagerFactory>
namespace Plasma
{
class Package;
}
class AppletAuthorization;
class PackageAccessManagerFactory : public QDeclarativeNetworkAccessManagerFactory
{
public:
PackageAccessManagerFactory(const Plasma::Package *package);
PackageAccessManagerFactory(const Plasma::Package *package, AppletAuthorization *auth);
~PackageAccessManagerFactory();
QNetworkAccessManager *create(QObject *parent);
private:
const Plasma::Package *m_package;
AppletAuthorization *m_auth;
};
#endif