dilanua 8 years ago
commit ed5af90c46

@ -44,7 +44,7 @@ var InitiateViewOption = null;
// error-callback
function () {
var defaultInnerHTML =
"<br><p class='fw-warning'>Device data may not have been updated. Please refresh to try again.<p>";
"<br><p class='small'><i class='fw-warning'></i>&nbsp;Device data may not have been updated. Please refresh to try again.<p>";
$(".panel-body").append(defaultInnerHTML);
}
);

@ -312,7 +312,7 @@ deviceModule = function () {
var url;
var license;
if (deviceType == "windows") {
url = devicemgtProps["httpURL"] + "/mdm-windows-agent/services/device/license";
url = devicemgtProps["httpURL"] + "/api/device-mgt/windows/v1.0/services/configuration/license";
} else if (deviceType == "ios") {
url = devicemgtProps["httpsURL"] + "/ios-enrollment/license/";
}

@ -63,7 +63,7 @@ if (platform != "Windows Phone") {
var status = restAPIResponse["status"];
if (status == 200) {
session.put("authenticatedUser", username);
session.put("windowsBinaryToken", parse(xmlHttpRequest["responseText"]).UserToken);
session.put("windowsBinaryToken", parse(restAPIResponse["responseText"]).UserToken);
response.sendRedirect(mdmProps["appContext"] + "enrollments/windows/license-agent");
} else if (status == 403) {
response.sendRedirect(mdmProps["appContext"] + "enrollments/windows/login-agent?error=auth-failed");

@ -36,10 +36,10 @@ if (platform != "Windows Phone") {
if (!authenticatedUser) {
response.sendRedirect(mdmProps["appContext"] + "enrollments/error/unintentional-request");
} else {
var enrollmentUtils = require("/modules/enrollments/util/utils.js")["methods"];
var Handlebars = require("/lib/handlebars-v2.0.0.js")["Handlebars"];
var enrollmentUtils = require("/app/modules/enrollments/util/utils.js")["methods"];
var Handlebars = require("/lib/modules/handlebars/handlebars-v2.0.0.js")["Handlebars"];
var template = Handlebars.compile(enrollmentUtils.
getResource("/modules/enrollments/windows/config/workplace-switch-request-template.hbs"));
getResource("/app/modules/enrollments/windows/config/workplace-switch-request-template.hbs"));
var windowsWorkplaceAppID = session.get("windowsWorkplaceAppID");
var windowsBinaryToken = session.get("windowsBinaryToken");

@ -263,6 +263,13 @@ public final class PluginConstants {
}
public static final int MULTI_STATUS_HTTP_CODE = 207;
}
public final class WindowsConstant {
public static final String DEVICE_TYPE_WINDOWS = "windows";
public static final String HEADER_CONTENT_TYPE = "Content-Type";
public static final String APPLICATION_JSON = "application/json";
}
/**
@ -282,6 +289,7 @@ public final class PluginConstants {
public static final String DEFAULT_AUTH_POLICY = "Federated";
}
/**
* Policy Configuration related constants.
*/

@ -0,0 +1,86 @@
/*
* Copyright (c) 2016, 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.device.mgt.mobile.windows.api.common.beans;
import java.util.ArrayList;
import java.util.List;
public class ErrorDTO {
private Long code = null;
private String message = null;
private String description = null;
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
public void setCode(Long code) {
this.code = code;
}
public void setMessage(String message) {
this.message = message;
}
public void setDescription(String description) {
this.description = description;
}
public void setError(List<ErrorDTO> error) {
this.error = error;
}
private String moreInfo = null;
public String getMessage() {
return message;
}
public Long getCode() {
return code;
}
public String getDescription() {
return description;
}
public String getMoreInfo() {
return moreInfo;
}
public List<ErrorDTO> getError() {
return error;
}
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("class ErrorDTO {\n");
stringBuilder.append(" code: ").append(code).append("\n");
stringBuilder.append(" message: ").append(message).append("\n");
stringBuilder.append(" description: ").append(description).append("\n");
stringBuilder.append(" moreInfo: ").append(moreInfo).append("\n");
stringBuilder.append(" error: ").append(error).append("\n");
stringBuilder.append("}\n");
return stringBuilder.toString();
}
private List<ErrorDTO> error = new ArrayList<>();
}

@ -0,0 +1,77 @@
/*
* Copyright (c) 2016, 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.device.mgt.mobile.windows.api.common.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import javax.validation.constraints.NotNull;
@ApiModel(description = "")
public class ErrorListItem {
@NotNull
private String code = null;
@NotNull
private String message = null;
@ApiModelProperty(required = true, value = "")
@JsonProperty("code")
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public ErrorListItem() {}
public ErrorListItem(String code, String msg) {
this.code = code;
this.message = msg;
}
/**
* Description about individual errors occurred
**/
@ApiModelProperty(required = true, value = "Description about individual errors occurred")
@JsonProperty("message")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@Override
public String toString() {
StringBuilder sb = new StringBuilder();
sb.append("errorItem {\n");
sb.append(" code: ").append(code).append("\n");
sb.append(" message: ").append(message).append("\n");
sb.append("}\n");
return sb.toString();
}
}

@ -0,0 +1,167 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.common.beans;
import com.fasterxml.jackson.annotation.JsonProperty;
import io.swagger.annotations.ApiModelProperty;
import java.util.ArrayList;
import java.util.List;
public class ErrorResponse {
private Long code = null;
private String message = null;
private String description = null;
private String moreInfo = null;
private List<ErrorListItem> errorItems = new ArrayList<>();
@JsonProperty(value = "code")
@ApiModelProperty(required = true, value = "")
public Long getCode() {
return code;
}
public void setCode(Long code) {
this.code = code;
}
@JsonProperty(value = "message")
@ApiModelProperty(required = true, value = "ErrorResponse message.")
public String getMessage() {
return message;
}
public void setMessage(String message) {
this.message = message;
}
@JsonProperty(value = "description")
@ApiModelProperty(value = "A detail description about the error message.")
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
@JsonProperty(value = "moreInfo")
@ApiModelProperty(value = "Preferably an url with more details about the error.")
public String getMoreInfo() {
return moreInfo;
}
public void setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
}
public void addErrorListItem(ErrorListItem item) {
this.errorItems.add(item);
}
/**
* If there are more than one error list them out. \nFor example, list out validation errors by each field.
*/
@JsonProperty(value = "errorItems")
@ApiModelProperty(value = "If there are more than one error list them out. \n" +
"For example, list out validation errors by each field.")
public List<ErrorListItem> getErrorItems() {
return errorItems;
}
public void setErrorItems(List<ErrorListItem> error) {
this.errorItems = error;
}
@Override
public String toString() {
// StringBuilder sb = new StringBuilder();
// sb.append("{");
// boolean cont = false;
// if (code != null) {
// cont = true;
// sb.append(" \"code\": ").append(code);
// }
// if (message != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"message\": \"").append(message).append("\"");
// }
// if (description != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"description\": ").append(description).append("\"");
// }
// if (moreInfo != null) {
// if (cont) {
// sb.append(",");
// }
// cont = true;
// sb.append(" \"moreInfo\": \"").append(moreInfo).append("\"");
// }
// if (error != null && error.size() > 0) {
// if (cont) {
// sb.append(",");
// }
// sb.append(" \"errorItems\": ").append(error);
// }
// sb.append("}");
// return sb.toString();
return null;
}
public static class ErrorResponseBuilder {
private Long code = null;
private String message = null;
private String description = null;
private String moreInfo = null;
private List<ErrorListItem> error;
public ErrorResponseBuilder() {
this.error = new ArrayList<>();
}
public ErrorResponseBuilder setCode(long code) {
this.code = code;
return this;
}
public ErrorResponseBuilder setMessage(String message) {
this.message = message;
return this;
}
public ErrorResponseBuilder setDescription(String description) {
this.description = description;
return this;
}
public ErrorResponseBuilder setMoreInfo(String moreInfo) {
this.moreInfo = moreInfo;
return this;
}
public ErrorResponseBuilder addErrorItem(String code, String msg) {
ErrorListItem item = new ErrorListItem();
item.setCode(code);
item.setMessage(msg);
this.error.add(item);
return this;
}
public ErrorResponse build() {
ErrorResponse errorResponse = new ErrorResponse();
errorResponse.setCode(code);
errorResponse.setMessage(message);
errorResponse.setErrorItems(error);
errorResponse.setDescription(description);
errorResponse.setMoreInfo(moreInfo);
return errorResponse;
}
}
}

@ -18,10 +18,9 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
@ -29,8 +28,7 @@ import javax.ws.rs.core.Response;
*/
public class BadRequestException extends WebApplicationException {
public BadRequestException(Message message, MediaType mediaType) {
super(Response.status(Response.Status.BAD_REQUEST).entity(message).
type(mediaType).build());
public BadRequestException(ErrorResponse error) {
super(Response.status(Response.Status.BAD_REQUEST).entity(error).build());
}
}

@ -0,0 +1,49 @@
/*
* Copyright (c) 2016, 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.device.mgt.mobile.windows.api.common.exceptions;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorDTO;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.Response;
public class UnexpectedServerErrorException extends WebApplicationException {
private String message;
private static final long serialVersionUID = 147943579458906890L;
public UnexpectedServerErrorException(ErrorResponse error) {
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build());
}
public UnexpectedServerErrorException(ErrorDTO errorDTO) {
super(Response.status(Response.Status.INTERNAL_SERVER_ERROR)
.entity(errorDTO)
.header(PluginConstants.WindowsConstant.HEADER_CONTENT_TYPE, PluginConstants.WindowsConstant.APPLICATION_JSON)
.build());
message = errorDTO.getDescription();
}
@Override
public String getMessage() {
return message;
}
}

@ -18,18 +18,24 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.common.util;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
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.notification.mgt.NotificationManagementService;
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException;
import org.wso2.carbon.identity.core.util.IdentityTenantUtil;
import org.wso2.carbon.identity.oauth2.OAuth2TokenValidationService;
import org.wso2.carbon.policy.mgt.core.PolicyManagerService;
@ -42,6 +48,7 @@ import org.wso2.carbon.webapp.authenticator.framework.config.AuthenticatorConfig
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.ArrayList;
import java.util.List;
/**
@ -49,6 +56,8 @@ import java.util.List;
*/
public class WindowsAPIUtils {
private static Log log = LogFactory.getLog(WindowsAPIUtils.class);
public static DeviceIdentifier convertToDeviceIdentifierObject(String deviceId) {
DeviceIdentifier identifier = new DeviceIdentifier();
identifier.setId(deviceId);
@ -87,21 +96,25 @@ public class WindowsAPIUtils {
return responseMediaType;
}
public static Response getOperationResponse(List<String> deviceIDs, Operation operation,
Message message, MediaType responseMediaType)
throws DeviceManagementException, OperationManagementException {
WindowsDeviceUtils deviceUtils = new WindowsDeviceUtils();
DeviceIDHolder deviceIDHolder = deviceUtils.validateDeviceIdentifiers(deviceIDs,
message, responseMediaType);
// getDeviceManagementService().addOperation(operation, deviceIDHolder.getValidDeviceIDList());
if (!deviceIDHolder.getInvalidDeviceIdList().isEmpty()) {
return Response.status(PluginConstants.StatusCodes.
MULTI_STATUS_HTTP_CODE).type(
responseMediaType).entity(deviceUtils.
convertErrorMapIntoErrorMessage(deviceIDHolder.getInvalidDeviceIdList())).build();
public static Response getOperationResponse(List<String> deviceIDs, Operation operation)
throws DeviceManagementException, OperationManagementException, InvalidDeviceException {
if (deviceIDs == null || deviceIDs.size() == 0) {
String errorMessage = "Device identifier list is empty";
log.error(errorMessage);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
DeviceIdentifier deviceIdentifier;
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
for (String deviceId : deviceIDs) {
deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceId);
deviceIdentifier.setType(PluginConstants.WindowsConstant.DEVICE_TYPE_WINDOWS);
deviceIdentifiers.add(deviceIdentifier);
}
return Response.status(Response.Status.CREATED).
type(responseMediaType).build();
Activity activity = getDeviceManagementService().addOperation(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS, operation, deviceIdentifiers);
return Response.status(Response.Status.CREATED).entity(activity).build();
}
public static PolicyManagerService getPolicyManagerService() {
@ -126,8 +139,8 @@ public class WindowsAPIUtils {
throws OperationManagementException, DeviceManagementException {
List<? extends Operation> pendingDataOperations;
pendingDataOperations = org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils.
getDeviceManagementService().getOperationsByDeviceAndStatus(
deviceIdentifier, Operation.Status.PENDING);
getDeviceManagementService().getOperationsByDeviceAndStatus(
deviceIdentifier, Operation.Status.PENDING);
return pendingDataOperations;
}

@ -1,86 +0,0 @@
/*
* Copyright (c) 2016, 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.device.mgt.mobile.windows.api.common.util;
import org.apache.commons.lang.StringUtils;
import org.wso2.carbon.device.mgt.common.Device;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementConstants;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException;
import javax.ws.rs.core.MediaType;
import java.util.ArrayList;
import java.util.List;
/**
* Class for get windows device utilities.
*/
public class WindowsDeviceUtils {
private static final String COMMA_SEPARATION_PATTERN = ", ";
public DeviceIDHolder validateDeviceIdentifiers(List<String> deviceIDs,
Message message, MediaType responseMediaType) {
if (deviceIDs == null) {
message.setResponseMessage("Device identifier list is empty");
throw new BadRequestException(message, responseMediaType);
}
List<String> errorDeviceIdList = new ArrayList<>();
List<DeviceIdentifier> validDeviceIDList = new ArrayList<>();
int deviceIDCounter = 0;
for (String deviceID : deviceIDs) {
deviceIDCounter++;
if (deviceID == null || deviceID.isEmpty()) {
errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_NOT_FOUND,
deviceIDCounter));
continue;
}
try {
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
deviceIdentifier.setId(deviceID);
deviceIdentifier.setType(DeviceManagementConstants.MobileDeviceTypes.
MOBILE_DEVICE_TYPE_WINDOWS);
Device device = WindowsAPIUtils.getDeviceManagementService().
getDevice(deviceIdentifier);
if (device == null || device.getDeviceIdentifier() == null ||
device.getDeviceIdentifier().isEmpty()) {
errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_NOT_FOUND,
deviceIDCounter));
continue;
}
validDeviceIDList.add(deviceIdentifier);
} catch (DeviceManagementException e) {
errorDeviceIdList.add(String.format(PluginConstants.DeviceConstants.DEVICE_ID_SERVICE_NOT_FOUND,
deviceIDCounter));
}
}
DeviceIDHolder deviceIDHolder = new DeviceIDHolder();
deviceIDHolder.setValidDeviceIDList(validDeviceIDList);
deviceIDHolder.setInvalidDeviceIdList(errorDeviceIdList);
return deviceIDHolder;
}
public String convertErrorMapIntoErrorMessage(List<String> errorDeviceIdList) {
return StringUtils.join(errorDeviceIdList.iterator(), COMMA_SEPARATION_PATTERN);
}
}

@ -18,7 +18,7 @@
package org.wso2.carbon.device.mgt.mobile.windows.api.services;
import io.swagger.annotations.Api;
import io.swagger.annotations.*;
import org.wso2.carbon.apimgt.annotations.api.API;
import org.wso2.carbon.apimgt.annotations.api.Permission;
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
@ -27,6 +27,8 @@ import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
import javax.jws.WebService;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
/**
* Windows Platform Configuration REST-API implementation.
@ -42,25 +44,47 @@ import javax.ws.rs.*;
@Produces({"application/json", "application/xml"})
@Consumes({"application/json", "application/xml"})
public interface ConfigurationMgtService {
/**
* Save Tenant configurations.
*
* @param configuration Tenant Configurations to be saved.
* @return Message type object for the provide save status.
* @throws WindowsConfigurationException
*/
@POST
@Permission(name = "Manage Configurations", permission = "/device-mgt/platform-configurations/manage")
Message ConfigureSettings(PlatformConfiguration configuration) throws WindowsConfigurationException;
/**
* Retrieve Tenant configurations according to the device type.
*
* @return Tenant configuration object contains specific tenant configurations.
* @throws WindowsConfigurationException
*/
@GET
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",
value = "Getting Windows Platform Configurations",
notes = "Get the Windows platform configuration details using this REST API",
response = PlatformConfiguration.class,
tags = "Windows Configuration Management"
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched Windows platform configuration.",
response = PlatformConfiguration.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "Content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching Windows platform configuration.")
})
@Permission(name = "View Configurations", permission = "/device-mgt/platform-configurations/view")
PlatformConfiguration getConfiguration() throws WindowsConfigurationException;
@ -72,6 +96,98 @@ public interface ConfigurationMgtService {
* @throws WindowsConfigurationException
*/
@PUT
@Permission(name = "Manage Configurations", permission = "/device-mgt/platform-configurations/manage")
Message updateConfiguration(PlatformConfiguration configuration) throws WindowsConfigurationException;
@ApiOperation(
consumes = MediaType.APPLICATION_JSON,
produces = MediaType.APPLICATION_JSON,
httpMethod = "PUT",
value = "Updating Windows Platform Configuration.",
notes = "Update the Windows platform configurations using this REST API.",
tags = "Windows Configuration Management"
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Windows platform configuration has been updated successfully",
responseHeaders = {
@ResponseHeader(
name = "Content-Location",
description = "URL of the updated Windows platform configuration."),
@ResponseHeader(
name = "Content-Type",
description = "Content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests.")}),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The entity of the request was in a not supported format."),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while modifying Windows platform configuration.")
})
@Permission(name = "Manage Configurations", permission = "/device-mgt/configurations/manage")
Message updateConfiguration( @ApiParam(name = "configuration",
value = "PlatformConfiguration")PlatformConfiguration configuration) throws WindowsConfigurationException;
@GET
@Path("license")
@Produces(MediaType.TEXT_PLAIN)
@ApiOperation(
produces = MediaType.TEXT_PLAIN,
httpMethod = "GET",
value = "Getting the License Agreement for Windows Device Registration",
notes = "Use this REST API to retrieve the license agreement that is used for the Windows device " +
"registration process",
response = String.class,
tags = "Windows Configuration Management")
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully fetched Windows license configuration.",
response = String.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "Content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource has been modified the last time.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 304,
message = "Not Modified. \n Empty body because the client has already the latest version of the requested resource."),
@ApiResponse(
code = 404,
message = "Not Found. \n Resource to be deleted does not exist."),
@ApiResponse(
code = 406,
message = "Not Acceptable.\n The requested media type is not supported"),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n Server error occurred while fetching Windows license configuration.")
})
Response getLicense(
@ApiParam(
name = "If-Modified-Since",
value = "Validates if the requested variant has not been modified since the time specified",
required = false)
@HeaderParam("If-Modified-Since") String ifModifiedSince) throws WindowsConfigurationException;
}

@ -26,6 +26,8 @@ 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.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.UnexpectedServerErrorException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsConfigurationException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.WindowsAPIUtils;
@ -46,58 +48,6 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
private static Log log = LogFactory.getLog(
org.wso2.carbon.device.mgt.mobile.windows.api.services.impl.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.
*
@ -182,4 +132,24 @@ public class ConfigurationMgtServiceImpl implements ConfigurationMgtService {
}
return responseMsg;
}
@GET
@Path("/license")
public Response getLicense(
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
License license;
try {
license =
WindowsAPIUtils.getDeviceManagementService().getLicense(
DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_WINDOWS,
DeviceManagementConstants.LanguageCodes.LANGUAGE_CODE_ENGLISH_US);
} catch (DeviceManagementException e) {
String msg = "Error occurred while retrieving the license configured for Windows device enrolment";
log.error(msg, e);
throw new UnexpectedServerErrorException(
new ErrorResponse.ErrorResponseBuilder().setCode(500l).setMessage(msg).build());
}
return Response.status(Response.Status.OK).entity(license).build();
}
}

@ -22,10 +22,13 @@ import com.ibm.wsdl.OperationImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException;
import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.PluginConstants;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.beans.ErrorResponse;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.BadRequestException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsDeviceEnrolmentException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.exceptions.WindowsOperationsException;
import org.wso2.carbon.device.mgt.mobile.windows.api.common.util.Message;
@ -69,7 +72,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(PluginConstants.OperationCodes.DEVICE_LOCK);
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
message.setResponseMessage(errorMessage);
@ -82,6 +85,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
log.error(errorMessage, e);
throw new WindowsOperationsException(message, responseMediaType);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
}
@ -105,7 +113,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setType(Operation.Type.COMMAND);
operation.setEnabled(true);
try {
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
message.setResponseMessage(errorMessage);
@ -118,7 +126,12 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
log.error(errorMessage, e);
throw new WindowsOperationsException(message, responseMediaType);
}
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
}
/**
@ -143,7 +156,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
operation.setCode(PluginConstants.OperationCodes.WIPE_DATA);
operation.setType(Operation.Type.COMMAND);
try {
return WindowsAPIUtils.getOperationResponse(deviceids, operation, message, responseMediaType);
return WindowsAPIUtils.getOperationResponse(deviceids, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
message.setResponseMessage(errorMessage);
@ -156,6 +169,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
log.error(errorMessage, e);
throw new WindowsOperationsException(message, responseMediaType);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
}
@ -181,7 +199,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(PluginConstants.OperationCodes.DEVICE_RING);
operation.setType(Operation.Type.COMMAND);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
message.setResponseMessage(errorMessage);
@ -194,6 +212,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
log.error(errorMessage, e);
throw new WindowsOperationsException(message, responseMediaType);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
}
@ -224,7 +247,7 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
CommandOperation operation = new CommandOperation();
operation.setCode(PluginConstants.OperationCodes.LOCK_RESET);
operation.setType(Operation.Type.COMMAND);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation, message, responseMediaType);
return WindowsAPIUtils.getOperationResponse(deviceIDs, operation);
} catch (OperationManagementException e) {
String errorMessage = "Issue in retrieving operation management service instance";
message.setResponseMessage(errorMessage);
@ -237,6 +260,11 @@ public class DeviceManagementAdminServiceImpl implements DeviceManagementAdminSe
message.setResponseCode(Response.Status.INTERNAL_SERVER_ERROR.toString());
log.error(errorMessage, e);
throw new WindowsOperationsException(message, responseMediaType);
} catch (InvalidDeviceException e) {
String errorMessage = "Invalid Device Identifiers found.";
log.error(errorMessage, e);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setCode(400l).setMessage(errorMessage).build());
}
}
}

Loading…
Cancel
Save