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 1b527337c8..807a9e53f8 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 2b5398fb88..6351c402e7 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 33bd6c0607..ed1e9abec3 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 210b0927cb..c4cb218959 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 c5ac4af267..dc5ea8db1e 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 0000000000..12e2b66667 --- /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 0000000000..fa1c03600d --- /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
+
+
+
+ + + ]]> + +