diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java index b655b7b26b..82aa78e1f9 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceManagementService.java @@ -415,6 +415,83 @@ public interface DeviceManagementService { @HeaderParam("If-Modified-Since") String ifModifiedSince); + + @GET + @Path("/{type}/{id}/location") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Location Details of a Device", + notes = "Get the location details of a device by specifying the device type and device identifier.", + tags = "Device Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:devices:details") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the location details of the device.", + response = Device.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. Empty body because the client already has the latest version" + + " of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n Location data for the specified device was not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while retrieving the device details.", + response = ErrorResponse.class) + }) + Response getDeviceLocation( + @ApiParam( + name = "type", + value = "The device type name, such as ios, android, windows or fire-alarm.", + required = true) + @PathParam("type") + @Size(max = 45) + String type, + @ApiParam( + name = "id", + value = "The device identifier of the device you want ot get details.", + required = true) + @PathParam("id") + @Size(max = 45) + String id, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time. \n" + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z. \n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") + String ifModifiedSince); + + //device rename request would looks like follows //POST devices/type/virtual_firealarm/id/us06ww93auzp/rename @POST @@ -567,7 +644,7 @@ public interface DeviceManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Feature Details of a Device", - notes = "WSO2 EMM features enable you to carry out many operations based on the device platform. " + + notes = "WSO2 IoTS features enable you to carry out many operations based on the device platform. " + "Using this REST API you can get the features that can be carried out on a preferred device type," + " such as iOS, Android or Windows.", tags = "Device Management", @@ -636,7 +713,7 @@ public interface DeviceManagementService { @ApiParam( name = "id", value = "The device identifier of the device.\n" + - "INFO: Make sure to add the ID of a device that is already registered with WSO2 EMM.", + "INFO: Make sure to add the ID of a device that is already registered with WSO2 IoTS.", required = true) @PathParam("id") @Size(max = 45) @@ -903,7 +980,7 @@ public interface DeviceManagementService { @ApiParam( name = "id", value = "The device identifier of the device you wish to get details.\n" + - "INFO: Make sure to add the ID of a device that is already registered with WSO2 EMM.", + "INFO: Make sure to add the ID of a device that is already registered with WSO2 IoTS.", required = true) @PathParam("id") @Size(max = 45) @@ -944,8 +1021,8 @@ public interface DeviceManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get the details of the policy that is enforced on a device.", - notes = "A policy is enforced on all the devices that register with WSO2 EMM." + - "WSO2 EMM filters the policies based on the device platform (device type)," + + notes = "A policy is enforced on all the devices that register with WSO2 IoTS." + + "WSO2 IoTS filters the policies based on the device platform (device type)," + "the device ownership type, the user role or name and finally, the policy that matches these filters will be enforced on the device.", tags = "Device Management", extensions = { @@ -1033,7 +1110,7 @@ public interface DeviceManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting Policy Compliance Details of a Device", - notes = "A policy is enforced on the devices that register with WSO2 EMM. " + + notes = "A policy is enforced on the devices that register with WSO2 IoTS. " + "The server checks if the settings in the device comply with the policy that is enforced on the device using this REST API.", tags = "Device Management", extensions = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java index e330d7d3d3..295fb47555 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/RoleManagementService.java @@ -18,17 +18,7 @@ */ 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.ApiOperation; -import io.swagger.annotations.ApiParam; -import io.swagger.annotations.ApiResponse; -import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.ResponseHeader; +import io.swagger.annotations.*; import org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -120,20 +110,20 @@ public interface RoleManagementService { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Getting the List of Roles", - notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 EMM.\n" + + notes = "WSO2 IoTS supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 IoTS.\n" + "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", tags = "Role Management", extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:view") - }) + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:view") + }) } ) @ApiResponses( value = { @ApiResponse( code = 200, - message = "OK. \n Successfully fetched the list of roles in WSO2 EMM.", + message = "OK. \n Successfully fetched the list of roles in WSO2 IoTS.", response = RoleList.class, responseHeaders = { @ResponseHeader( @@ -190,467 +180,549 @@ public interface RoleManagementService { defaultValue = "5") @QueryParam("limit") int limit); - @GET - @Path("/{roleName}/permissions") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Permission Details of a Role", - notes = "An individual is associated a with set of responsibilities based on their " + - "role. In WSO2 EMM you are able to configure permissions based on the responsibilities carried " + - "out by various roles. Therefore, if you wish to retrieve the permission details of a role, you can do " + - "so using this REST API.", - response = UIPermissionNode.class, - responseContainer = "List", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:permissions") + @GET + @Path("/filter/{prefix}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting the List of Roles filtered by the given prefix", + notes = "WSO2 IoTS supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 IoTS.\n" + + "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:view") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the list of roles in WSO2 IoTS.", + response = RoleList.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported"), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching list of roles.", + response = ErrorResponse.class) }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the permissions details for the specified role.", - response = UIPermissionNode.class, - responseContainer = "List", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified role does not exist.", - response = ErrorResponse.class), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list for the requested role.", - response = ErrorResponse.class) - }) - Response getPermissionsOfRole( - @ApiParam( - name = "roleName", - value = "The name of the role.", - required = true, - defaultValue = "Engineer") - @PathParam("roleName") String roleName, - @ApiParam( - name = "user-store", - value = "The name of the user store from which you wish to get the permission of role.", - required = false) - @QueryParam("user-store") String userStoreName, - @ApiParam( - name = "If-Modified-Since", - value = "Checks if the requested variant was modified, since the specified date-time." + - "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + - "Example: Mon, 05 Jan 2014 15:10:00 +0200", - required = false) - @HeaderParam("If-Modified-Since") String ifModifiedSince); + Response getFilteredRoles( + @ApiParam( + name = "prefix", + value = "Filtering prefix of the role.", + required = true, + defaultValue = "") + @PathParam("prefix") String prefix, + @ApiParam( + name = "filter", + value = "Provide a character or a few characters in the role name.", + required = false) + @QueryParam("filter") String filter, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time." + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "offset", + value = "The starting pagination index for the complete list of qualified items.", + required = false, + defaultValue = "0") + @QueryParam("offset") int offset, + @ApiParam( + name = "limit", + value = "Provide how many role details you require from the starting pagination index/offset.", + required = false, + defaultValue = "5") + @QueryParam("limit") int limit); - @GET - @Path("/{roleName}") - @ApiOperation( - produces = MediaType.APPLICATION_JSON, - httpMethod = "GET", - value = "Getting Details of a Role", - notes = "Get the permissions associated with a role and role specific details using this REST API.", - response = RoleInfo.class, - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:details") + @GET + @Path("/{roleName}/permissions") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Permission Details of a Role", + notes = "An individual is associated a with set of responsibilities based on their " + + "role. In WSO2 IoTS you are able to configure permissions based on the responsibilities carried " + + "out by various roles. Therefore, if you wish to retrieve the permission details of a role, you can do " + + "so using this REST API.", + response = UIPermissionNode.class, + responseContainer = "List", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:permissions") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the permissions details for the specified role.", + response = UIPermissionNode.class, + responseContainer = "List", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource.\n"), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified role does not exist.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server ErrorResponse. \n Server error occurred while fetching the permission list for the requested role.", + response = ErrorResponse.class) }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully fetched the details of the role.", - response = RoleInfo.class, - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests."), - }), - @ApiResponse( - code = 304, - message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified role does not exist.", - response = ErrorResponse.class), - @ApiResponse( - code = 406, - message = "Not Acceptable.\n The requested media type is not supported", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while fetching the details of" + - "requested role.", - response = ErrorResponse.class) - }) - Response getRole( - @ApiParam( - name = "roleName", - value = "The name of the role.", - required = true, - defaultValue = "admin") - @PathParam("roleName") String roleName, - @ApiParam( - name = "user-store", - value = "The name of the user store which the particular of role resides in", - required = false) - @QueryParam("user-store") String userStoreName, - @ApiParam( - name = "If-Modified-Since", - value = "Checks if the requested variant was modified, since the specified date-time." + - "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + - "Example: Mon, 05 Jan 2014 15:10:00 +0200", - required = false) - @HeaderParam("If-Modified-Since") String ifModifiedSince); + Response getPermissionsOfRole( + @ApiParam( + name = "roleName", + value = "The name of the role.", + required = true, + defaultValue = "Engineer") + @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the user store from which you wish to get the permission of role.", + required = false) + @QueryParam("user-store") String userStoreName, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time." + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); - @POST - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Adding a Role", - notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Add a new role to WSO2 EMM using this REST API.", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:add") + @GET + @Path("/{roleName}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting Details of a Role", + notes = "Get the permissions associated with a role and role specific details using this REST API.", + response = RoleInfo.class, + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:details") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the details of the role.", + response = RoleInfo.class, + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the requested resource."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified role does not exist.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the details of" + + "requested role.", + response = ErrorResponse.class) }) - } - ) - @ApiResponses(value = { - @ApiResponse( - code = 201, - message = "Created. \n Successfully created the role.", - responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "The URL to the newly added role."), - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse( - code = 303, - message = "See Other. \n The source can be retrieved from the URL specified in the location header.", - responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "The Source URL of the document.")}), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 415, - message = "Unsupported media type. \n The format of the requested entity was not supported.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while adding a new role.", - response = ErrorResponse.class) - }) - Response addRole( - @ApiParam( - name = "role", - value = "The properties required to add a new role.", - required = true) RoleInfo role); + Response getRole( + @ApiParam( + name = "roleName", + value = "The name of the role.", + required = true, + defaultValue = "admin") + @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the user store which the particular of role resides in", + required = false) + @QueryParam("user-store") String userStoreName, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time." + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince); - @POST - @Path("/create-combined-role/{roleName}") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "POST", - value = "Adding a combined Role", - notes = "WSO2 EMM supports role-based access control (RBAC) and role management. Add a new combined role to WSO2 EMM using this REST API.", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:create-combined-role") - }) - } - ) - @ApiResponses(value = { - @ApiResponse( - code = 201, - message = "Created. \n Successfully created the role.", - responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "The URL to the newly added role."), - @ResponseHeader( - name = "Content-Type", - description = "The content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse( - code = 303, - message = "See Other. \n The source can be retrieved from the URL specified in the location header.", - responseHeaders = { - @ResponseHeader( - name = "Content-Location", - description = "The Source URL of the document.")}), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 415, - message = "Unsupported media type. \n The format of the requested entity was not supported.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while adding a new role.", - response = ErrorResponse.class) - }) - Response addCombinedRole( - @ApiParam( - name = "roles", - value = "List of roles names required to add a new combined role.", - required = true) List roles, - @PathParam("roleName") String roleName, - @QueryParam("user-store") String userStoreName); + @POST + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Adding a Role", + notes = "WSO2 IoTS supports role-based access control (RBAC) and role management. Add a new role to WSO2 IoTS using this REST API.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:add") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully created the role.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL to the newly added role."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while adding a new role.", + response = ErrorResponse.class) + }) + Response addRole( + @ApiParam( + name = "role", + value = "The properties required to add a new role.", + required = true) RoleInfo role); - @PUT - @Path("/{roleName}") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Updating Role Details", - notes = "There will be situations where you need to update the role details, such as the permissions" + - " or the role name. Update the role details using this REST API.", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:update") - }) - } - ) - @ApiResponses(value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully updated the specified role.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "Content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource was last modified.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified role does not exist.", - 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 role.", - response = ErrorResponse.class) - }) - Response updateRole( - @ApiParam( - name = "roleName", - value = "The name of the role.", - required = true, - defaultValue = "admin") - @PathParam("roleName") String roleName, - @ApiParam( - name = "role", - value = "The properties required to update a role.\n" + - "NOTE: Don't change the role and the permissions of the admin user. " + - "If you want to try out this API by updating all the properties, create a new role and update the properties accordingly.", - required = true) RoleInfo role, - @ApiParam( - name = "user-store", - value = "The name of the user store which the particular role resides in.", - required = false) - @QueryParam("user-store") String userStoreName); + @POST + @Path("/create-combined-role/{roleName}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "POST", + value = "Adding a combined Role", + notes = "WSO2 IoTS supports role-based access control (RBAC) and role management. Add a new combined role to WSO2 IoTS using this REST API.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:create-combined-role") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 201, + message = "Created. \n Successfully created the role.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL to the newly added role."), + @ResponseHeader( + name = "Content-Type", + description = "The content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 303, + message = "See Other. \n The source can be retrieved from the URL specified in the location header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while adding a new role.", + response = ErrorResponse.class) + }) + Response addCombinedRole( + @ApiParam( + name = "roles", + value = "List of roles names required to add a new combined role.", + required = true) List roles, + @PathParam("roleName") String roleName, + @QueryParam("user-store") String userStoreName); - @DELETE - @Path("/{roleName}") - @ApiOperation( - httpMethod = "DELETE", - value = "Deleting a Role", - notes = "Roles become obsolete over time due to various reasons. In a situation where your Organization identifies that a specific role is no longer required, you " + - "can delete a role using this REST API.", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:delete") - }) - } - ) - @ApiResponses(value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully removed the specified role."), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified role does not exist.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n Server error occurred while removing the role.", - response = ErrorResponse.class) - }) - Response deleteRole( - @ApiParam( - name = "roleName", - value = "The name of the role that needs to de deleted.\n" + - "NOTE: Don't delete the admin role", - required = true) - @PathParam("roleName") String roleName, - @ApiParam( - name = "user-store", - value = "The name of the user store which the particular role resides in.", - required = false) - @QueryParam("user-store") String userStoreName); + @PUT + @Path("/{roleName}") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Updating Role Details", + notes = "There will be situations where you need to update the role details, such as the permissions" + + " or the role name. Update the role details using this REST API.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:update") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully updated the specified role.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource was last modified.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified role does not exist.", + 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 role.", + response = ErrorResponse.class) + }) + Response updateRole( + @ApiParam( + name = "roleName", + value = "The name of the role.", + required = true, + defaultValue = "admin") + @PathParam("roleName") String roleName, + @ApiParam( + name = "role", + value = "The properties required to update a role.\n" + + "NOTE: Don't change the role and the permissions of the admin user. " + + "If you want to try out this API by updating all the properties, create a new role and update the properties accordingly.", + required = true) RoleInfo role, + @ApiParam( + name = "user-store", + value = "The name of the user store which the particular role resides in.", + required = false) + @QueryParam("user-store") String userStoreName); - @PUT - @Path("/{roleName}/users") - @ApiOperation( - consumes = MediaType.APPLICATION_JSON, - produces = MediaType.APPLICATION_JSON, - httpMethod = "PUT", - value = "Adding Users to a Role", - notes = "Defining users to a role at the point of creating a new role is optional. " + - "You can update the users that belong to a given role after you have created " + - "a role using this REST API.\n" + - "Example: Your Organization hires 30 new engineers. Updating the role details for each user can " + - "be cumbersome. Therefore, you can define all the new employees that belong to the engineering " + - "role using this API.", - tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:add-users") + @DELETE + @Path("/{roleName}") + @ApiOperation( + httpMethod = "DELETE", + value = "Deleting a Role", + notes = "Roles become obsolete over time due to various reasons. In a situation where your Organization identifies that a specific role is no longer required, you " + + "can delete a role using this REST API.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:delete") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully removed the specified role."), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified role does not exist.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while removing the role.", + response = ErrorResponse.class) + }) + Response deleteRole( + @ApiParam( + name = "roleName", + value = "The name of the role that needs to de deleted.\n" + + "NOTE: Don't delete the admin role", + required = true) + @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the user store which the particular role resides in.", + required = false) + @QueryParam("user-store") String userStoreName); + + @PUT + @Path("/{roleName}/users") + @ApiOperation( + consumes = MediaType.APPLICATION_JSON, + produces = MediaType.APPLICATION_JSON, + httpMethod = "PUT", + value = "Adding Users to a Role", + notes = "Defining users to a role at the point of creating a new role is optional. " + + "You can update the users that belong to a given role after you have created " + + "a role using this REST API.\n" + + "Example: Your Organization hires 30 new engineers. Updating the role details for each user can " + + "be cumbersome. Therefore, you can define all the new employees that belong to the engineering " + + "role using this API.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:add-users") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully added the users to the specified role.", + responseHeaders = { + @ResponseHeader( + name = "Content-Type", + description = "Content type of the body"), + @ResponseHeader( + name = "ETag", + description = "Entity Tag of the response resource.\n" + + "Used by caches, or in conditional requests."), + @ResponseHeader( + name = "Last-Modified", + description = "Date and time the resource has been modified the last time.\n" + + "Used by caches, or in conditional requests.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified role does not exist.", + response = ErrorResponse.class), + @ApiResponse( + code = 415, + message = "Unsupported media type. \n The format of the requested entity was not supported.\n" + + "supported format.", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while adding the user to the specified role.", + response = ErrorResponse.class) }) - } - ) - @ApiResponses( - value = { - @ApiResponse( - code = 200, - message = "OK. \n Successfully added the users to the specified role.", - responseHeaders = { - @ResponseHeader( - name = "Content-Type", - description = "Content type of the body"), - @ResponseHeader( - name = "ETag", - description = "Entity Tag of the response resource.\n" + - "Used by caches, or in conditional requests."), - @ResponseHeader( - name = "Last-Modified", - description = "Date and time the resource has been modified the last time.\n" + - "Used by caches, or in conditional requests.")}), - @ApiResponse( - code = 400, - message = "Bad Request. \n Invalid request or validation error.", - response = ErrorResponse.class), - @ApiResponse( - code = 404, - message = "Not Found. \n The specified role does not exist.", - response = ErrorResponse.class), - @ApiResponse( - code = 415, - message = "Unsupported media type. \n The format of the requested entity was not supported.\n" + - "supported format.", - response = ErrorResponse.class), - @ApiResponse( - code = 500, - message = "Internal Server Error. \n " + - "Server error occurred while adding the user to the specified role.", - response = ErrorResponse.class) - }) - Response updateUsersOfRole( - @ApiParam( - name = "roleName", - value = "The name of the role.", - required = true, - defaultValue = "admin") - @PathParam("roleName") String roleName, - @ApiParam( - name = "user-store", - value = "The name of the user store which the particular role resides in.", - required = false) - @QueryParam("user-store") String userStoreName, - @ApiParam( - name = "users", - value = "Define the users that belong to the role.\n" + - "Multiple users can be added to a role by using comma separated values. ", - required = true, - defaultValue = "[admin]" - ) List users); + Response updateUsersOfRole( + @ApiParam( + name = "roleName", + value = "The name of the role.", + required = true, + defaultValue = "admin") + @PathParam("roleName") String roleName, + @ApiParam( + name = "user-store", + value = "The name of the user store which the particular role resides in.", + required = false) + @QueryParam("user-store") String userStoreName, + @ApiParam( + name = "users", + value = "Define the users that belong to the role.\n" + + "Multiple users can be added to a role by using comma separated values. ", + required = true, + defaultValue = "[admin]" + ) List users); -} + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index 3532fbe38f..e4da6a1ed6 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -18,21 +18,17 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.impl; +import io.swagger.annotations.ApiParam; 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 org.wso2.carbon.device.mgt.common.Device; -import org.wso2.carbon.device.mgt.common.DeviceIdentifier; -import org.wso2.carbon.device.mgt.common.DeviceManagementException; -import org.wso2.carbon.device.mgt.common.Feature; -import org.wso2.carbon.device.mgt.common.FeatureManager; -import org.wso2.carbon.device.mgt.common.PaginationRequest; -import org.wso2.carbon.device.mgt.common.PaginationResult; +import org.wso2.carbon.device.mgt.common.*; import org.wso2.carbon.device.mgt.common.app.mgt.Application; import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManagementException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationException; import org.wso2.carbon.device.mgt.common.authorization.DeviceAccessAuthorizationService; +import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; 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.policy.mgt.Policy; @@ -40,6 +36,8 @@ import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.NonComplianceData; import org.wso2.carbon.device.mgt.common.policy.mgt.monitor.PolicyComplianceException; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.core.app.mgt.ApplicationManagementProviderService; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceDetailsMgtException; +import org.wso2.carbon.device.mgt.core.device.details.mgt.DeviceInformationManager; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; @@ -55,15 +53,7 @@ import org.wso2.carbon.policy.mgt.core.PolicyManagerService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import javax.validation.constraints.Size; -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.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; import java.text.ParseException; @@ -97,8 +87,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (!StringUtils.isEmpty(name) && !StringUtils.isEmpty(role)) { return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Request contains both name and role " + - "parameters. Only one is allowed " + - "at once.").build()).build(); + "parameters. Only one is allowed " + + "at once.").build()).build(); } // RequestValidationUtil.validateSelectionCriteria(type, user, roleName, ownership, status); RequestValidationUtil.validatePaginationParameters(offset, limit); @@ -108,7 +98,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (deviceAccessAuthorizationService == null) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Device access authorization service is " + - "failed").build()).build(); + "failed").build()).build(); } PaginationRequest request = new PaginationRequest(offset, limit); PaginationResult result; @@ -131,7 +121,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { RequestValidationUtil.validateStatus(status); request.setStatus(status); } - if (groupId != 0 ) { + if (groupId != 0) { request.setGroupId(groupId); } if (role != null && !role.isEmpty()) { @@ -153,7 +143,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { request.setOwner(user); } else { String msg = "User '" + authorizedUser + "' is not authorized to retrieve devices of '" + user - + "' user"; + + "' user"; log.error(msg); return Response.status(Response.Status.UNAUTHORIZED).entity( new ErrorResponse.ErrorResponseBuilder().setCode(401l).setMessage(msg).build()).build(); @@ -328,12 +318,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } catch (ParseException e) { return Response.status(Response.Status.BAD_REQUEST).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("Invalid date " + - "string is provided in 'If-Modified-Since' header").build()).build(); + "string is provided in 'If-Modified-Since' header").build()).build(); } device = dms.getDevice(new DeviceIdentifier(id, type), sinceDate); if (device == null) { return Response.status(Response.Status.NOT_MODIFIED).entity("No device is modified " + - "after the timestamp provided in 'If-Modified-Since' header").build(); + "after the timestamp provided in 'If-Modified-Since' header").build(); } } else { device = dms.getDevice(new DeviceIdentifier(id, type)); @@ -357,6 +347,32 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { return Response.status(Response.Status.OK).entity(device).build(); } + @GET + @Path("/{type}/{id}/location") + @Override + public Response getDeviceLocation( + @PathParam("type") @Size(max = 45) String type, + @PathParam("id") @Size(max = 45) String id, + @HeaderParam("If-Modified-Since") String ifModifiedSince) { + DeviceInformationManager informationManager; + DeviceLocation deviceLocation; + try { + DeviceIdentifier deviceIdentifier = new DeviceIdentifier(); + deviceIdentifier.setId(id); + deviceIdentifier.setType(type); + informationManager = DeviceMgtAPIUtils.getDeviceInformationManagerService(); + deviceLocation = informationManager.getDeviceLocation(deviceIdentifier); + + } catch (DeviceDetailsMgtException e) { + String msg = "Error occurred while getting the device location."; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + return Response.status(Response.Status.OK).entity(deviceLocation).build(); + + } + @GET @Path("/{type}/{id}/features") @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java index dd6932981f..e947c258c0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -30,37 +30,20 @@ import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.FilteringUtil; import org.wso2.carbon.device.mgt.jaxrs.service.impl.util.RequestValidationUtil; import org.wso2.carbon.device.mgt.jaxrs.util.DeviceMgtAPIUtils; import org.wso2.carbon.device.mgt.jaxrs.util.SetReferenceTransformer; -import org.wso2.carbon.user.api.AuthorizationManager; -import org.wso2.carbon.user.api.Permission; -import org.wso2.carbon.user.api.UserRealm; -import org.wso2.carbon.user.api.UserStoreException; -import org.wso2.carbon.user.api.UserStoreManager; +import org.wso2.carbon.user.api.*; import org.wso2.carbon.user.core.common.AbstractUserStoreManager; import org.wso2.carbon.user.mgt.UserRealmProxy; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import org.wso2.carbon.user.mgt.common.UserAdminException; -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.*; 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.net.URLEncoder; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.HashSet; -import java.util.List; -import java.util.Set; +import java.util.*; import static org.wso2.carbon.device.mgt.jaxrs.util.Constants.PRIMARY_USER_STORE; @@ -105,6 +88,48 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } + @GET + @Path("/filter/{prefix}") + @Override + public Response getFilteredRoles( + @PathParam("prefix") String prefix, + @QueryParam("filter") String filter, + @QueryParam("user-store") String userStore, + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @QueryParam("offset") int offset, @QueryParam("limit") int limit) { + RequestValidationUtil.validatePaginationParameters(offset, limit); + List finalRoleList; + RoleList targetRoles = new RoleList(); + + //if user store is null set it to primary + if (userStore == null || "".equals(userStore)) { + userStore = PRIMARY_USER_STORE; + } + + try { + + //Get the total role count that matches the given filter + List filteredRoles = getRolesFromUserStore(filter, userStore); + finalRoleList = new ArrayList(); + + filteredRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit); + for (String rolename : filteredRoles){ + if (rolename.startsWith(prefix)){ + finalRoleList.add(rolename); + } + } + targetRoles.setCount(finalRoleList.size()); + targetRoles.setList(finalRoleList); + + return Response.ok().entity(targetRoles).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving roles from the underlying user stores"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } + @GET @Path("/{roleName}/permissions") @Override @@ -208,7 +233,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (!userStoreManager.isExistingRole(roleName)) { return Response.status(404).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + roleName + "'").build()).build(); } roleInfo.setRoleName(roleName); roleInfo.setUsers(userStoreManager.getUserListOfRole(roleName)); @@ -275,7 +300,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { //TODO fix what's returned in the entity return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleInfo.getRoleName(), "UTF-8"))). entity("Role '" + roleInfo.getRoleName() + "' has " + "successfully been" - + " added").build(); + + " added").build(); } catch (UserStoreException e) { String msg = "Error occurred while adding role '" + roleInfo.getRoleName() + "'"; log.error(msg, e); @@ -335,7 +360,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { //TODO fix what's returned in the entity return Response.created(new URI(API_BASE_PATH + "/" + URLEncoder.encode(roleName, "UTF-8"))). entity("Role '" + roleName + "' has " + "successfully been" - + " added").build(); + + " added").build(); } catch (UserAdminException e) { String msg = "Error occurred while retrieving the permissions of role '" + roleName + "'"; log.error(msg, e); @@ -376,7 +401,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (!userStoreManager.isExistingRole(roleName)) { return Response.status(404).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + roleName + "'").build()).build(); } final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager(); @@ -392,7 +417,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (roleInfo.getUsers() != null) { SetReferenceTransformer transformer = new SetReferenceTransformer<>(); transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(newRoleName)), - Arrays.asList(roleInfo.getUsers())); + Arrays.asList(roleInfo.getUsers())); final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer .getObjectsToAdd().size()]); final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer @@ -404,7 +429,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { // Get all role permissions final UIPermissionNode rolePermissions = this.getAllRolePermissions(roleName, userRealm); List permissions = new ArrayList(); - final UIPermissionNode emmRolePermissions = (UIPermissionNode)this.getRolePermissions(roleName); + final UIPermissionNode emmRolePermissions = (UIPermissionNode) this.getRolePermissions(roleName); List emmConsolePermissions = new ArrayList(); this.getAuthorizedPermissions(emmRolePermissions, emmConsolePermissions); emmConsolePermissions.removeAll(new ArrayList(Arrays.asList(roleInfo.getPermissions()))); @@ -413,7 +438,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { permissions.add(permission); } permissions.removeAll(emmConsolePermissions); - String [] allApplicablePerms = new String[permissions.size()]; + String[] allApplicablePerms = new String[permissions.size()]; allApplicablePerms = permissions.toArray(allApplicablePerms); roleInfo.setPermissions(allApplicablePerms); @@ -428,7 +453,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { } //TODO: Need to send the updated role information in the entity back to the client return Response.status(Response.Status.OK).entity("Role '" + roleInfo.getRoleName() + "' has " + - "successfully been updated").build(); + "successfully been updated").build(); } catch (UserStoreException e) { String msg = "Error occurred while updating role '" + roleName + "'"; log.error(msg, e); @@ -456,7 +481,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (!userStoreManager.isExistingRole(roleName)) { return Response.status(404).entity( new ErrorResponse.ErrorResponseBuilder().setMessage("No role exists with the name '" + - roleName + "'").build()).build(); + roleName + "'").build()).build(); } final AuthorizationManager authorizationManager = userRealm.getAuthorizationManager(); @@ -493,7 +518,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { } SetReferenceTransformer transformer = new SetReferenceTransformer<>(); transformer.transform(Arrays.asList(userStoreManager.getUserListOfRole(roleName)), - users); + users); final String[] usersToAdd = transformer.getObjectsToAdd().toArray(new String[transformer .getObjectsToAdd().size()]); final String[] usersToDelete = transformer.getObjectsToRemove().toArray(new String[transformer @@ -502,7 +527,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd); return Response.status(Response.Status.OK).entity("Role '" + roleName + "' has " + - "successfully been updated with the user list") + "successfully been updated with the user list") .build(); } catch (UserStoreException e) { String msg = "Error occurred while updating the users of the role '" + roleName + "'"; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js index 68fa4630d7..0138c57897 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/device.js @@ -98,6 +98,26 @@ deviceModule = function () { locationTimeData.push(gpsReadingTimes); } } + var locationInfo = {}; + try { + var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/devices/" + deviceType + "/" + deviceId + "/location"; + serviceInvokers.XMLHttp.get( + url, + function (backendResponse) { + + if (backendResponse.status == 200 && backendResponse.responseText) { + var device = parse(backendResponse.responseText); + locationInfo.latitude = device.latitude; + locationInfo.longitude = device.longitude; + locationInfo.updatedOn = device.updatedTime; + + } + }); + } catch (e) { + log.error(e.message, e); + } + + var utility = require('/app/modules/utility.js')["utility"]; try { utility.startTenantFlow(carbonUser); @@ -174,11 +194,26 @@ deviceModule = function () { } if (device["deviceInfo"]) { filteredDeviceData["latestDeviceInfo"] = device["deviceInfo"]; + + //location related verification and modifications + // adding the location histry for the movement path. + var locationHistory = {}; + locationHistory.locations = locationData; + locationHistory.times = locationTimeData; + filteredDeviceData["locationHistory"] = locationHistory; + + //checking for the latest location information. + if (filteredDeviceData.latestDeviceInfo.location && locationInfo) { + var infoDate = new Date(filteredDeviceData.latestDeviceInfo.location.updatedTime); + var locationDate = new Date(locationInfo.updatedOn); + if (infoDate < locationDate) { + filteredDeviceData.latestDeviceInfo.location.longitude = locationInfo.longitude; + filteredDeviceData.latestDeviceInfo.location.latitude = locationInfo.latitude; + } + } } - var locationHistory = {}; - locationHistory.locations = locationData; - locationHistory.times = locationTimeData; - filteredDeviceData["locationHistory"] = locationHistory; + + response["content"] = filteredDeviceData; response["status"] = "success"; return response; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js index d1b2838985..96f4d280bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/business-controllers/user.js @@ -302,6 +302,32 @@ var userModule = function () { } }; + /** + * Get User Roles from user store (Internal roles not included). + */ + publicMethods.getFilteredRoles = function (prefix) { + var carbonUser = session.get(constants["USER_SESSION_KEY"]); + var utility = require("/app/modules/utility.js")["utility"]; + if (!carbonUser) { + log.error("User object was not found in the session"); + throw constants["ERRORS"]["USER_NOT_FOUND"]; + } + try { + utility.startTenantFlow(carbonUser); + var url = devicemgtProps["httpsURL"] + devicemgtProps["backendRestEndpoints"]["deviceMgt"] + + "/roles/filter/" + prefix + "?offset=0&limit=100&user-store=all"; + var response = privateMethods.callBackend(url, constants["HTTP_GET"]); + if (response.status == "success") { + response.content = parse(response.content); + } + return response; + } catch (e) { + throw e; + } finally { + utility.endTenantFlow(); + } + }; + /** * Get User Roles count from user store (Internal roles not included). */ @@ -467,8 +493,8 @@ var userModule = function () { try { carbonUser = session.get(constants.USER_SESSION_KEY); } catch (e) { - log.error("User object was not found in the session"); - carbonUser = null; + log.error("User object was not found in the session"); + carbonUser = null; } var utility = require('/app/modules/utility.js').utility; if (!carbonUser) { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js index d1658872b3..7b6add5fa8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/modules/utility.js @@ -39,8 +39,8 @@ utility = function () { PrivilegedCarbonContext.startTenantFlow(); context = PrivilegedCarbonContext.getThreadLocalCarbonContext(); context.setTenantDomain(carbon.server.tenantDomain({ - tenantId: userInfo.tenantId - })); + tenantId: userInfo.tenantId + })); context.setTenantId(userInfo.tenantId); context.setUsername(userInfo.username || null); }; @@ -161,15 +161,19 @@ utility = function () { * @returns {*} */ publicMethods.encodeJson = function (text) { - return text - .replace(/\\u003c/g, "<") - .replace(//g, ">") - .replace(/\\u0027/g, "'") - .replace(/'/g, "'") - .replace(/\\"/g, """) - .replace(/\\u0022/g, """) + if (text) { + return text + .replace(/\\u003c/g, "<") + .replace(//g, ">") + .replace(/\\u0027/g, "'") + .replace(/'/g, "'") + .replace(/\\"/g, """) + .replace(/\\u0022/g, """); + } else { + return ""; + } }; return publicMethods; diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js index f52ce80319..1d2d7c8607 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.dashboard/dashboard.js @@ -39,8 +39,11 @@ function onRequest() { viewModel.groupCount = groupModule.getGroupCount(); viewModel.userCount = userModule.getUsersCount(); viewModel.policyCount = policyModule.getPoliciesCount(); - viewModel.roleCount = userModule.getRolesCount(); viewModel.isCloud = devicemgtProps.isCloud; - + if (devicemgtProps.isCloud) { + viewModel.roleCount = userModule.getFilteredRoles("devicemgt").content.count; + } else { + viewModel.roleCount = userModule.getRolesCount(); + } return viewModel; } \ No newline at end of file diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js index 6899f98fb2..516aacb7b5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/public/js/role-listing.js @@ -98,42 +98,22 @@ function loadRoles() { var dataFilter = function (data) { data = JSON.parse(data); - var objects = []; var count = 0; $(data.roles).each(function (index) { - if (isCloud && data.roles[index].startsWith("devicemgt")) { - count++; - objects.push( - { - name: htmlspecialchars(data.roles[index]), - DT_RowId: "role-" + htmlspecialchars(data.roles[index]) - } - ) - } else if (!isCloud) { - objects.push( - { - name: htmlspecialchars(data.roles[index]), - DT_RowId: "role-" + htmlspecialchars(data.roles[index]) - } - ) - } + objects.push( + { + name: htmlspecialchars(data.roles[index]), + DT_RowId: "role-" + htmlspecialchars(data.roles[index]) + } + ) }); - var json = {}; - if (isCloud) { - json = { - "recordsTotal": count, - "recordsFiltered": count, - "data": objects - }; - } else { - json = { - "recordsTotal": data.count, - "recordsFiltered": data.count, - "data": objects - }; - } + var json = { + "recordsTotal": data.count, + "recordsFiltered": data.count, + "data": objects + }; return JSON.stringify(json); }; @@ -156,7 +136,7 @@ function loadRoles() { class: "", data: "name", render: function (name, type, row, meta) { - return '

' + name + '

'; + return '

' + name.replace("devicemgt", ""); + '

'; } }, { @@ -225,8 +205,12 @@ function loadRoles() { var settings = { "sorting": false }; + var roleApiUrl = '/api/device-mgt/v1.0/roles?user-store=all'; + if (isCloud) { + roleApiUrl = '/api/device-mgt/v1.0/roles/filter/devicemgt?user-store=all'; + } - $('#role-grid').datatables_extended_serverside_paging(settings, '/api/device-mgt/v1.0/roles?user-store=all', dataFilter, columns, fnCreatedRow, null, options); + $('#role-grid').datatables_extended_serverside_paging(settings, roleApiUrl, dataFilter, columns, fnCreatedRow, null, options); loadingContent.hide(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/roles.hbs b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/roles.hbs index 47e8181218..5476c743dd 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/roles.hbs +++ b/components/device-mgt/org.wso2.carbon.device.mgt.ui/src/main/resources/jaggeryapps/devicemgt/app/pages/cdmf.page.roles/roles.hbs @@ -50,45 +50,66 @@ {{/zone}} {{#zone "content"}} -
- {{#unless isCloud}} - {{#if removePermitted}} - + {{#if hasRoles}} +
+ {{#unless isCloud}} + {{#if removePermitted}} + + {{/if}} + {{#if editPermitted}} + + {{/if}} + {{/unless}} + {{#if isCloud}} + {{/if}} - {{#if editPermitted}} - - {{/if}} - {{/unless}} - {{#if isCloud}} - - {{/if}} - - Loading roles . . . -
-
+ + Loading roles . . . +
+
+ +
+ + + + + + + + + + +
By Role Name
+
-
- - - - - - - - - - -
By Role Name
-
+ + + {{else}} -