mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Resolved wso2/product-iots#1035
This commit is contained in:
parent
b87d3898f6
commit
bbbd199cf7
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.jaxrs.beans;
|
||||||
|
|
||||||
|
import io.swagger.annotations.ApiModel;
|
||||||
|
import io.swagger.annotations.ApiModelProperty;
|
||||||
|
|
||||||
|
@ApiModel(value = "BasicUserInfoWrapper", description = "This contains basic details of a set of users that matches " +
|
||||||
|
"a given criteria as a collection and a message if there's any.")
|
||||||
|
public class BasicUserInfoWrapper {
|
||||||
|
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "basicUserInfo",
|
||||||
|
value = "Details of the User.",
|
||||||
|
required = true)
|
||||||
|
private BasicUserInfo basicUserInfo;
|
||||||
|
|
||||||
|
@ApiModelProperty(
|
||||||
|
name = "message",
|
||||||
|
value = "Response message if there's any.")
|
||||||
|
private String message;
|
||||||
|
|
||||||
|
public BasicUserInfo getBasicUserInfo() {
|
||||||
|
return basicUserInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBasicUserInfo(BasicUserInfo basicUserInfo) {
|
||||||
|
this.basicUserInfo = basicUserInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMessage() {
|
||||||
|
return message;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMessage(String message) {
|
||||||
|
this.message = message;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -25,11 +25,13 @@ import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder;
|
|||||||
import org.wso2.carbon.context.CarbonContext;
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
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.DeviceManagementProviderService;
|
||||||
import org.wso2.carbon.device.mgt.core.service.EmailMetaInfo;
|
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.BasicUserInfo;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoList;
|
||||||
|
import org.wso2.carbon.device.mgt.jaxrs.beans.BasicUserInfoWrapper;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.EnrollmentInvitation;
|
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.ErrorResponse;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
|
import org.wso2.carbon.device.mgt.jaxrs.beans.OldPasswordResetWrapper;
|
||||||
@ -155,10 +157,19 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|||||||
props.setProperty("password", initialUserPassword);
|
props.setProperty("password", initialUserPassword);
|
||||||
|
|
||||||
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
|
BasicUserInfoWrapper userInfoWrapper = new BasicUserInfoWrapper();
|
||||||
|
String message;
|
||||||
|
try {
|
||||||
dms.sendRegistrationEmail(metaInfo);
|
dms.sendRegistrationEmail(metaInfo);
|
||||||
|
message = "An invitation mail will be sent to this user to initiate device enrollment.";
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
message = "Mail Server is not configured. Email invitation will not be sent.";
|
||||||
|
}
|
||||||
|
userInfoWrapper.setBasicUserInfo(createdUserInfo);
|
||||||
|
userInfoWrapper.setMessage(message);
|
||||||
return Response.created(new URI(API_BASE_PATH + "/" + URIEncoder.encode(userInfo.getUsername(), "UTF-8")))
|
return Response.created(new URI(API_BASE_PATH + "/" + URIEncoder.encode(userInfo.getUsername(), "UTF-8")))
|
||||||
.entity(
|
.entity(
|
||||||
createdUserInfo).build();
|
userInfoWrapper).build();
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error occurred while trying to add user '" + userInfo.getUsername() + "' to the " +
|
String msg = "Error occurred while trying to add user '" + userInfo.getUsername() + "' to the " +
|
||||||
"underlying user management system";
|
"underlying user management system";
|
||||||
@ -573,6 +584,10 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
String msg = "Error occurred while sending the email invitations. Mail server not configured.";
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
|
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
|
||||||
}
|
}
|
||||||
@ -608,6 +623,10 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
} catch (ConfigurationManagementException e) {
|
||||||
|
String msg = "Error occurred while sending the email invitations. Mail server not configured.";
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
}
|
}
|
||||||
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
|
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.common.InvalidDeviceException;
|
|||||||
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
import org.wso2.carbon.device.mgt.common.MonitoringOperation;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
import org.wso2.carbon.device.mgt.common.license.mgt.License;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Activity;
|
||||||
@ -436,9 +437,10 @@ public interface DeviceManagementProviderService {
|
|||||||
|
|
||||||
HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
|
HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException;
|
||||||
|
|
||||||
void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException;
|
void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException,
|
||||||
|
ConfigurationManagementException;
|
||||||
|
|
||||||
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException;
|
void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException, ConfigurationManagementException;
|
||||||
|
|
||||||
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException;
|
FeatureManager getFeatureManager(String deviceType) throws DeviceManagementException;
|
||||||
|
|
||||||
|
|||||||
@ -28,9 +28,6 @@ import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
|||||||
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
import org.wso2.carbon.device.mgt.common.DeviceManager;
|
||||||
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
import org.wso2.carbon.device.mgt.common.DeviceNotFoundException;
|
||||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
|
|
||||||
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
|
||||||
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
import org.wso2.carbon.device.mgt.common.EnrolmentInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
import org.wso2.carbon.device.mgt.common.FeatureManager;
|
||||||
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
import org.wso2.carbon.device.mgt.common.InitialOperationConfig;
|
||||||
@ -41,6 +38,7 @@ import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
|||||||
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
import org.wso2.carbon.device.mgt.common.TransactionManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
import org.wso2.carbon.device.mgt.common.app.mgt.Application;
|
||||||
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration;
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo;
|
||||||
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation;
|
||||||
@ -55,6 +53,8 @@ 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.operation.mgt.OperationManagementException;
|
||||||
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
import org.wso2.carbon.device.mgt.common.policy.mgt.PolicyMonitoringManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationExecutionFailedException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.pull.notification.PullNotificationSubscriber;
|
||||||
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
import org.wso2.carbon.device.mgt.core.DeviceManagementConstants;
|
||||||
@ -69,6 +69,7 @@ import org.wso2.carbon.device.mgt.core.dao.EnrollmentDAO;
|
|||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO;
|
||||||
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsMgtDAOException;
|
||||||
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
import org.wso2.carbon.device.mgt.core.dto.DeviceType;
|
||||||
|
import org.wso2.carbon.device.mgt.core.dto.DeviceTypeServiceIdentifier;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
|
||||||
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
|
import org.wso2.carbon.device.mgt.core.internal.PluginInitializationListener;
|
||||||
@ -77,7 +78,9 @@ import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil;
|
|||||||
import org.wso2.carbon.email.sender.core.ContentProviderInfo;
|
import org.wso2.carbon.email.sender.core.ContentProviderInfo;
|
||||||
import org.wso2.carbon.email.sender.core.EmailContext;
|
import org.wso2.carbon.email.sender.core.EmailContext;
|
||||||
import org.wso2.carbon.email.sender.core.EmailSendingFailedException;
|
import org.wso2.carbon.email.sender.core.EmailSendingFailedException;
|
||||||
|
import org.wso2.carbon.email.sender.core.EmailTransportNotConfiguredException;
|
||||||
import org.wso2.carbon.email.sender.core.TypedValue;
|
import org.wso2.carbon.email.sender.core.TypedValue;
|
||||||
|
import org.wso2.carbon.email.sender.core.service.EmailSenderService;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -769,7 +772,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException {
|
public void sendEnrolmentInvitation(String templateName, EmailMetaInfo metaInfo) throws DeviceManagementException,
|
||||||
|
ConfigurationManagementException {
|
||||||
if (metaInfo == null) {
|
if (metaInfo == null) {
|
||||||
String msg = "Received incomplete data to method sendEnrolmentInvitation";
|
String msg = "Received incomplete data to method sendEnrolmentInvitation";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -798,6 +802,9 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
String msg = "Error occurred while sending enrollment invitation";
|
String msg = "Error occurred while sending enrollment invitation";
|
||||||
log.error(msg, ex);
|
log.error(msg, ex);
|
||||||
throw new DeviceManagementException(msg, ex);
|
throw new DeviceManagementException(msg, ex);
|
||||||
|
} catch (EmailTransportNotConfiguredException ex) {
|
||||||
|
String msg = "Mail Server is not configured.";
|
||||||
|
throw new ConfigurationManagementException(msg, ex);
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
String msg = "Error occurred in setEnrollmentInvitation";
|
String msg = "Error occurred in setEnrollmentInvitation";
|
||||||
log.error(msg, ex);
|
log.error(msg, ex);
|
||||||
@ -806,7 +813,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException {
|
public void sendRegistrationEmail(EmailMetaInfo metaInfo) throws DeviceManagementException,
|
||||||
|
ConfigurationManagementException {
|
||||||
if (metaInfo == null) {
|
if (metaInfo == null) {
|
||||||
String msg = "Received incomplete request for sendRegistrationEmail";
|
String msg = "Received incomplete request for sendRegistrationEmail";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -815,6 +823,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Send registration email");
|
log.debug("Send registration email");
|
||||||
}
|
}
|
||||||
|
EmailSenderService emailSenderService = DeviceManagementDataHolder.getInstance().getEmailSenderService();
|
||||||
|
if (emailSenderService != null) {
|
||||||
Map<String, TypedValue<Class<?>, Object>> params = new HashMap<>();
|
Map<String, TypedValue<Class<?>, Object>> params = new HashMap<>();
|
||||||
params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME,
|
params.put(org.wso2.carbon.device.mgt.core.DeviceManagementConstants.EmailAttributes.FIRST_NAME,
|
||||||
new TypedValue<Class<?>, Object>(String.class, metaInfo.getProperty("first-name")));
|
new TypedValue<Class<?>, Object>(String.class, metaInfo.getProperty("first-name")));
|
||||||
@ -835,17 +845,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
|
|||||||
DeviceManagementConstants.EmailAttributes.USER_REGISTRATION_TEMPLATE,
|
DeviceManagementConstants.EmailAttributes.USER_REGISTRATION_TEMPLATE,
|
||||||
params),
|
params),
|
||||||
metaInfo.getRecipients()).build();
|
metaInfo.getRecipients()).build();
|
||||||
DeviceManagementDataHolder.getInstance().getEmailSenderService().sendEmail(ctx);
|
emailSenderService.sendEmail(ctx);
|
||||||
} catch (EmailSendingFailedException e) {
|
} catch (EmailSendingFailedException e) {
|
||||||
String msg = "Error occurred while sending user registration notification." + e.getMessage();
|
String msg = "Error occurred while sending user registration notification." + e.getMessage();
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
|
} catch (EmailTransportNotConfiguredException e) {
|
||||||
|
String msg = "Error occurred while sending user registration email." + e.getMessage();
|
||||||
|
throw new ConfigurationManagementException(msg, e);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
String msg = "Error occurred in sendRegistrationEmail";
|
String msg = "Error occurred while sending Registration Email.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new DeviceManagementException(msg, e);
|
throw new DeviceManagementException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
public HashMap<Integer, Device> getTenantedDevice(DeviceIdentifier deviceIdentifier) throws DeviceManagementException {
|
||||||
|
|||||||
@ -131,6 +131,11 @@
|
|||||||
An invitation mail will be sent to this user to initiate device enrollment.
|
An invitation mail will be sent to this user to initiate device enrollment.
|
||||||
</h4>
|
</h4>
|
||||||
</div>
|
</div>
|
||||||
|
<div id="modal-content-user-created-with-message" class="hide">
|
||||||
|
<div id="notification-error-msg" class="alert alert-danger hidden" role="alert">
|
||||||
|
<i class="icon fw fw-error"></i><span></span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<!-- /content -->
|
<!-- /content -->
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -272,6 +272,7 @@ $(document).ready(function () {
|
|||||||
addUserFormData,
|
addUserFormData,
|
||||||
function (data, textStatus, jqXHR) {
|
function (data, textStatus, jqXHR) {
|
||||||
if (jqXHR.status == 201) {
|
if (jqXHR.status == 201) {
|
||||||
|
var response = JSON.parse(data);
|
||||||
// Clearing user input fields.
|
// Clearing user input fields.
|
||||||
$("input#username").val("");
|
$("input#username").val("");
|
||||||
$("input#firstname").val("");
|
$("input#firstname").val("");
|
||||||
@ -284,7 +285,12 @@ $(document).ready(function () {
|
|||||||
$("#user-create-form").addClass("hidden");
|
$("#user-create-form").addClass("hidden");
|
||||||
modalDialog.header('<span class="fw-stack">' +
|
modalDialog.header('<span class="fw-stack">' +
|
||||||
'<i class="fw fw-info fw-stack-1x"></i> </span> User was added successfully');
|
'<i class="fw fw-info fw-stack-1x"></i> </span> User was added successfully');
|
||||||
|
if (response.message) {
|
||||||
|
$("#modal-content-user-created-with-message").append("<h4>" + response.message + "</h4>");
|
||||||
|
modalDialog.content($("#modal-content-user-created-with-message").html());
|
||||||
|
} else {
|
||||||
modalDialog.content($("#modal-content-user-created").html());
|
modalDialog.content($("#modal-content-user-created").html());
|
||||||
|
}
|
||||||
modalDialog.footer('<div class="buttons"> ' +
|
modalDialog.footer('<div class="buttons"> ' +
|
||||||
'<a href="/devicemgt/users" id="reset-password-yes-link" class="btn-operations"> OK' +
|
'<a href="/devicemgt/users" id="reset-password-yes-link" class="btn-operations"> OK' +
|
||||||
'</a></div>');
|
'</a></div>');
|
||||||
|
|||||||
@ -0,0 +1,44 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.email.sender.core;
|
||||||
|
|
||||||
|
public class EmailTransportNotConfiguredException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3151279311929070294L;
|
||||||
|
|
||||||
|
public EmailTransportNotConfiguredException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailTransportNotConfiguredException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailTransportNotConfiguredException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailTransportNotConfiguredException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public EmailTransportNotConfiguredException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -19,9 +19,10 @@ package org.wso2.carbon.email.sender.core.service;
|
|||||||
|
|
||||||
import org.wso2.carbon.email.sender.core.EmailContext;
|
import org.wso2.carbon.email.sender.core.EmailContext;
|
||||||
import org.wso2.carbon.email.sender.core.EmailSendingFailedException;
|
import org.wso2.carbon.email.sender.core.EmailSendingFailedException;
|
||||||
|
import org.wso2.carbon.email.sender.core.EmailTransportNotConfiguredException;
|
||||||
|
|
||||||
public interface EmailSenderService {
|
public interface EmailSenderService {
|
||||||
|
|
||||||
void sendEmail(EmailContext emailCtx) throws EmailSendingFailedException;
|
void sendEmail(EmailContext emailCtx) throws EmailSendingFailedException, EmailTransportNotConfiguredException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -45,6 +45,7 @@ public class EmailSenderServiceImpl implements EmailSenderService {
|
|||||||
|
|
||||||
private static ThreadPoolExecutor threadPoolExecutor;
|
private static ThreadPoolExecutor threadPoolExecutor;
|
||||||
private EmailContentProvider contentProvider;
|
private EmailContentProvider contentProvider;
|
||||||
|
private static final String TRANSPORT_SENDER_NAME = "mailto";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
EmailSenderConfig config = EmailSenderConfig.getInstance();
|
EmailSenderConfig config = EmailSenderConfig.getInstance();
|
||||||
@ -60,23 +61,35 @@ public class EmailSenderServiceImpl implements EmailSenderService {
|
|||||||
this.contentProvider = EmailContentProviderFactory.getContentProvider();
|
this.contentProvider = EmailContentProviderFactory.getContentProvider();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean isMailServerConfigured() {
|
||||||
|
if(EmailSenderDataHolder.getInstance().getConfigurationContextService()
|
||||||
|
.getServerConfigContext().getAxisConfiguration().getTransportOut(TRANSPORT_SENDER_NAME) != null) {
|
||||||
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void sendEmail(EmailContext emailCtx) throws EmailSendingFailedException {
|
public void sendEmail(EmailContext emailCtx) throws EmailSendingFailedException,
|
||||||
|
EmailTransportNotConfiguredException {
|
||||||
|
if (this.isMailServerConfigured()) {
|
||||||
for (String recipient : emailCtx.getRecipients()) {
|
for (String recipient : emailCtx.getRecipients()) {
|
||||||
ContentProviderInfo info = emailCtx.getContentProviderInfo();
|
ContentProviderInfo info = emailCtx.getContentProviderInfo();
|
||||||
EmailData emailData;
|
EmailData emailData;
|
||||||
String transportSenderName = "mailto";
|
|
||||||
try {
|
try {
|
||||||
emailData = contentProvider.getContent(info.getTemplate(), info.getParams());
|
emailData = contentProvider.getContent(info.getTemplate(), info.getParams());
|
||||||
if(EmailSenderDataHolder.getInstance().getConfigurationContextService()
|
threadPoolExecutor.submit(new EmailSender(recipient, emailData.getSubject(), emailData.getBody()));
|
||||||
.getServerConfigContext().getAxisConfiguration().getTransportOut(transportSenderName) == null){
|
|
||||||
throw new EmailSendingFailedException("Email transport is not configured.");
|
|
||||||
}
|
|
||||||
} catch (ContentProcessingInterruptedException e) {
|
} catch (ContentProcessingInterruptedException e) {
|
||||||
throw new EmailSendingFailedException("Error occurred while retrieving email content to be " +
|
throw new EmailSendingFailedException("Error occurred while retrieving email content to be " +
|
||||||
"sent for recipient '" + recipient + "'", e);
|
"sent for recipient '" + recipient + "'", e);
|
||||||
}
|
}
|
||||||
threadPoolExecutor.submit(new EmailSender(recipient, emailData.getSubject(), emailData.getBody()));
|
}
|
||||||
|
} else {
|
||||||
|
String msg = "Email sender transport is not configured. Please configure the 'mailto' sender" +
|
||||||
|
" transport in axis2.xml.";
|
||||||
|
log.warn(msg);
|
||||||
|
throw new EmailTransportNotConfiguredException(msg);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user