Allow custom command role ACL files on classpath in Static Role API Checker.
This commit has a small refactoring of cloud-plugin-acl-static-role-based to allow it to read files on the classpath that might have a different name than "commands.properties". It also allows more than one file to be read from. Rationale: Third-party plugins may want to keep their API command access level configuration separate from the main file so as to reduce configuration maintenance work during packaging and deployments. Signed-off-by: Rohit Yadav <rohit.ya...@shapeblue.com> This closes #354 Project: http://git-wip-us.apache.org/repos/asf/cloudstack/repo Commit: http://git-wip-us.apache.org/repos/asf/cloudstack/commit/93b201d4 Tree: http://git-wip-us.apache.org/repos/asf/cloudstack/tree/93b201d4 Diff: http://git-wip-us.apache.org/repos/asf/cloudstack/diff/93b201d4 Branch: refs/heads/reporter Commit: 93b201d43a4263bc9b7e6e31c542255440a7cb39 Parents: 299c07c Author: jeff <j...@greenqloud.com> Authored: Wed Jun 3 17:15:57 2015 +0000 Committer: Rohit Yadav <rohit.ya...@shapeblue.com> Committed: Wed Jul 1 14:43:29 2015 +0200 ---------------------------------------------------------------------- .../spring-acl-static-role-based-context.xml | 5 +++++ .../acl/StaticRoleBasedAPIAccessChecker.java | 13 ++++++++++++- 2 files changed, 17 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b201d4/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml ---------------------------------------------------------------------- diff --git a/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml index f13acc1..0b22283 100644 --- a/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml +++ b/plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml @@ -29,6 +29,11 @@ <bean id="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker" > <property name="services" value="#{apiCommandsRegistry.registered}" /> + <property name="commandPropertyFiles"> + <set> + <value>commands.properties</value> + </set> + </property> </bean> </beans> http://git-wip-us.apache.org/repos/asf/cloudstack/blob/93b201d4/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 1316a92..4383b45 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 @@ -45,6 +45,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC protected static final Logger s_logger = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class); + Set<String> commandPropertyFiles = new HashSet<String>(); Set<String> commandsPropertiesOverrides = new HashSet<String>(); Map<RoleType, Set<String>> commandsPropertiesRoleBasedApisMap = new HashMap<RoleType, Set<String>>(); Map<RoleType, Set<String>> annotationRoleBasedApisMap = new HashMap<RoleType, Set<String>>(); @@ -84,7 +85,9 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC public boolean configure(String name, Map<String, Object> params) throws ConfigurationException { super.configure(name, params); - processMapping(PropertiesUtil.processConfigFile(new String[] {"commands.properties"})); + for (String commandPropertyFile : commandPropertyFiles) { + processMapping(PropertiesUtil.processConfigFile(new String[] { commandPropertyFile })); + } return true; } @@ -129,4 +132,12 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC this._services = services; } + public Set<String> getCommandPropertyFiles() { + return commandPropertyFiles; + } + + public void setCommandPropertyFiles(Set<String> commandPropertyFiles) { + this.commandPropertyFiles = commandPropertyFiles; + } + }