mirror of
https://repository.entgra.net/community/device-mgt-plugins.git
synced 2025-09-16 23:42:15 +00:00
few changes to resolve after scope validation issue
This commit is contained in:
parent
2555a91b4d
commit
255e6b5566
@ -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<ConfigurationEntry> 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<ConfigurationEntry> 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<ConfigurationEntry> 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;
|
||||
}
|
||||
|
||||
@ -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<ConfigurationEntry> 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<ConfigurationEntry> 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<ConfigurationEntry> 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;
|
||||
}
|
||||
}
|
||||
@ -197,7 +197,7 @@
|
||||
class="org.wso2.carbon.mdm.mobileservices.windows.services.wstep.util.MessageHandler"/>
|
||||
<bean id="jsonProvider" class="org.wso2.carbon.mdm.mobileservices.windows.common.util.GsonMessageBodyHandler"/>
|
||||
<bean id="configurationServiceBean"
|
||||
class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.ConfigurationMgtService"/>
|
||||
class="org.wso2.carbon.mdm.mobileservices.windows.services.configurationmgtservice.ConfigurationMgtServiceImpl"/>
|
||||
<bean id="policyServiceBean"
|
||||
class="org.wso2.carbon.mdm.mobileservices.windows.services.policymgtservice.PolicyMgtService"/>
|
||||
<bean id="errorHandler" class="org.wso2.carbon.mdm.mobileservices.windows.common.util.ErrorHandler"/>
|
||||
|
||||
@ -48,7 +48,18 @@
|
||||
<session-config>
|
||||
<session-timeout>60</session-timeout>
|
||||
</session-config>
|
||||
|
||||
<context-param>
|
||||
<param-name>isAdminService</param-name>
|
||||
<param-value>false</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-enabled</param-name>
|
||||
<param-value>true</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>managed-api-owner</param-name>
|
||||
<param-value>admin</param-value>
|
||||
</context-param>
|
||||
<context-param>
|
||||
<param-name>doAuthentication</param-name>
|
||||
<param-value>true</param-value>
|
||||
|
||||
@ -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) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user