Skip to content

Commit 93b201d

Browse files
jeffyadvr
authored andcommitted
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.yadav@shapeblue.com> This closes apache#354
1 parent 299c07c commit 93b201d

2 files changed

Lines changed: 17 additions & 1 deletion

File tree

plugins/acl/static-role-based/resources/META-INF/cloudstack/acl-static-role-based/spring-acl-static-role-based-context.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@
2929

3030
<bean id="StaticRoleBasedAPIAccessChecker" class="org.apache.cloudstack.acl.StaticRoleBasedAPIAccessChecker" >
3131
<property name="services" value="#{apiCommandsRegistry.registered}" />
32+
<property name="commandPropertyFiles">
33+
<set>
34+
<value>commands.properties</value>
35+
</set>
36+
</property>
3237
</bean>
3338

3439
</beans>

plugins/acl/static-role-based/src/org/apache/cloudstack/acl/StaticRoleBasedAPIAccessChecker.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIC
4545

4646
protected static final Logger s_logger = Logger.getLogger(StaticRoleBasedAPIAccessChecker.class);
4747

48+
Set<String> commandPropertyFiles = new HashSet<String>();
4849
Set<String> commandsPropertiesOverrides = new HashSet<String>();
4950
Map<RoleType, Set<String>> commandsPropertiesRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
5051
Map<RoleType, Set<String>> annotationRoleBasedApisMap = new HashMap<RoleType, Set<String>>();
@@ -84,7 +85,9 @@ public boolean checkAccess(User user, String commandName) throws PermissionDenie
8485
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
8586
super.configure(name, params);
8687

87-
processMapping(PropertiesUtil.processConfigFile(new String[] {"commands.properties"}));
88+
for (String commandPropertyFile : commandPropertyFiles) {
89+
processMapping(PropertiesUtil.processConfigFile(new String[] { commandPropertyFile }));
90+
}
8891
return true;
8992
}
9093

@@ -129,4 +132,12 @@ public void setServices(List<PluggableService> services) {
129132
this._services = services;
130133
}
131134

135+
public Set<String> getCommandPropertyFiles() {
136+
return commandPropertyFiles;
137+
}
138+
139+
public void setCommandPropertyFiles(Set<String> commandPropertyFiles) {
140+
this.commandPropertyFiles = commandPropertyFiles;
141+
}
142+
132143
}

0 commit comments

Comments
 (0)