[Account] Privilege checks moved to JS.
authorPawel Andruszkiewicz <p.andruszkie@samsung.com>
Thu, 30 Apr 2015 10:46:21 +0000 (12:46 +0200)
committerPawel Andruszkiewicz <p.andruszkie@samsung.com>
Mon, 4 May 2015 07:53:07 +0000 (16:53 +0900)
Privileges need to be check before validation of arguments.

Change-Id: I145568782afcce0e25e6abd4227821be66f1a51f

src/account/account_api.js
src/account/account_instance.cc

index 00aeee9babb4a25174adbd50b65f810d0e48df35..910131a61bfd725a14ca33a535d38afa5eb6d103 100644 (file)
@@ -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 }
     ]);
index 01dadbe9ab8ddb231e87b6c2327e6861b6178ef4..954d11227f566e5909ee06386f802a6f01d4e71c 100644 (file)
@@ -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<int>(args.get("accountId").get<double>());
@@ -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<int>(args.get("callbackId").get<double>());
 
@@ -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<std::string>();
   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<int>(args.get("callbackId").get<double>());
 
@@ -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");