Make policykit stuff 'work' (well, it doesn't, I'll still have to figure

out why, but the basic code is there), and delay the starting of the
jolie service and unlocking of the keyring for your credentials to when
it's actually needed.

svn path=/trunk/KDE/kdelibs/; revision=1019142
This commit is contained in:
Rob Scheepmaker 2009-09-02 23:49:58 +00:00
parent b809967eb3
commit 5b160ac802
9 changed files with 50 additions and 13 deletions

View File

@ -20,8 +20,10 @@
#include "accessmanager.h"
#include "private/accessmanager_p.h"
#include "authorizationmanager.h"
#include "service.h"
#include "serviceaccessjob.h"
#include "private/authorizationmanager_p.h"
#include <QtCore/QMap>
#include <QtCore/QTimer>
@ -66,6 +68,8 @@ AccessManager::~AccessManager()
AccessAppletJob *AccessManager::accessRemoteApplet(const KUrl &location) const
{
AuthorizationManager::self()->d->prepareForServiceAccess();
KUrl resolvedLocation;
if (location.protocol() == "zeroconf") {
if (d->zeroconfServices.contains(location.host())) {

View File

@ -32,6 +32,7 @@
#include <QGraphicsGridLayout>
#include <QGraphicsSceneMouseEvent>
#include <QGraphicsView>
#include <QHostInfo>
#include <QLabel>
#include <QList>
#include <QGraphicsLinearLayout>
@ -1464,7 +1465,7 @@ void Applet::publish(AnnouncementMethods methods)
QString resourceName =
i18nc("%1 is the name of a plasmoid, %2 the name of the machine that plasmoid is published on",
"%1 on %2", name(), AuthorizationManager::self()->d->myCredentials.name());
"%1 on %2", name(), QHostInfo::localHostName());
kDebug() << "publishing package under name " << resourceName;
d->service->d->publish(methods, resourceName);
}
@ -1484,7 +1485,7 @@ void Applet::unpublish()
bool Applet::isPublished() const
{
if (d->package) {
d->package->d->isPublished();
return d->package->d->isPublished();
} else {
if (d->service) {
return d->service->d->isPublished();

View File

@ -132,21 +132,13 @@ void AuthorizationManager::setAuthorizationInterface(AuthorizationInterface *int
AuthorizationManagerPrivate::AuthorizationManagerPrivate(AuthorizationManager *manager)
: q(manager),
server(0),
authorizationPolicy(AuthorizationManager::DenyAll),
authorizationInterface(new DenyAllAuthorization()),
customAuthorizationInterface(0),
rulesConfig(KSharedConfig::openConfig("/etc/plasma-remotewidgets.conf")->group("Rules")),
locked(false)
{
wallet = KWallet::Wallet::openWallet("Plasma", 0, KWallet::Wallet::Asynchronous);
q->connect(wallet, SIGNAL(walletOpened(bool)), q, SLOT(slotWalletOpened()));
//Let's set up plasma for remote service support. Since most of the set up involves crypto,
//AuthorizationManager seems the sensible place.
//First, let's start the JOLIE server:
server = new Jolie::Server(4000);
QTimer::singleShot(0, q, SLOT(slotLoadRules()));
}
AuthorizationManagerPrivate::~AuthorizationManagerPrivate()
@ -157,10 +149,34 @@ AuthorizationManagerPrivate::~AuthorizationManagerPrivate()
delete wallet;
}
void AuthorizationManagerPrivate::prepareForServiceAccess()
{
if (myCredentials.isValid()) {
return;
}
wallet = KWallet::Wallet::openWallet("Plasma", 0, KWallet::Wallet::Asynchronous);
q->connect(wallet, SIGNAL(walletOpened(bool)), q, SLOT(slotWalletOpened()));
QTimer::singleShot(0, q, SLOT(slotLoadRules()));
}
void AuthorizationManagerPrivate::prepareForServicePublication()
{
if (!server) {
//Let's set up plasma for remote service support. Since most of the set up involves crypto,
//AuthorizationManager seems the sensible place.
//First, let's start the JOLIE server:
server = new Jolie::Server(4000);
}
}
void AuthorizationManagerPrivate::saveRules()
{
kDebug() << "SAVE RULES";
KTemporaryFile tempFile;
tempFile.open();
tempFile.setAutoRemove(false);
KConfigGroup rulesGroup = KSharedConfig::openConfig(tempFile.fileName())->group("Rules");
int i = 0;
@ -178,6 +194,8 @@ void AuthorizationManagerPrivate::saveRules()
rulesGroup.sync();
tempFile.close();
kDebug() << "tempfile = " << tempFile.fileName();
KAuth::Action action("org.kde.kcontrol.kcmremotewidgets.save");
action.addArgument("source", tempFile.fileName());
action.addArgument("filename", "/etc/plasma-remotewidgets.conf");

View File

@ -102,9 +102,11 @@ class PLASMA_EXPORT AuthorizationManager : public QObject
Q_PRIVATE_SLOT(d, void slotLoadRules())
Q_PRIVATE_SLOT(d, void slotWalletOpened())
friend class AccessManager;
friend class AuthorizationManagerPrivate;
friend class AuthorizationManagerSingleton;
friend class AuthorizationRule;
friend class AuthorizationRulePrivate;
friend class Applet;
friend class Credentials;
friend class DataEngine;
@ -113,6 +115,7 @@ class PLASMA_EXPORT AuthorizationManager : public QObject
friend class PlasmoidServiceJob;
friend class RemoteService;
friend class RemoteServiceJob;
friend class ServicePrivate;
friend class ServiceProvider;
};
} // Plasma namespace

View File

@ -74,6 +74,11 @@ void AuthorizationRulePrivate::scheduleChangedSignal()
void AuthorizationRulePrivate::fireChangedSignal()
{
if ((persistence == AuthorizationRule::Persistent) &&
(policy != AuthorizationRule::PinRequired)) {
AuthorizationManager::self()->d->saveRules();
}
emit q->changed(q);
}

View File

@ -53,6 +53,8 @@ class AuthorizationManagerPrivate
AuthorizationManagerPrivate(AuthorizationManager *manager);
~AuthorizationManagerPrivate();
void prepareForServiceAccess();
void prepareForServicePublication();
void slotWalletOpened();
void slotLoadRules();
AuthorizationRule *matchingRule(const QString &serviceName, const Credentials &key) const;

View File

@ -53,6 +53,7 @@ void PinPairingAuthorization::authorizationRequest(AuthorizationRule &rule)
rule.setPolicy(AuthorizationRule::Allow);
rule.setTargets(AuthorizationRule::AllServices);
} else {
rule.setPolicy(AuthorizationRule::PinRequired);
new PinPairingDialog(rule);
}
}

View File

@ -267,6 +267,7 @@ void ServiceProvider::ruleChanged(Plasma::AuthorizationRule *rule)
authorizationFailed(message, Message::Error::REQUIREPIN);
m_messagesPendingAuthorization.removeAt(i);
return;
/**
} else if (matches && rule->policy() == AuthorizationRule::PinRequired) {
kDebug() << "AUTHORIZATION: Service is freely accessable for verified caller.";
rule->setPolicy(AuthorizationRule::Allow);
@ -274,6 +275,7 @@ void ServiceProvider::ruleChanged(Plasma::AuthorizationRule *rule)
//TODO: it might be nicer to do a removeAll once Jolie::Message implements ==
m_messagesPendingAuthorization.removeAt(i);
return;
*/
} else if (matches && rule->policy() == AuthorizationRule::Allow) {
kDebug() << "AUTHORIZATION: Service is freely accessable for verified caller.";
authorizationSuccess(message);

View File

@ -18,6 +18,7 @@
*/
#include "service.h"
#include "private/authorizationmanager_p.h"
#include "private/remoteservice_p.h"
#include "private/service_p.h"
#include "private/serviceprovider_p.h"
@ -37,8 +38,6 @@
#include "configloader.h"
#include "version.h"
#include "private/configloader_p.h"
//#include "widgets/widget.h.template"
//#include "packagemetadata.h"
namespace Plasma
{
@ -122,6 +121,8 @@ void ServicePrivate::jobFinished(KJob *job)
void ServicePrivate::publish(AnnouncementMethods methods, const QString &name, PackageMetadata metadata)
{
if (!serviceProvider) {
AuthorizationManager::self()->d->prepareForServicePublication();
serviceProvider = new ServiceProvider(name, q);
if (methods.testFlag(ZeroconfAnnouncement) &&