From 255e6b55663fc8e7d754d7e190737c6e789e6efb Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sat, 13 Aug 2016 10:38:30 +0530 Subject: [PATCH] few changes to resolve after scope validation issue --- .../ConfigurationMgtService.java | 139 ++----------- .../ConfigurationMgtServiceImpl.java | 183 ++++++++++++++++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 13 +- .../public/js/platform-configuration.js | 2 +- 5 files changed, 209 insertions(+), 130 deletions(-) create mode 100644 components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java index 26b01620ee..320b75ad8c 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtService.java @@ -18,40 +18,33 @@ package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.annotations.api.API; import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -import org.wso2.carbon.device.mgt.common.license.mgt.License; -import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; -import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; import javax.jws.WebService; -import javax.ws.rs.*; -import javax.ws.rs.core.Response; -import java.util.ArrayList; -import java.util.List; +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.Produces; /** * Windows Platform Configuration REST-API implementation. * All end points supports JSON, XMl with content negotiation. */ @API(name = "Windows Configuration Management", version = "1.0.0", - context = "api/device-mgt/windows/v1.0/configuration", + context = "api/device-mgt/windows/v1.0/services/configuration", tags = {"windows"}) @WebService @Produces({"application/json", "application/xml"}) @Consumes({"application/json", "application/xml"}) -public class ConfigurationMgtService { - - private static Log log = LogFactory.getLog(ConfigurationMgtService.class); +@Path("services/configuration") +public interface ConfigurationMgtService { /** * Save Tenant configurations. @@ -62,49 +55,7 @@ public class ConfigurationMgtService { */ @POST @Scope(key = "configuration:manage", name = "Add configurations", description = "") - public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { - Message responseMsg = new Message(); - ConfigurationEntry licenseEntry = null; - String message; - - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - if (!configuration.getConfiguration().isEmpty()) { - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); - licenseEntry = entry; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Windows platform configuration saved successfully."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - return responseMsg; - } else { - Response.status(Response.Status.BAD_REQUEST); - responseMsg.setResponseMessage("Windows platform configuration can not be saved."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } - } catch (DeviceManagementException e) { - message = "Error Occurred while configuring Windows Platform."; - log.error(message, e); - throw new WindowsConfigurationException(message, e); - } - return responseMsg; - } + Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException; /** * Retrieve Tenant configurations according to the device type. @@ -114,39 +65,7 @@ public class ConfigurationMgtService { */ @GET @Scope(key = "configuration:view", name = "View configurations", description = "") - public PlatformConfiguration getConfiguration() throws WindowsConfigurationException { - String msg; - PlatformConfiguration tenantConfiguration; - List configs; - try { - tenantConfiguration = WindowsAPIUtils.getDeviceManagementService(). - getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - if (tenantConfiguration != null) { - configs = tenantConfiguration.getConfiguration(); - } else { - tenantConfiguration = new PlatformConfiguration(); - configs = new ArrayList<>(); - } - - ConfigurationEntry entry = new ConfigurationEntry(); - License license = WindowsAPIUtils.getDeviceManagementService().getLicense( - DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, - PluginConstants.TenantConfigProperties.LANGUAGE_US); - - if (license != null && configs != null) { - entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); - entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY); - entry.setValue(license.getText()); - configs.add(entry); - tenantConfiguration.setConfiguration(configs); - } - } catch (DeviceManagementException e) { - msg = "Error occurred while retrieving the Windows tenant configuration"; - log.error(msg, e); - throw new WindowsConfigurationException(msg, e); - } - return tenantConfiguration; - } + PlatformConfiguration getConfiguration() throws WindowsConfigurationException; /** * Update Tenant Configurations for the specific Device type. @@ -157,39 +76,5 @@ public class ConfigurationMgtService { */ @PUT @Scope(key = "configuration:manage", name = "Add configurations", description = "") - public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException { - String message; - Message responseMsg = new Message(); - ConfigurationEntry licenseEntry = null; - try { - configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - List configs = configuration.getConfiguration(); - for (ConfigurationEntry entry : configs) { - if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { - License license = new License(); - license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); - license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); - license.setVersion("1.0.0"); - license.setText(entry.getValue().toString()); - WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. - MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); - licenseEntry = entry; - } - } - - if (licenseEntry != null) { - configs.remove(licenseEntry); - } - configuration.setConfiguration(configs); - WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); - Response.status(Response.Status.CREATED); - responseMsg.setResponseMessage("Windows platform configuration succeeded."); - responseMsg.setResponseCode(Response.Status.CREATED.toString()); - } catch (DeviceManagementException e) { - message = "Error occurred while modifying configuration settings of Windows platform."; - log.error(message, e); - throw new WindowsConfigurationException(message, e); - } - return responseMsg; - } + Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException; } diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java new file mode 100644 index 0000000000..c6b94383bd --- /dev/null +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/java/org/wso2/carbon/mdm/mobileservices/windows/services/configurationmgtservice/ConfigurationMgtServiceImpl.java @@ -0,0 +1,183 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; +import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; +import org.wso2.carbon.device.mgt.common.license.mgt.License; +import org.wso2.carbon.mdm.mobileservices.windows.common.PluginConstants; +import org.wso2.carbon.mdm.mobileservices.windows.common.exceptions.WindowsConfigurationException; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.Message; +import org.wso2.carbon.mdm.mobileservices.windows.common.util.WindowsAPIUtils; + +import javax.jws.WebService; +import javax.ws.rs.*; +import javax.ws.rs.core.Response; +import java.util.ArrayList; +import java.util.List; + +@WebService +@Produces({"application/json", "application/xml"}) +@Consumes({"application/json", "application/xml"}) +@Path("/") +public class ConfigurationMgtServiceImpl implements ConfigurationMgtService{ + + private static Log log = LogFactory.getLog(ConfigurationMgtServiceImpl.class); + + /** + * Save Tenant configurations. + * + * @param configuration Tenant Configurations to be saved. + * @return Message type object for the provide save status. + * @throws WindowsConfigurationException + */ + @POST + public Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException { + Message responseMsg = new Message(); + ConfigurationEntry licenseEntry = null; + String message; + + try { + configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + if (!configuration.getConfiguration().isEmpty()) { + List configs = configuration.getConfiguration(); + for (ConfigurationEntry entry : configs) { + if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { + License license = new License(); + license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); + license.setVersion("1.0.0"); + license.setText(entry.getValue().toString()); + WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); + licenseEntry = entry; + } + } + + if (licenseEntry != null) { + configs.remove(licenseEntry); + } + configuration.setConfiguration(configs); + WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + Response.status(Response.Status.CREATED); + responseMsg.setResponseMessage("Windows platform configuration saved successfully."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + return responseMsg; + } else { + Response.status(Response.Status.BAD_REQUEST); + responseMsg.setResponseMessage("Windows platform configuration can not be saved."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + } + } catch (DeviceManagementException e) { + message = "Error Occurred while configuring Windows Platform."; + log.error(message, e); + throw new WindowsConfigurationException(message, e); + } + return responseMsg; + } + + /** + * Retrieve Tenant configurations according to the device type. + * + * @return Tenant configuration object contains specific tenant configurations. + * @throws WindowsConfigurationException + */ + @GET + public PlatformConfiguration getConfiguration() throws WindowsConfigurationException { + String msg; + PlatformConfiguration tenantConfiguration; + List configs; + try { + tenantConfiguration = WindowsAPIUtils.getDeviceManagementService(). + getConfiguration(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + if (tenantConfiguration != null) { + configs = tenantConfiguration.getConfiguration(); + } else { + tenantConfiguration = new PlatformConfiguration(); + configs = new ArrayList<>(); + } + + ConfigurationEntry entry = new ConfigurationEntry(); + License license = WindowsAPIUtils.getDeviceManagementService().getLicense( + DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, + PluginConstants.TenantConfigProperties.LANGUAGE_US); + + if (license != null && configs != null) { + entry.setContentType(PluginConstants.TenantConfigProperties.CONTENT_TYPE_TEXT); + entry.setName(PluginConstants.TenantConfigProperties.LICENSE_KEY); + entry.setValue(license.getText()); + configs.add(entry); + tenantConfiguration.setConfiguration(configs); + } + } catch (DeviceManagementException e) { + msg = "Error occurred while retrieving the Windows tenant configuration"; + log.error(msg, e); + throw new WindowsConfigurationException(msg, e); + } + return tenantConfiguration; + } + + /** + * Update Tenant Configurations for the specific Device type. + * + * @param configuration Tenant configurations to be updated. + * @return Response message. + * @throws WindowsConfigurationException + */ + @PUT + public Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException { + String message; + Message responseMsg = new Message(); + ConfigurationEntry licenseEntry = null; + try { + configuration.setType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + List configs = configuration.getConfiguration(); + for (ConfigurationEntry entry : configs) { + if (PluginConstants.TenantConfigProperties.LICENSE_KEY.equals(entry.getName())) { + License license = new License(); + license.setName(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS); + license.setLanguage(PluginConstants.TenantConfigProperties.LANGUAGE_US); + license.setVersion("1.0.0"); + license.setText(entry.getValue().toString()); + WindowsAPIUtils.getDeviceManagementService().addLicense(DeviceManagementConstants. + MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, license); + licenseEntry = entry; + } + } + + if (licenseEntry != null) { + configs.remove(licenseEntry); + } + configuration.setConfiguration(configs); + WindowsAPIUtils.getDeviceManagementService().saveConfiguration(configuration); + Response.status(Response.Status.CREATED); + responseMsg.setResponseMessage("Windows platform configuration succeeded."); + responseMsg.setResponseCode(Response.Status.CREATED.toString()); + } catch (DeviceManagementException e) { + message = "Error occurred while modifying configuration settings of Windows platform."; + log.error(message, e); + throw new WindowsConfigurationException(message, e); + } + return responseMsg; + } +} diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml index ad2863d955..117db3174b 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -197,7 +197,7 @@ class="org.wso2.carbon.mdm.mobileservices.windows.services.wstep.util.MessageHandler"/> + class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.ConfigurationMgtServiceImpl"/> diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml index e9f5de0f80..cfff9d4b35 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.api/src/main/webapp/WEB-INF/web.xml @@ -48,7 +48,18 @@ 60 - + + isAdminService + false + + + managed-api-enabled + true + + + managed-api-owner + admin + doAuthentication true diff --git a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js index fc5a5aa662..79ce06bcfb 100644 --- a/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js +++ b/components/mobile-plugins/windows-plugin/org.wso2.carbon.device.mgt.mobile.windows.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.windows.platform.configuration/public/js/platform-configuration.js @@ -189,7 +189,7 @@ $(document).ready(function () { addConfigFormData, function (data, textStatus, jqXHR) { data = jqXHR.status; - if (data == 201) { + if (data == 200) { $("#config-save-form").addClass("hidden"); $("#record-created-msg").removeClass("hidden"); } else if (data == 500) {