From 2619c626b29e51784f9b6242b906f54772807721 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Mon, 19 Dec 2016 18:23:06 +0530 Subject: [PATCH 1/3] added scope annotation --- .../CertificateManagementAdminService.java | 48 +++-- .../api/ActivityInfoProviderService.java | 22 +- .../api/ConfigurationManagementService.java | 10 +- .../mgt/jaxrs/service/api/Dashboard.java | 160 +++++++++++++- .../service/api/DeviceManagementService.java | 166 ++++++++------ .../api/DeviceTypeManagementService.java | 42 ++-- .../service/api/GroupManagementService.java | 202 +++++++++++------- .../api/NotificationManagementService.java | 41 ++-- .../service/api/PolicyManagementService.java | 155 +++++++++----- .../service/api/RoleManagementService.java | 135 +++++++----- .../service/api/UserManagementService.java | 180 ++++++++++------ .../ApplicationManagementAdminService.java | 31 ++- .../admin/DeviceManagementAdminService.java | 12 +- .../admin/GroupManagementAdminService.java | 22 +- .../api/admin/UserManagementAdminService.java | 25 ++- 15 files changed, 851 insertions(+), 400 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index 3f849cba9ce..df92a10eb33 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -1,6 +1,16 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.api; -import io.swagger.annotations.*; +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 org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.CertificateList; @@ -31,16 +41,28 @@ import javax.ws.rs.core.Response; @Path("/admin/certificates") @Scopes(scopes = { @Scope( - name = "Manage certificates", - description = "", - key = "cdmf:manage-certificate", - permissions = {"/device-mgt/certificates/manage"} + name = "Adding a new SSL certificate", + description = "Adding a new SSL certificate", + key = "cdmf:admin:certificates:add", + permissions = {"/device-mgt/admin/certificates/add"} ), @Scope( - name = "View certificate", - description = "", - key = "cdmf:view-certificate", - permissions = {"/device-mgt/certificates/view"} + name = "Getting Details of an SSL Certificate", + description = "Getting Details of an SSL Certificate", + key = "cdmf:admin:certificates:details", + permissions = {"/device-mgt/admin/certificates/details"} + ), + @Scope( + name = "Getting Details of Certificates", + description = "Getting Details of Certificates", + key = "cdmf:admin:certificates:view", + permissions = {"/device-mgt/admin/certificates/view"} + ), + @Scope( + name = "Deleting an SSL Certificate", + description = "Deleting an SSL Certificate", + key = "cdmf:admin:certificates:delete", + permissions = {"/device-mgt/admin/certificates/delete"} ) } ) @@ -67,7 +89,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:add") }) } ) @@ -136,7 +158,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:details") }) } ) @@ -207,7 +229,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:view") }) } ) @@ -286,7 +308,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:delete") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 9c3e2c4f5bc..3a040fa2161 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -18,7 +18,17 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; +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 org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -55,9 +65,9 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Get activities", - description = "Get activities", - key = "cdmf:get-activity", + name = "Getting Details of an Activity", + description = "Getting Details of an Activity", + key = "cdmf:activities:details", permissions = {"/device-mgt/devices/owning-device/view"} ) } @@ -77,7 +87,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") }) } ) @@ -150,7 +160,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index 504bd75f1d7..87fa47c5d3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -68,13 +66,13 @@ import javax.ws.rs.core.Response; @Scope( name = "View configurations", description = "", - key = "cdmf:view-configuration", + key = "cdmf:configuration:view", permissions = {"/device-mgt/platform-configurations/view"} ), @Scope( name = "Manage configurations", description = "", - key = "cdmf:manage-configuration", + key = "cdmf:configuration:manage", permissions = {"/device-mgt/platform-configurations/manage"} ) } @@ -92,7 +90,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-configuration") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:view") }) } ) @@ -151,7 +149,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-configuration") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:manage") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java index 903c92e5cde..8251ff40ae1 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java @@ -1,15 +1,23 @@ 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -18,9 +26,89 @@ import javax.ws.rs.core.Response; /** * Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics. */ +@SwaggerDefinition( + info = @Info( + version = "1.0.0", + title = "", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = "name", value = "DeviceAnalyticsDashboard"), + @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/dashboard"), + }) + } + ), + tags = { + @Tag(name = "device_management", description = "Device Analytics Dashboard related information APIs" + + " are described here.") + } +) @Path("/dashboard") @Api(value = "Device Analytics Dashboard", description = "Device Analytics Dashboard related information APIs are described here.") +@Scopes( + scopes = { + @Scope( + name = "Device Count Overview", + description = "Device Count Overview", + key = "cdmf:dashboard:count-overview", + permissions = {"/device-mgt/dashboard/device-count"} + ), + @Scope( + name = "Device Counts by Potential Vulnerabilities", + description = "Device Counts by Potential Vulnerabilities", + key = "cdmf:dashboard:vulnerabilities", + permissions = {"/device-mgt/dashboard/vulnerabilities"} + ), + @Scope( + name = "Get the number of devices that have not complied to a policy", + description = "Get the number of devices that have not complied to a policy", + key = "cdmf:dashboard:non-compliant", + permissions = {"/device-mgt/dashboard/features"} + ), + @Scope( + name = "Get the number of devices for a given device type, such as connectivity status, " + + "potential vulnerability, platform, and ownership", + description = "Get the number of devices for a given device type, such as connectivity status, " + + "potential vulnerability, platform, and ownership", + key = "cdmf:dashboard:by-groups", + permissions = {"/device-mgt/dashboard/groups"} + ), + @Scope( + name = "Get the number of devices that have not complied to a given policy based on a particular", + description = "Get the number of devices that have not complied to a given policy based on a particular", + key = "cdmf:dashboard:device-counts", + permissions = {"/device-mgt/dashboard/groups"} + ), + @Scope( + name = "Get the number of devices that have not complied to a given policy based on a particular" + + " device type.", + description = "Get the number of devices that have not complied to a given policy based on a " + + "particular device type.", + key = "cdmf:dashboard:filtered-count", + permissions = {"/device-mgt/dashboard/total"} + ), + @Scope( + name = "Get the number of devices that have not complied to a given policy over the total" + + " number of devices registered with WSO2 EMM.\n", + description = "Get the number of devices that have not complied to a given policy over the total" + + " number of devices registered with WSO2 EMM.\n", + key = "cdmf:dashboard:non-compliant-count", + permissions = {"/device-mgt/dashboard/total"} + ), + @Scope( + name = "Get device details of devices based on a particular device type.", + description = "Get device details of devices based on a particular device type.", + key = "cdmf:dashboard:details", + permissions = {"/device-mgt/dashboard/details"} + ), + @Scope( + name = "Get device details of non-compliant devices which do not comply to a given policy.", + description = "Get device details of non-compliant devices which do not comply to a given policy.", + key = "cdmf:dashboard:feature-non-compliant", + permissions = {"/device-mgt/dashboard/details"} + ) + } +) @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("NonJaxWsWebServices") public interface Dashboard { @@ -43,7 +131,13 @@ public interface Dashboard { value = "Get the details of registered devices in WSO2 EMM.", notes = "Get the details of active, inactive, removed and total number of registered devices in" + " WSO2 EMM.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:count-overview") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -93,7 +187,13 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get the number of unmonitored and non-compliant devices in WSO2 EMM.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:vulnerabilities") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -144,7 +244,13 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a policy that was enforced on a " + "device.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:non-compliant") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -208,7 +314,13 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices for a given device type, such as connectivity status, " + "potential vulnerability, platform, and ownership.\n", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:by-groups") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -291,7 +403,13 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a given policy based on a particular" + " device type.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:device-counts") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -364,7 +482,13 @@ public interface Dashboard { + "Connectivity status of the device, such as active, inactive or removed.\n" + "The device ownership type, such as BYOD or COPE.\n" + "The device platform.\n" + "The potential vulnerabilities faced by the devices.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:filtered-count") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -450,7 +574,13 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a given policy over the total" + " number of devices registered with WSO2 EMM.\n", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:non-compliant-count") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -519,7 +649,13 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get device details of devices based on a particular device type.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:details") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, @@ -615,7 +751,13 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get device details of non-compliant devices which do not comply to a given policy.", - tags = "Dashboard") + tags = "Dashboard", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:feature-non-compliant") + }) + } + ) @ApiResponses(value = { @ApiResponse( code = 200, 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 650ae34f7b6..ed9290df4ca 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 @@ -24,13 +24,13 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; @@ -38,6 +38,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; @@ -64,6 +65,64 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting Details of Registered Devices", + description = "Getting Details of Registered Devices", + key = "cdmf:devices:view", + permissions = {"/device-mgt/devices/owning-device/view"} + ), + @Scope( + name = "Getting Details of a Device", + description = "Getting Details of a Device", + key = "cdmf:devices:details", + permissions = {"/device-mgt/devices/owning-device/details"} + ), + @Scope( + name = "Delete the device specified by device id", + description = "Delete the device specified by device id", + key = "cdmf:devices:delete", + permissions = {"/device-mgt/devices/owning-device/delete"} + ), + @Scope( + name = "Getting Feature Details of a Device", + description = "Getting Feature Details of a Device", + key = "cdmf:devices:features", + permissions = {"/device-mgt/devices/owning-device/features"} + ), + @Scope( + name = "Advanced Search for Devices", + description = "Advanced Search for Devices", + key = "cdmf:devices:search", + permissions = {"/device-mgt/devices/owning-device/view"} + ), + @Scope( + name = "Getting Installed Application Details of a Device", + description = "Getting Installed Application Details of a Device", + key = "cdmf:devices:applications", + permissions = {"/device-mgt/devices/owning-device/applications"} + ), + @Scope( + name = "Getting Device Operation Details", + description = "Getting Device Operation Details", + key = "cdmf:devices:operations", + permissions = {"/device-mgt/devices/owning-device/operations"} + ), + @Scope( + name = "Get the details of the policy that is enforced on a device.", + description = "Get the details of the policy that is enforced on a device.", + key = "cdmf:devices:effective-policy", + permissions = {"/device-mgt/devices/owning-device/effective-policy"} + ), + @Scope( + name = "Getting Policy Compliance Details of a Device", + description = "Getting Policy Compliance Details of a Device", + key = "cdmf:devices:compliance-data", + permissions = {"/device-mgt/devices/owning-device/compliance-data"} + ) + } +) @Path("/devices") @Api(value = "Device Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @@ -78,13 +137,11 @@ public interface DeviceManagementService { value = "Getting Details of Registered Devices", notes = "Provides details of all the devices enrolled with WSO2 EMM.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view" - , description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:view") + }) + } ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @@ -205,12 +262,10 @@ public interface DeviceManagementService { value = "Getting Details of a Device", notes = "Get the details of a device by specifying the device type and device identifier.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:details") + }) } ) @ApiResponses( @@ -282,15 +337,13 @@ public interface DeviceManagementService { @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "DELETE", - value = "Delete the device speccified by device id", + value = "Delete the device specified by device id", notes = "Returns the status of the deleted device operation.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:delete") + }) } ) @ApiResponses( @@ -359,13 +412,11 @@ public interface DeviceManagementService { "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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:features") + }) + } ) @ApiResponses( value = { @@ -450,12 +501,10 @@ public interface DeviceManagementService { value = "Advanced Search for Devices", notes = "Search for devices by filtering the search result through the specified search terms.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:search") + }) } ) @ApiResponses( @@ -529,13 +578,12 @@ public interface DeviceManagementService { value = "Getting Installed Application Details of a Device", notes = "Get the list of applications subscribed to by a device.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:applications") + }) + + } ) @ApiResponses( value = { @@ -633,13 +681,11 @@ public interface DeviceManagementService { value = "Getting Device Operation Details", notes = "Get the details of operations carried out on a selected device.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:operations") + }) + } ) @ApiResponses( value = { @@ -746,13 +792,11 @@ public interface DeviceManagementService { "WSO2 EMM 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:effective-policy") + }) + } ) @ApiResponses( value = { @@ -837,12 +881,10 @@ public interface DeviceManagementService { notes = "A policy is enforced on the devices that register with WSO2 EMM. " + "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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:compliance-data") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index 94b06ea7513..963edc84f75 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -24,15 +24,16 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -54,6 +55,22 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting the Supported Device Platforms", + description = "Getting the Supported Device Platforms", + key = "cdmf:device-types:types", + permissions = {"/device-mgt/device-types/types"} + ), + @Scope( + name = "Get Feature Details of a Device Type", + description = "Get Feature Details of a Device Type", + key = "cdmf:device-types:features", + permissions = {"/device-mgt/device-types/features"} + ) + } +) @Path("/device-types") @Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " + "type management") @@ -68,12 +85,10 @@ public interface DeviceTypeManagementService { value = "Getting the Supported Device Platforms", notes = "Get the list of device platforms supported by WSO2 EMM.", tags = "Device Type Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Device Types") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:types") + }) } ) @ApiResponses( @@ -123,6 +138,7 @@ public interface DeviceTypeManagementService { String ifModifiedSince); @GET + @Path("/{type}/features") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", @@ -131,12 +147,10 @@ public interface DeviceTypeManagementService { "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 Type Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Device Types") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:features") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index a982a3c3d53..aff13f24375 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.AuthorizationScope; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Info; @@ -33,12 +31,15 @@ import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; import org.apache.axis2.transport.http.HTTPConstants; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -74,6 +75,82 @@ import java.util.List; "details.") } ) +@Scopes( + scopes = { + @Scope( + name = "Get the list of groups belongs to current user.", + description = "Get the list of groups belongs to current user.", + key = "cdmf:groups:groups", + permissions = {"/device-mgt/groups/groups"} + ), + @Scope( + name = "Get the count of groups belongs to current user.", + description = "Get the count of groups belongs to current user.", + key = "cdmf:groups:count", + permissions = {"/device-mgt/groups/count"} + ), + @Scope( + name = "Add new device group to the system.", + description = "Add new device group to the system.", + key = "cdmf:groups:add", + permissions = {"/device-mgt/groups/add"} + ), + @Scope( + name = "View group specified", + description = "View group specified", + key = "cdmf:groups:groups-view", + permissions = {"/device-mgt/groups/groups-view"} + ), + @Scope( + name = "Update a group", + description = "Update a group", + key = "cdmf:groups:update", + permissions = {"/device-mgt/groups/update"} + ), + @Scope( + name = "Delete a group", + description = "Delete a group", + key = "cdmf:groups:remove", + permissions = {"/device-mgt/groups/remove"} + ), + @Scope( + name = "Manage group sharing with a user", + description = "Manage group sharing with a user", + key = "cdmf:groups:share", + permissions = {"/device-mgt/groups/share"} + ), + @Scope( + name = "View list of roles of a device group", + description = "View list of roles of a device group", + key = "cdmf:groups:roles", + permissions = {"/device-mgt/groups/roles"} + ), + @Scope( + name = "View list of devices in the device group", + description = "View list of devices in the device group", + key = "cdmf:groups:devices", + permissions = {"/device-mgt/groups/devices"} + ), + @Scope( + name = "View list of device count in the device group", + description = "View list of device count in the device group", + key = "cdmf:groups:devices-count", + permissions = {"/device-mgt/groups/devices/devices-count"} + ), + @Scope( + name = "Add devices to group", + description = "Add devices to group", + key = "cdmf:groups:devices-add", + permissions = {"/device-mgt/groups/devices/devices-add"} + ), + @Scope( + name = "Remove devices from group", + description = "Remove devices from group", + key = "cdmf:groups:devices-remove", + permissions = {"/device-mgt/groups/devices/devices-remove"} + ) + } +) @Path("/groups") @Api(value = "Device Group Management", description = "This API carries all device group management related " + "operations such as get all the available groups, etc.") @@ -88,12 +165,10 @@ public interface GroupManagementService { value = "Get the list of groups belongs to current user.", notes = "Returns all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups") + }) } ) @ApiResponses(value = { @@ -153,13 +228,12 @@ public interface GroupManagementService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:count") + }) } + ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", @@ -202,12 +276,10 @@ public interface GroupManagementService { value = "Add new device group to the system.", notes = "Add device group with current user as the owner.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/add", - description = "Add Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:add") + }) } ) @ApiResponses( @@ -270,12 +342,10 @@ public interface GroupManagementService { value = "View group specified.", notes = "Returns details of group enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups-view") + }) } ) @ApiResponses(value = { @@ -325,12 +395,10 @@ public interface GroupManagementService { notes = "If you wish to make changes to an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/update", - description = "Update Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:update") + }) } ) @ApiResponses(value = { @@ -384,12 +452,10 @@ public interface GroupManagementService { notes = "If you wish to remove an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/remove", - description = "Remove Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:remove") + }) } ) @ApiResponses(value = { @@ -438,12 +504,10 @@ public interface GroupManagementService { notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " + "that can be done using this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/share", - description = "Share Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:share") + }) } ) @ApiResponses(value = { @@ -496,12 +560,10 @@ public interface GroupManagementService { value = "View list of roles of a device group.", notes = "Returns details of roles which particular group has been shared with.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/roles/view", - description = "View roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:roles") + }) } ) @ApiResponses(value = { @@ -550,12 +612,10 @@ public interface GroupManagementService { value = "View list of devices in the device group.", notes = "Returns list of devices in the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", - description = "View devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices") + }) } ) @ApiResponses(value = { @@ -612,12 +672,10 @@ public interface GroupManagementService { value = "View list of device count in the device group.", notes = "Returns device count in the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", - description = "View devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-count") + }) } ) @ApiResponses(value = { @@ -666,12 +724,10 @@ public interface GroupManagementService { value = "Add devices to group.", notes = "Add existing devices to the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/add", - description = "Add devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-add") + }) } ) @ApiResponses(value = { @@ -724,12 +780,10 @@ public interface GroupManagementService { value = "Remove devices from group.", notes = "Remove existing devices from the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/remove", - description = "Remove devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-remove") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index 0a2998251c8..a3d0d556f3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.jaxrs.NotificationList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Max; import javax.validation.constraints.Size; @@ -60,6 +61,22 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting All Device Notification Details", + description = "Getting All Device Notification Details", + key = "cdmf:notifications:view", + permissions = {"/device-mgt/notifications/view"} + ), + @Scope( + name = "Updating the Device Notification Status", + description = "Updating the Device Notification Status", + key = "cdmf:notifications:mark-checked", + permissions = {"/device-mgt/notifications/mark-checked"} + ) + } +) @Api(value = "Device Notification Management", description = "Device notification related operations can be found here.") @Path("/notifications") @Produces(MediaType.APPLICATION_JSON) @@ -73,12 +90,10 @@ public interface NotificationManagementService { value = "Getting All Device Notification Details", notes = "Get the details of all the notifications that were pushed to the devices registered with WSO2 EMM using this REST API.", tags = "Device Notification Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", - description = "View notifications") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:view") + }) } ) @ApiResponses( @@ -164,12 +179,10 @@ public interface NotificationManagementService { notes = "When a user has read the the device notification the device notification status must " + "change from NEW to CHECKED. This API is used to update device notification status.", tags = "Device Notification Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", - description = "View notifications") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:mark-checked") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 6a77938b0fe..2994994ac00 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import javax.validation.Valid; @@ -62,6 +63,64 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Adding a Policy", + description = "Adding a Policy", + key = "cdmf:policies:manage", + permissions = {"/device-mgt/policies/manage"} + ), + @Scope( + name = "Getting Details of Policies", + description = "Getting Details of Policies", + key = "cdmf:policies:get-details", + permissions = {"/device-mgt/policies/get-details"} + ), + @Scope( + name = "Getting Details of a Policy", + description = "Getting Details of a Policy", + key = "cdmf:policies:get-policy-details", + permissions = {"/device-mgt/policies/get-policy-details"} + ), + @Scope( + name = "Updating a Policy", + description = "Updating a Policy", + key = "cdmf:policies:update", + permissions = {"/device-mgt/policies/update"} + ), + @Scope( + name = "Removing Multiple Policies", + description = "Removing Multiple Policies", + key = "cdmf:policies:remove", + permissions = {"/device-mgt/policies/remove"} + ), + @Scope( + name = "Activating Policies", + description = "Activating Policies", + key = "cdmf:policies:activate", + permissions = {"/device-mgt/policies/activate"} + ), + @Scope( + name = "Deactivating Policies", + description = "Deactivating Policies", + key = "cdmf:policies:deactivate", + permissions = {"/device-mgt/policies/deactivate"} + ), + @Scope( + name = "Applying Changes on Policies", + description = "Applying Changes on Policies", + key = "cdmf:policies:changes", + permissions = {"/device-mgt/policies/changes"} + ), + @Scope( + name = "Updating the Policy Priorities", + description = "Updating the Policy Priorities", + key = "cdmf:policies:priorities", + permissions = {"/device-mgt/policies/priorities"} + ) + } +) @Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management") @Path("/policies") @Produces(MediaType.APPLICATION_JSON) @@ -77,12 +136,10 @@ public interface PolicyManagementService { notes = "Add a policy using this REST API command. When adding a policy you will have the option of saving the policy or saving and publishing the policy." + "Using this REST API you are able to save a created Policy and this policy will be in the inactive state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:manage") + }) } ) @ApiResponses( @@ -147,12 +204,10 @@ public interface PolicyManagementService { notes = "Retrieve the details of all the policies in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", - description = "View policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-details") + }) } ) @ApiResponses( @@ -224,12 +279,10 @@ public interface PolicyManagementService { notes = "Retrieve the details of a policy that is in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", - description = "View policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-policy-details") + }) } ) @ApiResponses( @@ -294,12 +347,10 @@ public interface PolicyManagementService { value = "Updating a Policy", notes = "Make changes to an existing policy by updating the policy using this resource.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:update") + }) } ) @ApiResponses( @@ -364,12 +415,10 @@ public interface PolicyManagementService { value = "Removing Multiple Policies", notes = "Delete one or more than one policy using this API.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:remove") + }) } ) @ApiResponses( @@ -412,12 +461,10 @@ public interface PolicyManagementService { value = "Activating Policies", notes = "Publish a policy using this API to bring a policy that is in the inactive state to the active state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:activate") + }) } ) @ApiResponses( @@ -455,12 +502,10 @@ public interface PolicyManagementService { value = "Deactivating Policies", notes = "Unpublish a policy using this API to bring a policy that is in the active state to the inactive state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:deactivate") + }) } ) @ApiResponses( @@ -503,12 +548,10 @@ public interface PolicyManagementService { " devices will not receive these changes immediately. Once all the required changes are made" + " you need to apply the changes to push the policy changes to the existing devices.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:changes") + }) } ) @ApiResponses( @@ -533,13 +576,11 @@ public interface PolicyManagementService { value = "Updating the Policy Priorities", notes = "Make changes to the existing policy priority order by updating the priority order using this API.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:priorities") + }) + } ) @ApiResponses( value = { 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 cc894b9c0b0..b308ddc9702 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 @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import javax.ws.rs.*; @@ -56,6 +57,58 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting the List of Roles", + description = "Getting the List of Roles", + key = "cdmf:roles:view", + permissions = {"/device-mgt/roles/view"} + ), + @Scope( + name = "Getting Permission Details of a Role", + description = "Getting Permission Details of a Role", + key = "cdmf:roles:permissions", + permissions = {"/device-mgt/roles/permissions"} + ), + @Scope( + name = "Getting the List of Roles", + description = "Getting the List of Roles", + key = "cdmf:roles:details", + permissions = {"/device-mgt/roles/details"} + ), + @Scope( + name = "Adding a Role", + description = "Adding a Role", + key = "cdmf:roles:add", + permissions = {"/device-mgt/roles/add"} + ), + @Scope( + name = "Adding a combined Role", + description = "Adding a combined Role", + key = "cdmf:roles:create-combined-role", + permissions = {"/device-mgt/roles/create-combined-role"} + ), + @Scope( + name = "Updating Role Details", + description = "Updating Role Details", + key = "cdmf:roles:update", + permissions = {"/device-mgt/roles/update"} + ), + @Scope( + name = "Deleting a Role", + description = "Deleting a Role", + key = "cdmf:roles:delete", + permissions = {"/device-mgt/roles/delete"} + ), + @Scope( + name = "Adding Users to a Role", + description = "Adding Users to a Role", + key = "cdmf:roles:add-users", + permissions = {"/device-mgt/roles/add-users"} + ) + } +) @Path("/roles") @Api(value = "Role Management", description = "Role management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -70,11 +123,10 @@ public interface RoleManagementService { 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" + "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:view") + }) } ) @ApiResponses( @@ -151,11 +203,10 @@ public interface RoleManagementService { response = UIPermissionNode.class, responseContainer = "List", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:permissions") + }) } ) @ApiResponses( @@ -227,12 +278,10 @@ public interface RoleManagementService { notes = "Get the permissions associated with a role and role specific details using this REST API.", response = RoleInfo.class, tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", - description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:details") + }) } ) @ApiResponses( @@ -303,12 +352,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:add") + }) } ) @ApiResponses(value = { @@ -365,12 +412,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:create-combined-role") + }) } ) @ApiResponses(value = { @@ -430,12 +475,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:update") + }) } ) @ApiResponses(value = { @@ -498,12 +541,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:delete") + }) } ) @ApiResponses(value = { @@ -550,12 +591,10 @@ public interface RoleManagementService { "be cumbersome. Therefore, you can define all the new employees that belong to the engineering " + "role using this API.", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:add-users") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index b211a3a1012..e7154089c60 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -24,14 +24,14 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.*; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -53,6 +53,76 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Adding a User", + description = "Adding a User", + key = "cdmf:users:add", + permissions = {"/device-mgt/users/add"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting Details of a User", + description = "Getting Details of a User", + key = "cdmf:users:details", + permissions = {"/device-mgt/users/details"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Updating Details of a User", + description = "Updating Details of a User", + key = "cdmf:users:update", + permissions = {"/device-mgt/policies/update"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Deleting a User", + description = "Deleting a User", + key = "cdmf:users:delete", + permissions = {"/device-mgt/policies/delete"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the Role Details of a User", + description = "Getting the Role Details of a User", + key = "cdmf:users:roles", + permissions = {"/device-mgt/policies/roles"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting Details of Users", + description = "Getting Details of Users", + key = "cdmf:users:user-details", + permissions = {"/device-mgt/policies/user-details"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the User Count", + description = "Getting the User Count", + key = "cdmf:users:count", + permissions = {"/device-mgt/policies/count"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the User existence status", + description = "Getting the User existence status", + key = "cdmf:users:is-exist", + permissions = {"/device-mgt/policies/is-exist"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Searching for a User Name", + description = "Searching for a User Name", + key = "cdmf:users:search", + permissions = {"/device-mgt/policies/search"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Changing the User Password", + description = "Adding a User", + key = "cdmf:users:credentials", + permissions = {"/device-mgt/policies/credentials"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Sending Enrollment Invitations to Users", + description = "Sending Enrollment Invitations to Users", + key = "cdmf:users:send-invitation", + permissions = {"/device-mgt/policies/send-invitation"} + ) + } +) @Path("/users") @Api(value = "User Management", description = "User management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -67,12 +137,10 @@ public interface UserManagementService { value = "Adding a User", notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:add") + }) } ) @ApiResponses( @@ -129,12 +197,10 @@ public interface UserManagementService { notes = "Get the details of a user registered with WSO2 EMM using the REST API.", response = BasicUserInfo.class, tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:details") + }) } ) @ApiResponses(value = { @@ -202,12 +268,10 @@ public interface UserManagementService { notes = "There will be situations where you will want to update the user details. In such " + "situation you can update the user details using this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:update") + }) } ) @ApiResponses(value = { @@ -269,12 +333,10 @@ public interface UserManagementService { value = "Deleting a User", notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:delete") + }) } ) @ApiResponses(value = { @@ -314,12 +376,10 @@ public interface UserManagementService { value = "Getting the Role Details of a User", notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:roles") + }) } ) @ApiResponses(value = { @@ -378,12 +438,10 @@ public interface UserManagementService { notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so " + "using this REST API", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:user-details") + }) } ) @ApiResponses(value = { @@ -451,11 +509,10 @@ public interface UserManagementService { value = "Getting the User Count", notes = "Get the number of users in WSO2 EMM via this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:count") + }) } ) @ApiResponses(value = { @@ -487,12 +544,10 @@ public interface UserManagementService { value = "Getting the User existence status", notes = "Check if the user exists in the user store.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:is-exist") + }) } ) @ApiResponses(value = { @@ -532,11 +587,10 @@ public interface UserManagementService { + "You will be given a list of users having the user name in the exact order of the " + "characters you provided.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:search") + }) } ) @ApiResponses(value = { @@ -610,11 +664,10 @@ public interface UserManagementService { value = "Changing the User Password", notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/login", description = "Reset user password") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:credentials") + }) } ) @ApiResponses(value = { @@ -656,11 +709,10 @@ public interface UserManagementService { notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" + "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:send-invitation") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java index 8f492612023..450b3a3778d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java @@ -18,9 +18,18 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -55,10 +64,16 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Manage application", - description = "", - key = "cdmf:manage-application", - permissions = {"/device-mgt/applications/manage"} + name = "Installing an Application (Internal API)", + description = "Installing an Application (Internal API)", + key = "cdmf:applications:install", + permissions = {"/device-mgt/applications/install"} + ), + @Scope( + name = "Uninstalling an Application (Internal API)", + description = "Uninstalling an Application (Internal API)", + key = "cdmf:applications:uninstall", + permissions = {"/device-mgt/applications/uninstall"} ) } ) @@ -78,7 +93,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:install") }) } ) @@ -122,7 +137,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:uninstall") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index a2e80bcbf9d..72ba18d5065 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -66,10 +64,10 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Manage device", - description = "", - key = "cdmf:manage-own-device", - permissions = {"/device-mgt/devices/owning-device/view"} + name = "Getting Details of a Device", + description = "Getting Details of a Device", + key = "cdmf:admin:devices:view", + permissions = {"/device-mgt/devices/admin/devices/view"} ) } ) @@ -86,7 +84,7 @@ public interface DeviceManagementAdminService { tags = "Device Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-own-device") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin:devices:view") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index b5716e9db39..06d0842985f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -25,8 +25,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -69,8 +67,14 @@ import javax.ws.rs.core.Response; @Scope( name = "View groups", description = "", - key = "cdmf:view-groups", + key = "cdmf:admin-groups:view", permissions = {"/device-mgt/admin/groups/view"} + ), + @Scope( + name = "Count groups", + description = "", + key = "cdmf:admin-groups:count", + permissions = {"/device-mgt/admin/groups/count"} ) } ) @@ -85,7 +89,7 @@ public interface GroupManagementAdminService { tags = "Device Group Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-groups") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:view") }) } ) @@ -146,12 +150,10 @@ public interface GroupManagementAdminService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/admin/groups/view", description - = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:count") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index 99914a94aba..fbb3603e569 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -24,14 +24,15 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +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; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -53,6 +54,16 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "View Users", + description = "View Users", + key = "cdmf:admin-users:view", + permissions = {"/device-mgt/admin/users/view"} + ) + } +) @Path("/admin/users") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -71,12 +82,10 @@ public interface UserManagementAdminService { notes = "The EMM administrator is able to change the password of the users in " + "the system and block them from logging into their EMM profile using this REST API.", tags = "User Management Administrative Service", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description - = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-users:view") + }) } ) @ApiResponses(value = { From 6860c6688283c04e2fef5ae82784e7c93be52bed Mon Sep 17 00:00:00 2001 From: GPrathap Date: Thu, 5 Jan 2017 12:05:40 +0530 Subject: [PATCH 2/3] Revert "added scope annotation" This reverts commit 2619c626b29e51784f9b6242b906f54772807721. --- .../CertificateManagementAdminService.java | 48 ++--- .../api/ActivityInfoProviderService.java | 22 +- .../api/ConfigurationManagementService.java | 10 +- .../mgt/jaxrs/service/api/Dashboard.java | 160 +------------- .../service/api/DeviceManagementService.java | 166 ++++++-------- .../api/DeviceTypeManagementService.java | 42 ++-- .../service/api/GroupManagementService.java | 202 +++++++----------- .../api/NotificationManagementService.java | 41 ++-- .../service/api/PolicyManagementService.java | 155 +++++--------- .../service/api/RoleManagementService.java | 135 +++++------- .../service/api/UserManagementService.java | 180 ++++++---------- .../ApplicationManagementAdminService.java | 31 +-- .../admin/DeviceManagementAdminService.java | 12 +- .../admin/GroupManagementAdminService.java | 22 +- .../api/admin/UserManagementAdminService.java | 25 +-- 15 files changed, 400 insertions(+), 851 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index df92a10eb33..3f849cba9ce 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -1,16 +1,6 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.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.certificate.mgt.cert.jaxrs.api.beans.CertificateList; @@ -41,28 +31,16 @@ import javax.ws.rs.core.Response; @Path("/admin/certificates") @Scopes(scopes = { @Scope( - name = "Adding a new SSL certificate", - description = "Adding a new SSL certificate", - key = "cdmf:admin:certificates:add", - permissions = {"/device-mgt/admin/certificates/add"} + name = "Manage certificates", + description = "", + key = "cdmf:manage-certificate", + permissions = {"/device-mgt/certificates/manage"} ), @Scope( - name = "Getting Details of an SSL Certificate", - description = "Getting Details of an SSL Certificate", - key = "cdmf:admin:certificates:details", - permissions = {"/device-mgt/admin/certificates/details"} - ), - @Scope( - name = "Getting Details of Certificates", - description = "Getting Details of Certificates", - key = "cdmf:admin:certificates:view", - permissions = {"/device-mgt/admin/certificates/view"} - ), - @Scope( - name = "Deleting an SSL Certificate", - description = "Deleting an SSL Certificate", - key = "cdmf:admin:certificates:delete", - permissions = {"/device-mgt/admin/certificates/delete"} + name = "View certificate", + description = "", + key = "cdmf:view-certificate", + permissions = {"/device-mgt/certificates/view"} ) } ) @@ -89,7 +67,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:add") + @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") }) } ) @@ -158,7 +136,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:details") + @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") }) } ) @@ -229,7 +207,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:view") + @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") }) } ) @@ -308,7 +286,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:delete") + @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 3a040fa2161..9c3e2c4f5bc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.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.common.operation.mgt.Activity; @@ -65,9 +55,9 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Getting Details of an Activity", - description = "Getting Details of an Activity", - key = "cdmf:activities:details", + name = "Get activities", + description = "Get activities", + key = "cdmf:get-activity", permissions = {"/device-mgt/devices/owning-device/view"} ) } @@ -87,7 +77,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") }) } ) @@ -160,7 +150,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index 87fa47c5d3e..504bd75f1d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -24,6 +24,8 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -66,13 +68,13 @@ import javax.ws.rs.core.Response; @Scope( name = "View configurations", description = "", - key = "cdmf:configuration:view", + key = "cdmf:view-configuration", permissions = {"/device-mgt/platform-configurations/view"} ), @Scope( name = "Manage configurations", description = "", - key = "cdmf:configuration:manage", + key = "cdmf:manage-configuration", permissions = {"/device-mgt/platform-configurations/manage"} ) } @@ -90,7 +92,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:view") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-configuration") }) } ) @@ -149,7 +151,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:manage") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-configuration") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java index 8251ff40ae1..903c92e5cde 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/Dashboard.java @@ -1,23 +1,15 @@ 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.analytics.dashboard.bean.DeviceCountByGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardGadgetDataWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.DashboardPaginationGadgetDataWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -26,89 +18,9 @@ import javax.ws.rs.core.Response; /** * Device Analytics Dashboard related REST-APIs. This can be used to obtain device related analytics. */ -@SwaggerDefinition( - info = @Info( - version = "1.0.0", - title = "", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = "name", value = "DeviceAnalyticsDashboard"), - @ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/dashboard"), - }) - } - ), - tags = { - @Tag(name = "device_management", description = "Device Analytics Dashboard related information APIs" + - " are described here.") - } -) @Path("/dashboard") @Api(value = "Device Analytics Dashboard", description = "Device Analytics Dashboard related information APIs are described here.") -@Scopes( - scopes = { - @Scope( - name = "Device Count Overview", - description = "Device Count Overview", - key = "cdmf:dashboard:count-overview", - permissions = {"/device-mgt/dashboard/device-count"} - ), - @Scope( - name = "Device Counts by Potential Vulnerabilities", - description = "Device Counts by Potential Vulnerabilities", - key = "cdmf:dashboard:vulnerabilities", - permissions = {"/device-mgt/dashboard/vulnerabilities"} - ), - @Scope( - name = "Get the number of devices that have not complied to a policy", - description = "Get the number of devices that have not complied to a policy", - key = "cdmf:dashboard:non-compliant", - permissions = {"/device-mgt/dashboard/features"} - ), - @Scope( - name = "Get the number of devices for a given device type, such as connectivity status, " - + "potential vulnerability, platform, and ownership", - description = "Get the number of devices for a given device type, such as connectivity status, " - + "potential vulnerability, platform, and ownership", - key = "cdmf:dashboard:by-groups", - permissions = {"/device-mgt/dashboard/groups"} - ), - @Scope( - name = "Get the number of devices that have not complied to a given policy based on a particular", - description = "Get the number of devices that have not complied to a given policy based on a particular", - key = "cdmf:dashboard:device-counts", - permissions = {"/device-mgt/dashboard/groups"} - ), - @Scope( - name = "Get the number of devices that have not complied to a given policy based on a particular" - + " device type.", - description = "Get the number of devices that have not complied to a given policy based on a " + - "particular device type.", - key = "cdmf:dashboard:filtered-count", - permissions = {"/device-mgt/dashboard/total"} - ), - @Scope( - name = "Get the number of devices that have not complied to a given policy over the total" - + " number of devices registered with WSO2 EMM.\n", - description = "Get the number of devices that have not complied to a given policy over the total" - + " number of devices registered with WSO2 EMM.\n", - key = "cdmf:dashboard:non-compliant-count", - permissions = {"/device-mgt/dashboard/total"} - ), - @Scope( - name = "Get device details of devices based on a particular device type.", - description = "Get device details of devices based on a particular device type.", - key = "cdmf:dashboard:details", - permissions = {"/device-mgt/dashboard/details"} - ), - @Scope( - name = "Get device details of non-compliant devices which do not comply to a given policy.", - description = "Get device details of non-compliant devices which do not comply to a given policy.", - key = "cdmf:dashboard:feature-non-compliant", - permissions = {"/device-mgt/dashboard/details"} - ) - } -) @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("NonJaxWsWebServices") public interface Dashboard { @@ -131,13 +43,7 @@ public interface Dashboard { value = "Get the details of registered devices in WSO2 EMM.", notes = "Get the details of active, inactive, removed and total number of registered devices in" + " WSO2 EMM.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:count-overview") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -187,13 +93,7 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get the number of unmonitored and non-compliant devices in WSO2 EMM.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:vulnerabilities") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -244,13 +144,7 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a policy that was enforced on a " + "device.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:non-compliant") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -314,13 +208,7 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices for a given device type, such as connectivity status, " + "potential vulnerability, platform, and ownership.\n", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:by-groups") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -403,13 +291,7 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a given policy based on a particular" + " device type.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:device-counts") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -482,13 +364,7 @@ public interface Dashboard { + "Connectivity status of the device, such as active, inactive or removed.\n" + "The device ownership type, such as BYOD or COPE.\n" + "The device platform.\n" + "The potential vulnerabilities faced by the devices.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:filtered-count") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -574,13 +450,7 @@ public interface Dashboard { httpMethod = "GET", value = "Get the number of devices that have not complied to a given policy over the total" + " number of devices registered with WSO2 EMM.\n", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:non-compliant-count") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -649,13 +519,7 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get device details of devices based on a particular device type.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:details") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, @@ -751,13 +615,7 @@ public interface Dashboard { produces = MediaType.APPLICATION_JSON, httpMethod = "GET", value = "Get device details of non-compliant devices which do not comply to a given policy.", - tags = "Dashboard", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:dashboard:feature-non-compliant") - }) - } - ) + tags = "Dashboard") @ApiResponses(value = { @ApiResponse( code = 200, 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 ed9290df4ca..650ae34f7b6 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 @@ -24,13 +24,13 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; @@ -38,7 +38,6 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; @@ -65,64 +64,6 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "Getting Details of Registered Devices", - description = "Getting Details of Registered Devices", - key = "cdmf:devices:view", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Details of a Device", - description = "Getting Details of a Device", - key = "cdmf:devices:details", - permissions = {"/device-mgt/devices/owning-device/details"} - ), - @Scope( - name = "Delete the device specified by device id", - description = "Delete the device specified by device id", - key = "cdmf:devices:delete", - permissions = {"/device-mgt/devices/owning-device/delete"} - ), - @Scope( - name = "Getting Feature Details of a Device", - description = "Getting Feature Details of a Device", - key = "cdmf:devices:features", - permissions = {"/device-mgt/devices/owning-device/features"} - ), - @Scope( - name = "Advanced Search for Devices", - description = "Advanced Search for Devices", - key = "cdmf:devices:search", - permissions = {"/device-mgt/devices/owning-device/view"} - ), - @Scope( - name = "Getting Installed Application Details of a Device", - description = "Getting Installed Application Details of a Device", - key = "cdmf:devices:applications", - permissions = {"/device-mgt/devices/owning-device/applications"} - ), - @Scope( - name = "Getting Device Operation Details", - description = "Getting Device Operation Details", - key = "cdmf:devices:operations", - permissions = {"/device-mgt/devices/owning-device/operations"} - ), - @Scope( - name = "Get the details of the policy that is enforced on a device.", - description = "Get the details of the policy that is enforced on a device.", - key = "cdmf:devices:effective-policy", - permissions = {"/device-mgt/devices/owning-device/effective-policy"} - ), - @Scope( - name = "Getting Policy Compliance Details of a Device", - description = "Getting Policy Compliance Details of a Device", - key = "cdmf:devices:compliance-data", - permissions = {"/device-mgt/devices/owning-device/compliance-data"} - ) - } -) @Path("/devices") @Api(value = "Device Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @@ -137,11 +78,13 @@ public interface DeviceManagementService { value = "Getting Details of Registered Devices", notes = "Provides details of all the devices enrolled with WSO2 EMM.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:view") - }) - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view" + , description = "View Devices") } + ) + } ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @@ -262,10 +205,12 @@ public interface DeviceManagementService { value = "Getting Details of a Device", notes = "Get the details of a device by specifying the device type and device identifier.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) } ) @ApiResponses( @@ -337,13 +282,15 @@ public interface DeviceManagementService { @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "DELETE", - value = "Delete the device specified by device id", + value = "Delete the device speccified by device id", notes = "Returns the status of the deleted device operation.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:delete") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) } ) @ApiResponses( @@ -412,11 +359,13 @@ public interface DeviceManagementService { "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", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:features") - }) - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } ) @ApiResponses( value = { @@ -501,10 +450,12 @@ public interface DeviceManagementService { value = "Advanced Search for Devices", notes = "Search for devices by filtering the search result through the specified search terms.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:search") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) } ) @ApiResponses( @@ -578,12 +529,13 @@ public interface DeviceManagementService { value = "Getting Installed Application Details of a Device", notes = "Get the list of applications subscribed to by a device.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:applications") - }) - - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } ) @ApiResponses( value = { @@ -681,11 +633,13 @@ public interface DeviceManagementService { value = "Getting Device Operation Details", notes = "Get the details of operations carried out on a selected device.", tags = "Device Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:operations") - }) - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } ) @ApiResponses( value = { @@ -792,11 +746,13 @@ public interface DeviceManagementService { "WSO2 EMM 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 = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:effective-policy") - }) - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) + } ) @ApiResponses( value = { @@ -881,10 +837,12 @@ public interface DeviceManagementService { notes = "A policy is enforced on the devices that register with WSO2 EMM. " + "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 = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:compliance-data") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Devices") } + ) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index 963edc84f75..94b06ea7513 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -24,16 +24,15 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -55,22 +54,6 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "Getting the Supported Device Platforms", - description = "Getting the Supported Device Platforms", - key = "cdmf:device-types:types", - permissions = {"/device-mgt/device-types/types"} - ), - @Scope( - name = "Get Feature Details of a Device Type", - description = "Get Feature Details of a Device Type", - key = "cdmf:device-types:features", - permissions = {"/device-mgt/device-types/features"} - ) - } -) @Path("/device-types") @Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " + "type management") @@ -85,10 +68,12 @@ public interface DeviceTypeManagementService { value = "Getting the Supported Device Platforms", notes = "Get the list of device platforms supported by WSO2 EMM.", tags = "Device Type Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:types") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Device Types") } + ) } ) @ApiResponses( @@ -138,7 +123,6 @@ public interface DeviceTypeManagementService { String ifModifiedSince); @GET - @Path("/{type}/features") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", @@ -147,10 +131,12 @@ public interface DeviceTypeManagementService { "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 Type Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:features") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", + description = "View Device Types") } + ) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index aff13f24375..a982a3c3d53 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -24,6 +24,8 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +import io.swagger.annotations.Authorization; +import io.swagger.annotations.AuthorizationScope; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Info; @@ -31,15 +33,12 @@ import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; import org.apache.axis2.transport.http.HTTPConstants; -import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -75,82 +74,6 @@ import java.util.List; "details.") } ) -@Scopes( - scopes = { - @Scope( - name = "Get the list of groups belongs to current user.", - description = "Get the list of groups belongs to current user.", - key = "cdmf:groups:groups", - permissions = {"/device-mgt/groups/groups"} - ), - @Scope( - name = "Get the count of groups belongs to current user.", - description = "Get the count of groups belongs to current user.", - key = "cdmf:groups:count", - permissions = {"/device-mgt/groups/count"} - ), - @Scope( - name = "Add new device group to the system.", - description = "Add new device group to the system.", - key = "cdmf:groups:add", - permissions = {"/device-mgt/groups/add"} - ), - @Scope( - name = "View group specified", - description = "View group specified", - key = "cdmf:groups:groups-view", - permissions = {"/device-mgt/groups/groups-view"} - ), - @Scope( - name = "Update a group", - description = "Update a group", - key = "cdmf:groups:update", - permissions = {"/device-mgt/groups/update"} - ), - @Scope( - name = "Delete a group", - description = "Delete a group", - key = "cdmf:groups:remove", - permissions = {"/device-mgt/groups/remove"} - ), - @Scope( - name = "Manage group sharing with a user", - description = "Manage group sharing with a user", - key = "cdmf:groups:share", - permissions = {"/device-mgt/groups/share"} - ), - @Scope( - name = "View list of roles of a device group", - description = "View list of roles of a device group", - key = "cdmf:groups:roles", - permissions = {"/device-mgt/groups/roles"} - ), - @Scope( - name = "View list of devices in the device group", - description = "View list of devices in the device group", - key = "cdmf:groups:devices", - permissions = {"/device-mgt/groups/devices"} - ), - @Scope( - name = "View list of device count in the device group", - description = "View list of device count in the device group", - key = "cdmf:groups:devices-count", - permissions = {"/device-mgt/groups/devices/devices-count"} - ), - @Scope( - name = "Add devices to group", - description = "Add devices to group", - key = "cdmf:groups:devices-add", - permissions = {"/device-mgt/groups/devices/devices-add"} - ), - @Scope( - name = "Remove devices from group", - description = "Remove devices from group", - key = "cdmf:groups:devices-remove", - permissions = {"/device-mgt/groups/devices/devices-remove"} - ) - } -) @Path("/groups") @Api(value = "Device Group Management", description = "This API carries all device group management related " + "operations such as get all the available groups, etc.") @@ -165,10 +88,12 @@ public interface GroupManagementService { value = "Get the list of groups belongs to current user.", notes = "Returns all permitted groups enrolled with the system.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", + description = "View Groups") } + ) } ) @ApiResponses(value = { @@ -228,12 +153,13 @@ public interface GroupManagementService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:count") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", + description = "View Groups") } + ) } - ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", @@ -276,10 +202,12 @@ public interface GroupManagementService { value = "Add new device group to the system.", notes = "Add device group with current user as the owner.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:add") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/add", + description = "Add Group") } + ) } ) @ApiResponses( @@ -342,10 +270,12 @@ public interface GroupManagementService { value = "View group specified.", notes = "Returns details of group enrolled with the system.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups-view") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", + description = "View Groups") } + ) } ) @ApiResponses(value = { @@ -395,10 +325,12 @@ public interface GroupManagementService { notes = "If you wish to make changes to an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:update") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/update", + description = "Update Group") } + ) } ) @ApiResponses(value = { @@ -452,10 +384,12 @@ public interface GroupManagementService { notes = "If you wish to remove an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:remove") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/remove", + description = "Remove Group") } + ) } ) @ApiResponses(value = { @@ -504,10 +438,12 @@ public interface GroupManagementService { notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " + "that can be done using this resource.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:share") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/share", + description = "Share Group") } + ) } ) @ApiResponses(value = { @@ -560,10 +496,12 @@ public interface GroupManagementService { value = "View list of roles of a device group.", notes = "Returns details of roles which particular group has been shared with.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:roles") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/roles/view", + description = "View roles") } + ) } ) @ApiResponses(value = { @@ -612,10 +550,12 @@ public interface GroupManagementService { value = "View list of devices in the device group.", notes = "Returns list of devices in the device group.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", + description = "View devices") } + ) } ) @ApiResponses(value = { @@ -672,10 +612,12 @@ public interface GroupManagementService { value = "View list of device count in the device group.", notes = "Returns device count in the device group.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-count") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", + description = "View devices") } + ) } ) @ApiResponses(value = { @@ -724,10 +666,12 @@ public interface GroupManagementService { value = "Add devices to group.", notes = "Add existing devices to the device group.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-add") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/add", + description = "Add devices") } + ) } ) @ApiResponses(value = { @@ -780,10 +724,12 @@ public interface GroupManagementService { value = "Remove devices from group.", notes = "Remove existing devices from the device group.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-remove") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/remove", + description = "Remove devices") } + ) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index a3d0d556f3b..0a2998251c8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -24,17 +24,16 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.jaxrs.NotificationList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Max; import javax.validation.constraints.Size; @@ -61,22 +60,6 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "Getting All Device Notification Details", - description = "Getting All Device Notification Details", - key = "cdmf:notifications:view", - permissions = {"/device-mgt/notifications/view"} - ), - @Scope( - name = "Updating the Device Notification Status", - description = "Updating the Device Notification Status", - key = "cdmf:notifications:mark-checked", - permissions = {"/device-mgt/notifications/mark-checked"} - ) - } -) @Api(value = "Device Notification Management", description = "Device notification related operations can be found here.") @Path("/notifications") @Produces(MediaType.APPLICATION_JSON) @@ -90,10 +73,12 @@ public interface NotificationManagementService { value = "Getting All Device Notification Details", notes = "Get the details of all the notifications that were pushed to the devices registered with WSO2 EMM using this REST API.", tags = "Device Notification Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:view") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", + description = "View notifications") } + ) } ) @ApiResponses( @@ -179,10 +164,12 @@ public interface NotificationManagementService { notes = "When a user has read the the device notification the device notification status must " + "change from NEW to CHECKED. This API is used to update device notification status.", tags = "Device Notification Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:mark-checked") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", + description = "View notifications") } + ) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 2994994ac00..6a77938b0fe 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -24,17 +24,16 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import javax.validation.Valid; @@ -63,64 +62,6 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "Adding a Policy", - description = "Adding a Policy", - key = "cdmf:policies:manage", - permissions = {"/device-mgt/policies/manage"} - ), - @Scope( - name = "Getting Details of Policies", - description = "Getting Details of Policies", - key = "cdmf:policies:get-details", - permissions = {"/device-mgt/policies/get-details"} - ), - @Scope( - name = "Getting Details of a Policy", - description = "Getting Details of a Policy", - key = "cdmf:policies:get-policy-details", - permissions = {"/device-mgt/policies/get-policy-details"} - ), - @Scope( - name = "Updating a Policy", - description = "Updating a Policy", - key = "cdmf:policies:update", - permissions = {"/device-mgt/policies/update"} - ), - @Scope( - name = "Removing Multiple Policies", - description = "Removing Multiple Policies", - key = "cdmf:policies:remove", - permissions = {"/device-mgt/policies/remove"} - ), - @Scope( - name = "Activating Policies", - description = "Activating Policies", - key = "cdmf:policies:activate", - permissions = {"/device-mgt/policies/activate"} - ), - @Scope( - name = "Deactivating Policies", - description = "Deactivating Policies", - key = "cdmf:policies:deactivate", - permissions = {"/device-mgt/policies/deactivate"} - ), - @Scope( - name = "Applying Changes on Policies", - description = "Applying Changes on Policies", - key = "cdmf:policies:changes", - permissions = {"/device-mgt/policies/changes"} - ), - @Scope( - name = "Updating the Policy Priorities", - description = "Updating the Policy Priorities", - key = "cdmf:policies:priorities", - permissions = {"/device-mgt/policies/priorities"} - ) - } -) @Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management") @Path("/policies") @Produces(MediaType.APPLICATION_JSON) @@ -136,10 +77,12 @@ public interface PolicyManagementService { notes = "Add a policy using this REST API command. When adding a policy you will have the option of saving the policy or saving and publishing the policy." + "Using this REST API you are able to save a created Policy and this policy will be in the inactive state.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:manage") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -204,10 +147,12 @@ public interface PolicyManagementService { notes = "Retrieve the details of all the policies in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", + description = "View policies") } + ) } ) @ApiResponses( @@ -279,10 +224,12 @@ public interface PolicyManagementService { notes = "Retrieve the details of a policy that is in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-policy-details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", + description = "View policies") } + ) } ) @ApiResponses( @@ -347,10 +294,12 @@ public interface PolicyManagementService { value = "Updating a Policy", notes = "Make changes to an existing policy by updating the policy using this resource.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:update") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -415,10 +364,12 @@ public interface PolicyManagementService { value = "Removing Multiple Policies", notes = "Delete one or more than one policy using this API.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:remove") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -461,10 +412,12 @@ public interface PolicyManagementService { value = "Activating Policies", notes = "Publish a policy using this API to bring a policy that is in the inactive state to the active state.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:activate") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -502,10 +455,12 @@ public interface PolicyManagementService { value = "Deactivating Policies", notes = "Unpublish a policy using this API to bring a policy that is in the active state to the inactive state.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:deactivate") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -548,10 +503,12 @@ public interface PolicyManagementService { " devices will not receive these changes immediately. Once all the required changes are made" + " you need to apply the changes to push the policy changes to the existing devices.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:changes") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) } ) @ApiResponses( @@ -576,11 +533,13 @@ public interface PolicyManagementService { value = "Updating the Policy Priorities", notes = "Make changes to the existing policy priority order by updating the priority order using this API.", tags = "Device Policy Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:priorities") - }) - } + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", + description = "Manage policies") } + ) + } ) @ApiResponses( value = { 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 b308ddc9702..cc894b9c0b0 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 @@ -24,17 +24,16 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import javax.ws.rs.*; @@ -57,58 +56,6 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "Getting the List of Roles", - description = "Getting the List of Roles", - key = "cdmf:roles:view", - permissions = {"/device-mgt/roles/view"} - ), - @Scope( - name = "Getting Permission Details of a Role", - description = "Getting Permission Details of a Role", - key = "cdmf:roles:permissions", - permissions = {"/device-mgt/roles/permissions"} - ), - @Scope( - name = "Getting the List of Roles", - description = "Getting the List of Roles", - key = "cdmf:roles:details", - permissions = {"/device-mgt/roles/details"} - ), - @Scope( - name = "Adding a Role", - description = "Adding a Role", - key = "cdmf:roles:add", - permissions = {"/device-mgt/roles/add"} - ), - @Scope( - name = "Adding a combined Role", - description = "Adding a combined Role", - key = "cdmf:roles:create-combined-role", - permissions = {"/device-mgt/roles/create-combined-role"} - ), - @Scope( - name = "Updating Role Details", - description = "Updating Role Details", - key = "cdmf:roles:update", - permissions = {"/device-mgt/roles/update"} - ), - @Scope( - name = "Deleting a Role", - description = "Deleting a Role", - key = "cdmf:roles:delete", - permissions = {"/device-mgt/roles/delete"} - ), - @Scope( - name = "Adding Users to a Role", - description = "Adding Users to a Role", - key = "cdmf:roles:add-users", - permissions = {"/device-mgt/roles/add-users"} - ) - } -) @Path("/roles") @Api(value = "Role Management", description = "Role management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -123,10 +70,11 @@ public interface RoleManagementService { 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" + "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 = "cdmf:roles:view") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } + ) } ) @ApiResponses( @@ -203,10 +151,11 @@ public interface RoleManagementService { response = UIPermissionNode.class, responseContainer = "List", tags = "Role Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:permissions") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } + ) } ) @ApiResponses( @@ -278,10 +227,12 @@ public interface RoleManagementService { 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 = "cdmf:roles:details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", + description = "View Roles") } + ) } ) @ApiResponses( @@ -352,10 +303,12 @@ public interface RoleManagementService { 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 = "cdmf:roles:add") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) } ) @ApiResponses(value = { @@ -412,10 +365,12 @@ public interface RoleManagementService { 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 = "cdmf:roles:create-combined-role") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) } ) @ApiResponses(value = { @@ -475,10 +430,12 @@ public interface RoleManagementService { 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 = "cdmf:roles:update") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) } ) @ApiResponses(value = { @@ -541,10 +498,12 @@ public interface RoleManagementService { 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 = "cdmf:roles:delete") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) } ) @ApiResponses(value = { @@ -591,10 +550,12 @@ public interface RoleManagementService { "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 = "cdmf:roles:add-users") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", + description = "Manage Roles") } + ) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index e7154089c60..b211a3a1012 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -24,14 +24,14 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.*; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.ws.rs.*; import javax.ws.rs.core.MediaType; @@ -53,76 +53,6 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Adding a User", - description = "Adding a User", - key = "cdmf:users:add", - permissions = {"/device-mgt/users/add"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Getting Details of a User", - description = "Getting Details of a User", - key = "cdmf:users:details", - permissions = {"/device-mgt/users/details"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Updating Details of a User", - description = "Updating Details of a User", - key = "cdmf:users:update", - permissions = {"/device-mgt/policies/update"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Deleting a User", - description = "Deleting a User", - key = "cdmf:users:delete", - permissions = {"/device-mgt/policies/delete"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Getting the Role Details of a User", - description = "Getting the Role Details of a User", - key = "cdmf:users:roles", - permissions = {"/device-mgt/policies/roles"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Getting Details of Users", - description = "Getting Details of Users", - key = "cdmf:users:user-details", - permissions = {"/device-mgt/policies/user-details"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Getting the User Count", - description = "Getting the User Count", - key = "cdmf:users:count", - permissions = {"/device-mgt/policies/count"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Getting the User existence status", - description = "Getting the User existence status", - key = "cdmf:users:is-exist", - permissions = {"/device-mgt/policies/is-exist"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Searching for a User Name", - description = "Searching for a User Name", - key = "cdmf:users:search", - permissions = {"/device-mgt/policies/search"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Changing the User Password", - description = "Adding a User", - key = "cdmf:users:credentials", - permissions = {"/device-mgt/policies/credentials"} - ), - @org.wso2.carbon.apimgt.annotations.api.Scope( - name = "Sending Enrollment Invitations to Users", - description = "Sending Enrollment Invitations to Users", - key = "cdmf:users:send-invitation", - permissions = {"/device-mgt/policies/send-invitation"} - ) - } -) @Path("/users") @Api(value = "User Management", description = "User management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -137,10 +67,12 @@ public interface UserManagementService { value = "Adding a User", notes = "WSO2 EMM supports user management. Add a new user to the WSO2 EMM user management system via this REST API", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:add") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", + description = "Manage Users") } + ) } ) @ApiResponses( @@ -197,10 +129,12 @@ public interface UserManagementService { notes = "Get the details of a user registered with WSO2 EMM using the REST API.", response = BasicUserInfo.class, tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", + description = "View Users") } + ) } ) @ApiResponses(value = { @@ -268,10 +202,12 @@ public interface UserManagementService { notes = "There will be situations where you will want to update the user details. In such " + "situation you can update the user details using this REST API.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:update") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", + description = "Manage Users") } + ) } ) @ApiResponses(value = { @@ -333,10 +269,12 @@ public interface UserManagementService { value = "Deleting a User", notes = "When an employee leaves the organization, you can remove the user details from WSO2 EMM using this REST API.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:delete") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", + description = "Manage Users") } + ) } ) @ApiResponses(value = { @@ -376,10 +314,12 @@ public interface UserManagementService { value = "Getting the Role Details of a User", notes = "A user can be assigned to one or more role in EMM. Using this REST API you can get the role/roles a user is assigned to.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:roles") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", + description = "View Users") } + ) } ) @ApiResponses(value = { @@ -438,10 +378,12 @@ public interface UserManagementService { notes = "You are able to manage users in WSO2 EMM by adding, updating and removing users. If you wish to get the list of users registered with WSO2 EMM, you can do so " + "using this REST API", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:user-details") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", + description = "View Users") } + ) } ) @ApiResponses(value = { @@ -509,10 +451,11 @@ public interface UserManagementService { value = "Getting the User Count", notes = "Get the number of users in WSO2 EMM via this REST API.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:count") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } + ) } ) @ApiResponses(value = { @@ -544,10 +487,12 @@ public interface UserManagementService { value = "Getting the User existence status", notes = "Check if the user exists in the user store.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:is-exist") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", + description = "View Users") } + ) } ) @ApiResponses(value = { @@ -587,10 +532,11 @@ public interface UserManagementService { + "You will be given a list of users having the user name in the exact order of the " + "characters you provided.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:search") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } + ) } ) @ApiResponses(value = { @@ -664,10 +610,11 @@ public interface UserManagementService { value = "Changing the User Password", notes = "A user is able to change the password to secure their WSO2 EMM profile via this REST API.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:credentials") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/login", description = "Reset user password") } + ) } ) @ApiResponses(value = { @@ -709,10 +656,11 @@ public interface UserManagementService { notes = "Send the users a mail inviting them to download the EMM mobile application on their devices using the REST API given below.\n" + "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 EMM as explained in step 4, under the WSO2 EMM general server configurations documentation.", tags = "User Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:send-invitation") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description = "Manage Users") } + ) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java index 450b3a3778d..8f492612023 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java @@ -18,18 +18,9 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; -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.*; +import org.wso2.carbon.apimgt.annotations.api.*; import org.wso2.carbon.apimgt.annotations.api.Scope; -import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -64,16 +55,10 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Installing an Application (Internal API)", - description = "Installing an Application (Internal API)", - key = "cdmf:applications:install", - permissions = {"/device-mgt/applications/install"} - ), - @Scope( - name = "Uninstalling an Application (Internal API)", - description = "Uninstalling an Application (Internal API)", - key = "cdmf:applications:uninstall", - permissions = {"/device-mgt/applications/uninstall"} + name = "Manage application", + description = "", + key = "cdmf:manage-application", + permissions = {"/device-mgt/applications/manage"} ) } ) @@ -93,7 +78,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:install") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") }) } ) @@ -137,7 +122,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:uninstall") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index 72ba18d5065..a2e80bcbf9d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -24,6 +24,8 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -64,10 +66,10 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Getting Details of a Device", - description = "Getting Details of a Device", - key = "cdmf:admin:devices:view", - permissions = {"/device-mgt/devices/admin/devices/view"} + name = "Manage device", + description = "", + key = "cdmf:manage-own-device", + permissions = {"/device-mgt/devices/owning-device/view"} ) } ) @@ -84,7 +86,7 @@ public interface DeviceManagementAdminService { tags = "Device Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin:devices:view") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-own-device") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index 06d0842985f..b5716e9db39 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -25,6 +25,8 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -67,14 +69,8 @@ import javax.ws.rs.core.Response; @Scope( name = "View groups", description = "", - key = "cdmf:admin-groups:view", + key = "cdmf:view-groups", permissions = {"/device-mgt/admin/groups/view"} - ), - @Scope( - name = "Count groups", - description = "", - key = "cdmf:admin-groups:count", - permissions = {"/device-mgt/admin/groups/count"} ) } ) @@ -89,7 +85,7 @@ public interface GroupManagementAdminService { tags = "Device Group Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:view") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-groups") }) } ) @@ -150,10 +146,12 @@ public interface GroupManagementAdminService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:count") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/admin/groups/view", description + = "View Groups") } + ) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index fbb3603e569..99914a94aba 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -24,15 +24,14 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; +import io.swagger.annotations.AuthorizationScope; +import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -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; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; -import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -54,16 +53,6 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) -@Scopes( - scopes = { - @Scope( - name = "View Users", - description = "View Users", - key = "cdmf:admin-users:view", - permissions = {"/device-mgt/admin/users/view"} - ) - } -) @Path("/admin/users") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -82,10 +71,12 @@ public interface UserManagementAdminService { notes = "The EMM administrator is able to change the password of the users in " + "the system and block them from logging into their EMM profile using this REST API.", tags = "User Management Administrative Service", - extensions = { - @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-users:view") - }) + authorizations = { + @Authorization( + value="permission", + scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description + = "View Users") } + ) } ) @ApiResponses(value = { From 0bd7b90e9aa9a6a363acea28ed6724c804b79201 Mon Sep 17 00:00:00 2001 From: GPrathap Date: Mon, 19 Dec 2016 18:23:06 +0530 Subject: [PATCH 3/3] added scope annotation --- .../CertificateManagementAdminService.java | 48 +++-- .../api/ActivityInfoProviderService.java | 22 +- .../api/ConfigurationManagementService.java | 10 +- .../service/api/DeviceManagementService.java | 166 ++++++++------ .../api/DeviceTypeManagementService.java | 42 ++-- .../service/api/GroupManagementService.java | 202 +++++++++++------- .../api/NotificationManagementService.java | 41 ++-- .../service/api/PolicyManagementService.java | 155 +++++++++----- .../service/api/RoleManagementService.java | 135 +++++++----- .../service/api/UserManagementService.java | 183 ++++++++++------ .../ApplicationManagementAdminService.java | 31 ++- .../admin/DeviceManagementAdminService.java | 12 +- .../admin/GroupManagementAdminService.java | 22 +- .../api/admin/UserManagementAdminService.java | 25 ++- 14 files changed, 705 insertions(+), 389 deletions(-) diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java index 3f849cba9ce..df92a10eb33 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/src/main/java/org/wso2/carbon/certificate/mgt/cert/jaxrs/api/CertificateManagementAdminService.java @@ -1,6 +1,16 @@ package org.wso2.carbon.certificate.mgt.cert.jaxrs.api; -import io.swagger.annotations.*; +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 org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.certificate.mgt.cert.jaxrs.api.beans.CertificateList; @@ -31,16 +41,28 @@ import javax.ws.rs.core.Response; @Path("/admin/certificates") @Scopes(scopes = { @Scope( - name = "Manage certificates", - description = "", - key = "cdmf:manage-certificate", - permissions = {"/device-mgt/certificates/manage"} + name = "Adding a new SSL certificate", + description = "Adding a new SSL certificate", + key = "cdmf:admin:certificates:add", + permissions = {"/device-mgt/admin/certificates/add"} ), @Scope( - name = "View certificate", - description = "", - key = "cdmf:view-certificate", - permissions = {"/device-mgt/certificates/view"} + name = "Getting Details of an SSL Certificate", + description = "Getting Details of an SSL Certificate", + key = "cdmf:admin:certificates:details", + permissions = {"/device-mgt/admin/certificates/details"} + ), + @Scope( + name = "Getting Details of Certificates", + description = "Getting Details of Certificates", + key = "cdmf:admin:certificates:view", + permissions = {"/device-mgt/admin/certificates/view"} + ), + @Scope( + name = "Deleting an SSL Certificate", + description = "Deleting an SSL Certificate", + key = "cdmf:admin:certificates:delete", + permissions = {"/device-mgt/admin/certificates/delete"} ) } ) @@ -67,7 +89,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:add") }) } ) @@ -136,7 +158,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:details") }) } ) @@ -207,7 +229,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:view-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:view") }) } ) @@ -286,7 +308,7 @@ public interface CertificateManagementAdminService { tags = "Certificate Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = SCOPE, value = "cdmf:manage-certificate") + @ExtensionProperty(name = SCOPE, value = "cdmf:admin:certificates:delete") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java index 9c3e2c4f5bc..3a040fa2161 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ActivityInfoProviderService.java @@ -18,7 +18,17 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api; -import io.swagger.annotations.*; +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 org.wso2.carbon.apimgt.annotations.api.Scope; import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; @@ -55,9 +65,9 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Get activities", - description = "Get activities", - key = "cdmf:get-activity", + name = "Getting Details of an Activity", + description = "Getting Details of an Activity", + key = "cdmf:activities:details", permissions = {"/device-mgt/devices/owning-device/view"} ) } @@ -77,7 +87,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") }) } ) @@ -150,7 +160,7 @@ public interface ActivityInfoProviderService { tags = "Activity Info Provider", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:get-activity") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:activities:details") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java index 504bd75f1d7..87fa47c5d3e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/ConfigurationManagementService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -68,13 +66,13 @@ import javax.ws.rs.core.Response; @Scope( name = "View configurations", description = "", - key = "cdmf:view-configuration", + key = "cdmf:configuration:view", permissions = {"/device-mgt/platform-configurations/view"} ), @Scope( name = "Manage configurations", description = "", - key = "cdmf:manage-configuration", + key = "cdmf:configuration:manage", permissions = {"/device-mgt/platform-configurations/manage"} ) } @@ -92,7 +90,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-configuration") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:view") }) } ) @@ -151,7 +149,7 @@ public interface ConfigurationManagementService { tags = "Configuration Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-configuration") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:configuration:manage") }) } ) 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 650ae34f7b6..ed9290df4ca 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 @@ -24,13 +24,13 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.Feature; import org.wso2.carbon.device.mgt.common.app.mgt.Application; @@ -38,6 +38,7 @@ import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.search.SearchContext; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import org.wso2.carbon.policy.mgt.common.monitor.ComplianceData; @@ -64,6 +65,64 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting Details of Registered Devices", + description = "Getting Details of Registered Devices", + key = "cdmf:devices:view", + permissions = {"/device-mgt/devices/owning-device/view"} + ), + @Scope( + name = "Getting Details of a Device", + description = "Getting Details of a Device", + key = "cdmf:devices:details", + permissions = {"/device-mgt/devices/owning-device/details"} + ), + @Scope( + name = "Delete the device specified by device id", + description = "Delete the device specified by device id", + key = "cdmf:devices:delete", + permissions = {"/device-mgt/devices/owning-device/delete"} + ), + @Scope( + name = "Getting Feature Details of a Device", + description = "Getting Feature Details of a Device", + key = "cdmf:devices:features", + permissions = {"/device-mgt/devices/owning-device/features"} + ), + @Scope( + name = "Advanced Search for Devices", + description = "Advanced Search for Devices", + key = "cdmf:devices:search", + permissions = {"/device-mgt/devices/owning-device/view"} + ), + @Scope( + name = "Getting Installed Application Details of a Device", + description = "Getting Installed Application Details of a Device", + key = "cdmf:devices:applications", + permissions = {"/device-mgt/devices/owning-device/applications"} + ), + @Scope( + name = "Getting Device Operation Details", + description = "Getting Device Operation Details", + key = "cdmf:devices:operations", + permissions = {"/device-mgt/devices/owning-device/operations"} + ), + @Scope( + name = "Get the details of the policy that is enforced on a device.", + description = "Get the details of the policy that is enforced on a device.", + key = "cdmf:devices:effective-policy", + permissions = {"/device-mgt/devices/owning-device/effective-policy"} + ), + @Scope( + name = "Getting Policy Compliance Details of a Device", + description = "Getting Policy Compliance Details of a Device", + key = "cdmf:devices:compliance-data", + permissions = {"/device-mgt/devices/owning-device/compliance-data"} + ) + } +) @Path("/devices") @Api(value = "Device Management", description = "This API carries all device management related operations " + "such as get all the available devices, etc.") @@ -78,13 +137,11 @@ public interface DeviceManagementService { value = "Getting Details of Registered Devices", notes = "Provides details of all the devices enrolled with WSO2 EMM.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view" - , description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:view") + }) + } ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the list of devices.", @@ -205,12 +262,10 @@ public interface DeviceManagementService { value = "Getting Details of a Device", notes = "Get the details of a device by specifying the device type and device identifier.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:details") + }) } ) @ApiResponses( @@ -282,15 +337,13 @@ public interface DeviceManagementService { @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "DELETE", - value = "Delete the device speccified by device id", + value = "Delete the device specified by device id", notes = "Returns the status of the deleted device operation.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:delete") + }) } ) @ApiResponses( @@ -359,13 +412,11 @@ public interface DeviceManagementService { "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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:features") + }) + } ) @ApiResponses( value = { @@ -450,12 +501,10 @@ public interface DeviceManagementService { value = "Advanced Search for Devices", notes = "Search for devices by filtering the search result through the specified search terms.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:search") + }) } ) @ApiResponses( @@ -529,13 +578,12 @@ public interface DeviceManagementService { value = "Getting Installed Application Details of a Device", notes = "Get the list of applications subscribed to by a device.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:applications") + }) + + } ) @ApiResponses( value = { @@ -633,13 +681,11 @@ public interface DeviceManagementService { value = "Getting Device Operation Details", notes = "Get the details of operations carried out on a selected device.", tags = "Device Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:operations") + }) + } ) @ApiResponses( value = { @@ -746,13 +792,11 @@ public interface DeviceManagementService { "WSO2 EMM 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:effective-policy") + }) + } ) @ApiResponses( value = { @@ -837,12 +881,10 @@ public interface DeviceManagementService { notes = "A policy is enforced on the devices that register with WSO2 EMM. " + "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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:devices:compliance-data") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java index 94b06ea7513..963edc84f75 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/DeviceTypeManagementService.java @@ -24,15 +24,16 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -54,6 +55,22 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting the Supported Device Platforms", + description = "Getting the Supported Device Platforms", + key = "cdmf:device-types:types", + permissions = {"/device-mgt/device-types/types"} + ), + @Scope( + name = "Get Feature Details of a Device Type", + description = "Get Feature Details of a Device Type", + key = "cdmf:device-types:features", + permissions = {"/device-mgt/device-types/features"} + ) + } +) @Path("/device-types") @Api(value = "Device Type Management", description = "This API corresponds to all tasks related to device " + "type management") @@ -68,12 +85,10 @@ public interface DeviceTypeManagementService { value = "Getting the Supported Device Platforms", notes = "Get the list of device platforms supported by WSO2 EMM.", tags = "Device Type Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Device Types") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:types") + }) } ) @ApiResponses( @@ -123,6 +138,7 @@ public interface DeviceTypeManagementService { String ifModifiedSince); @GET + @Path("/{type}/features") @ApiOperation( produces = MediaType.APPLICATION_JSON, httpMethod = "GET", @@ -131,12 +147,10 @@ public interface DeviceTypeManagementService { "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 Type Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/devices/owning-device/view", - description = "View Device Types") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:device-types:features") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java index 9d1b255e96b..ab274b5a94f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/GroupManagementService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; -import io.swagger.annotations.Authorization; -import io.swagger.annotations.AuthorizationScope; import io.swagger.annotations.Extension; import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Info; @@ -33,6 +31,8 @@ import io.swagger.annotations.ResponseHeader; import io.swagger.annotations.SwaggerDefinition; import io.swagger.annotations.Tag; import org.apache.axis2.transport.http.HTTPConstants; +import org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.DeviceIdentifier; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceGroupList; @@ -40,6 +40,7 @@ import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceList; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceToGroupsAssignment; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.Valid; import javax.ws.rs.Consumes; @@ -75,6 +76,82 @@ import java.util.List; "details.") } ) +@Scopes( + scopes = { + @Scope( + name = "Get the list of groups belongs to current user.", + description = "Get the list of groups belongs to current user.", + key = "cdmf:groups:groups", + permissions = {"/device-mgt/groups/groups"} + ), + @Scope( + name = "Get the count of groups belongs to current user.", + description = "Get the count of groups belongs to current user.", + key = "cdmf:groups:count", + permissions = {"/device-mgt/groups/count"} + ), + @Scope( + name = "Add new device group to the system.", + description = "Add new device group to the system.", + key = "cdmf:groups:add", + permissions = {"/device-mgt/groups/add"} + ), + @Scope( + name = "View group specified", + description = "View group specified", + key = "cdmf:groups:groups-view", + permissions = {"/device-mgt/groups/groups-view"} + ), + @Scope( + name = "Update a group", + description = "Update a group", + key = "cdmf:groups:update", + permissions = {"/device-mgt/groups/update"} + ), + @Scope( + name = "Delete a group", + description = "Delete a group", + key = "cdmf:groups:remove", + permissions = {"/device-mgt/groups/remove"} + ), + @Scope( + name = "Manage group sharing with a user", + description = "Manage group sharing with a user", + key = "cdmf:groups:share", + permissions = {"/device-mgt/groups/share"} + ), + @Scope( + name = "View list of roles of a device group", + description = "View list of roles of a device group", + key = "cdmf:groups:roles", + permissions = {"/device-mgt/groups/roles"} + ), + @Scope( + name = "View list of devices in the device group", + description = "View list of devices in the device group", + key = "cdmf:groups:devices", + permissions = {"/device-mgt/groups/devices"} + ), + @Scope( + name = "View list of device count in the device group", + description = "View list of device count in the device group", + key = "cdmf:groups:devices-count", + permissions = {"/device-mgt/groups/devices/devices-count"} + ), + @Scope( + name = "Add devices to group", + description = "Add devices to group", + key = "cdmf:groups:devices-add", + permissions = {"/device-mgt/groups/devices/devices-add"} + ), + @Scope( + name = "Remove devices from group", + description = "Remove devices from group", + key = "cdmf:groups:devices-remove", + permissions = {"/device-mgt/groups/devices/devices-remove"} + ) + } +) @Path("/groups") @Api(value = "Device Group Management", description = "This API carries all device group management related " + "operations such as get all the available groups, etc.") @@ -89,12 +166,10 @@ public interface GroupManagementService { value = "Get the list of groups belongs to current user.", notes = "Returns all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups") + }) } ) @ApiResponses(value = { @@ -154,13 +229,12 @@ public interface GroupManagementService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:count") + }) } + ) @ApiResponses(value = { @ApiResponse(code = 200, message = "OK. \n Successfully fetched the device group count.", @@ -203,12 +277,10 @@ public interface GroupManagementService { value = "Add new device group to the system.", notes = "Add device group with current user as the owner.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/add", - description = "Add Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:add") + }) } ) @ApiResponses( @@ -271,12 +343,10 @@ public interface GroupManagementService { value = "View group specified.", notes = "Returns details of group enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/view", - description = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:groups-view") + }) } ) @ApiResponses(value = { @@ -326,12 +396,10 @@ public interface GroupManagementService { notes = "If you wish to make changes to an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/update", - description = "Update Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:update") + }) } ) @ApiResponses(value = { @@ -385,12 +453,10 @@ public interface GroupManagementService { notes = "If you wish to remove an existing group, that can be done by updating the group using " + "this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/remove", - description = "Remove Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:remove") + }) } ) @ApiResponses(value = { @@ -439,12 +505,10 @@ public interface GroupManagementService { notes = "If you wish to share /un share an existing group with a user under defined sharing roles, " + "that can be done using this resource.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/share", - description = "Share Group") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:share") + }) } ) @ApiResponses(value = { @@ -497,12 +561,10 @@ public interface GroupManagementService { value = "View list of roles of a device group.", notes = "Returns details of roles which particular group has been shared with.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/roles/view", - description = "View roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:roles") + }) } ) @ApiResponses(value = { @@ -551,12 +613,10 @@ public interface GroupManagementService { value = "View list of devices in the device group.", notes = "Returns list of devices in the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", - description = "View devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices") + }) } ) @ApiResponses(value = { @@ -613,12 +673,10 @@ public interface GroupManagementService { value = "View list of device count in the device group.", notes = "Returns device count in the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/view", - description = "View devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-count") + }) } ) @ApiResponses(value = { @@ -667,12 +725,10 @@ public interface GroupManagementService { value = "Add devices to group.", notes = "Add existing devices to the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/add", - description = "Add devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-add") + }) } ) @ApiResponses(value = { @@ -725,12 +781,10 @@ public interface GroupManagementService { value = "Remove devices from group.", notes = "Remove existing devices from the device group.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/groups/devices/remove", - description = "Remove devices") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:groups:devices-remove") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java index 0a2998251c8..a3d0d556f3b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/NotificationManagementService.java @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.notification.mgt.Notification; import org.wso2.carbon.device.mgt.jaxrs.NotificationList; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Max; import javax.validation.constraints.Size; @@ -60,6 +61,22 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting All Device Notification Details", + description = "Getting All Device Notification Details", + key = "cdmf:notifications:view", + permissions = {"/device-mgt/notifications/view"} + ), + @Scope( + name = "Updating the Device Notification Status", + description = "Updating the Device Notification Status", + key = "cdmf:notifications:mark-checked", + permissions = {"/device-mgt/notifications/mark-checked"} + ) + } +) @Api(value = "Device Notification Management", description = "Device notification related operations can be found here.") @Path("/notifications") @Produces(MediaType.APPLICATION_JSON) @@ -73,12 +90,10 @@ public interface NotificationManagementService { value = "Getting All Device Notification Details", notes = "Get the details of all the notifications that were pushed to the devices registered with WSO2 EMM using this REST API.", tags = "Device Notification Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", - description = "View notifications") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:view") + }) } ) @ApiResponses( @@ -164,12 +179,10 @@ public interface NotificationManagementService { notes = "When a user has read the the device notification the device notification status must " + "change from NEW to CHECKED. This API is used to update device notification status.", tags = "Device Notification Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/notifications/view", - description = "View notifications") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:notifications:mark-checked") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java index 7f282279647..968d0ea0ea0 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/PolicyManagementService.java @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.PolicyWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.PriorityUpdatedPolicyWrapper; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.policy.mgt.common.Policy; import javax.validation.Valid; @@ -62,6 +63,64 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Adding a Policy", + description = "Adding a Policy", + key = "cdmf:policies:manage", + permissions = {"/device-mgt/policies/manage"} + ), + @Scope( + name = "Getting Details of Policies", + description = "Getting Details of Policies", + key = "cdmf:policies:get-details", + permissions = {"/device-mgt/policies/get-details"} + ), + @Scope( + name = "Getting Details of a Policy", + description = "Getting Details of a Policy", + key = "cdmf:policies:get-policy-details", + permissions = {"/device-mgt/policies/get-policy-details"} + ), + @Scope( + name = "Updating a Policy", + description = "Updating a Policy", + key = "cdmf:policies:update", + permissions = {"/device-mgt/policies/update"} + ), + @Scope( + name = "Removing Multiple Policies", + description = "Removing Multiple Policies", + key = "cdmf:policies:remove", + permissions = {"/device-mgt/policies/remove"} + ), + @Scope( + name = "Activating Policies", + description = "Activating Policies", + key = "cdmf:policies:activate", + permissions = {"/device-mgt/policies/activate"} + ), + @Scope( + name = "Deactivating Policies", + description = "Deactivating Policies", + key = "cdmf:policies:deactivate", + permissions = {"/device-mgt/policies/deactivate"} + ), + @Scope( + name = "Applying Changes on Policies", + description = "Applying Changes on Policies", + key = "cdmf:policies:changes", + permissions = {"/device-mgt/policies/changes"} + ), + @Scope( + name = "Updating the Policy Priorities", + description = "Updating the Policy Priorities", + key = "cdmf:policies:priorities", + permissions = {"/device-mgt/policies/priorities"} + ) + } +) @Api(value = "Device Policy Management", description = "This API includes the functionality around device policy management") @Path("/policies") @Produces(MediaType.APPLICATION_JSON) @@ -77,12 +136,10 @@ public interface PolicyManagementService { notes = "Add a policy using this REST API command. When adding a policy you will have the option of saving the policy or saving and publishing the policy." + "Using this REST API you are able to save a created Policy and this policy will be in the inactive state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:manage") + }) } ) @ApiResponses( @@ -147,12 +204,10 @@ public interface PolicyManagementService { notes = "Retrieve the details of all the policies in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", - description = "View policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-details") + }) } ) @ApiResponses( @@ -224,12 +279,10 @@ public interface PolicyManagementService { notes = "Retrieve the details of a policy that is in WSO2 EMM.", response = Policy.class, tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/view", - description = "View policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:get-policy-details") + }) } ) @ApiResponses( @@ -294,12 +347,10 @@ public interface PolicyManagementService { value = "Updating a Policy", notes = "Make changes to an existing policy by updating the policy using this resource.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:update") + }) } ) @ApiResponses( @@ -364,12 +415,10 @@ public interface PolicyManagementService { value = "Removing Multiple Policies", notes = "Delete one or more than one policy using this API.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:remove") + }) } ) @ApiResponses( @@ -412,12 +461,10 @@ public interface PolicyManagementService { value = "Activating Policies", notes = "Publish a policy using this API to bring a policy that is in the inactive state to the active state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:activate") + }) } ) @ApiResponses( @@ -455,12 +502,10 @@ public interface PolicyManagementService { value = "Deactivating Policies", notes = "Unpublish a policy using this API to bring a policy that is in the active state to the inactive state.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:deactivate") + }) } ) @ApiResponses( @@ -503,12 +548,10 @@ public interface PolicyManagementService { " devices will not receive these changes immediately. Once all the required changes are made" + " you need to apply the changes to push the policy changes to the existing devices.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:changes") + }) } ) @ApiResponses( @@ -533,13 +576,11 @@ public interface PolicyManagementService { value = "Updating the Policy Priorities", notes = "Make changes to the existing policy priority order by updating the priority order using this API.", tags = "Device Policy Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/policies/manage", - description = "Manage policies") } - ) - } + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:policies:priorities") + }) + } ) @ApiResponses( value = { 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 cc894b9c0b0..b308ddc9702 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 @@ -24,16 +24,17 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; 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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleInfo; import org.wso2.carbon.device.mgt.jaxrs.beans.RoleList; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import org.wso2.carbon.user.mgt.common.UIPermissionNode; import javax.ws.rs.*; @@ -56,6 +57,58 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "Getting the List of Roles", + description = "Getting the List of Roles", + key = "cdmf:roles:view", + permissions = {"/device-mgt/roles/view"} + ), + @Scope( + name = "Getting Permission Details of a Role", + description = "Getting Permission Details of a Role", + key = "cdmf:roles:permissions", + permissions = {"/device-mgt/roles/permissions"} + ), + @Scope( + name = "Getting the List of Roles", + description = "Getting the List of Roles", + key = "cdmf:roles:details", + permissions = {"/device-mgt/roles/details"} + ), + @Scope( + name = "Adding a Role", + description = "Adding a Role", + key = "cdmf:roles:add", + permissions = {"/device-mgt/roles/add"} + ), + @Scope( + name = "Adding a combined Role", + description = "Adding a combined Role", + key = "cdmf:roles:create-combined-role", + permissions = {"/device-mgt/roles/create-combined-role"} + ), + @Scope( + name = "Updating Role Details", + description = "Updating Role Details", + key = "cdmf:roles:update", + permissions = {"/device-mgt/roles/update"} + ), + @Scope( + name = "Deleting a Role", + description = "Deleting a Role", + key = "cdmf:roles:delete", + permissions = {"/device-mgt/roles/delete"} + ), + @Scope( + name = "Adding Users to a Role", + description = "Adding Users to a Role", + key = "cdmf:roles:add-users", + permissions = {"/device-mgt/roles/add-users"} + ) + } +) @Path("/roles") @Api(value = "Role Management", description = "Role management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -70,11 +123,10 @@ public interface RoleManagementService { 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" + "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:view") + }) } ) @ApiResponses( @@ -151,11 +203,10 @@ public interface RoleManagementService { response = UIPermissionNode.class, responseContainer = "List", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:permissions") + }) } ) @ApiResponses( @@ -227,12 +278,10 @@ public interface RoleManagementService { notes = "Get the permissions associated with a role and role specific details using this REST API.", response = RoleInfo.class, tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/view", - description = "View Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:details") + }) } ) @ApiResponses( @@ -303,12 +352,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:add") + }) } ) @ApiResponses(value = { @@ -365,12 +412,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:create-combined-role") + }) } ) @ApiResponses(value = { @@ -430,12 +475,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:update") + }) } ) @ApiResponses(value = { @@ -498,12 +541,10 @@ public interface RoleManagementService { 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", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:delete") + }) } ) @ApiResponses(value = { @@ -550,12 +591,10 @@ public interface RoleManagementService { "be cumbersome. Therefore, you can define all the new employees that belong to the engineering " + "role using this API.", tags = "Role Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/roles/manage", - description = "Manage Roles") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:roles:add-users") + }) } ) @ApiResponses( diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java index 41353a0f4ca..f2ad567c6cc 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/UserManagementService.java @@ -18,7 +18,14 @@ */ 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.AuthorizationScope; +import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -70,6 +77,76 @@ import java.util.List; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Adding a User", + description = "Adding a User", + key = "cdmf:users:add", + permissions = {"/device-mgt/users/add"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting Details of a User", + description = "Getting Details of a User", + key = "cdmf:users:details", + permissions = {"/device-mgt/users/details"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Updating Details of a User", + description = "Updating Details of a User", + key = "cdmf:users:update", + permissions = {"/device-mgt/policies/update"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Deleting a User", + description = "Deleting a User", + key = "cdmf:users:delete", + permissions = {"/device-mgt/policies/delete"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the Role Details of a User", + description = "Getting the Role Details of a User", + key = "cdmf:users:roles", + permissions = {"/device-mgt/policies/roles"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting Details of Users", + description = "Getting Details of Users", + key = "cdmf:users:user-details", + permissions = {"/device-mgt/policies/user-details"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the User Count", + description = "Getting the User Count", + key = "cdmf:users:count", + permissions = {"/device-mgt/policies/count"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Getting the User existence status", + description = "Getting the User existence status", + key = "cdmf:users:is-exist", + permissions = {"/device-mgt/policies/is-exist"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Searching for a User Name", + description = "Searching for a User Name", + key = "cdmf:users:search", + permissions = {"/device-mgt/policies/search"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Changing the User Password", + description = "Adding a User", + key = "cdmf:users:credentials", + permissions = {"/device-mgt/policies/credentials"} + ), + @org.wso2.carbon.apimgt.annotations.api.Scope( + name = "Sending Enrollment Invitations to Users", + description = "Sending Enrollment Invitations to Users", + key = "cdmf:users:send-invitation", + permissions = {"/device-mgt/policies/send-invitation"} + ) + } +) @Path("/users") @Api(value = "User Management", description = "User management related operations can be found here.") @Produces(MediaType.APPLICATION_JSON) @@ -84,12 +161,10 @@ public interface UserManagementService { value = "Adding a User", notes = "WSO2 IoTS supports user management. Add a new user to the WSO2 IoTS user management system via this REST API", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:add") + }) } ) @ApiResponses( @@ -146,12 +221,10 @@ public interface UserManagementService { notes = "Get the details of a user registered with WSO2 IoTS using the REST API.", response = BasicUserInfo.class, tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:details") + }) } ) @ApiResponses(value = { @@ -219,12 +292,10 @@ public interface UserManagementService { notes = "There will be situations where you will want to update the user details. In such " + "situation you can update the user details using this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:update") + }) } ) @ApiResponses(value = { @@ -286,12 +357,10 @@ public interface UserManagementService { value = "Deleting a User", notes = "When an employee leaves the organization, you can remove the user details from WSO2 IoTS using this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", - description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:delete") + }) } ) @ApiResponses(value = { @@ -331,12 +400,10 @@ public interface UserManagementService { value = "Getting the Role Details of a User", notes = "A user can be assigned to one or more role in IoTS. Using this REST API you can get the role/roles a user is assigned to.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:roles") + }) } ) @ApiResponses(value = { @@ -395,12 +462,10 @@ public interface UserManagementService { notes = "You are able to manage users in WSO2 IoTS by adding, updating and removing users. If you wish to get the list of users registered with WSO2 IoTS, you can do so " + "using this REST API", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:user-details") + }) } ) @ApiResponses(value = { @@ -468,11 +533,10 @@ public interface UserManagementService { value = "Getting the User Count", notes = "Get the number of users in WSO2 IoTS via this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:count") + }) } ) @ApiResponses(value = { @@ -504,12 +568,10 @@ public interface UserManagementService { value = "Getting the User existence status", notes = "Check if the user exists in the user store.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", - description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:is-exist") + }) } ) @ApiResponses(value = { @@ -549,11 +611,10 @@ public interface UserManagementService { + "You will be given a list of users having the user name in the exact order of the " + "characters you provided.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/view", description = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:search") + }) } ) @ApiResponses(value = { @@ -627,11 +688,10 @@ public interface UserManagementService { value = "Changing the User Password", notes = "A user is able to change the password to secure their WSO2 IoTS profile via this REST API.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/login", description = "Reset user password") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:credentials") + }) } ) @ApiResponses(value = { @@ -673,11 +733,10 @@ public interface UserManagementService { notes = "Send the users a mail inviting them to enroll their devices using the REST API given below.\n" + "Before running the REST API command to send the enrollment invitations to users make sure to configure WSO2 IoTS as explained in step 4, under the WSO2 IoTS general server configurations documentation.", tags = "User Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description = "Manage Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:users:send-invitation") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java index 8f492612023..450b3a3778d 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/ApplicationManagementAdminService.java @@ -18,9 +18,18 @@ */ package org.wso2.carbon.device.mgt.jaxrs.service.api.admin; -import io.swagger.annotations.*; -import org.wso2.carbon.apimgt.annotations.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 org.wso2.carbon.apimgt.annotations.api.Scope; +import org.wso2.carbon.apimgt.annotations.api.Scopes; import org.wso2.carbon.device.mgt.common.operation.mgt.Activity; import org.wso2.carbon.device.mgt.jaxrs.beans.ApplicationWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; @@ -55,10 +64,16 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Manage application", - description = "", - key = "cdmf:manage-application", - permissions = {"/device-mgt/applications/manage"} + name = "Installing an Application (Internal API)", + description = "Installing an Application (Internal API)", + key = "cdmf:applications:install", + permissions = {"/device-mgt/applications/install"} + ), + @Scope( + name = "Uninstalling an Application (Internal API)", + description = "Uninstalling an Application (Internal API)", + key = "cdmf:applications:uninstall", + permissions = {"/device-mgt/applications/uninstall"} ) } ) @@ -78,7 +93,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:install") }) } ) @@ -122,7 +137,7 @@ public interface ApplicationManagementAdminService { tags = "Application Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-application") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:applications:uninstall") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java index a2e80bcbf9d..72ba18d5065 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/DeviceManagementAdminService.java @@ -24,8 +24,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -66,10 +64,10 @@ import javax.ws.rs.core.Response; @Scopes( scopes = { @Scope( - name = "Manage device", - description = "", - key = "cdmf:manage-own-device", - permissions = {"/device-mgt/devices/owning-device/view"} + name = "Getting Details of a Device", + description = "Getting Details of a Device", + key = "cdmf:admin:devices:view", + permissions = {"/device-mgt/devices/admin/devices/view"} ) } ) @@ -86,7 +84,7 @@ public interface DeviceManagementAdminService { tags = "Device Management Administrative Service", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:manage-own-device") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin:devices:view") }) } ) diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java index b5716e9db39..06d0842985f 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -25,8 +25,6 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; @@ -69,8 +67,14 @@ import javax.ws.rs.core.Response; @Scope( name = "View groups", description = "", - key = "cdmf:view-groups", + key = "cdmf:admin-groups:view", permissions = {"/device-mgt/admin/groups/view"} + ), + @Scope( + name = "Count groups", + description = "", + key = "cdmf:admin-groups:count", + permissions = {"/device-mgt/admin/groups/count"} ) } ) @@ -85,7 +89,7 @@ public interface GroupManagementAdminService { tags = "Device Group Management", extensions = { @Extension(properties = { - @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:view-groups") + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:view") }) } ) @@ -146,12 +150,10 @@ public interface GroupManagementAdminService { value = "Get the count of groups belongs to current user.", notes = "Returns count of all permitted groups enrolled with the system.", tags = "Device Group Management", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/admin/groups/view", description - = "View Groups") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-groups:count") + }) } ) @ApiResponses(value = { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java index 99914a94aba..fbb3603e569 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/api/admin/UserManagementAdminService.java @@ -24,14 +24,15 @@ import io.swagger.annotations.ExtensionProperty; import io.swagger.annotations.Extension; import io.swagger.annotations.Tag; import io.swagger.annotations.Api; -import io.swagger.annotations.AuthorizationScope; -import io.swagger.annotations.Authorization; import io.swagger.annotations.ApiOperation; import io.swagger.annotations.ApiParam; import io.swagger.annotations.ApiResponse; import io.swagger.annotations.ApiResponses; +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; import org.wso2.carbon.device.mgt.jaxrs.beans.PasswordResetWrapper; +import org.wso2.carbon.device.mgt.jaxrs.util.Constants; import javax.validation.constraints.Size; import javax.ws.rs.*; @@ -53,6 +54,16 @@ import javax.ws.rs.core.Response; @Tag(name = "device_management", description = "") } ) +@Scopes( + scopes = { + @Scope( + name = "View Users", + description = "View Users", + key = "cdmf:admin-users:view", + permissions = {"/device-mgt/admin/users/view"} + ) + } +) @Path("/admin/users") @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) @@ -71,12 +82,10 @@ public interface UserManagementAdminService { notes = "The EMM administrator is able to change the password of the users in " + "the system and block them from logging into their EMM profile using this REST API.", tags = "User Management Administrative Service", - authorizations = { - @Authorization( - value="permission", - scopes = { @AuthorizationScope(scope = "/device-mgt/users/manage", description - = "View Users") } - ) + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "cdmf:admin-users:view") + }) } ) @ApiResponses(value = {