cloudstack-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mc...@apache.org
Subject [42/43] git commit: We need to catch PermissionDeniedException in checking if command is available to an user.
Date Tue, 15 Jan 2013 23:55:10 GMT
We need to catch PermissionDeniedException in checking if command is
available to an user.


Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/7f1486e2
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/7f1486e2
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/7f1486e2

Branch: refs/heads/api_limit
Commit: 7f1486e2dc9f612af94901ab8804e24c48b8122b
Parents: a6b9027
Author: Min Chen <min.chen@citrix.com>
Authored: Tue Jan 15 11:40:49 2013 -0800
Committer: Min Chen <min.chen@citrix.com>
Committed: Tue Jan 15 11:43:59 2013 -0800

----------------------------------------------------------------------
 server/src/com/cloud/api/ApiServer.java |   13 +++++++++----
 1 files changed, 9 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/7f1486e2/server/src/com/cloud/api/ApiServer.java
----------------------------------------------------------------------
diff --git a/server/src/com/cloud/api/ApiServer.java b/server/src/com/cloud/api/ApiServer.java
index 4d60215..e106f03 100755
--- a/server/src/com/cloud/api/ApiServer.java
+++ b/server/src/com/cloud/api/ApiServer.java
@@ -549,7 +549,10 @@ public class ApiServer implements HttpRequestHandler {
             // if userId not null, that mean that user is logged in
             if (userId != null) {
             	User user = ApiDBUtils.findUserById(userId);
-                if (!isCommandAvailable(user, commandName)) {
+            	try{
+            	    checkCommandAvailable(user, commandName);
+            	}
+            	catch (PermissionDeniedException ex){
                     s_logger.debug("The given command:" + commandName + " does not exist
or it is not available for user with id:" + userId);
                     throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given
command does not exist or it is not available for user");
                 }
@@ -649,7 +652,10 @@ public class ApiServer implements HttpRequestHandler {
 
             UserContext.updateContext(user.getId(), account, null);
 
-            if (!isCommandAvailable(user, commandName)) {
+            try{
+                checkCommandAvailable(user, commandName);
+            }
+            catch (PermissionDeniedException ex){
                 s_logger.debug("The given command:" + commandName + " does not exist or it
is not available for user");
                 throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given
command:" + commandName + " does not exist or it is not available for user with id:" + userId);
             }
@@ -780,7 +786,7 @@ public class ApiServer implements HttpRequestHandler {
         return true;
     }
 
-    private boolean isCommandAvailable(User user, String commandName) throws PermissionDeniedException
{
+    private void checkCommandAvailable(User user, String commandName) throws PermissionDeniedException
{
         if (user == null) {
             throw new PermissionDeniedException("User is null for role based API access check
for command" + commandName);
         }
@@ -788,7 +794,6 @@ public class ApiServer implements HttpRequestHandler {
         for (APIChecker apiChecker : _apiAccessCheckers) {
             apiChecker.checkAccess(user, commandName);
         }
-        return true;
     }
 
     private Class<?> getCmdClass(String cmdName) {


Mime
View raw message