From ddabbb7329e0d6f8847bc321e92def7b9cd5501f Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 9 Aug 2017 11:29:47 +0530 Subject: [PATCH 1/7] Add remote session service --- .../mgt/jaxrs/beans/RemoteSessionInfo.java | 52 +++++++ .../service/api/RemoteSessionService.java | 130 ++++++++++++++++++ .../impl/RemoteSessionServiceImpl.java | 68 +++++++++ .../src/main/webapp/WEB-INF/cxf-servlet.xml | 2 + .../core/config/DeviceManagementConfig.java | 11 ++ .../session/RemoteSessionConfiguration.java | 53 +++++++ .../mgt/dao/impl/ConfigOperationDAOImpl.java | 2 + .../devicemgt/app/conf/config.json | 1 + 8 files changed, 319 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RemoteSessionInfo.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RemoteSessionService.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RemoteSessionInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RemoteSessionInfo.java new file mode 100644 index 00000000000..34883532f12 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/RemoteSessionInfo.java @@ -0,0 +1,52 @@ +/* + * Copyright (c) 2017, 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.jaxrs.beans; + +import com.fasterxml.jackson.annotation.JsonProperty; +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; + +import java.util.List; + +@ApiModel(value = "RemoteSessionInfo", description = "Template of the remote session") +public class RemoteSessionInfo { + + @ApiModelProperty(name = "Server Url", value = "Url of the remote session server.", required = true) + private String serverUrl; + + @ApiModelProperty(name = "isEnabled", value = "Is remote session functionality enabled", required = true) + private Boolean isEnabled; + + public String getServerUrl() { + return serverUrl; + } + + public void setServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + } + + public Boolean getEnabled() { + return isEnabled; + } + + public void setEnabled(Boolean enabled) { + isEnabled = enabled; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RemoteSessionService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RemoteSessionService.java new file mode 100644 index 00000000000..52c0eaf7f23 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RemoteSessionService.java @@ -0,0 +1,130 @@ +/* + * Copyright (c) 2017, 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.jaxrs.service.api; + +import io.swagger.annotations.Api; +import io.swagger.annotations.ApiOperation; +import io.swagger.annotations.ApiParam; +import io.swagger.annotations.ApiResponse; +import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; +import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; + +import javax.validation.constraints.Size; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.core.Response; + +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "remote_session_services"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/remote-session-services"), + }) + } + ), + tags = { + @Tag(name = "device_management", description = "") + } +) +@Scopes( + scopes = { + @Scope( + name = "Remote Session Connection", + description = "", + key = "perm:remote-session-service:connect", + permissions = {"/device-mgt/devices/owning-device/remote-session"} + ) + } +) +@Path("/remote-session-services") +@Api(value = "Remote Session Service", + description = "This carries all the resources related to the remote session service functionality.") +public interface RemoteSessionService { + /** + * Retrieve Analytics for the device type + */ + @GET + @Path("connection/{deviceType}/{deviceId}") + @ApiOperation( + consumes = "application/json", + produces = "application/json", + httpMethod = "GET", + value = "Retrieve Connection Information for the device type", + notes = "", + response = Response.class, + tags = "Remote Session Service Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:remote-session-service:connect") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK.", + response = Response.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid Device Identifiers found.", + response = Response.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Unauthorized request."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Error on retrieving stats", + response = Response.class) + }) + Response getRemoteSessionDeviceConnect( + @ApiParam( + name = "deviceId", + value = "The registered device Id.", + required = true) + @PathParam("deviceId") String deviceId, + @ApiParam( + name = "device-type", + value = "The device type, such as ios, android or windows.", + required = true) + @PathParam("deviceType") + @Size(max = 45) + String deviceType); +} \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java new file mode 100644 index 00000000000..b25318a4b01 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2017, 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.jaxrs.service.impl; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.config.remote.session.RemoteSessionConfiguration; +import org.wso2.carbon.device.mgt.jaxrs.beans.RemoteSessionInfo; +import org.wso2.carbon.device.mgt.jaxrs.service.api.RemoteSessionService; + +import javax.ws.rs.Consumes; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.core.Response; + +/** + * The api for + */ +public class RemoteSessionServiceImpl implements RemoteSessionService { + + private static Log log = LogFactory.getLog(RemoteSessionServiceImpl.class); + + @Path("connect/{deviceType}/{deviceId}") + @GET + @Consumes("application/json") + @Produces("application/json") + public Response getRemoteSessionDeviceConnect(@PathParam("deviceId") String deviceId, + @PathParam("deviceType") String deviceType) { + //First, check whether the remote session is enabled. + RemoteSessionInfo sessionInfo = new RemoteSessionInfo(); + sessionInfo.setEnabled(false); + DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance() + .getDeviceManagementConfig(); + if (deviceManagementConfig != null) { + RemoteSessionConfiguration remoteSessionConfiguration = deviceManagementConfig.getRemoteSessionConfiguration(); + if (remoteSessionConfiguration != null) { + boolean isEnabled = remoteSessionConfiguration.getIsEnabled(); + sessionInfo.setEnabled(isEnabled); + if (isEnabled) { + sessionInfo.setServerUrl(remoteSessionConfiguration.getRemoteSessionServerUrl()); + } + return Response.ok().entity(sessionInfo).build(); + } + } + + return Response.ok().entity(sessionInfo).build(); + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index b59be7cf4ff..482544fabcb 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -38,6 +38,7 @@ + @@ -81,6 +82,7 @@ + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index 5d757f4f0bf..ae47eaf6a54 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -24,6 +24,7 @@ import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.config.pull.notification.PullNotificationConfiguration; import org.wso2.carbon.device.mgt.core.config.push.notification.PushNotificationConfiguration; +import org.wso2.carbon.device.mgt.core.config.remote.session.RemoteSessionConfiguration; import org.wso2.carbon.device.mgt.core.config.status.task.DeviceStatusTaskConfig; import org.wso2.carbon.device.mgt.core.config.task.TaskConfiguration; @@ -48,6 +49,8 @@ public final class DeviceManagementConfig { private DeviceCacheConfiguration deviceCacheConfiguration; private GeoLocationConfiguration geoLocationConfiguration; private String defaultGroupsConfiguration; + private RemoteSessionConfiguration remoteSessionConfiguration; + @XmlElement(name = "ManagementRepository", required = true) public DeviceManagementConfigRepository getDeviceManagementConfigRepository() { @@ -148,5 +151,13 @@ public final class DeviceManagementConfig { public void setDefaultGroupsConfiguration(String defaultGroupsConfiguration) { this.defaultGroupsConfiguration = defaultGroupsConfiguration; } + @XmlElement(name = "RemoteSessionConfiguration", required = true) + public RemoteSessionConfiguration getRemoteSessionConfiguration() { + return remoteSessionConfiguration; + } + + public void setRemoteSessionConfiguration(RemoteSessionConfiguration remoteSessionConfiguration) { + this.remoteSessionConfiguration = remoteSessionConfiguration; + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java new file mode 100644 index 00000000000..e422d979451 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2017, 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.core.config.remote.session; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * This class represents the information related to Remote Session configuration. + */ +@XmlRootElement(name = "RemoteSessionConfiguration") +public class RemoteSessionConfiguration { + + private String remoteSessionServerUrl; + private boolean isEnabled; + + @XmlElement(name = "RemoteSessionServerUrl", required = true) + public void setRemoteSessionServerUrl(String remoteSessionServerUrl) { + this.remoteSessionServerUrl = remoteSessionServerUrl; + } + + public String getRemoteSessionServerUrl() { + return remoteSessionServerUrl; + } + + public boolean getIsEnabled() { + return isEnabled; + } + + @XmlElement(name = "isEnabled", required = true) + public void setEnabled(boolean enabled) { + isEnabled = enabled; + } + +} + + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java index 30200969720..6cf2c43f9cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/impl/ConfigOperationDAOImpl.java @@ -32,6 +32,7 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.sql.Timestamp; import java.util.ArrayList; import java.util.List; @@ -45,6 +46,7 @@ public class ConfigOperationDAOImpl extends GenericOperationDAOImpl { PreparedStatement stmt = null; try { operationId = super.addOperation(operation); + operation.setCreatedTimeStamp(new Timestamp(new java.util.Date().getTime()).toString()); Connection conn = OperationManagementDAOFactory.getConnection(); stmt = conn.prepareStatement("INSERT INTO DM_CONFIG_OPERATION(OPERATION_ID, OPERATION_CONFIG) VALUES(?, ?)"); stmt.setInt(1, operationId); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json index 2e85a4798b0..5146f6c7c72 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/conf/config.json @@ -5,6 +5,7 @@ "httpsURL": "https://%iot.gateway.host%:%iot.gateway.https.port%", "httpURL": "http://%iot.gateway.host%:%iot.gateway.http.port%", "wssURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", + "remoteSessionWSURL": "https://%iot.core.host%:%iot.core.https.port%", "portalURL": "https://%iot.analytics.host%:%iot.analytics.https.port%", "dashboardServerURL": "%https.ip%", "androidEnrollmentDir": "/android-web-agent/enrollment", From fbe3ffe7ef327a3c96faeb53f7b2e3f31934e562 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Wed, 9 Aug 2017 11:51:50 +0530 Subject: [PATCH 2/7] Add set control based on operation information --- .../mgt/dao/util/OperationDAOUtil.java | 39 ++++++++++++------- 1 file changed, 24 insertions(+), 15 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java index 5262fe2e2b6..ff402f7e977 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/operation/mgt/dao/util/OperationDAOUtil.java @@ -22,7 +22,11 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationResponse; import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; -import org.wso2.carbon.device.mgt.core.dto.operation.mgt.*; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.CommandOperation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ConfigOperation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.Operation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.PolicyOperation; +import org.wso2.carbon.device.mgt.core.dto.operation.mgt.ProfileOperation; import java.io.ByteArrayInputStream; import java.io.IOException; @@ -32,6 +36,7 @@ import java.sql.SQLException; public class OperationDAOUtil { private static final Log log = LogFactory.getLog(OperationDAOUtil.class); + public static Operation convertOperation(org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation) { Operation dtoOperation = null; @@ -40,28 +45,28 @@ public class OperationDAOUtil { dtoOperation = new CommandOperation(); } else if (operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.PROFILE)) { dtoOperation = new ProfileOperation(); - }else if(operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY)){ + } else if (operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.POLICY)) { dtoOperation = new PolicyOperation(); - }else if(operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.CONFIG)) { + } else if (operation.getType().equals(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.CONFIG)) { dtoOperation = new ConfigOperation(); - }else{ + } else { dtoOperation = new Operation(); } dtoOperation.setEnabled(operation.isEnabled()); dtoOperation.setCode(operation.getCode()); - if (operation.getType() != null){ + if (operation.getType() != null) { dtoOperation.setType(Operation.Type.valueOf(operation.getType().toString())); - }else{ + } else { dtoOperation.setType(null); } dtoOperation.setCreatedTimeStamp(operation.getCreatedTimeStamp()); - if (operation.getStatus() != null){ + if (operation.getStatus() != null) { dtoOperation.setStatus(Operation.Status.valueOf(operation.getStatus().toString())); - }else{ + } else { dtoOperation.setStatus(null); } @@ -70,31 +75,35 @@ public class OperationDAOUtil { dtoOperation.setReceivedTimeStamp(operation.getReceivedTimeStamp()); dtoOperation.setProperties(operation.getProperties()); + if (operation.getControl() != null) { + dtoOperation.setControl(Operation.Control.valueOf(operation.getControl().toString())); + } + return dtoOperation; } - public static org.wso2.carbon.device.mgt.common.operation.mgt.Operation convertOperation(Operation dtoOperation){ + public static org.wso2.carbon.device.mgt.common.operation.mgt.Operation convertOperation(Operation dtoOperation) { org.wso2.carbon.device.mgt.common.operation.mgt.Operation operation = null; - - if (dtoOperation.getType().equals(Operation.Type.COMMAND)){ + + if (dtoOperation.getType().equals(Operation.Type.COMMAND)) { operation = new org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation(); - }else if(dtoOperation.getType().equals(Operation.Type.PROFILE)){ + } else if (dtoOperation.getType().equals(Operation.Type.PROFILE)) { operation = new org.wso2.carbon.device.mgt.core.operation.mgt.ProfileOperation(); - }else{ + } else { operation = new org.wso2.carbon.device.mgt.common.operation.mgt.Operation(); } operation.setEnabled(dtoOperation.isEnabled()); operation.setCode(dtoOperation.getCode()); - if(dtoOperation.getType() != null) { + if (dtoOperation.getType() != null) { operation.setType(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Type.valueOf(dtoOperation .getType().toString())); } operation.setCreatedTimeStamp(dtoOperation.getCreatedTimeStamp()); - if(dtoOperation.getStatus() != null) { + if (dtoOperation.getStatus() != null) { operation.setStatus(org.wso2.carbon.device.mgt.common.operation.mgt.Operation.Status.valueOf(dtoOperation .getStatus().toString())); } From 72d29f0687b9087bd71c729c7c81f6a4e4f93420 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 1 Oct 2017 10:47:21 +0530 Subject: [PATCH 3/7] add km configurations to iot server --- .../keymanager/KeyManagerConfigurations.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/keymanager/KeyManagerConfigurations.java diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/keymanager/KeyManagerConfigurations.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/keymanager/KeyManagerConfigurations.java new file mode 100644 index 00000000000..b76f932e5b2 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/keymanager/KeyManagerConfigurations.java @@ -0,0 +1,59 @@ +/* + * Copyright (c) 2017, 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.core.config.keymanager; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +/** + * Configurations related to key management. + */ +@XmlRootElement(name = "KeyManagerConfiguration") +public class KeyManagerConfigurations { + private String serverUrl; + private String adminUsername; + private String adminPassword; + + @XmlElement(name = "AdminUsername", required = true) + public String getAdminUsername() { + return adminUsername; + } + + public void setAdminUsername(String adminUsername) { + this.adminUsername = adminUsername; + } + + @XmlElement(name = "AdminPassword", required = true) + public String getAdminPassword() { + return adminPassword; + } + + public void setAdminPassword(String adminPassword) { + this.adminPassword = adminPassword; + } + + @XmlElement(name = "ServerUrl", required = true) + public String getServerUrl() { + return serverUrl; + } + + public void setServerUrl(String serverUrl) { + this.serverUrl = serverUrl; + } + +} From 14478aa7a53f4d45be4b33f07afc355b865bfa97 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 1 Oct 2017 10:48:11 +0530 Subject: [PATCH 4/7] add remote session config service --- .../mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java | 2 +- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java index b25318a4b01..a972df9826e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RemoteSessionServiceImpl.java @@ -54,7 +54,7 @@ public class RemoteSessionServiceImpl implements RemoteSessionService { if (deviceManagementConfig != null) { RemoteSessionConfiguration remoteSessionConfiguration = deviceManagementConfig.getRemoteSessionConfiguration(); if (remoteSessionConfiguration != null) { - boolean isEnabled = remoteSessionConfiguration.getIsEnabled(); + boolean isEnabled = remoteSessionConfiguration.isEnabled(); sessionInfo.setEnabled(isEnabled); if (isEnabled) { sessionInfo.setServerUrl(remoteSessionConfiguration.getRemoteSessionServerUrl()); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml index 482544fabcb..e1e2c46e8ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/webapp/WEB-INF/cxf-servlet.xml @@ -81,7 +81,7 @@ - + @@ -101,4 +101,4 @@ - + \ No newline at end of file From 39794c19c1b1997ed42199207398692e3e610172 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 1 Oct 2017 10:48:41 +0530 Subject: [PATCH 5/7] add remote session configurations to cdm-config.xml --- .../src/main/resources/conf/cdm-config.xml | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index fbf6103cfff..153916b1cf8 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -46,6 +46,11 @@ admin admin + + https://localhost:9443 + admin + admin + org.wso2.carbon.policy.mgt true @@ -82,6 +87,16 @@ false false + + true + ws://localhost:9763 + 2 + 100 + 20 + 15 + 60 + 640 + BYOD,COPE From 62d0f3720eb8de94efa1ef730d47344b6882b260 Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 1 Oct 2017 10:49:51 +0530 Subject: [PATCH 6/7] add remote session configurations --- .../core/config/DeviceManagementConfig.java | 11 ++ .../session/RemoteSessionConfiguration.java | 102 ++++++++++++++++-- 2 files changed, 107 insertions(+), 6 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java index ae47eaf6a54..464980e3d7f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/DeviceManagementConfig.java @@ -20,6 +20,7 @@ package org.wso2.carbon.device.mgt.core.config; import org.wso2.carbon.device.mgt.core.config.geo.location.GeoLocationConfiguration; import org.wso2.carbon.device.mgt.core.config.cache.DeviceCacheConfiguration; import org.wso2.carbon.device.mgt.core.config.identity.IdentityConfigurations; +import org.wso2.carbon.device.mgt.core.config.keymanager.KeyManagerConfigurations; import org.wso2.carbon.device.mgt.core.config.pagination.PaginationConfiguration; import org.wso2.carbon.device.mgt.core.config.policy.PolicyConfiguration; import org.wso2.carbon.device.mgt.core.config.pull.notification.PullNotificationConfiguration; @@ -41,6 +42,7 @@ public final class DeviceManagementConfig { private DeviceManagementConfigRepository deviceManagementConfigRepository; private TaskConfiguration taskConfiguration; private IdentityConfigurations identityConfigurations; + private KeyManagerConfigurations keyManagerConfigurations; private PolicyConfiguration policyConfiguration; private PaginationConfiguration paginationConfiguration; private PushNotificationConfiguration pushNotificationConfiguration; @@ -71,6 +73,15 @@ public final class DeviceManagementConfig { this.identityConfigurations = identityConfigurations; } + @XmlElement(name = "KeyManagerConfiguration", required = true) + public KeyManagerConfigurations getKeyManagerConfigurations() { + return keyManagerConfigurations; + } + + public void setKeyManagerConfigurations(KeyManagerConfigurations keyManagerConfigurations) { + this.keyManagerConfigurations = keyManagerConfigurations; + } + @XmlElement(name = "PolicyConfiguration", required = true) public PolicyConfiguration getPolicyConfiguration() { return policyConfiguration; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java index e422d979451..426e2db3080 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/config/remote/session/RemoteSessionConfiguration.java @@ -28,26 +28,116 @@ import javax.xml.bind.annotation.XmlRootElement; public class RemoteSessionConfiguration { private String remoteSessionServerUrl; - private boolean isEnabled; + private boolean enabled; + private int maxHTTPConnectionPerHost; + private int maxTotalHTTPConnections; + private int maxMessagesPerSecond; + private int sessionIdleTimeOut; + private int maxSessionDuration; + private int sessionBufferSize; - @XmlElement(name = "RemoteSessionServerUrl", required = true) public void setRemoteSessionServerUrl(String remoteSessionServerUrl) { this.remoteSessionServerUrl = remoteSessionServerUrl; } + /** + * Remote session server url + * @return + */ + @XmlElement(name = "RemoteSessionServerUrl", required = true) public String getRemoteSessionServerUrl() { return remoteSessionServerUrl; } - public boolean getIsEnabled() { - return isEnabled; + /** + * Remote session enabled + * @return + */ + @XmlElement(name = "Enabled", required = true) + public boolean isEnabled() { + return enabled; } - @XmlElement(name = "isEnabled", required = true) public void setEnabled(boolean enabled) { - isEnabled = enabled; + this.enabled = enabled; + } + + /** + * Maximum connections per host for external http invocations + * @return + */ + @XmlElement(name = "MaximumHTTPConnectionPerHost", required = true, defaultValue = "2") + public int getMaxHTTPConnectionPerHost() { + return maxHTTPConnectionPerHost; } + public void setMaxHTTPConnectionPerHost(int maxHTTPConnectionPerHost) { + this.maxHTTPConnectionPerHost = maxHTTPConnectionPerHost; + } + + /** + * Maximum total connections for external http invocation + */ + @XmlElement(name = "MaximumTotalHTTPConnections", required = true, defaultValue = "100") + public int getMaxTotalHTTPConnections() { + return maxTotalHTTPConnections; + } + + public void setMaxTotalHTTPConnections(int maxTotalHTTPConnections) { + this.maxTotalHTTPConnections = maxTotalHTTPConnections; + } + + /** + * This is for protect device from message spamming. Throttling limit in term of messages for device + * @return + */ + @XmlElement(name = "MaximumMessagesPerSecond", required = true, defaultValue = "10") + public int getMaxMessagesPerSession() { + return maxMessagesPerSecond; + } + + public void setMaxMessagesPerSession(int maxMessagesPerSession) { + this.maxMessagesPerSecond = maxMessagesPerSession; + } + + /** + * Maximum idle timeout in minutes + * @return + */ + @XmlElement(name = "SessionIdleTimeOut", required = true, defaultValue = "5") + public int getSessionIdleTimeOut() { + return sessionIdleTimeOut; + } + + public void setSessionIdleTimeOut(int sessionIdleTimeOut) { + this.sessionIdleTimeOut = sessionIdleTimeOut; + } + + /** + * Maximum session duration in minutes + * @return + */ + @XmlElement(name = "MaximumSessionDuration", required = true, defaultValue = "15") + public int getMaxSessionDuration() { + return maxSessionDuration; + } + + public void setMaxSessionDuration(int maxSessionDuration) { + this.maxSessionDuration = maxSessionDuration; + } + + /** + * Maximum session buffer size in kilo bytes + * @return + */ + @XmlElement(name = "SessionBufferSize", required = true, defaultValue = "640") + public int getSessionBufferSize() { + return sessionBufferSize; + } + + public void setSessionBufferSize(int sessionBufferSize) { + this.sessionBufferSize = sessionBufferSize; + } } From bbcba7380c894cadfcd019411937d4366ced3abf Mon Sep 17 00:00:00 2001 From: warunalakshitha Date: Sun, 15 Oct 2017 19:44:04 +0530 Subject: [PATCH 7/7] change config to wss --- .../src/main/resources/conf/cdm-config.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml index c63d1a003ba..c4c12e60627 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/src/main/resources/conf/cdm-config.xml @@ -98,7 +98,7 @@ true - ws://localhost:9763 + wss://localhost:9443 2 100 20