Return-Path: X-Original-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-cloudstack-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 6374BE5FE for ; Tue, 15 Jan 2013 08:21:24 +0000 (UTC) Received: (qmail 95910 invoked by uid 500); 15 Jan 2013 08:21:24 -0000 Delivered-To: apmail-incubator-cloudstack-commits-archive@incubator.apache.org Received: (qmail 95715 invoked by uid 500); 15 Jan 2013 08:21:23 -0000 Mailing-List: contact cloudstack-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: cloudstack-dev@incubator.apache.org Delivered-To: mailing list cloudstack-commits@incubator.apache.org Received: (qmail 94490 invoked by uid 99); 15 Jan 2013 08:21:20 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 15 Jan 2013 08:21:20 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id EE0DB1D9C8; Tue, 15 Jan 2013 08:21:19 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: hugo@apache.org To: cloudstack-commits@incubator.apache.org X-Mailer: ASF-Git Admin Mailer Subject: [11/26] git commit: StaticRoleBased: commands.properties is actually cfg for this plugin Message-Id: <20130115082119.EE0DB1D9C8@tyr.zones.apache.org> Date: Tue, 15 Jan 2013 08:21:19 +0000 (UTC) StaticRoleBased: commands.properties is actually cfg for this plugin Signed-off-by: Rohit Yadav Project: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/commit/3ec985f4 Tree: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/tree/3ec985f4 Diff: http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/diff/3ec985f4 Branch: refs/heads/cloud-agent-with-openvswitch Commit: 3ec985f46f7f251e5fb47cc3f4aa89e57f349454 Parents: c318561 Author: Rohit Yadav Authored: Mon Jan 14 18:58:23 2013 -0800 Committer: Rohit Yadav Committed: Mon Jan 14 19:01:26 2013 -0800 ---------------------------------------------------------------------- .../acl/StaticRoleBasedAPIAccessChecker.java | 29 +++++++-------- 1 files changed, 13 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-cloudstack/blob/3ec985f4/plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java ---------------------------------------------------------------------- diff --git a/plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java b/plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java index 55db288..1635784 100644 --- a/plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java +++ b/plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java @@ -21,15 +21,14 @@ import com.cloud.server.ManagementServer; import com.cloud.user.Account; import com.cloud.user.AccountService; import com.cloud.user.User; +import com.cloud.utils.PropertiesUtil; import com.cloud.utils.component.AdapterBase; import com.cloud.utils.component.ComponentLocator; -import com.cloud.utils.component.PluggableService; import javax.ejb.Local; import javax.naming.ConfigurationException; import java.util.HashMap; import java.util.HashSet; -import java.util.List; import java.util.Map; import java.util.Set; @@ -37,7 +36,7 @@ import org.apache.log4j.Logger; // This is the default API access checker that grab's the user's account // based on the account type, access is granted -@Local(value=APIChecker.class) +@Local(value = APIChecker.class) public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIChecker { protected static final Logger s_logger = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class); @@ -49,7 +48,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC protected StaticRoleBasedAPIAccessChecker() { super(); - for (RoleType roleType: RoleType.values()) + for (RoleType roleType : RoleType.values()) s_roleBasedApisMap.put(roleType, new HashSet()); } @@ -57,6 +56,10 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC public boolean checkAccess(User user, String commandName) throws PermissionDeniedException { Account account = s_accountService.getAccount(user.getAccountId()); + if (account == null) { + throw new PermissionDeniedException("The account id=" + user.getAccountId() + "for user id=" + user.getId() + "is null"); + } + RoleType roleType = s_accountService.getRoleType(account); boolean isAllowed = s_roleBasedApisMap.get(roleType).contains(commandName); if (!isAllowed) { @@ -71,32 +74,26 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC // Read command properties files to build the static map per role. ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name); - s_accountService = locator.getManager(AccountService.class); - List services = locator.getAllPluggableServices(); - services.add((PluggableService) ComponentLocator.getComponent(ManagementServer.Name)); + processMapping(PropertiesUtil.processConfigFile(new String[] + {"commands.properties"})); - for (PluggableService service : services) { - processConfigFiles(service.getProperties(), service.getClass().toString()); - s_logger.info("Processed role based acl for: " + service.toString()); - } return true; } - private void processConfigFiles(Map configMap, String service) { - for (Map.Entry entry: configMap.entrySet()) { + private void processMapping(Map configMap) { + for (Map.Entry entry : configMap.entrySet()) { String apiName = entry.getKey(); String roleMask = entry.getValue(); try { short cmdPermissions = Short.parseShort(roleMask); - for (RoleType roleType: RoleType.values()) { + for (RoleType roleType : RoleType.values()) { if ((cmdPermissions & roleType.getValue()) != 0) s_roleBasedApisMap.get(roleType).add(apiName); } } catch (NumberFormatException nfe) { - s_logger.info("Malformed getProperties() value for service: " + service - + " for entry: " + entry.toString()); + s_logger.info("Malformed key=value pair for entry: " + entry.toString()); } } }