mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Added send-invitation endpoint
This commit is contained in:
parent
58666bc4b0
commit
c7eef634ac
@ -26,6 +26,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.*;
|
|||||||
import javax.ws.rs.*;
|
import javax.ws.rs.*;
|
||||||
import javax.ws.rs.core.MediaType;
|
import javax.ws.rs.core.MediaType;
|
||||||
import javax.ws.rs.core.Response;
|
import javax.ws.rs.core.Response;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
|
||||||
@API(name = "User Management API", version = "1.0.0", context = "/devicemgt_admin/users", tags = {"devicemgt_admin"})
|
@API(name = "User Management API", version = "1.0.0", context = "/devicemgt_admin/users", tags = {"devicemgt_admin"})
|
||||||
@ -451,4 +452,42 @@ public interface UserManagementService {
|
|||||||
value = "Credential.",
|
value = "Credential.",
|
||||||
required = true) OldPasswordResetWrapper credentials);
|
required = true) OldPasswordResetWrapper credentials);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Path("/send-invitation")
|
||||||
|
@ApiOperation(
|
||||||
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
|
produces = MediaType.APPLICATION_JSON,
|
||||||
|
httpMethod = "POST",
|
||||||
|
value = "Send invitation mail.",
|
||||||
|
notes = "A user is able to send invitation mail via this REST API.",
|
||||||
|
tags = "User Management")
|
||||||
|
@ApiResponses(value = {
|
||||||
|
@ApiResponse(
|
||||||
|
code = 200,
|
||||||
|
message = "OK. \n Invitation mails have been sent."),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 400,
|
||||||
|
message = "Bad Request. \n Invalid request or validation error.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 404,
|
||||||
|
message = "Not Found. \n Resource to be deleted does not exist.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 415,
|
||||||
|
message = "Unsupported media type. \n The entity of the request was in a not supported format.",
|
||||||
|
response = ErrorResponse.class),
|
||||||
|
@ApiResponse(
|
||||||
|
code = 500,
|
||||||
|
message = "Internal Server Error. \n " +
|
||||||
|
"Server error occurred while updating credentials of the user.",
|
||||||
|
response = ErrorResponse.class)
|
||||||
|
})
|
||||||
|
@Permission(scope = "user-invite", permissions = {"/permission/admin/device-mgt/admin/user/invite"})
|
||||||
|
Response inviteExistingUsersToEnrollDevice(
|
||||||
|
@ApiParam(
|
||||||
|
name = "users",
|
||||||
|
value = "List of users",
|
||||||
|
required = true) List<String> usernames);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,6 +21,9 @@ package org.wso2.carbon.device.mgt.jaxrs.service.impl;
|
|||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
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.*;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
|
import org.wso2.carbon.device.mgt.jaxrs.service.api.UserManagementService;
|
||||||
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
import org.wso2.carbon.device.mgt.jaxrs.util.Constants;
|
||||||
@ -338,6 +341,43 @@ public class UserManagementServiceImpl implements UserManagementService {
|
|||||||
return CredentialManagementResponseBuilder.buildChangePasswordResponse(username, credentials);
|
return CredentialManagementResponseBuilder.buildChangePasswordResponse(username, credentials);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Method used to send an invitation email to a existing user to enroll a device.
|
||||||
|
*
|
||||||
|
* @param usernames Username list of the users to be invited
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("send-invitation")
|
||||||
|
@Produces({MediaType.APPLICATION_JSON})
|
||||||
|
public Response inviteExistingUsersToEnrollDevice(List<String> usernames) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Sending enrollment invitation mail to existing user.");
|
||||||
|
}
|
||||||
|
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
|
||||||
|
try {
|
||||||
|
for (String username : usernames) {
|
||||||
|
String recipient = getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS);
|
||||||
|
|
||||||
|
Properties props = new Properties();
|
||||||
|
props.setProperty("first-name", getClaimValue(username, Constants.USER_CLAIM_FIRST_NAME));
|
||||||
|
props.setProperty("username", username);
|
||||||
|
|
||||||
|
EmailMetaInfo metaInfo = new EmailMetaInfo(recipient, props);
|
||||||
|
dms.sendEnrolmentInvitation(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<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) {
|
private Map<String, String> buildDefaultUserClaims(String firstName, String lastName, String emailAddress) {
|
||||||
Map<String, String> defaultUserClaims = new HashMap<>();
|
Map<String, String> defaultUserClaims = new HashMap<>();
|
||||||
defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstName);
|
defaultUserClaims.put(Constants.USER_CLAIM_FIRST_NAME, firstName);
|
||||||
|
|||||||
@ -248,6 +248,12 @@
|
|||||||
<url>/admin/users/*/credentials</url>
|
<url>/admin/users/*/credentials</url>
|
||||||
<method>POST</method>
|
<method>POST</method>
|
||||||
</Permission>
|
</Permission>
|
||||||
|
<Permission>
|
||||||
|
<name>Send invitation mail</name>
|
||||||
|
<path>/device-mgt/admin/users/Send-invitations</path>
|
||||||
|
<url>/users/send-invitation</url>
|
||||||
|
<method>POST</method>
|
||||||
|
</Permission>
|
||||||
<!-- End of User related APIs -->
|
<!-- End of User related APIs -->
|
||||||
<Permission>
|
<Permission>
|
||||||
<name>Roles</name>
|
<name>Roles</name>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user