From: Pawel Andruszkiewicz
Date: Thu, 30 Apr 2015 10:46:21 +0000 (+0200)
Subject: [Account] Privilege checks moved to JS.
X-Git-Tag: submit/tizen_tv/20150603.064601~1^2~95
X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=56d62cfd264357832fb8349c2a7be159efc4715e;p=platform%2Fcore%2Fapi%2Fwebapi-plugins.git
[Account] Privilege checks moved to JS.
Privileges need to be check before validation of arguments.
Change-Id: I145568782afcce0e25e6abd4227821be66f1a51f
---
diff --git a/src/account/account_api.js b/src/account/account_api.js
index 00aeee9b..910131a6 100644
--- a/src/account/account_api.js
+++ b/src/account/account_api.js
@@ -68,6 +68,8 @@ function Account() {
Account.prototype.setExtendedData = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_WRITE);
+
var args = validator_.validateArgs(arguments, [
{ name: 'key', type: types_.STRING },
{ name: 'value', type: types_.STRING }
@@ -88,6 +90,8 @@ Account.prototype.setExtendedData = function() {
Account.prototype.getExtendedData = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
if (T_.isFunction(arguments[0]) || arguments.length > 1) {
var args = validator_.validateArgs(arguments, [
{
@@ -150,6 +154,8 @@ function AccountManager() {}
AccountManager.prototype.add = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_WRITE);
+
var args = validator_.validateArgs(arguments, [
{ name: 'account', type: types_.PLATFORM_OBJECT, values: Account }
]);
@@ -171,6 +177,8 @@ AccountManager.prototype.add = function() {
AccountManager.prototype.remove = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_WRITE);
+
var args = validator_.validateArgs(arguments, [
{ name: 'accountId', type: types_.UNSIGNED_LONG}
]);
@@ -184,6 +192,8 @@ AccountManager.prototype.remove = function() {
AccountManager.prototype.update = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_WRITE);
+
var args = validator_.validateArgs(arguments, [
{ name: 'account', type: types_.PLATFORM_OBJECT, values: Account }
]);
@@ -203,6 +213,8 @@ AccountManager.prototype.update = function() {
AccountManager.prototype.getAccount = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'accountId', type: types_.UNSIGNED_LONG }
]);
@@ -227,6 +239,8 @@ AccountManager.prototype.getAccount = function() {
AccountManager.prototype.getAccounts = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'successCallback', type: types_.FUNCTION, optional: false, nullable: false },
{ name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true },
@@ -258,6 +272,8 @@ AccountManager.prototype.getAccounts = function() {
AccountManager.prototype.getProvider = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'applicationId', type: types_.STRING }
]);
@@ -282,6 +298,8 @@ AccountManager.prototype.getProvider = function() {
AccountManager.prototype.getProviders = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'successCallback', type: types_.FUNCTION, optional: false, nullable: false },
{ name: 'errorCallback', type: types_.FUNCTION, optional: true, nullable: true },
@@ -391,6 +409,8 @@ var _accountListeners = new AccountListeners();
AccountManager.prototype.addAccountListener = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'callback', type: types_.LISTENER, values: ['onadded', 'onremoved', 'onupdated'] }
]);
@@ -400,6 +420,8 @@ AccountManager.prototype.addAccountListener = function() {
AccountManager.prototype.removeAccountListener = function() {
+ xwalk.utils.checkPrivilegeAccess(xwalk.utils.privilege.ACCOUNT_READ);
+
var args = validator_.validateArgs(arguments, [
{ name: 'accountListenerId', type: types_.UNSIGNED_LONG }
]);
diff --git a/src/account/account_instance.cc b/src/account/account_instance.cc
index 01dadbe9..954d1122 100644
--- a/src/account/account_instance.cc
+++ b/src/account/account_instance.cc
@@ -21,14 +21,6 @@ using common::TypeMismatchException;
using common::UnknownException;
using common::SecurityException;
-namespace {
-// The privileges that required in Account API
-const std::string kPrivilegeAccountRead =
- "http://tizen.org/privilege/account.read";
-const std::string kPrivilegeAccountWrite =
- "http://tizen.org/privilege/account.write";
-} // namespace
-
#define CHECK_EXIST(args, name, out) \
if (!args.contains(name)) {\
ReportError(TypeMismatchException(name" is required argument"), out);\
@@ -81,8 +73,6 @@ void AccountInstance::AccountSetExtendedData(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountWrite, &out);
-
CHECK_EXIST(args, "key", out)
CHECK_EXIST(args, "value", out)
CHECK_EXIST(args, "accountId", out)
@@ -98,8 +88,6 @@ void AccountInstance::AccountGetExtendedData(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
CHECK_EXIST(args, "accountId", out)
CHECK_EXIST(args, "callbackId", out)
@@ -127,8 +115,6 @@ void AccountInstance::AccountGetExtendedDataSync(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
CHECK_EXIST(args, "key", out)
CHECK_EXIST(args, "accountId", out)
@@ -140,21 +126,18 @@ void AccountInstance::AccountGetExtendedDataSync(const picojson::value& args,
void AccountInstance::AccountManagerAdd(const picojson::value& args, picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountWrite, &out);
manager_->AddAccount(args, out);
}
void AccountInstance::AccountManagerRemove(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountWrite, &out);
manager_->RemoveAccount(args, out);
}
void AccountInstance::AccountManagerUpdate(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountWrite, &out);
manager_->UpdateAccount(args, out);
}
@@ -162,8 +145,6 @@ void AccountInstance::AccountManagerGetAccount(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
CHECK_EXIST(args, "accountId", out)
int account_id = static_cast(args.get("accountId").get());
@@ -175,8 +156,6 @@ void AccountInstance::AccountManagerGetAccounts(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
CHECK_EXIST(args, "callbackId", out)
int callback_id = static_cast(args.get("callbackId").get());
@@ -204,8 +183,6 @@ void AccountInstance::AccountManagerGetProvider(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
std::string application_id = args.get("applicationId").get();
LoggerD("application_id [%s]", application_id.c_str());
@@ -216,8 +193,6 @@ void AccountInstance::AccountManagerGetProviders(const picojson::value& args,
picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
CHECK_EXIST(args, "callbackId", out)
int callback_id = static_cast(args.get("callbackId").get());
@@ -289,8 +264,6 @@ void AccountInstance::AccountManagerAddAccountListener(
const picojson::value& args, picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
int ret = 0;
if (!subscribe_) {
LoggerD("Creating subscription");
@@ -319,8 +292,6 @@ void AccountInstance::AccountManagerRemoveAccountListener(
const picojson::value& args, picojson::object& out) {
LoggerD("Enter");
- CHECK_PRIVILEGE_ACCESS(kPrivilegeAccountRead, &out);
-
if (subscribe_) {
LoggerD("Removing subscription");