From f6d75bb88078b65e535bf9901c9413bb02bb6752 Mon Sep 17 00:00:00 2001 From: mharindu Date: Wed, 27 Apr 2016 12:28:43 +0530 Subject: [PATCH] Added permissions to firealarm API --- .../impl/VirtualFireAlarmControllerService.java | 17 +++++++---------- .../VirtualFireAlarmControllerServiceImpl.java | 2 ++ .../impl/VirtualFireAlarmManagerService.java | 2 +- 3 files changed, 10 insertions(+), 11 deletions(-) diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java index 9c73acf29..fee6744a2 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerService.java @@ -19,23 +19,16 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl; import org.wso2.carbon.apimgt.annotations.api.API; +import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.DeviceType; import org.wso2.carbon.device.mgt.extensions.feature.mgt.annotations.Feature; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.DeviceData; import javax.servlet.http.HttpServletRequest; -import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.PathParam; -import javax.ws.rs.Produces; -import javax.ws.rs.QueryParam; +import javax.ws.rs.*; import javax.ws.rs.core.Context; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; -import java.io.InputStream; /** * This class consists the functions/APIs specific to the "actions" of the VirtualFirealarm device-type. These APIs @@ -44,7 +37,7 @@ import java.io.InputStream; * the transport 'Connectors' [XMPP & MQTT] specific to the VirtualFirealarm device-type in order to communicate with * such devices and to receive messages form it. */ -@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm", tags = "virtual_firealarm") +@API(name = "virtual_firealarm", version = "1.0.0", context = "/virtual_firealarm", tags = {"virtual_firealarm"}) @DeviceType(value = "virtual_firealarm") public interface VirtualFireAlarmControllerService { @@ -64,6 +57,7 @@ public interface VirtualFireAlarmControllerService { */ @POST @Path("device/register/{deviceId}/{ip}/{port}") + @Permission(scope = "virtual_firealarm_admin", permissions = {"device-mgt/virtual_firealarm/admin"}) Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, @PathParam("port") String devicePort, @Context HttpServletRequest request); @@ -80,6 +74,7 @@ public interface VirtualFireAlarmControllerService { */ @POST @Path("device/{deviceId}/buzz") + @Permission(scope = "virtual_firealarm_user", permissions = {"device-mgt/virtual_firealarm/user"}) @Feature(code = "buzz", name = "Buzzer On / Off", type = "operation", description = "Switch on/off Virtual Fire Alarm Buzzer. (On / Off)") Response switchBuzzer(@PathParam("deviceId") String deviceId, @QueryParam("protocol") String protocol, @@ -94,6 +89,7 @@ public interface VirtualFireAlarmControllerService { */ @POST @Path("device/temperature") + @Permission(scope = "virtual_firealarm_admin", permissions = {"device-mgt/virtual_firealarm/admin"}) @Consumes(MediaType.APPLICATION_JSON) Response pushTemperatureData(final DeviceData dataMsg); @@ -103,6 +99,7 @@ public interface VirtualFireAlarmControllerService { */ @Path("device/stats/{deviceId}/sensors/{sensorName}") @GET + @Permission(scope = "virtual_firealarm_user", permissions = {"device-mgt/virtual_firealarm/user"}) @Consumes("application/json") @Produces("application/json") Response getVirtualFirealarmStats(@PathParam("deviceId") String deviceId, diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java index a489685ad..0afca3d0e 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmControllerServiceImpl.java @@ -23,6 +23,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.analytics.dataservice.commons.SORT; import org.wso2.carbon.analytics.dataservice.commons.SortByField; import org.wso2.carbon.analytics.datasource.commons.exception.AnalyticsException; +import org.wso2.carbon.apimgt.annotations.api.Permission; import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; @@ -78,6 +79,7 @@ public class VirtualFireAlarmControllerServiceImpl implements VirtualFireAlarmCo // holds a mapping of the IP addresses to Device-IDs for HTTP communication private ConcurrentHashMap deviceToIpMap = new ConcurrentHashMap<>(); + @Permission(scope = "virtual_firealarm_user", permissions = {"device-mgt/virtual_firealarm/user"}) @POST @Path("device/register/{deviceId}/{ip}/{port}") public Response registerDeviceIP(@PathParam("deviceId") String deviceId, @PathParam("ip") String deviceIP, diff --git a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java index 0b4077b2d..7b5bdaf09 100644 --- a/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java +++ b/components/iot-plugins/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmManagerService.java @@ -33,7 +33,7 @@ import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; @Path("enrollment") -@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = "virtual_firealarm") +@API(name = "virtual_firealarm_mgt", version = "1.0.0", context = "/virtual_firealarm_mgt", tags = {"virtual_firealarm"}) public interface VirtualFireAlarmManagerService { @Path("/devices/{device_id}")