From d13c3f8dde273d63422db809777b9909cf6ebc26 Mon Sep 17 00:00:00 2001 From: Shabirmean Date: Tue, 22 Dec 2015 14:24:24 +0530 Subject: [PATCH] Added XMPP modification to encrypt payload --- .../xmpp/FireAlarmXMPPCommunicator.java | 33 +++++++++++-------- .../service/VirtualFireAlarmService.java | 8 ++--- .../VirtualFireAlarmXMPPConnector.java | 1 + .../controlqueue/xmpp/XmppServerClient.java | 2 +- 4 files changed, 26 insertions(+), 18 deletions(-) diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java index 5d2f5564bb..f73cb12110 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -71,7 +71,7 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { resource = agentManager.getAgentConfigs().getDeviceOwner(); xmppDeviceJID = username + "@" + server; - xmppAdminJID = AgentConstants.XMPP_ADMIN_ACCOUNT_UNAME + "@" + server; + xmppAdminJID = agentManager.getAgentConfigs().getServerName() + "_" + AgentConstants.DEVICE_TYPE + "@" + server; Runnable connect = new Runnable() { @@ -187,19 +187,26 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { Runnable pushDataRunnable = new Runnable() { @Override public void run() { - int currentTemperature = agentManager.getTemperature(); - String payLoad = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; - Message xmppMessage = new Message(); - xmppMessage.setTo(xmppAdminJID); - xmppMessage.setSubject("PUBLISHER"); - xmppMessage.setBody(payLoad); - xmppMessage.setType(Message.Type.chat); - - sendXMPPMessage(xmppAdminJID, xmppMessage); - log.info(AgentConstants.LOG_APPENDER + "Message: '" + xmppMessage.getBody() + - "' sent to XMPP JID [" + xmppAdminJID + "] under subject [" + - xmppMessage.getSubject() + "]"); + + try { + int currentTemperature = agentManager.getTemperature(); + + String message = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); + + xmppMessage.setTo(xmppAdminJID); + xmppMessage.setSubject("PUBLISHER"); + xmppMessage.setBody(payLoad); + xmppMessage.setType(Message.Type.chat); + + sendXMPPMessage(xmppAdminJID, xmppMessage); + log.info(AgentConstants.LOG_APPENDER + "Message: '" + message + "' sent to XMPP JID - " + + "[" + xmppAdminJID + "] under subject [" + xmppMessage.getSubject() + "]."); + } catch (AgentCoreOperationException e) { + log.warn(AgentConstants.LOG_APPENDER + "Preparing Secure payload failed for XMPP JID - " + + "[" + xmppAdminJID + "] with subject - [" + xmppMessage.getSubject() + "]."); + } } }; diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java index 9631cc6f2e..06207be3d6 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/VirtualFireAlarmService.java @@ -572,8 +572,8 @@ public class VirtualFireAlarmService { */ @Path("controller/bulb") @POST - @Feature( code="VIRTUALFIREALARM_BULBCONTROL", name="Control Bulb", - description="Switch on/off Virtual Fire Alarm Bulb") + @Feature(code = "VIRTUALFIREALARM_BULBCONTROL", name = "Control Bulb", type = "operation", + description = "Switch on/off Virtual Fire Alarm Bulb") public void switchBulb(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @HeaderParam("protocol") String protocol, @@ -657,7 +657,7 @@ public class VirtualFireAlarmService { */ @Path("controller/readhumidity") @GET - @Feature( code="VIRTUALFIREALARM_READHUMIDITY", name="Read Humidity", + @Feature( code="VIRTUALFIREALARM_READHUMIDITY", name="Read Humidity", type = "monitor", description="Read Humidity Readings from Virtual Fire Alarm") public String requestHumidity(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, @@ -738,7 +738,7 @@ public class VirtualFireAlarmService { @GET @Consumes(MediaType.APPLICATION_JSON) @Produces(MediaType.APPLICATION_JSON) - @Feature( code="VIRTUALFIREALARM_REQTEMP", name="Request Tempreature", + @Feature( code="VIRTUALFIREALARM_REQTEMP", name="Request Tempreature", type = "monitor", description="Request Tempreature reading from Virtual Fire Alarm") public SensorRecord requestTemperature(@HeaderParam("owner") String owner, @HeaderParam("deviceId") String deviceId, diff --git a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java index 285783d850..f47aeb4fd6 100644 --- a/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java +++ b/components/device-mgt-iot-virtualfirealarm/org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/transport/VirtualFireAlarmXMPPConnector.java @@ -73,6 +73,7 @@ public class VirtualFireAlarmXMPPConnector extends XMPPTransportHandler { public void createXMPPAccountForDeviceType() { boolean accountExists = false; XmppServerClient xmppServerClient = new XmppServerClient(); + xmppServerClient.initControlQueue(); try { accountExists = xmppServerClient.doesXMPPUserAccountExist(xmppVFireAlarmAdminUsername); diff --git a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java index 043adafdaa..0cc9021b10 100644 --- a/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java +++ b/components/device-mgt-iot/org.wso2.carbon.device.mgt.iot/src/main/java/org/wso2/carbon/device/mgt/iot/controlqueue/xmpp/XmppServerClient.java @@ -62,7 +62,7 @@ public class XmppServerClient implements ControlQueueConnector { } @Override - public void initControlQueue() throws DeviceControllerException { + public void initControlQueue() { xmppEndpoint = XmppConfig.getInstance().getXmppEndpoint(); xmppUsername = XmppConfig.getInstance().getXmppUsername(); xmppPassword = XmppConfig.getInstance().getXmppPassword();