From 795ccb740cdf60b76e549694d175b4b66fa80e94 Mon Sep 17 00:00:00 2001 From: charitha Date: Tue, 20 Dec 2016 23:46:55 +0530 Subject: [PATCH 1/8] Add backend support for enrollment invitations --- .../impl/UserManagementServiceImpl.java | 29 ++++++- .../mgt/core/DeviceManagementConstants.java | 3 + .../DeviceManagementProviderService.java | 2 +- .../DeviceManagementProviderServiceImpl.java | 12 ++- .../mgt/core/service/EmailMetaInfo.java | 17 +++- .../email/templates/user-enrollment.vm | 71 ++++++++++++++++ .../email/templates/user-registration.vm | 81 +++++++++++++++++++ 7 files changed, 205 insertions(+), 10 deletions(-) create mode 100644 features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm create mode 100644 features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 1b527337c8f..807a9e53f8d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -23,9 +23,15 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder; import org.wso2.carbon.device.mgt.common.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; -import org.wso2.carbon.device.mgt.jaxrs.beans.*; +import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo; +import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; +import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo; import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.Constants; @@ -34,14 +40,28 @@ import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; -import javax.ws.rs.*; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; import java.security.SecureRandom; -import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Properties; @Path("/users") @Produces(MediaType.APPLICATION_JSON) @@ -462,7 +482,8 @@ public class UserManagementServiceImpl implements UserManagementService { props.setProperty("username", username); EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props); - dms.sendEnrolmentInvitation(metaInfo); + dms.sendEnrolmentInvitation(DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE, + metaInfo); } } catch (DeviceManagementException e) { String msg = "Error occurred while inviting user to enrol their device"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 2b5398fb88c..6351c402e78 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -75,6 +75,9 @@ public final class DeviceManagementConstants { public static final String SERVER_BASE_URL_HTTPS = "base-url-https"; public static final String SERVER_BASE_URL_HTTP = "base-url-http"; public static final String DOWNLOAD_URL = "download-url"; + + public static final String USER_REGISTRATION_TEMPLATE = "user-registration"; + public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment"; } public static final class OperationAttributes { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java index 33bd6c0607b..ed1e9abec32 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderService.java @@ -81,7 +81,7 @@ public interface DeviceManagementProviderService { */ PaginationResult getAllDevices(PaginationRequest request) throws DeviceManagementException; - void sendEnrolmentInvitation(EmailMetaInfo metaInfo) throws DeviceManagementException; + void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException; void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 210b0927cb3..c4cb2189599 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -50,6 +50,7 @@ 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.common.spi.DeviceManagementService; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; import org.wso2.carbon.device.mgt.core.DeviceManagementPluginRepository; import org.wso2.carbon.device.mgt.core.dao.ApplicationDAO; import org.wso2.carbon.device.mgt.core.dao.DeviceDAO; @@ -752,7 +753,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } @Override - public void sendEnrolmentInvitation(EmailMetaInfo metaInfo) throws DeviceManagementException { + public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException { Map, Object>> params = new HashMap<>(); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME, new TypedValue, Object>(String.class, metaInfo.getProperty("first-name"))); @@ -762,8 +763,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); try { EmailContext ctx = - new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-enrollment", params), - metaInfo.getRecipients()).build(); + new EmailContext.EmailContextBuilder(new ContentProviderInfo(templateName, params), + metaInfo.getRecipients()).build(); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); } catch (EmailSendingFailedException e) { throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); @@ -787,7 +788,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpUrl())); try { EmailContext ctx = - new EmailContext.EmailContextBuilder(new ContentProviderInfo("user-registration", params), + new EmailContext.EmailContextBuilder( + new ContentProviderInfo( + DeviceManagementConstants.EmailAttributes.USER_REGISTRATION_TEMPLATE, + params), metaInfo.getRecipients()).build(); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); } catch (EmailSendingFailedException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java index c5ac4af2672..dc5ea8db1e3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java @@ -18,13 +18,28 @@ */ package org.wso2.carbon.device.mgt.core.service; +import io.swagger.annotations.ApiModelProperty; + +import java.io.Serializable; import java.util.HashSet; import java.util.Properties; import java.util.Set; -public class EmailMetaInfo { +public class EmailMetaInfo implements Serializable { + private static final long serialVersionUID = 1998101711L; + @ApiModelProperty( + name = "recipients", + value = "Set of recipients.", + required = true + ) private Set recipients; + + @ApiModelProperty( + name = "properties", + value = "Map of properties.", + required = true + ) private Properties properties; public EmailMetaInfo(final Set recipients, final Properties properties) { diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm new file mode 100644 index 00000000000..12e2b666676 --- /dev/null +++ b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm @@ -0,0 +1,71 @@ +#* + 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. +*# + + You have been invited to enroll your device in WSO2 IoT + + + + WSO2 IoT Server + + +
+
+
+
+ WSO2 +
+
+
+

+ Hi $first-name, +

+ +

+ You have been invited to enrol your device in WSO2 IoT Server. + Click here to begin device enrolment.

+ +

+ Should you need assistance, please contact your administrator. +

+ +

+ Regards, +

+ +

+ WSO2 IoT Administrator +

+
+
+ + + + +
WSO2
+
+
+
+ + + ]]> + +
diff --git a/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm new file mode 100644 index 00000000000..fa1c03600d6 --- /dev/null +++ b/features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/user-registration.vm @@ -0,0 +1,81 @@ +#* + 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. +*# + + You have successfully been registered in WSO2 IoT + + + + WSO2 IoT Server + + +
+
+
+
+ WSO2 +
+
+
+

+ Hi $first-name, +

+ +

+ You have been registered in WSO2 IoT and invited to enrol your device. + Click here to begin device enrolment.

+ +

+ Use following credentials to log in to WSO2 IoT Device Management application. +

+ +

+ Username: $username +
+ Password: $password +

+ +

+ Should you need assistance, please contact your administrator. +

+ +

+ Regards, +

+ +

+ WSO2 IoT Administrator +

+
+
+ + + + +
WSO2
+
+
+
+ + + ]]> + +
From d486ad14fd90b083f1438adc495c6d5bee58ea9d Mon Sep 17 00:00:00 2001 From: madhawap Date: Thu, 22 Dec 2016 13:47:39 +0530 Subject: [PATCH 2/8] Task operation config related changes --- .../mgt/common/MonitoringOperation.java | 1 - .../common/OperationMonitoringTaskConfig.java | 2 +- .../DeviceManagementPluginRepository.java | 1 - .../DeviceTaskManagerServiceComponent.java | 19 +++--- .../DeviceManagementProviderServiceImpl.java | 10 +--- .../task/impl/DeviceDetailsRetrieverTask.java | 20 ++++++- .../core/task/impl/DeviceTaskManagerImpl.java | 42 ++++++------- .../impl/DeviceTaskManagerServiceImpl.java | 60 ++++++++++--------- 8 files changed, 83 insertions(+), 72 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MonitoringOperation.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MonitoringOperation.java index 7ce7000d815..8d5a8cc4341 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MonitoringOperation.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/MonitoringOperation.java @@ -42,6 +42,5 @@ public class MonitoringOperation { this.recurrentTimes = recurrentTimes; } - } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationMonitoringTaskConfig.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationMonitoringTaskConfig.java index ec50a02b6fb..237516b26ad 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationMonitoringTaskConfig.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/OperationMonitoringTaskConfig.java @@ -52,6 +52,6 @@ public class OperationMonitoringTaskConfig { public void setMonitoringOperation(List monitoringOperation) { this.monitoringOperation = monitoringOperation; - } + } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java index 9e2a81d5c38..ca32fa037b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementPluginRepository.java @@ -195,7 +195,6 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis } else { deviceTaskManagerService.startTask(deviceManagementService.getType(), operationMonitoringTaskConfig); - // TODO: In here a race condition can arise. Need to handle it. } } } catch (DeviceMgtTaskException e) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java index 7dab5413215..344d567f0f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/internal/DeviceTaskManagerServiceComponent.java @@ -58,11 +58,11 @@ public class DeviceTaskManagerServiceComponent { log.debug("Initializing device details retrieving task manager bundle."); } // This will start the device details retrieving task. -// DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl(); -// DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService( -// deviceTaskManagerService); -// componentContext.getBundleContext().registerService(DeviceTaskManagerService.class, -// deviceTaskManagerService, null); + // DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl(); + // DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService( + // deviceTaskManagerService); + // componentContext.getBundleContext().registerService(DeviceTaskManagerService.class, + // deviceTaskManagerService, null); getDeviceOperationMonitoringConfig(componentContext); @@ -76,12 +76,12 @@ public class DeviceTaskManagerServiceComponent { } } - private void getDeviceOperationMonitoringConfig(ComponentContext componentContext) throws DeviceMgtTaskException { + private void getDeviceOperationMonitoringConfig(ComponentContext componentContext) + throws DeviceMgtTaskException { DeviceTaskManagerService deviceTaskManagerService = new DeviceTaskManagerServiceImpl(); - DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService( - deviceTaskManagerService); + DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(deviceTaskManagerService); componentContext.getBundleContext().registerService(DeviceTaskManagerService.class, deviceTaskManagerService, null); @@ -89,11 +89,10 @@ public class DeviceTaskManagerServiceComponent { Map deviceConfigMap = DeviceMonitoringOperationDataHolder .getInstance().getOperationMonitoringConfigFromMap(); - for (String platformType : new ArrayList(deviceConfigMap.keySet())) { + for (String platformType : new ArrayList<>(deviceConfigMap.keySet())) { deviceTaskManagerService.startTask(platformType, deviceConfigMap.get(platformType)); deviceConfigMap.remove(platformType); } - } @SuppressWarnings("unused") diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 210b0927cb3..e3f64f6d595 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -1222,17 +1222,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public List getMonitoringOperationList(String deviceType) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); -// Map deviceManagementServiceMap = -// pluginRepository.getAllDeviceManagementServices(tenantId); + DeviceManagementService dms = pluginRepository.getDeviceManagementService(deviceType, tenantId); - // ; - // OperationMonitoringTaskConfig operationMonitoringTaskConfig; - //Map> deviceTypeSpecificMonitoringOperations = new HashMap<>(); -// for(DeviceTypeIdentifier dti : deviceManagementServiceMap.keySet()){ -// dms = deviceManagementServiceMap.get(dti); -// -// } OperationMonitoringTaskConfig operationMonitoringTaskConfig = dms.getOperationMonitoringConfig(); return operationMonitoringTaskConfig.getMonitoringOperation(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java index 37a90f6f823..69e49b78741 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceDetailsRetrieverTask.java @@ -19,8 +19,10 @@ package org.wso2.carbon.device.mgt.core.task.impl; +import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; import org.wso2.carbon.device.mgt.core.task.DeviceMgtTaskException; import org.wso2.carbon.device.mgt.core.task.DeviceTaskManager; import org.wso2.carbon.ntask.core.Task; @@ -32,10 +34,18 @@ public class DeviceDetailsRetrieverTask implements Task { private static Log log = LogFactory.getLog(DeviceDetailsRetrieverTask.class); // private DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(); private String deviceType; + private String oppConfig; + private OperationMonitoringTaskConfig operationMonitoringTaskConfig; @Override public void setProperties(Map map) { deviceType = map.get("DEVICE_TYPE"); + oppConfig = map.get("OPPCONFIG"); + + Gson gson = new Gson(); + + operationMonitoringTaskConfig = gson.fromJson(oppConfig, + OperationMonitoringTaskConfig.class); } @Override @@ -49,14 +59,18 @@ public class DeviceDetailsRetrieverTask implements Task { log.debug("Device details retrieving task started to run."); } - DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType); - + DeviceTaskManager deviceTaskManager = new DeviceTaskManagerImpl(deviceType, + operationMonitoringTaskConfig); + //pass the configurations also from here, monitoring tasks try { deviceTaskManager.addOperations(); } catch (DeviceMgtTaskException e) { - log.error("Error occurred while trying to add the operations to device to retrieve device details.", e); + log.error( + "Error occurred while trying to add the operations to device to retrieve device details.", + e); } } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java index 2606f07fd38..16fff9ce13b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerImpl.java @@ -25,6 +25,7 @@ import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.InvalidDeviceException; import org.wso2.carbon.device.mgt.common.MonitoringOperation; +import org.wso2.carbon.device.mgt.common.OperationMonitoringTaskConfig; 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.internal.DeviceManagementDataHolder; @@ -46,30 +47,26 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { private static Log log = LogFactory.getLog(DeviceTaskManagerImpl.class); private String deviceType; private static Map> map = new HashMap<>(); + private OperationMonitoringTaskConfig operationMonitoringTaskConfig; + + public DeviceTaskManagerImpl(String deviceType, + OperationMonitoringTaskConfig operationMonitoringTaskConfig) { + this.operationMonitoringTaskConfig = operationMonitoringTaskConfig; + this.deviceType = deviceType; + } public DeviceTaskManagerImpl(String deviceType) { this.deviceType = deviceType; } //get device type specific operations - public List getOperationList() throws DeviceMgtTaskException { - - DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder - .getInstance(). - getDeviceManagementProvider(); - - return deviceManagementProviderService.getMonitoringOperationList( - deviceType);//Get task list from each device type + private List getOperationList() throws DeviceMgtTaskException { + return operationMonitoringTaskConfig.getMonitoringOperation(); } @Override public int getTaskFrequency() throws DeviceMgtTaskException { - DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder - .getInstance(). - getDeviceManagementProvider(); - - return deviceManagementProviderService.getDeviceMonitoringFrequency(deviceType); - + return operationMonitoringTaskConfig.getFrequency(); } // @Override @@ -80,11 +77,7 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { @Override public boolean isTaskEnabled() throws DeviceMgtTaskException { - DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder - .getInstance(). - getDeviceManagementProvider(); - - return deviceManagementProviderService.isDeviceMonitoringEnabled(deviceType); + return operationMonitoringTaskConfig.isEnabled(); } @@ -149,13 +142,22 @@ public class DeviceTaskManagerImpl implements DeviceTaskManager { return opNames; } + private List getOperationListforTask() throws DeviceMgtTaskException { + + DeviceManagementProviderService deviceManagementProviderService = DeviceManagementDataHolder + .getInstance(). + getDeviceManagementProvider(); + + return deviceManagementProviderService.getMonitoringOperationList( + deviceType);//Get task list from each device type + } @Override public boolean isTaskOperation(String opName) { try { - List monitoringOperations = this.getOperationList(); + List monitoringOperations = this.getOperationListforTask(); for (MonitoringOperation taop : monitoringOperations) { if (taop.getTaskName().equalsIgnoreCase(opName)) { return true; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java index 7a47f8d6bfd..d23939f866b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/task/impl/DeviceTaskManagerServiceImpl.java @@ -19,6 +19,7 @@ package org.wso2.carbon.device.mgt.core.task.impl; +import com.google.gson.Gson; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -46,9 +47,8 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { private static Log log = LogFactory.getLog(DeviceTaskManagerServiceImpl.class); @Override - public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { - -// String TASK_NAME = deviceType; + public void startTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) + throws DeviceMgtTaskException { log.info("Task adding for " + deviceType); @@ -60,45 +60,52 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { if (log.isDebugEnabled()) { log.debug("Device details retrieving task is started for the tenant id " + tenantId); -// log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager -// .getTaskFrequency()); - log.debug("Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig - .getFrequency()); + // log.debug("Device details retrieving task is at frequency of : " + deviceTaskManager + // .getTaskFrequency()); + log.debug( + "Device details retrieving task is at frequency of : " + operationMonitoringTaskConfig + .getFrequency()); } TaskManager taskManager = taskService.getTaskManager(TASK_TYPE); TaskInfo.TriggerInfo triggerInfo = new TaskInfo.TriggerInfo(); -// triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency()); + // triggerInfo.setIntervalMillis(deviceTaskManager.getTaskFrequency()); triggerInfo.setIntervalMillis(operationMonitoringTaskConfig.getFrequency()); triggerInfo.setRepeatCount(-1); + Gson gson = new Gson(); + String operationConfigs = gson.toJson(operationMonitoringTaskConfig); + Map properties = new HashMap<>(); + properties.put(TENANT_ID, String.valueOf(tenantId)); properties.put("DEVICE_TYPE", deviceType); + properties.put("OPPCONFIG", operationConfigs); + String taskName = deviceType + String.valueOf(tenantId); if (!taskManager.isTaskScheduled(deviceType)) { - TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo); + TaskInfo taskInfo = new TaskInfo(taskName, TASK_CLASS, properties, triggerInfo); taskManager.registerTask(taskInfo); taskManager.rescheduleTask(taskInfo.getName()); } else { - throw new DeviceMgtTaskException("Device details retrieving task is already started for this tenant " + - tenantId); + throw new DeviceMgtTaskException( + "Device details retrieving task is already started for this tenant " + tenantId); } } catch (TaskException e) { - throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId, e); + throw new DeviceMgtTaskException("Error occurred while creating the task for tenant " + tenantId, + e); } } @Override - public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { - -// String TASK_NAME = deviceType; + public void stopTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) + throws DeviceMgtTaskException { try { TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService(); @@ -108,18 +115,18 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { } } catch (TaskException e) { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); - throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId, e); + throw new DeviceMgtTaskException("Error occurred while deleting the task for tenant " + tenantId, + e); } } @Override - public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) throws DeviceMgtTaskException { - -// String TASK_NAME = deviceType; + public void updateTask(String deviceType, OperationMonitoringTaskConfig operationMonitoringTaskConfig) + throws DeviceMgtTaskException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); -// deviceTaskManager = new DeviceTaskManagerImpl(); + // deviceTaskManager = new DeviceTaskManagerImpl(); try { TaskService taskService = DeviceManagementDataHolder.getInstance().getTaskService(); TaskManager taskManager = taskService.getTaskManager(TASK_TYPE); @@ -134,21 +141,20 @@ public class DeviceTaskManagerServiceImpl implements DeviceTaskManagerService { Map properties = new HashMap<>(); properties.put(TENANT_ID, String.valueOf(tenantId)); - TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, - triggerInfo); + TaskInfo taskInfo = new TaskInfo(deviceType, TASK_CLASS, properties, triggerInfo); taskManager.registerTask(taskInfo); taskManager.rescheduleTask(taskInfo.getName()); } else { - throw new DeviceMgtTaskException("Device details retrieving task has not been started for this tenant " + - tenantId + ". Please start the task first."); + throw new DeviceMgtTaskException( + "Device details retrieving task has not been started for this tenant " + + tenantId + ". Please start the task first."); } } catch (TaskException e) { - throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId, e); + throw new DeviceMgtTaskException("Error occurred while updating the task for tenant " + tenantId, + e); } - - } } From ad92a5278ebb370a775d63df3c52894475bce063 Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Dec 2016 15:59:10 +0530 Subject: [PATCH 3/8] Adding on-image anchor links instead of separate btn for device-view --- .../cdmf.page.devices/public/js/listing.js | 12 ++++------ .../public/css/custom-desktop.css | 24 +++++++++---------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 65c74e886c8..6ad505e240f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -258,8 +258,9 @@ function loadDevices(searchType, searchParam) { data: 'name', class: 'remove-padding icon-only content-fill', render: function (data, type, row, meta) { - return '
'; + return '
'; } }, { @@ -333,12 +334,7 @@ function loadDevices(searchType, searchParam) { var deviceIdentifier = row.deviceIdentifier; var html = ''; if (status != 'REMOVED') { - html = - '' - + - ''; + html = ''; if (analyticsEnabled(row.deviceType)) { html += diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css index 5ecc4e2118b..b143e04d3dc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.ui.theme/public/css/custom-desktop.css @@ -6546,21 +6546,21 @@ select > option:hover { } @media (min-width: 1200px){ - table tbody tr { - width: 18% !important; - } - .table .fw-stack{ - font-size: 1.2vw; - } + table tbody tr { + width: 14% !important; + } + .table .fw-stack{ + font-size: 1.2vw; + } } @media (min-width: 1500px){ - table tbody tr { - width: 14% !important; - } - .table .fw-stack{ - font-size: 0.8vw; - } + table tbody tr { + width: 10% !important; + } + .table .fw-stack{ + font-size: 0.8vw; + } } /** End **/ From b0d32a140e1568572a79663ac7e47443abbf33da Mon Sep 17 00:00:00 2001 From: Rasika Perera Date: Thu, 22 Dec 2016 16:12:04 +0530 Subject: [PATCH 4/8] Adding context for anchor links --- .../cdmf.page.devices/public/js/listing.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js index 6ad505e240f..9121f1d3a9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.devices/public/js/listing.js @@ -258,9 +258,10 @@ function loadDevices(searchType, searchParam) { data: 'name', class: 'remove-padding icon-only content-fill', render: function (data, type, row, meta) { - return '
'; + return '
'; } }, { @@ -337,14 +338,11 @@ function loadDevices(searchType, searchParam) { html = ''; if (analyticsEnabled(row.deviceType)) { - html += - '' - + - '' - + - ''; + html += '' + + '' + + ''; } if ((!groupName || !groupId) && groupingEnabled(row.deviceType)) { From 2b1d46f45fb4fe53161da94aa7ae62f844718eef Mon Sep 17 00:00:00 2001 From: charitha Date: Thu, 22 Dec 2016 18:30:07 +0530 Subject: [PATCH 5/8] Finalized enrollment invitations --- .../mgt/jaxrs/beans/EnrollmentInvitation.java | 32 ++++++ .../service/api/UserManagementService.java | 104 ++++++++++++++---- .../impl/UserManagementServiceImpl.java | 56 +++++++++- .../mgt/jaxrs/util/DeviceMgtAPIUtils.java | 10 ++ .../mgt/core/DeviceManagementConstants.java | 1 + .../DeviceManagementProviderServiceImpl.java | 14 ++- .../mgt/core/service/EmailMetaInfo.java | 17 +-- .../invite-modal.hbs | 53 +++------ .../public/js/invite-modal.js | 53 ++++++--- .../app/units/cdmf.unit.ui.modal/modal.hbs | 2 +- .../default-enrollment-invitation.vm | 72 ++++++++++++ 11 files changed, 316 insertions(+), 98 deletions(-) create mode 100644 components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentInvitation.java create mode 100644 features/email-sender/org.wso2.carbon.email.sender.feature/src/main/resources/email/templates/default-enrollment-invitation.vm diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentInvitation.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentInvitation.java new file mode 100644 index 00000000000..c42c3caad4f --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/beans/EnrollmentInvitation.java @@ -0,0 +1,32 @@ +package org.wso2.carbon.device.mgt.jaxrs.beans; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; + +import java.util.List; + +@ApiModel(value = "EnrollmentInvitation", description = "Holds data to send enrollment invitation to list of recipients.") +public class EnrollmentInvitation { + + @ApiModelProperty(name = "deviceType", value = "Device type name.", required = true) + private String deviceType; + + @ApiModelProperty(name = "recipients", value = "List of recipients.", required = true) + private List recipients; + + public String getDeviceType() { + return deviceType; + } + + public void setDeviceType(String deviceType) { + this.deviceType = deviceType; + } + + public List getRecipients() { + return recipients; + } + + public void setRecipients(List recipients) { + this.recipients = recipients; + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index b211a3a1012..41353a0f4ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -18,22 +18,39 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.SwaggerDefinition; -import io.swagger.annotations.Info; -import io.swagger.annotations.ExtensionProperty; -import io.swagger.annotations.Extension; -import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Authorization; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Extension; +import io.swagger.annotations.ExtensionProperty; +import io.swagger.annotations.Info; import io.swagger.annotations.ResponseHeader; -import org.wso2.carbon.device.mgt.jaxrs.beans.*; +import io.swagger.annotations.SwaggerDefinition; +import io.swagger.annotations.Tag; +import org.apache.axis2.transport.http.HTTPConstants; +import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo; +import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList; +import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentInvitation; +import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; +import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.beans.UserInfo; -import javax.ws.rs.*; +import javax.validation.Valid; +import javax.ws.rs.Consumes; +import javax.ws.rs.DELETE; +import javax.ws.rs.GET; +import javax.ws.rs.HeaderParam; +import javax.ws.rs.POST; +import javax.ws.rs.PUT; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; +import javax.ws.rs.Produces; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.util.List; @@ -65,7 +82,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Adding a User", - notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API", + notes = "WSO2 IoTS supports user management. Add a new user to the WSO2 IoTS user management system via this REST API", tags = "User Management", authorizations = { @Authorization( @@ -126,7 +143,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of a User", - notes = "Get the details of a user registered with WSO2 EMM using the REST API.", + notes = "Get the details of a user registered with WSO2 IoTS using the REST API.", response = BasicUserInfo.class, tags = "User Management", authorizations = { @@ -267,7 +284,7 @@ public interface UserManagementService { @ApiOperation( httpMethod = "DELETE", value = "Deleting a User", - notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.", + notes = "When an employee leaves the organization, you can remove the user details from WSO2 IoTS using this REST API.", tags = "User Management", authorizations = { @Authorization( @@ -280,7 +297,7 @@ public interface UserManagementService { @ApiResponses(value = { @ApiResponse( code = 200, - message = "OK. \n Successfully removed the user from WSO2 EMM."), + message = "OK. \n Successfully removed the user from WSO2 IoTS."), @ApiResponse( code = 404, message = "Not Found. \n The specified resource does not exist.", @@ -312,7 +329,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting the Role Details of a User", - notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.", + notes = "A user can be assigned to one or more role in IoTS. Using this REST API you can get the role/roles a user is assigned to.", tags = "User Management", authorizations = { @Authorization( @@ -375,7 +392,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Details of Users", - notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so " + notes = "You are able to manage users in WSO2 IoTS by adding, updating and removing users. If you wish to get the list of users registered with WSO2 IoTS, you can do so " + "using this REST API", tags = "User Management", authorizations = { @@ -389,7 +406,7 @@ public interface UserManagementService { @ApiResponses(value = { @ApiResponse( code = 200, - message = "OK. \n Successfully fetched the list of users registered with WSO2 EMM.", + message = "OK. \n Successfully fetched the list of users registered with WSO2 IoTS.", response = BasicUserInfoList.class, responseHeaders = { @ResponseHeader( @@ -414,7 +431,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 EMM users.", + message = "Internal Server Error. \n Server error occurred while fetching the list of WSO2 IoTS users.", response = ErrorResponse.class) }) Response getUsers( @@ -449,7 +466,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting the User Count", - notes = "Get the number of users in WSO2 EMM via this REST API.", + notes = "Get the number of users in WSO2 IoTS via this REST API.", tags = "User Management", authorizations = { @Authorization( @@ -474,7 +491,7 @@ public interface UserManagementService { response = ErrorResponse.class), @ApiResponse( code = 500, - message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 EMM.", + message = "Internal Server Error. \n Server error occurred while fetching the total number of users in WSO2 IoTS.", response = ErrorResponse.class) }) Response getUserCount(); @@ -608,7 +625,7 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "PUT", value = "Changing the User Password", - notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.", + notes = "A user is able to change the password to secure their WSO2 IoTS profile via this REST API.", tags = "User Management", authorizations = { @Authorization( @@ -653,8 +670,8 @@ public interface UserManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "POST", value = "Sending Enrollment Invitations to Users", - notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" + - "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.", + notes = "Send the users a mail inviting them to enroll their devices using the REST API given below.\n" + + "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 IoTS as explained in step 4, under the WSO2 IoTS general server configurations documentation.", tags = "User Management", authorizations = { @Authorization( @@ -691,4 +708,47 @@ public interface UserManagementService { value = "List of users", required = true) List usernames); + @POST + @Path("/enrollment-invite") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_POST, + value = "Sending Enrollment Invitations to email address", + notes = "Send the a mail inviting recipients to enroll devices.", + tags = "User Management", + authorizations = { + @Authorization( + value = "permission", + scopes = {@AuthorizationScope(scope = "/device-mgt/users/invite", description = "Invite Users")} + ) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully sent the invitation mail."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource does not exist.\n", + response = ErrorResponse.class), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while updating the user credentials.", + response = ErrorResponse.class) + }) + Response inviteToEnrollDevice( + @ApiParam( + name = "enrollmentInvitation", + value = "List of email address of recipients", + required = true) + @Valid EnrollmentInvitation enrollmentInvitation); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java index 807a9e53f8d..0390e5b13df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/UserManagementServiceImpl.java @@ -28,6 +28,7 @@ import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList; +import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentInvitation; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; @@ -39,6 +40,7 @@ import org.wso2.carbon.device.mgt.jaxrs.util.CredentialManagementResponseBuilder import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.utils.CarbonUtils; import javax.ws.rs.Consumes; import javax.ws.rs.DELETE; @@ -52,6 +54,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.io.File; import java.io.UnsupportedEncodingException; import java.net.URI; import java.net.URISyntaxException; @@ -59,9 +62,11 @@ import java.security.SecureRandom; import java.util.ArrayList; import java.util.Arrays; import java.util.HashMap; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; @Path("/users") @Produces(MediaType.APPLICATION_JSON) @@ -466,7 +471,7 @@ public class UserManagementServiceImpl implements UserManagementService { * @param usernames Username list of the users to be invited */ @POST - @Path("send-invitation") + @Path("/send-invitation") @Produces({MediaType.APPLICATION_JSON}) public Response inviteExistingUsersToEnrollDevice(List usernames) { if (log.isDebugEnabled()) { @@ -497,6 +502,40 @@ public class UserManagementServiceImpl implements UserManagementService { return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); } + @POST + @Path("/enrollment-invite") + @Override + public Response inviteToEnrollDevice(EnrollmentInvitation enrollmentInvitation) { + if (log.isDebugEnabled()) { + log.debug("Sending enrollment invitation mail to existing user."); + } + DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); + try { + Set recipients = new HashSet<>(); + for (String recipient : enrollmentInvitation.getRecipients()) { + recipients.add(recipient); + } + Properties props = new Properties(); + String username = DeviceMgtAPIUtils.getAuthenticatedUser(); + String firstName = getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME); + if (firstName == null) { + firstName = username; + } + props.setProperty("first-name", firstName); + props.setProperty("device-type", enrollmentInvitation.getDeviceType()); + EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props); + dms.sendEnrolmentInvitation(getEnrollmentTemplateName(enrollmentInvitation.getDeviceType()), metaInfo); + } catch (DeviceManagementException e) { + String msg = "Error occurred while inviting user to enrol their device"; + log.error(msg, e); + } catch (UserStoreException e) { + String msg = "Error occurred while getting claim values to invite user"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build(); + } private Map buildDefaultUserClaims(String firstName, String lastName, String emailAddress) { Map defaultUserClaims = new HashMap<>(); @@ -543,4 +582,19 @@ public class UserManagementServiceImpl implements UserManagementService { return userStoreManager.getUserClaimValue(username, claimUri, null); } + private String getEnrollmentTemplateName(String deviceType) { + String templateName = deviceType + "-enrollment-invitation"; + File template = new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + + "resources" + File.separator + "email-templates" + File.separator + templateName + + ".vm"); + if (template.exists()) { + return templateName; + } else { + if (log.isDebugEnabled()) { + log.debug("The template that is expected to use is not available. Therefore, using default template."); + } + } + return DeviceManagementConstants.EmailAttributes.DEFAULT_ENROLLMENT_TEMPLATE; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index c15e92eb9f3..afc03336d55 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -286,4 +286,14 @@ public class DeviceMgtAPIUtils { } } + public static String getAuthenticatedUser() { + PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + String username = threadLocalCarbonContext.getUsername(); + String tenantDomain = threadLocalCarbonContext.getTenantDomain(); + if (username != null && username.endsWith(tenantDomain)) { + return username.substring(0, username.lastIndexOf("@")); + } + return username; + } + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java index 6351c402e78..a1749b8f317 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/DeviceManagementConstants.java @@ -78,6 +78,7 @@ public final class DeviceManagementConstants { public static final String USER_REGISTRATION_TEMPLATE = "user-registration"; public static final String USER_ENROLLMENT_TEMPLATE = "user-enrollment"; + public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; } public static final class OperationAttributes { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index c4cb2189599..8ad213c0aea 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -74,10 +74,12 @@ import org.wso2.carbon.user.api.UserStoreException; import java.sql.SQLException; import java.util.ArrayList; import java.util.Date; +import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; import java.util.List; import java.util.Map; +import java.util.Properties; import java.util.Set; public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, @@ -755,8 +757,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv @Override public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException { Map, Object>> params = new HashMap<>(); - params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME, - new TypedValue, Object>(String.class, metaInfo.getProperty("first-name"))); + Properties props = metaInfo.getProperties(); + Enumeration e = props.propertyNames(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + params.put(key, new TypedValue, Object>(String.class, props.getProperty(key))); + } params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTPS, new TypedValue, Object>(String.class, DeviceManagerUtil.getServerBaseHttpsUrl())); params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.SERVER_BASE_URL_HTTP, @@ -766,8 +772,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv new EmailContext.EmailContextBuilder(new ContentProviderInfo(templateName, params), metaInfo.getRecipients()).build(); DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx); - } catch (EmailSendingFailedException e) { - throw new DeviceManagementException("Error occurred while sending enrollment invitation", e); + } catch (EmailSendingFailedException ex) { + throw new DeviceManagementException("Error occurred while sending enrollment invitation", ex); } } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java index dc5ea8db1e3..c5ac4af2672 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/EmailMetaInfo.java @@ -18,28 +18,13 @@ */ package org.wso2.carbon.device.mgt.core.service; -import io.swagger.annotations.ApiModelProperty; - -import java.io.Serializable; import java.util.HashSet; import java.util.Properties; import java.util.Set; -public class EmailMetaInfo implements Serializable { - private static final long serialVersionUID = 1998101711L; +public class EmailMetaInfo { - @ApiModelProperty( - name = "recipients", - value = "Set of recipients.", - required = true - ) private Set recipients; - - @ApiModelProperty( - name = "properties", - value = "Map of properties.", - required = true - ) private Properties properties; public EmailMetaInfo(final Set recipients, final Properties properties) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.email.invite-modal/invite-modal.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.email.invite-modal/invite-modal.hbs index 5a435b4ec91..91b636d6e18 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.email.invite-modal/invite-modal.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.email.invite-modal/invite-modal.hbs @@ -15,54 +15,27 @@ specific language governing permissions and limitations under the License. }} +{{unit "cdmf.unit.ui.modal"}} {{#zone "content"}} -