mirror of
https://github.com/apache/cloudstack.git
synced 2025-10-26 08:42:29 +01:00
Fix PluggableService to provide interface for ACL adapters etc. to get configs
- Fix interface to return array of strings, or filenames - Fix StaticRoleBased ACL adapter to process config files by going through all pluggable services - Refactor interface names Signed-off-by: Rohit Yadav <bhaisaab@apache.org>
This commit is contained in:
parent
d8d87adc22
commit
d235859168
@ -19,8 +19,8 @@ package com.cloud.server;
|
||||
|
||||
public class ManagementServerSimulatorImpl extends ManagementServerExtImpl {
|
||||
@Override
|
||||
public String[] getApiConfig() {
|
||||
String[] apis = super.getApiConfig();
|
||||
public String[] getPropertiesFiles() {
|
||||
String[] apis = super.getPropertiesFiles();
|
||||
String[] newapis = new String[apis.length + 1];
|
||||
for (int i = 0; i < apis.length; i++) {
|
||||
newapis[i] = apis[i];
|
||||
|
||||
@ -540,8 +540,8 @@ public class NiciraNvpElement extends AdapterBase implements
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertiesFile() {
|
||||
return "nicira-nvp_commands.properties";
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "nicira-nvp_commands.properties" };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -21,10 +21,7 @@ import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.*;
|
||||
|
||||
import javax.ejb.Local;
|
||||
import javax.naming.ConfigurationException;
|
||||
@ -60,7 +57,6 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA
|
||||
private static List<String> s_adminCommands = null;
|
||||
private static List<String> s_resourceDomainAdminCommands = null;
|
||||
private static List<String> s_allCommands = null;
|
||||
private static List<String> s_pluggableServiceCommands = null;
|
||||
private Properties _apiCommands = null;
|
||||
|
||||
protected @Inject AccountManager _accountMgr;
|
||||
@ -72,7 +68,6 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA
|
||||
s_resellerCommands = new ArrayList<String>();
|
||||
s_adminCommands = new ArrayList<String>();
|
||||
s_resourceDomainAdminCommands = new ArrayList<String>();
|
||||
s_pluggableServiceCommands = new ArrayList<String>();
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -119,88 +114,70 @@ public class StaticRoleBasedAPIAccessChecker extends AdapterBase implements APIA
|
||||
public boolean configure(String name, Map<String, Object> params) throws ConfigurationException {
|
||||
super.configure(name, params);
|
||||
|
||||
//load command.properties to build the static map per role.
|
||||
// Read command properties files to build the static map per role.
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
String[] apiConfig = ((ManagementServer) ComponentLocator.getComponent(ManagementServer.Name)).getApiConfig();
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
services.add((PluggableService) ComponentLocator.getComponent(ManagementServer.Name));
|
||||
|
||||
processConfigFiles(apiConfig, false);
|
||||
|
||||
// get commands for all pluggable services
|
||||
String[] pluggableServicesApiConfigs = getPluggableServicesApiConfigs();
|
||||
processConfigFiles(pluggableServicesApiConfigs, true);
|
||||
List<String> configFiles = new ArrayList<String>();
|
||||
for (PluggableService service : services) {
|
||||
configFiles.addAll(Arrays.asList(service.getPropertiesFiles()));
|
||||
}
|
||||
|
||||
processConfigFiles(configFiles);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private String[] getPluggableServicesApiConfigs() {
|
||||
List<String> pluggableServicesApiConfigs = new ArrayList<String>();
|
||||
|
||||
ComponentLocator locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
List<PluggableService> services = locator.getAllPluggableServices();
|
||||
for (PluggableService service : services) {
|
||||
pluggableServicesApiConfigs.add(service.getPropertiesFile());
|
||||
}
|
||||
return pluggableServicesApiConfigs.toArray(new String[0]);
|
||||
}
|
||||
|
||||
private void processConfigFiles(String[] apiConfig, boolean pluggableServicesConfig) {
|
||||
private void processConfigFiles(List<String> configFiles) {
|
||||
try {
|
||||
if (_apiCommands == null)
|
||||
_apiCommands = new Properties();
|
||||
|
||||
Properties preProcessedCommands = new Properties();
|
||||
if (apiConfig != null) {
|
||||
for (String configFile : apiConfig) {
|
||||
File commandsFile = PropertiesUtil.findConfigFile(configFile);
|
||||
if (commandsFile != null) {
|
||||
try {
|
||||
preProcessedCommands.load(new FileInputStream(commandsFile));
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
// in case of a file within a jar in classpath, try to open stream using url
|
||||
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);
|
||||
if (stream != null) {
|
||||
preProcessedCommands.load(stream);
|
||||
} else {
|
||||
s_logger.error("Unable to find properites file", fnfex);
|
||||
}
|
||||
for (String configFile : configFiles) {
|
||||
File commandsFile = PropertiesUtil.findConfigFile(configFile);
|
||||
if (commandsFile != null) {
|
||||
try {
|
||||
preProcessedCommands.load(new FileInputStream(commandsFile));
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
// in case of a file within a jar in classpath, try to open stream using url
|
||||
InputStream stream = PropertiesUtil.openStreamFromURL(configFile);
|
||||
if (stream != null) {
|
||||
preProcessedCommands.load(stream);
|
||||
} else {
|
||||
s_logger.error("Unable to find properites file", fnfex);
|
||||
}
|
||||
}
|
||||
}
|
||||
for (Object key : preProcessedCommands.keySet()) {
|
||||
String preProcessedCommand = preProcessedCommands.getProperty((String) key);
|
||||
String[] commandParts = preProcessedCommand.split(";");
|
||||
_apiCommands.setProperty(key.toString(), commandParts[0]);
|
||||
}
|
||||
for (Object key : preProcessedCommands.keySet()) {
|
||||
String preProcessedCommand = preProcessedCommands.getProperty((String) key);
|
||||
String[] commandParts = preProcessedCommand.split(";");
|
||||
_apiCommands.setProperty(key.toString(), commandParts[0]);
|
||||
|
||||
if (pluggableServicesConfig) {
|
||||
s_pluggableServiceCommands.add(commandParts[0]);
|
||||
}
|
||||
|
||||
if (commandParts.length > 1) {
|
||||
try {
|
||||
short cmdPermissions = Short.parseShort(commandParts[1]);
|
||||
if ((cmdPermissions & ADMIN_COMMAND) != 0) {
|
||||
s_adminCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & RESOURCE_DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resourceDomainAdminCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resellerCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & USER_COMMAND) != 0) {
|
||||
s_userCommands.add((String) key);
|
||||
}
|
||||
s_allCommands.addAll(s_adminCommands);
|
||||
s_allCommands.addAll(s_resourceDomainAdminCommands);
|
||||
s_allCommands.addAll(s_userCommands);
|
||||
s_allCommands.addAll(s_resellerCommands);
|
||||
} catch (NumberFormatException nfe) {
|
||||
s_logger.info("Malformed command.properties permissions value, key = " + key + ", value = " + preProcessedCommand);
|
||||
if (commandParts.length > 1) {
|
||||
try {
|
||||
short cmdPermissions = Short.parseShort(commandParts[1]);
|
||||
if ((cmdPermissions & ADMIN_COMMAND) != 0) {
|
||||
s_adminCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & RESOURCE_DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resourceDomainAdminCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & DOMAIN_ADMIN_COMMAND) != 0) {
|
||||
s_resellerCommands.add((String) key);
|
||||
}
|
||||
if ((cmdPermissions & USER_COMMAND) != 0) {
|
||||
s_userCommands.add((String) key);
|
||||
}
|
||||
s_allCommands.addAll(s_adminCommands);
|
||||
s_allCommands.addAll(s_resourceDomainAdminCommands);
|
||||
s_allCommands.addAll(s_userCommands);
|
||||
s_allCommands.addAll(s_resellerCommands);
|
||||
} catch (NumberFormatException nfe) {
|
||||
s_logger.info("Malformed command.properties permissions value, key = " + key + ", value = " + preProcessedCommand);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
} catch (FileNotFoundException fnfex) {
|
||||
s_logger.error("Unable to find properties file", fnfex);
|
||||
|
||||
@ -680,8 +680,8 @@ public class VirtualRouterElement extends AdapterBase implements VirtualRouterEl
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getPropertiesFile() {
|
||||
return "virtualrouter_commands.properties";
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "virtualrouter_commands.properties" };
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -25,11 +25,12 @@ import com.cloud.info.ConsoleProxyInfo;
|
||||
import com.cloud.storage.GuestOSVO;
|
||||
import com.cloud.storage.StoragePoolVO;
|
||||
import com.cloud.utils.Pair;
|
||||
import com.cloud.utils.component.PluggableService;
|
||||
import com.cloud.vm.VirtualMachine;
|
||||
|
||||
/**
|
||||
*/
|
||||
public interface ManagementServer extends ManagementService {
|
||||
public interface ManagementServer extends ManagementService, PluggableService {
|
||||
|
||||
/**
|
||||
* returns the instance id of this management server.
|
||||
@ -43,8 +44,6 @@ public interface ManagementServer extends ManagementService {
|
||||
*/
|
||||
@Override
|
||||
String getVersion();
|
||||
|
||||
String[] getApiConfig();
|
||||
|
||||
/**
|
||||
* Retrieves a host by id
|
||||
|
||||
@ -206,7 +206,7 @@ public class ManagementServerExtImpl extends ManagementServerImpl implements Man
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getApiConfig() {
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "commands.properties", "commands-ext.properties" };
|
||||
}
|
||||
|
||||
|
||||
@ -2309,7 +2309,7 @@ public class ManagementServerImpl implements ManagementServer {
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getApiConfig() {
|
||||
public String[] getPropertiesFiles() {
|
||||
return new String[] { "commands.properties" };
|
||||
}
|
||||
|
||||
|
||||
@ -48,7 +48,7 @@ public class CloudStartupServlet extends HttpServlet implements ServletContextLi
|
||||
s_locator = ComponentLocator.getLocator(ManagementServer.Name);
|
||||
ManagementServer ms = (ManagementServer)ComponentLocator.getComponent(ManagementServer.Name);
|
||||
ms.enableAdminUser("password");
|
||||
ApiServer.initApiServer(ms.getApiConfig());
|
||||
ApiServer.initApiServer(ms.getPropertiesFiles());
|
||||
} catch (InvalidParameterValueException ipve) {
|
||||
s_logger.error("Exception starting management server ", ipve);
|
||||
throw new ServletException (ipve.getMessage());
|
||||
|
||||
@ -16,16 +16,9 @@
|
||||
// under the License.
|
||||
package com.cloud.utils.component;
|
||||
|
||||
|
||||
|
||||
/**
|
||||
* This interface defines methods for pluggable code within the Cloud Stack.
|
||||
*/
|
||||
// This interface defines methods for pluggable code within the Cloud Stack.
|
||||
public interface PluggableService {
|
||||
|
||||
/**
|
||||
* The config file name that lists API commands supported by this pluggable service
|
||||
*/
|
||||
String getPropertiesFile();
|
||||
|
||||
// The config command properties filenames that lists allowed API commands
|
||||
// and role masks supported by this pluggable service
|
||||
String[] getPropertiesFiles();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user