diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java index 98c5ef28708..87795967f10 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/DeviceTypeManager.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; @@ -42,12 +43,14 @@ import org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util. import org.wso2.carbon.device.mgt.extensions.license.mgt.registry.RegistryBasedLicenseManager; import org.wso2.carbon.registry.api.RegistryException; import org.wso2.carbon.registry.api.Resource; +import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBException; import javax.xml.bind.Marshaller; import javax.xml.bind.Unmarshaller; +import java.io.File; import java.io.StringReader; import java.io.StringWriter; import java.nio.charset.Charset; @@ -63,10 +66,15 @@ public class DeviceTypeManager implements DeviceManager { private String deviceType; private DeviceTypePluginDAOManager deviceTypePluginDAOManager; private LicenseManager licenseManager; + private PlatformConfiguration defaultPlatformConfiguration; private boolean propertiesExist; private boolean requiredDeviceTypeAuthorization; private boolean claimable; + private static final String PATH_MOBILE_PLUGIN_CONF_DIR = + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugin-configs" + File.separator + + "mobile"; + private FeatureManager featureManager; public DeviceTypeManager(DeviceTypeConfigIdentifier deviceTypeConfigIdentifier, @@ -107,6 +115,14 @@ public class DeviceTypeManager implements DeviceManager { claimable = deviceTypeConfiguration.getClaimable().isEnabled(); } + // Loading default platform configuration + try { + defaultPlatformConfiguration = this.getDefaultConfiguration(); + } catch (DeviceManagementException e) { + String msg = "Error occurred while default platform configuration"; + throw new DeviceTypeDeployerFileException(msg, e); + } + DeviceDetails deviceDetails = deviceTypeConfiguration.getDeviceDetails(); if (deviceDetails != null) { @@ -205,6 +221,8 @@ public class DeviceTypeManager implements DeviceManager { return (PlatformConfiguration) unmarshaller.unmarshal( new StringReader(new String((byte[]) resource.getContent(), Charset. forName(DeviceTypePluginConstants.CHARSET_UTF8)))); + } else if (defaultPlatformConfiguration != null) { + return defaultPlatformConfiguration; } return null; } catch (DeviceTypeMgtPluginException e) { @@ -371,6 +389,39 @@ public class DeviceTypeManager implements DeviceManager { return requiredDeviceTypeAuthorization; } + @Override + public PlatformConfiguration getDefaultConfiguration() throws DeviceManagementException { + + if (log.isDebugEnabled()) { + log.debug("Loading default " + deviceType + " platform configuration from " + deviceType + + "-default-platform-configuration.xml"); + } + try { + String platformConfigurationPath = + PATH_MOBILE_PLUGIN_CONF_DIR + File.separator + deviceType + "-default-platform-configuration.xml"; + File platformConfig = new File(platformConfigurationPath); + + if (platformConfig.exists()) { + Document doc = DeviceTypeUtils.convertToDocument(platformConfig); + JAXBContext context = JAXBContext.newInstance(PlatformConfiguration.class); + Unmarshaller unmarshaller = context.createUnmarshaller(); + return (PlatformConfiguration) unmarshaller.unmarshal(doc); + } else { + log.warn(deviceType + "-default-platform-configuration.xml is not available, hence default " + + deviceType + "platform configuration cannot be loaded."); + } + return null; + } catch (JAXBException e) { + throw new DeviceManagementException( + "Error occurred while parsing the " + deviceType + " default platform configuration : " + e + .getMessage(), e); + } catch (DeviceTypeMgtPluginException e) { + throw new DeviceManagementException( + "Error occurred while parsing the " + deviceType + " default platform configuration : " + e + .getMessage(), e); + } + } + @Override public boolean updateDeviceInfo(DeviceIdentifier deviceIdentifier, Device device) throws DeviceManagementException { diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java index 466b3edcfea..20417fa4be8 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/src/main/java/org/wso2/carbon/device/mgt/extensions/device/type/deployer/template/util/DeviceTypeUtils.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.extensions.device.type.deployer.template.util import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.w3c.dom.Document; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.exception.DeviceTypeMgtPluginException; import org.wso2.carbon.device.mgt.extensions.device.type.deployer.internal.DeviceTypeManagementDataHolder; @@ -30,6 +31,10 @@ import org.wso2.carbon.registry.core.Registry; import javax.naming.Context; import javax.naming.InitialContext; import javax.sql.DataSource; +import javax.xml.XMLConstants; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import java.io.File; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -128,4 +133,18 @@ public class DeviceTypeUtils { } } + public static Document convertToDocument(File file) throws DeviceTypeMgtPluginException { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + try { + factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); + DocumentBuilder docBuilder = factory.newDocumentBuilder(); + return docBuilder.parse(file); + } catch (Exception e) { + throw new DeviceTypeMgtPluginException("Error occurred while parsing file '" + file.getName() + "' to" + + " a org.w3c.dom.Document", e); + } + } + + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java index 060865c726c..3c97fa81cec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/DeviceManager.java @@ -157,4 +157,13 @@ public interface DeviceManager { */ boolean requireDeviceAuthorization(); + /** + * This method returns the default configuration values which is stored in the configuration file + * rather than fetching from the registry. + * + * @return Returns Default PlatformConfiguration + * @throws DeviceManagementException + */ + PlatformConfiguration getDefaultConfiguration() throws DeviceManagementException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs index 78aa84e0016..f5416944dd8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.navbar.nav-menu/nav-menu.hbs @@ -87,7 +87,6 @@
  • Policy Management
  • {{/if}} - {{#unless isCloud}} {{#if permissions.TENANT_CONFIGURATION}}
  • Configuration Management
  • {{/if}} - {{/unless}}