From 8c0ae2511e5bffce32cc12453d9002f9bcc03fff Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Mon, 4 Dec 2023 11:46:37 +0530 Subject: [PATCH 1/2] Add enrollment mails --- .../invitation/mgt/EnrollmentTypeMail.java | 57 +++ .../invitation/mgt/UserMailAttributes.java | 61 +++ .../mgt/core/DeviceManagementConstants.java | 3 + .../mgt/service/OTPManagementServiceImpl.java | 160 ++++-- .../email/templates/user-registration.vm | 478 ++++++++++++++++-- 5 files changed, 657 insertions(+), 102 deletions(-) create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java create mode 100644 components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java new file mode 100644 index 0000000000..86bec9ebff --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.invitation.mgt; + +import java.util.Properties; + +public class EnrollmentTypeMail { + private String template; + private String username; + private String recipient; + private Properties properties; + + public String getTemplate() { + return template; + } + + public void setTemplate(String template) { + this.template = template; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + public String getRecipient() { + return recipient; + } + public void setRecipient(String recipient) { + this.recipient = recipient; + } + + public Properties getProperties() { + return properties; + } + public void setProperties(Properties properties) { + this.properties = properties; + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java new file mode 100644 index 0000000000..147298a666 --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/UserMailAttributes.java @@ -0,0 +1,61 @@ +/* + * Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. 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 io.entgra.device.mgt.core.device.mgt.common.invitation.mgt; + +public class UserMailAttributes { + private String username; + private String firstName; + private String email; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getFirstName() { + return firstName; + } + + public void setFirstName(String firstName) { + this.firstName = firstName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + + public String getUsernamePlaceholder() { + return "username"; + } + + public String getEmailPlaceholder() { + return "email"; + } + + public String getFirstNamePlaceholder() { + return "first-name"; + } +} diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java index 8fc2e2804a..872b25205a 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/DeviceManagementConstants.java @@ -121,6 +121,9 @@ public final class DeviceManagementConstants { public static final String USER_WELCOME_TEMPLATE = "user-welcome"; public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation"; public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide"; + public static final String DEVICE_ENROLLMENT_MAIL_KEY = "enrollment"; + public static final String TEMPLATE_NAME_PART_JOINER = "-"; + public static final String ENROLLMENT_TYPE_SPLITTER = "_"; } public static final class OperationAttributes { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index bc9204eecb..564c9f073e 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service; import com.google.gson.Gson; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.*; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -28,9 +29,6 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.DBConnectionExcept import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentType; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO; import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService; @@ -47,13 +45,7 @@ import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; import java.sql.Timestamp; -import java.util.ArrayList; -import java.util.Calendar; -import java.util.Collections; -import java.util.List; -import java.util.Map; -import java.util.Properties; -import java.util.UUID; +import java.util.*; public class OTPManagementServiceImpl implements OTPManagementService { @@ -218,53 +210,12 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } - @Override public void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) - throws OTPManagementException { - DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider(); - StringBuilder enrollmentSteps = new StringBuilder(); - DeviceEnrollmentInvitationDetails deviceEnrollmentInvitationDetails; - for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentInvitation.getDeviceEnrollmentTypes()) { - deviceEnrollmentInvitationDetails = dms.getDeviceEnrollmentInvitationDetails( - deviceEnrollmentType.getDeviceType()); - if (deviceEnrollmentInvitationDetails != null && - deviceEnrollmentInvitationDetails.getEnrollmentDetails() != null) { - for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) { - deviceEnrollmentInvitationDetails.getEnrollmentDetails().stream() - .filter(details -> enrollmentType.equals(details.getEnrollmentType())).findFirst() - .ifPresent(details -> enrollmentSteps.append(details.getEnrollmentSteps())); - } - } - } - Properties props = new Properties(); - props.setProperty("enrollment-steps", enrollmentSteps.toString()); - try { - ConnectionManagerUtil.beginDBTransaction(); - for (String username : deviceEnrollmentInvitation.getUsernames()) { - String emailAddress = DeviceManagerUtil.getUserClaimValue( - username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS); - props.setProperty("first-name", DeviceManagerUtil. - getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); - props.setProperty("username", username); - sendMail(props, emailAddress, DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE); - } - ConnectionManagerUtil.commitDBTransaction(); - } catch (UserStoreException e) { - String msg = "Error occurred while getting claim values to invite user"; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } catch (DBConnectionException e) { - String msg = "Error occurred while getting database connection to add OPT data."; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } catch (TransactionManagementException e) { - String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation."; - log.error(msg, e); - throw new OTPManagementException(msg, e); - } finally { - ConnectionManagerUtil.closeDBConnection(); - } + throws OTPManagementException { + List enrollmentTypeMails = + getEnrollmentTypeMails(deviceEnrollmentInvitation.getDeviceEnrollmentTypes()); + sendEnrollmentTypeMails(deviceEnrollmentInvitation.getUsernames(), enrollmentTypeMails); } /** @@ -380,4 +331,103 @@ public class OTPManagementServiceImpl implements OTPManagementService { ConnectionManagerUtil.closeDBConnection(); } } + + /** + * Send enrollment type mails to users + * @param usernames List of usernames to send enrollment type mails + * @param enrollmentTypeMails List of enrollment types + * @throws OTPManagementException Throws when error occurred while sending emails + */ + private void sendEnrollmentTypeMails(List usernames, List enrollmentTypeMails) + throws OTPManagementException { + try { + ConnectionManagerUtil.beginDBTransaction(); + for (String username : usernames) { + populateUserAttributes(getUserMailAttributes(username), enrollmentTypeMails); + for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { + sendMail(enrollmentTypeMail); + } + } + ConnectionManagerUtil.commitDBTransaction(); + } catch (UserStoreException e) { + String msg = "Error occurred while populating user attributes"; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while getting database connection to add OTP data."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation."; + log.error(msg, e); + throw new OTPManagementException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + /** + * Send enrollment type mail + * @param enrollmentTypeMail Data related to the enrollment mail + * @throws OTPManagementException Throws when error occurred while sending email + */ + private void sendMail(EnrollmentTypeMail enrollmentTypeMail) throws OTPManagementException { + sendMail(enrollmentTypeMail.getProperties(), enrollmentTypeMail.getRecipient(), enrollmentTypeMail.getTemplate()); + } + + /** + * Get user claims based on the username + * @param username Username + * @return {@link UserMailAttributes} + * @throws UserStoreException Throws when error occurred while retrieving user claims + */ + private UserMailAttributes getUserMailAttributes(String username) throws UserStoreException { + UserMailAttributes userMailAttributes = new UserMailAttributes(); + userMailAttributes.setEmail(DeviceManagerUtil.getUserClaimValue( + username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS)); + userMailAttributes.setFirstName(DeviceManagerUtil. + getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); + userMailAttributes.setUsername(username); + return userMailAttributes; + } + + private void populateUserAttributes(UserMailAttributes userMailAttributes, List enrollmentTypeMails) { + for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { + Properties properties = new Properties(); + properties.setProperty(userMailAttributes.getEmailPlaceholder(), userMailAttributes.getEmail()); + properties.setProperty(userMailAttributes.getFirstNamePlaceholder(), userMailAttributes.getFirstName()); + properties.setProperty(userMailAttributes.getUsernamePlaceholder(), userMailAttributes.getUsername()); + enrollmentTypeMail.setProperties(properties); + enrollmentTypeMail.setUsername(userMailAttributes.getUsername()); + enrollmentTypeMail.setRecipient(userMailAttributes.getEmail()); + } + } + + /** + * Generate enrollment type mail + * @param deviceType Device type of the enrollment type + * @param enrollmentType Enrollment type + * @return {@link EnrollmentTypeMail} + */ + private EnrollmentTypeMail getEnrollmentTypeMail(String deviceType, String enrollmentType) { + EnrollmentTypeMail enrollmentTypeMail = new EnrollmentTypeMail(); + enrollmentTypeMail.setUsername(enrollmentTypeMail.getUsername()); + enrollmentTypeMail.setTemplate(String.join(DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER, + deviceType.toLowerCase(), enrollmentType.toLowerCase(). + replace(DeviceManagementConstants.EmailAttributes.ENROLLMENT_TYPE_SPLITTER, + DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER), + DeviceManagementConstants.EmailAttributes.DEVICE_ENROLLMENT_MAIL_KEY)); + return enrollmentTypeMail; + } + + private List getEnrollmentTypeMails(List deviceEnrollmentTypes) { + List enrollmentTypeMails = new ArrayList<>(); + for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentTypes) { + String deviceType = deviceEnrollmentType.getDeviceType(); + for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) { + enrollmentTypeMails.add(getEnrollmentTypeMail(deviceType, enrollmentType)); + } + } + return enrollmentTypeMails; + } } \ No newline at end of file diff --git a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm index bcca3b19ca..1bdea39053 100644 --- a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm +++ b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-registration.vm @@ -15,56 +15,440 @@ specific language governing permissions and limitations under the License. *# + - You have successfully been registered in Entgra IoT + You have been invited to enroll your device in Entgra UEM - - Entgra IoT Server - - -
-
-
-
- entgra -
-
-
-

- Hi $first-name, -

- -

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

- -

- Use following credentials to log in to Entgra IoT Device Management application. -

- -

- Username: $username -
- Password: $password -

- -

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

- -

- Regards, -

- -

- Entgra IoT Administrator -

-
-
-
- + + + + + + + + + + Entgra UEM Server + + + + + + + + + + + +
+ +
+
+
+ + +
+
+ +
+ + + + + + + +
+ + + + +
+ +
+
+ +
+ +
+
+ + +
+
+
+
+
+
+ + +
+
+ +
+ + + + + + + +
+
+

Dear $first-name,

+
+

We have completed your Entgra UEM registration. You are now invited to proceed with the enrollment of your device.

+
+
+

Please click on the link below to initiate this process.

+
+
+ + + + + + +
+ + +
+ + + + + + +
+
+

Here are your login credentials:

+
+

Username: $username

+

Password: $password

+
+

If you require any assistance or have questions during the enrollment process, reach out to your designated administrator via the Entgra Support Portal.

+
+

Thank you.

+
+

Best wishes,

+

Entgra team

+
+
+ +
+ +
+
+ + +
+
+
+
+
+
+ + +
+
+ +
+ + + + + + + +
+ + + + + + +
+
+
+ + + + + + +
+ +
+ + + + + + +
+
+

Follow Entgra on social media

+
+
+ + + + + + +
+
+
+ + + + + + + + +
+ + Facebook + +
+ + + + + + + + +
+ + LinkedIn + +
+ + + + + + + + +
+ + X + +
+ + + + + + + + +
+ + YouTube + +
+ + +
+
+
+ +
+ +
+
+ + +
+
+
+ +
+ + + ]]> From 6ee86e8cd2018500411e6092129d383c4bbe0db0 Mon Sep 17 00:00:00 2001 From: Rajitha Kumara Date: Tue, 5 Dec 2023 09:47:55 +0530 Subject: [PATCH 2/2] Add java doc comments --- .../invitation/mgt/EnrollmentTypeMail.java | 3 ++ .../mgt/service/OTPManagementServiceImpl.java | 40 +++++++++++-------- 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java index 86bec9ebff..e8fd8484f6 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/invitation/mgt/EnrollmentTypeMail.java @@ -41,9 +41,11 @@ public class EnrollmentTypeMail { public void setUsername(String username) { this.username = username; } + public String getRecipient() { return recipient; } + public void setRecipient(String recipient) { this.recipient = recipient; } @@ -51,6 +53,7 @@ public class EnrollmentTypeMail { public Properties getProperties() { return properties; } + public void setProperties(Properties properties) { this.properties = properties; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index 564c9f073e..55e4fe46d8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -18,18 +18,12 @@ package io.entgra.device.mgt.core.device.mgt.core.otp.mgt.service; import com.google.gson.Gson; -import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.*; -import org.apache.commons.lang.StringUtils; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.context.CarbonContext; import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.BadRequestException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DBConnectionException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException; -import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; -import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.*; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentType; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.EnrollmentTypeMail; +import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.UserMailAttributes; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO; import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService; import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants; @@ -38,9 +32,11 @@ import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAO; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAOFactory; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.exception.OTPManagementDAOException; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.util.ConnectionManagerUtil; -import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo; import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; @@ -212,7 +208,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { @Override public void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation) - throws OTPManagementException { + throws OTPManagementException { List enrollmentTypeMails = getEnrollmentTypeMails(deviceEnrollmentInvitation.getDeviceEnrollmentTypes()); sendEnrollmentTypeMails(deviceEnrollmentInvitation.getUsernames(), enrollmentTypeMails); @@ -247,7 +243,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { throw new OTPManagementException(msg, e); } catch (OTPManagementDAOException e) { ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while saving the OTP data for given email" ; + String msg = "Error occurred while saving the OTP data for given email"; log.error(msg, e); throw new OTPManagementException(msg, e); } finally { @@ -263,7 +259,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { * @return {@link OneTimePinDTO} * @throws OTPManagementException if error occurred while getting OTP data for given OTP in DB */ - private OneTimePinDTO getOTPDataByToken (String oneTimeToken) throws OTPManagementException { + private OneTimePinDTO getOTPDataByToken(String oneTimeToken) throws OTPManagementException { try { ConnectionManagerUtil.openDBConnection(); return otpManagementDAO.getOTPDataByToken(oneTimeToken); @@ -284,7 +280,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { * If OTP expired, resend the user verifying mail with renewed OTP * @param props Mail body properties * @param mailAddress Mail Address of the User - * @param template Mail template to be used + * @param template Mail template to be used * @throws OTPManagementException if error occurred while resend the user verifying mail */ private void sendMail(Properties props, String mailAddress, String template) throws OTPManagementException { @@ -306,7 +302,7 @@ public class OTPManagementServiceImpl implements OTPManagementService { /** * Renew the OTP * @param oneTimePinDTO {@link OneTimePinDTO} - * @param renewedOTP Renewed OTP + * @param renewedOTP Renewed OTP * @throws OTPManagementException if error occurred while renew the OTP */ private void renewOTP(OneTimePinDTO oneTimePinDTO, String renewedOTP) throws OTPManagementException { @@ -391,6 +387,11 @@ public class OTPManagementServiceImpl implements OTPManagementService { return userMailAttributes; } + /** + * Populate enrollment type mails with provided user attributes + * @param userMailAttributes User attributes + * @param enrollmentTypeMails Enrollment type mails + */ private void populateUserAttributes(UserMailAttributes userMailAttributes, List enrollmentTypeMails) { for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) { Properties properties = new Properties(); @@ -420,6 +421,11 @@ public class OTPManagementServiceImpl implements OTPManagementService { return enrollmentTypeMail; } + /** + * Generate enrollment type mails from device enrollment types + * @param deviceEnrollmentTypes List of device enrollment types + * @return List of enrollment type mails + */ private List getEnrollmentTypeMails(List deviceEnrollmentTypes) { List enrollmentTypeMails = new ArrayList<>(); for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentTypes) {