|
51 | 51 | import javax.servlet.http.HttpSession; |
52 | 52 |
|
53 | 53 | import com.cloud.utils.ReflectUtil; |
54 | | -import org.apache.cloudstack.acl.APIAccessChecker; |
55 | | -import org.apache.cloudstack.acl.ControlledEntity; |
| 54 | +import org.apache.cloudstack.acl.APIChecker; |
56 | 55 | import org.apache.cloudstack.acl.RoleType; |
57 | 56 | import org.apache.cloudstack.api.*; |
58 | 57 | import org.apache.cloudstack.api.command.user.account.ListAccountsCmd; |
@@ -146,8 +145,8 @@ public class ApiServer implements HttpRequestHandler { |
146 | 145 | @Inject private DomainManager _domainMgr = null; |
147 | 146 | @Inject private AsyncJobManager _asyncMgr = null; |
148 | 147 |
|
149 | | - @Inject(adapter = APIAccessChecker.class) |
150 | | - protected Adapters<APIAccessChecker> _apiAccessCheckers; |
| 148 | + @Inject(adapter = APIChecker.class) |
| 149 | + protected Adapters<APIChecker> _apiAccessCheckers; |
151 | 150 |
|
152 | 151 | private Account _systemAccount = null; |
153 | 152 | private User _systemUser = null; |
@@ -558,7 +557,7 @@ public boolean verifyRequest(Map<String, Object[]> requestParameters, Long userI |
558 | 557 | return true; |
559 | 558 | } else { |
560 | 559 | // check against every available command to see if the command exists or not |
561 | | - if (!isCommandAvailable(null, commandName) && !commandName.equals("login") && !commandName.equals("logout")) { |
| 560 | + if (!doesCommandExist(commandName) && !commandName.equals("login") && !commandName.equals("logout")) { |
562 | 561 | s_logger.debug("The given command:" + commandName + " does not exist or it is not available for user with id:" + userId); |
563 | 562 | throw new ServerApiException(BaseCmd.UNSUPPORTED_ACTION_ERROR, "The given command does not exist or it is not available for user"); |
564 | 563 | } |
@@ -790,17 +789,25 @@ public boolean verifyUser(Long userId) { |
790 | 789 | return true; |
791 | 790 | } |
792 | 791 |
|
793 | | - private boolean isCommandAvailable(User user, String commandName) |
794 | | - throws PermissionDeniedException { |
| 792 | + private boolean doesCommandExist(String apiName) { |
| 793 | + for (APIChecker apiChecker : _apiAccessCheckers) { |
| 794 | + // If any checker has api info on the command, return true |
| 795 | + if (apiChecker.checkExistence(apiName)) |
| 796 | + return true; |
| 797 | + } |
| 798 | + return false; |
| 799 | + } |
| 800 | + |
| 801 | + private boolean isCommandAvailable(User user, String commandName) { |
795 | 802 | if (user == null) { |
796 | 803 | return false; |
797 | 804 | } |
798 | 805 |
|
799 | 806 | Account account = _accountMgr.getAccount(user.getAccountId()); |
800 | 807 | RoleType roleType = _accountMgr.getRoleType(account); |
801 | | - for (APIAccessChecker apiChecker : _apiAccessCheckers) { |
| 808 | + for (APIChecker apiChecker : _apiAccessCheckers) { |
802 | 809 | // Fail the checking if any checker fails to verify |
803 | | - if (!apiChecker.canAccessAPI(roleType, commandName)) |
| 810 | + if (!apiChecker.checkAccess(roleType, commandName)) |
804 | 811 | return false; |
805 | 812 | } |
806 | 813 | return true; |
|
0 commit comments