From 2e8279b61abda03133bd3ac938c17c33d0558493 Mon Sep 17 00:00:00 2001 From: ayyoob Date: Sat, 7 Jan 2017 14:54:46 +0530 Subject: [PATCH] removed scep impl from virtual fire alarm --- .../mqtt/FireAlarmMQTTCommunicator.java | 5 +- .../xmpp/FireAlarmXMPPCommunicator.java | 5 +- .../agent/advanced/core/AgentConstants.java | 2 +- .../agent/advanced/core/AgentManager.java | 14 +- .../advanced/core/AgentUtilOperations.java | 90 ++++---- .../enrollment/EnrollmentManager.java | 10 + .../mqtt/FireAlarmMQTTCommunicator.java | 5 +- .../xmpp/FireAlarmXMPPCommunicator.java | 6 +- .../agent/core/AgentConstants.java | 2 +- .../agent/core/AgentManager.java | 18 +- .../agent/core/AgentUtilOperations.java | 90 ++++---- .../agent/enrollment/EnrollmentManager.java | 2 +- .../build.xml | 38 ++++ .../pom.xml | 75 +++++++ .../src/assembly/src.xml | 36 ++++ .../carbonapps/virtualfirealarm/artifacts.xml | 26 +++ .../virtualfirealarm_execution/artifact.xml | 23 ++ .../virtualfirealarm_execution.siddhiql | 20 ++ .../virtualfirealarm_receiver/artifact.xml | 22 ++ .../virtualfirealarm_receiver.xml | 31 +++ .../virtualfirealarm_stream/artifact.xml | 23 ++ .../org.wso2.iot.virtualfirealarm_1.0.0.json | 16 ++ .../pom.xml | 5 - .../impl/VirtualFireAlarmServiceImpl.java | 65 ++---- .../constants/VirtualFireAlarmConstants.java | 84 ++++++++ .../util/VirtualFireAlarmServiceUtils.java | 51 ----- .../util/VirtualFireAlarmUtilConstants.java | 1 - .../service/impl/util/ZipUtil.java | 2 +- .../xmpp/VirtualFirealarmXMPPException.java | 56 +++++ .../service/impl/xmpp/XmppAccount.java | 63 ++++++ .../service/impl/xmpp/XmppConfig.java | 124 +++++++++++ .../service/impl/xmpp/XmppServerClient.java | 66 ++++++ .../src/main/webapp/WEB-INF/web.xml | 2 + .../src/main/webapp/WEB-INF/xmpp.properties | 25 +++ .../pom.xml | 199 ------------------ .../impl/VirtualFireAlarmScepServer.java | 65 ------ .../impl/VirtualFireAlarmScepServerImpl.java | 136 ------------ .../exception/VirtualFireAlarmException.java | 31 --- .../util/VirtualFireAlarmServiceUtils.java | 103 --------- .../service/impl/util/scep/ContentType.java | 26 --- .../service/impl/util/scep/SCEPOperation.java | 39 ---- .../webapp/META-INF/webapp-classloading.xml | 33 --- .../src/main/webapp/WEB-INF/cxf-servlet.xml | 38 ---- .../src/main/webapp/WEB-INF/web.xml | 38 ---- .../virtual-fire-alarm-plugin/pom.xml | 2 +- .../pom.xml | 31 ++- .../src/main/resources/p2.inf | 6 +- pom.xml | 6 - 48 files changed, 909 insertions(+), 947 deletions(-) create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/build.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/assembly/src.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/artifact.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/virtualfirealarm_execution.siddhiql create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/artifact.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/virtualfirealarm_receiver.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/artifact.xml create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/org.wso2.iot.virtualfirealarm_1.0.0.json create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/constants/VirtualFireAlarmConstants.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/VirtualFirealarmXMPPException.java create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppAccount.java create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppConfig.java create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppServerClient.java create mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/xmpp.properties delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServer.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServerImpl.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/exception/VirtualFireAlarmException.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/VirtualFireAlarmServiceUtils.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/ContentType.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/SCEPOperation.java delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/META-INF/webapp-classloading.xml delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/cxf-servlet.xml delete mode 100644 components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/web.xml diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java index f9e6bd6d3..cd5c25571 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/mqtt/FireAlarmMQTTCommunicator.java @@ -191,7 +191,10 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { @Override public void run() { int currentTemperature = agentManager.getTemperature(); - String message = "PUBLISHER:" + AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " + + "0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}"; try { String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java index 668b0e16d..8ba82906f 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -189,7 +189,10 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { try { int currentTemperature = agentManager.getTemperature(); - String message = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " + + "0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}"; String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); xmppMessage.setTo(xmppAdminJID); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java index 7c02e675d..c3c2f77da 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentConstants.java @@ -58,7 +58,7 @@ public class AgentConstants { public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s"; - public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/publisher"; + public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/temperature"; /* --------------------------------------------------------------------------------------- XMPP Connection specific information --------------------------------------------------------------------------------------- */ diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentManager.java index 30a4fe0b9..e3b83a4c4 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentManager.java @@ -168,13 +168,13 @@ public class AgentManager { } } - try { - EnrollmentManager.getInstance().beginEnrollmentFlow(); - } catch (AgentCoreOperationException e) { - log.error("Device Enrollment Failed:\n"); - e.printStackTrace(); - System.exit(0); - } +// try { +// EnrollmentManager.getInstance().beginEnrollmentFlow(); +// } catch (AgentCoreOperationException e) { +// log.error("Device Enrollment Failed:\n"); +// e.printStackTrace(); +// System.exit(0); +// } //Start agent communication agentCommunicator.get(protocol).connect(); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java index 15e15c1be..9123c5fac 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/core/AgentUtilOperations.java @@ -241,59 +241,67 @@ public class AgentUtilOperations { public static String prepareSecurePayLoad(String message) throws AgentCoreOperationException { - PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey(); - String encodedMessage = Base64.encodeBase64String(message.getBytes()); - String signedPayload; - try { - signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey); - } catch (TransportHandlerException e) { - String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]"; - log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg, e); - } + if (EnrollmentManager.getInstance().isEnrolled()) { + PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey(); + String encodedMessage = Base64.encodeBase64String(message.getBytes()); + String signedPayload; + try { + signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey); + } catch (TransportHandlerException e) { + String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]"; + log.error(errorMsg); + throw new AgentCoreOperationException(errorMsg, e); + } - JSONObject jsonPayload = new JSONObject(); - jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage); - jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload); - //below statements are temporary fix. - jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber()); + JSONObject jsonPayload = new JSONObject(); + jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage); + jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload); + //below statements are temporary fix. + jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber()); - return jsonPayload.toString(); + return jsonPayload.toString(); + } else { + return message; + } } public static String extractMessageFromPayload(String message) throws AgentCoreOperationException { - String actualMessage; + if (EnrollmentManager.getInstance().isEnrolled()) { + String actualMessage; - PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey(); - JSONObject jsonPayload = new JSONObject(message); - Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY); - Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY); - boolean verification; + PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey(); + JSONObject jsonPayload = new JSONObject(message); + Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY); + Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY); + boolean verification; - if (encodedMessage != null && signedPayload != null) { - try { - verification = CommunicationUtils.verifySignature( - encodedMessage.toString(), signedPayload.toString(), serverPublicKey); - } catch (TransportHandlerException e) { - String errorMsg = - "Error occurred whilst trying to verify signature on received message: [" + message + "]"; + if (encodedMessage != null && signedPayload != null) { + try { + verification = CommunicationUtils.verifySignature( + encodedMessage.toString(), signedPayload.toString(), serverPublicKey); + } catch (TransportHandlerException e) { + String errorMsg = + "Error occurred whilst trying to verify signature on received message: [" + message + "]"; + log.error(errorMsg); + throw new AgentCoreOperationException(errorMsg, e); + } + } else { + String errorMsg = "The received message is in an INVALID format. " + + "Need to be JSON - {\"Msg\":\"\", \"Sig\":\"\"}."; + throw new AgentCoreOperationException(errorMsg); + } + if (verification) { + actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8); + } else { + String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg, e); + throw new AgentCoreOperationException(errorMsg); } + return actualMessage; } else { - String errorMsg = "The received message is in an INVALID format. " + - "Need to be JSON - {\"Msg\":\"\", \"Sig\":\"\"}."; - throw new AgentCoreOperationException(errorMsg); - } - if (verification) { - actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8); - } else { - String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; - log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg); + return message; } - return actualMessage; } public static String formatMessage(String message) { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/enrollment/EnrollmentManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/enrollment/EnrollmentManager.java index a60f25f03..d6d6954d7 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/enrollment/EnrollmentManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/advanced/enrollment/EnrollmentManager.java @@ -96,6 +96,7 @@ public class EnrollmentManager { private PublicKey publicKey; private PublicKey serverPublicKey; private X509Certificate SCEPCertificate; + private boolean isEnrolled = false; /** @@ -443,4 +444,13 @@ public class EnrollmentManager { public PublicKey getServerPublicKey() { return serverPublicKey; } + + /** + * Checks whether the device has already been enrolled with the SCEP Server. + * + * @return the enrollment status; 'TRUE' if already enrolled else 'FALSE'. + */ + public boolean isEnrolled() { + return isEnrolled; + } } diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java index 5b24783e7..8f89750fd 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/mqtt/FireAlarmMQTTCommunicator.java @@ -208,7 +208,10 @@ public class FireAlarmMQTTCommunicator extends MQTTTransportHandler { @Override public void run() { int currentTemperature = agentManager.getTemperature(); - String message = "PUBLISHER:" + AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " + + "0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}"; try { String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); diff --git a/components/device-types/virtual-fire-alarm-plugin/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-types/virtual-fire-alarm-plugin/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 abb8d7965..0780f2d84 100644 --- a/components/device-types/virtual-fire-alarm-plugin/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-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/communication/xmpp/FireAlarmXMPPCommunicator.java @@ -189,8 +189,10 @@ public class FireAlarmXMPPCommunicator extends XMPPTransportHandler { try { int currentTemperature = agentManager.getTemperature(); - - String message = AgentConstants.TEMPERATURE_CONTROL + ":" + currentTemperature; + String message = "{\"event\": {\"metaData\": {\"owner\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceOwner() + "\",\"deviceId\": \"" + AgentManager + .getInstance().getAgentConfigs().getDeviceId() + "\",\"time\": " + + "0},\"payloadData\": { \"temperature\": " + currentTemperature + "} }}"; String payLoad = AgentUtilOperations.prepareSecurePayLoad(message); xmppMessage.setTo(xmppAdminJID); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java index 566e5cfc0..f1372b25a 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentConstants.java @@ -62,7 +62,7 @@ public class AgentConstants { public static final int DEFAULT_MQTT_RECONNECTION_INTERVAL = 2; // time in seconds public static final int DEFAULT_MQTT_QUALITY_OF_SERVICE = 0; public static final String MQTT_SUBSCRIBE_TOPIC = "%s/" + DEVICE_TYPE + "/%s"; - public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/publisher"; + public static final String MQTT_PUBLISH_TOPIC = "%s/" + DEVICE_TYPE + "/%s/temperature"; /* --------------------------------------------------------------------------------------- Device/Agent specific properties to be read from the 'deviceConfig.properties' file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java index 2e7634054..6ee95dceb 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentManager.java @@ -153,15 +153,15 @@ public class AgentManager { } } - try { - if (!EnrollmentManager.getInstance().isEnrolled()) { - EnrollmentManager.getInstance().beginEnrollmentFlow(); - } - } catch (AgentCoreOperationException e) { - log.error("Device Enrollment Failed:\n"); - log.error(e); - System.exit(0); - } +// try { +// if (!EnrollmentManager.getInstance().isEnrolled()) { +// EnrollmentManager.getInstance().beginEnrollmentFlow(); +// } +// } catch (AgentCoreOperationException e) { +// log.error("Device Enrollment Failed:\n"); +// log.error(e); +// System.exit(0); +// } //Start agent communication agentCommunicator.get(protocol).connect(); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java index 60c3941b8..7a365174b 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/core/AgentUtilOperations.java @@ -250,57 +250,65 @@ public class AgentUtilOperations { } public static String prepareSecurePayLoad(String message) throws AgentCoreOperationException { - PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey(); - String encodedMessage = Base64.encodeBase64String(message.getBytes()); - String signedPayload; - try { - signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey); - } catch (TransportHandlerException e) { - String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]"; - log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg, e); - } + if (EnrollmentManager.getInstance().isEnrolled()) { + PrivateKey devicePrivateKey = EnrollmentManager.getInstance().getPrivateKey(); + String encodedMessage = Base64.encodeBase64String(message.getBytes()); + String signedPayload; + try { + signedPayload = CommunicationUtils.signMessage(encodedMessage, devicePrivateKey); + } catch (TransportHandlerException e) { + String errorMsg = "Error occurred whilst trying to sign encrypted message of: [" + message + "]"; + log.error(errorMsg); + throw new AgentCoreOperationException(errorMsg, e); + } - JSONObject jsonPayload = new JSONObject(); - jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage); - jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload); - //below statements are temporary fix. - jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber()); - return jsonPayload.toString(); + JSONObject jsonPayload = new JSONObject(); + jsonPayload.put(JSON_MESSAGE_KEY, encodedMessage); + jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload); + //below statements are temporary fix. + jsonPayload.put(JSON_SERIAL_KEY, EnrollmentManager.getInstance().getSCEPCertificate().getSerialNumber()); + return jsonPayload.toString(); + } else { + return message; + } } public static String extractMessageFromPayload(String message) throws AgentCoreOperationException { - String actualMessage; + if (EnrollmentManager.getInstance().isEnrolled()) { + String actualMessage; - PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey(); - JSONObject jsonPayload = new JSONObject(message); - Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY); - Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY); - boolean verification; + PublicKey serverPublicKey = EnrollmentManager.getInstance().getServerPublicKey(); + JSONObject jsonPayload = new JSONObject(message); + Object encodedMessage = jsonPayload.get(JSON_MESSAGE_KEY); + Object signedPayload = jsonPayload.get(JSON_SIGNATURE_KEY); + boolean verification; - if (encodedMessage != null && signedPayload != null) { - try { - verification = CommunicationUtils.verifySignature( - encodedMessage.toString(), signedPayload.toString(), serverPublicKey); - } catch (TransportHandlerException e) { - String errorMsg = - "Error occurred whilst trying to verify signature on received message: [" + message + "]"; + if (encodedMessage != null && signedPayload != null) { + try { + verification = CommunicationUtils.verifySignature( + encodedMessage.toString(), signedPayload.toString(), serverPublicKey); + } catch (TransportHandlerException e) { + String errorMsg = + "Error occurred whilst trying to verify signature on received message: [" + message + "]"; + log.error(errorMsg); + throw new AgentCoreOperationException(errorMsg, e); + } + } else { + String errorMsg = "The received message is in an INVALID format. " + + "Need to be JSON - {\"Msg\":\"\", \"Sig\":\"\"}."; + throw new AgentCoreOperationException(errorMsg); + } + if (verification) { + actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8); + } else { + String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg, e); + throw new AgentCoreOperationException(errorMsg); } + return actualMessage; } else { - String errorMsg = "The received message is in an INVALID format. " + - "Need to be JSON - {\"Msg\":\"\", \"Sig\":\"\"}."; - throw new AgentCoreOperationException(errorMsg); - } - if (verification) { - actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()), StandardCharsets.UTF_8); - } else { - String errorMsg = "Could not verify payload signature. The message was not signed by a valid client"; - log.error(errorMsg); - throw new AgentCoreOperationException(errorMsg); + return message; } - return actualMessage; } public static String getAuthenticationMethod() { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java index 6059483bc..deaa5ac24 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/agent/enrollment/EnrollmentManager.java @@ -111,7 +111,7 @@ public class EnrollmentManager { */ private EnrollmentManager() { this.SCEPUrl = AgentManager.getInstance().getEnrollmentEP(); - setEnrollmentStatus(); + //setEnrollmentStatus(); } /** diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/build.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/build.xml new file mode 100644 index 000000000..90687661e --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/build.xml @@ -0,0 +1,38 @@ + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml new file mode 100644 index 000000000..afcd89e0f --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/pom.xml @@ -0,0 +1,75 @@ + + + + + + virtual-fire-alarm-plugin + org.wso2.carbon.devicemgt-plugins + 3.0.5-SNAPSHOT + ../pom.xml + + + 4.0.0 + org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics + WSO2 Carbon - IoT Server Virtual Firealarm Analytics capp + pom + + + + + maven-antrun-plugin + 1.7 + + + process-resources + + + + + + + run + + + + + + maven-assembly-plugin + 2.5.5 + + ${project.artifactId}-${carbon.devicemgt.plugins.version} + false + + src/assembly/src.xml + + + + + create-archive + package + + single + + + + + + + + \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/assembly/src.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/assembly/src.xml new file mode 100644 index 000000000..a5a375010 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/assembly/src.xml @@ -0,0 +1,36 @@ + + + + src + + zip + + false + ${basedir}/src + + + ${basedir}/target/carbonapps + / + true + + + \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml new file mode 100644 index 000000000..fbd1362af --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/artifacts.xml @@ -0,0 +1,26 @@ + + + + + + + + + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/artifact.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/artifact.xml new file mode 100644 index 000000000..b23fa50d7 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/artifact.xml @@ -0,0 +1,23 @@ + + + + + virtualfirealarm_execution.siddhiql + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/virtualfirealarm_execution.siddhiql b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/virtualfirealarm_execution.siddhiql new file mode 100644 index 000000000..4346a6199 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_execution/virtualfirealarm_execution.siddhiql @@ -0,0 +1,20 @@ +/* Enter a unique ExecutionPlan */ +@Plan:name('virtualfirealarm_execution') + +/* Enter a unique description for ExecutionPlan */ +-- @Plan:description('virtualfirealarm_execution') + +/* define streams/tables and write queries here ... */ + +@Import('org.wso2.iot.virtualfirealarm:1.0.0') +define stream virtualfirealarm (meta_owner string, meta_deviceId string, meta_time long, temperature float); + +@Export('org.wso2.iot.devices.temperature:1.0.0') +define stream temperature (meta_owner string, meta_deviceType string, meta_deviceId string, meta_time long, temperature float); + +from virtualfirealarm +select meta_owner, 'virtual_firealarm' as meta_deviceType, meta_deviceId, time:timestampInMilliseconds() as meta_time, temperature +insert into temperature; + + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/artifact.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/artifact.xml new file mode 100644 index 000000000..14141e7da --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/artifact.xml @@ -0,0 +1,22 @@ + + + + + virtualfirealarm_receiver.xml + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/virtualfirealarm_receiver.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/virtualfirealarm_receiver.xml new file mode 100644 index 000000000..465f22269 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_receiver/virtualfirealarm_receiver.xml @@ -0,0 +1,31 @@ + + + + + carbon.super/virtual_firealarm/+/temperature + admin + org.wso2.carbon.device.mgt.input.adapter.mqtt.util.MQTTContentValidator + default + https://${iot.core.host}:${iot.core.https.port}/dynamic-client-web/register + tcp://${mqtt.broker.host}:${mqtt.broker.port} + true + + + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/artifact.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/artifact.xml new file mode 100644 index 000000000..d14485b3b --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/artifact.xml @@ -0,0 +1,23 @@ + + + + + org.wso2.iot.virtualfirealarm_1.0.0.json + + diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/org.wso2.iot.virtualfirealarm_1.0.0.json b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/org.wso2.iot.virtualfirealarm_1.0.0.json new file mode 100644 index 000000000..0ba70911e --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics/src/main/resources/carbonapps/virtualfirealarm/virtualfirealarm_stream/org.wso2.iot.virtualfirealarm_1.0.0.json @@ -0,0 +1,16 @@ +{ + "name": "org.wso2.iot.virtualfirealarm", + "version": "1.0.0", + "nickName": "virtual_firealarm", + "description": "Temperature data received from the virtual_firealarm", + "metaData": [ + {"name":"owner","type":"STRING"}, + {"name":"deviceId","type":"STRING"}, + {"name":"time","type":"LONG"} + ], + "payloadData": [ + { + "name": "temperature","type": "FLOAT" + } + ] +} \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml index 59ccc4a79..7d00d0033 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/pom.xml @@ -235,11 +235,6 @@ org.wso2.carbon.device.mgt.extensions provided - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin - provided - diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java index c00dd6ab7..f5bb1d84b 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/VirtualFireAlarmServiceImpl.java @@ -18,7 +18,6 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl; -import org.apache.commons.codec.binary.Base64; import org.apache.commons.io.FileUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -35,18 +34,15 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroupConstants; import org.wso2.carbon.device.mgt.common.operation.mgt.Operation; import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManagementException; import org.wso2.carbon.device.mgt.core.operation.mgt.CommandOperation; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFirealarmSecurityManager; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppAccount; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppServerClient; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.constants.VirtualFireAlarmConstants; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.dto.SensorRecord; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.APIUtil; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.VirtualFireAlarmServiceUtils; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.ZipArchive; import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util.ZipUtil; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp.VirtualFirealarmXMPPException; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp.XmppAccount; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp.XmppServerClient; import org.wso2.carbon.identity.jwt.client.extension.JWTClient; import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; @@ -76,11 +72,8 @@ import java.util.UUID; public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { - private static final String XMPP_PROTOCOL = "XMPP"; - private static final String MQTT_PROTOCOL = "MQTT"; private static final String KEY_TYPE = "PRODUCTION"; private static ApiApplicationKey apiApplicationKey; - private static final String DEVICE_MGT_SCOPE_IDENTIFIER = "device-mgt"; private static Log log = LogFactory.getLog(VirtualFireAlarmServiceImpl.class); @POST @@ -103,10 +96,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); } String resource = VirtualFireAlarmConstants.BULB_CONTEXT.replace("/", ""); - PrivateKey serverPrivateKey = VirtualFirealarmSecurityManager.getServerPrivateKey(); String actualMessage = resource + ":" + switchToState; - String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage, - serverPrivateKey); String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; @@ -114,7 +104,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { commandOp.setCode("buzz"); commandOp.setType(Operation.Type.COMMAND); commandOp.setEnabled(true); - commandOp.setPayLoad(encryptedMsg); + commandOp.setPayLoad(actualMessage); Properties props = new Properties(); props.setProperty(VirtualFireAlarmConstants.MQTT_ADAPTER_TOPIC_PROPERTY_NAME, publishTopic); @@ -137,10 +127,6 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { } catch (DeviceAccessAuthorizationException e) { log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (VirtualFireAlarmException e) { - String errorMsg = "Preparing Secure payload failed for device - [" + deviceId + "]"; - log.error(errorMsg); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } catch (OperationManagementException e) { String msg = "Error occurred while executing command operation upon ringing the buzzer"; log.error(msg, e); @@ -162,37 +148,22 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { DeviceGroupConstants.Permissions.DEFAULT_MANAGE_POLICIES_PERMISSIONS)) { return Response.status(Response.Status.UNAUTHORIZED.getStatusCode()).build(); } - PrivateKey serverPrivateKey = VirtualFirealarmSecurityManager.getServerPrivateKey(); String actualMessage = VirtualFireAlarmConstants.POLICY_CONTEXT + ":" + policy; - String encryptedMsg = VirtualFireAlarmServiceUtils.prepareSecurePayLoad(actualMessage, - serverPrivateKey); Map dynamicProperties = new HashMap<>(); - switch (protocolString) { - case XMPP_PROTOCOL: - dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, - deviceId + "@" + XmppConfig.getInstance().getServerName()); - dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST"); - dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, - VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); - APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.XMPP_ADAPTER_NAME, - dynamicProperties, encryptedMsg); - break; - default: - - String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" - + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; - dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic); - APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.MQTT_ADAPTER_NAME, - dynamicProperties, encryptedMsg); - break; - } + String publishTopic = APIUtil.getTenantDomainOftheUser() + "/" + + VirtualFireAlarmConstants.DEVICE_TYPE + "/" + deviceId; + dynamicProperties.put(VirtualFireAlarmConstants.ADAPTER_TOPIC_PROPERTY, publishTopic); + dynamicProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, + deviceId + "@" + XmppConfig.getInstance().getServerName()); + dynamicProperties.put(VirtualFireAlarmConstants.SUBJECT_PROPERTY_KEY, "POLICTY-REQUEST"); + dynamicProperties.put(VirtualFireAlarmConstants.MESSAGE_TYPE_PROPERTY_KEY, + VirtualFireAlarmConstants.CHAT_PROPERTY_KEY); + APIUtil.getOutputEventAdapterService().publish(VirtualFireAlarmConstants.XMPP_ADAPTER_NAME, + dynamicProperties, actualMessage); return Response.ok().build(); } catch (DeviceAccessAuthorizationException e) { log.error(e.getErrorMessage(), e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); - } catch (VirtualFireAlarmException e) { - log.error(e); - return Response.status(Response.Status.INTERNAL_SERVER_ERROR).build(); } } @@ -260,7 +231,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { } catch (UserStoreException ex) { log.error(ex.getMessage(), ex); return Response.status(500).entity(ex.getMessage()).build(); - } catch (VirtualFirealarmDeviceMgtPluginException ex) { + } catch (VirtualFirealarmXMPPException ex) { log.error(ex.getMessage(), ex); return Response.status(500).entity(ex.getMessage()).build(); } @@ -294,7 +265,7 @@ public class VirtualFireAlarmServiceImpl implements VirtualFireAlarmService { private ZipArchive createDownloadFile(String owner, String deviceName, String sketchType) throws DeviceManagementException, APIManagerException, JWTClientException, - UserStoreException, VirtualFirealarmDeviceMgtPluginException { + UserStoreException, VirtualFirealarmXMPPException { //create new device id String deviceId = shortUUID(); boolean status = register(deviceId, deviceName); diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/constants/VirtualFireAlarmConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/constants/VirtualFireAlarmConstants.java new file mode 100644 index 000000000..204ede004 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/constants/VirtualFireAlarmConstants.java @@ -0,0 +1,84 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.constants; + +public class VirtualFireAlarmConstants { + public final static String DEVICE_TYPE = "virtual_firealarm"; + public final static String DEVICE_PLUGIN_DEVICE_NAME = "DEVICE_NAME"; + public final static String DEVICE_PLUGIN_DEVICE_ID = "VIRTUAL_FIREALARM_DEVICE_ID"; + public final static String STATE_ON = "ON"; + public final static String STATE_OFF = "OFF"; + + public static final String URL_PREFIX = "http://"; + public static final String BULB_CONTEXT = "BULB"; + public static final String POLICY_CONTEXT = "POLICY"; + + //sensor events sumerized table name for temperature + public static final String TEMPERATURE_EVENT_TABLE = "DEVICE_TEMPERATURE_SUMMARY"; + public final static String DEVICE_TYPE_PROVIDER_DOMAIN = "carbon.super"; + + //mqtt tranport related constants + public static final String MQTT_ADAPTER_NAME = "virtual_firealarm_mqtt"; + public static final String MQTT_ADAPTER_TYPE = "oauth-mqtt"; + public static final String ADAPTER_TOPIC_PROPERTY = "topic"; + public static final String MQTT_PORT = "\\$\\{mqtt.broker.port\\}"; + public static final String MQTT_BROKER_HOST = "\\$\\{mqtt.broker.host\\}"; + public static final String CARBON_CONFIG_PORT_OFFSET = "Ports.Offset"; + public static final String DEFAULT_CARBON_LOCAL_IP_PROPERTY = "carbon.local.ip"; + public static final int CARBON_DEFAULT_PORT_OFFSET = 0; + public static final int DEFAULT_MQTT_PORT = 1886; + + //xmpp transport related constants + public static final String XMPP_ADAPTER_NAME = "virtual_firealarm_xmpp"; + public static final String XMPP_ADAPTER_TYPE = "xmpp"; + public static final String PASSWORD_PROPERTY_KEY = "password"; + public static final String JID_PROPERTY_KEY = "jid"; + public static final String CLIENT_JID_PROPERTY_KEY = "xmpp.client.jid"; + public static final String SUBJECT_PROPERTY_KEY = "xmpp.client.subject"; + public static final String MESSAGE_TYPE_PROPERTY_KEY = "xmpp.client.messageType"; + public static final String CHAT_PROPERTY_KEY = "chat"; + + public static final String USERNAME_PROPERTY_KEY = "username"; + public static final String DCR_PROPERTY_KEY = "dcrUrl"; + public static final String BROKER_URL_PROPERTY_KEY = "url"; + public static final String SCOPES_PROPERTY_KEY = "scopes"; + public static final String QOS_PROPERTY_KEY = "qos"; + public static final String CLIENT_ID_PROPERTY_KEY = "qos"; + public static final String CLEAR_SESSION_PROPERTY_KEY = "clearSession"; + public static final String TOPIC = "topic"; + public static final String SUBSCRIBED_TOPIC = "carbon.super/virtual_firealarm/+/publisher"; + + public static final String CONTENT_VALIDATION = "contentValidator"; + public static final String CONTENT_TRANSFORMATION = "contentTransformer"; + public static final String RESOURCE = "resource"; + + public static final String JSON_SERIAL_KEY = "SerialNumber"; + public static final String TEMPERATURE_STREAM_DEFINITION = "org.wso2.iot.devices.temperature"; + public static final String JSON_MESSAGE_KEY = "Msg"; + public static final String JSON_SIGNATURE_KEY = "Sig"; + + public static final String HOST_KEY = "host"; + public static final String PORT_KEY = "port"; + + public static final String SERVER_NAME = "serverName"; + + public static final String MQTT_ADAPTER_TOPIC_PROPERTY_NAME = "mqtt.adapter.topic"; + + public static final String APIM_APPLICATION_TOKEN_VALIDITY_PERIOD = "3600"; +} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java deleted file mode 100644 index 277000e0f..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmServiceUtils.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util; - -import org.apache.commons.codec.binary.Base64; -import org.json.JSONObject; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFirealarmSecurityManager; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.exception.VirtualFireAlarmException; - -import java.lang.*; -import java.security.PrivateKey; - -/** - * - */ -public class VirtualFireAlarmServiceUtils { - - private static final String JSON_MESSAGE_KEY = "Msg"; - private static final String JSON_SIGNATURE_KEY = "Sig"; - - public static String prepareSecurePayLoad(String message, PrivateKey signatureKey) throws VirtualFireAlarmException { - try { - message = Base64.encodeBase64String(message.getBytes()); - String signedPayload = VirtualFirealarmSecurityManager.signMessage(message, signatureKey); - JSONObject jsonPayload = new JSONObject(); - jsonPayload.put(JSON_MESSAGE_KEY, message); - jsonPayload.put(JSON_SIGNATURE_KEY, signedPayload); - return jsonPayload.toString(); - } catch (VirtualFirealarmDeviceMgtPluginException e) { - throw new VirtualFireAlarmException(e); - } - - } -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmUtilConstants.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmUtilConstants.java index fae96848d..a255b9537 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmUtilConstants.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/VirtualFireAlarmUtilConstants.java @@ -1,6 +1,5 @@ package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.util; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig; public class VirtualFireAlarmUtilConstants { diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java index 2c6cd2840..39e938f2b 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/util/ZipUtil.java @@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.DeviceManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationEntry; import org.wso2.carbon.device.mgt.common.configuration.mgt.ConfigurationManagementException; import org.wso2.carbon.device.mgt.common.configuration.mgt.PlatformConfiguration; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig; +import org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp.XmppConfig; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.NetworkUtils; diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/VirtualFirealarmXMPPException.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/VirtualFirealarmXMPPException.java new file mode 100644 index 000000000..57d0b8a0b --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/VirtualFirealarmXMPPException.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp; + + +public class VirtualFirealarmXMPPException extends Exception{ + + private String errorMessage; + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + + public VirtualFirealarmXMPPException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public VirtualFirealarmXMPPException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public VirtualFirealarmXMPPException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public VirtualFirealarmXMPPException() { + super(); + } + + public VirtualFirealarmXMPPException(Throwable cause) { + super(cause); + } + +} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppAccount.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppAccount.java new file mode 100644 index 000000000..162ea957f --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppAccount.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp; + +/** + * holds the information related to account that needs to be created on xmpp server. + */ +public class XmppAccount { + + private String username; + private String password; + private String accountName; + private String email; + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getAccountName() { + return accountName; + } + + public void setAccountName(String accountName) { + this.accountName = accountName; + } + + public String getEmail() { + return email; + } + + public void setEmail(String email) { + this.email = email; + } + +} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppConfig.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppConfig.java new file mode 100644 index 000000000..d96f14c6e --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppConfig.java @@ -0,0 +1,124 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; + +public class XmppConfig { + + private String host; + private int port; + private String username; + private String password; + private String serverName; + private boolean enabled; + private String jid; + private static XmppConfig xmppConfig = new XmppConfig(); + private static final Log log = LogFactory.getLog(XmppConfig.class); + private static final String ENABLED = "enabled"; + private static final String USERNAME = "username"; + private static final String PASSWORD = "password"; + private static final String HOST = "host"; + private static final String PORT = "port"; + private static final String SERVERNAME = "serverName"; + private static final String JID = "jid"; + + private XmppConfig() { + ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); + InputStream input = classLoader.getResourceAsStream("../xmpp.properties"); + Properties properties = new Properties(); + try { + properties.load(input); + enabled = Boolean.parseBoolean(properties.getProperty(ENABLED, "false")); + host = properties.getProperty(HOST); + port = Integer.parseInt(properties.getProperty(PORT)); + username = properties.getProperty(USERNAME); + password = properties.getProperty(PASSWORD); + serverName = properties.getProperty(SERVERNAME); + jid = properties.getProperty(JID); + } catch (IOException e) { + log.error("Failed to load xmpp config properties."); + } + } + + public static XmppConfig getInstance() { + return xmppConfig; + } + + public String getHost() { + return host; + } + + public void setHost(String host) { + this.host = host; + } + + public int getPort() { + return port; + } + + public void setPort(int port) { + this.port = port; + } + + public String getUsername() { + return username; + } + + public void setUsername(String username) { + this.username = username; + } + + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getServerName() { + return serverName; + } + + public void setServerName(String serverName) { + this.serverName = serverName; + } + + public boolean isEnabled() { + return enabled; + } + + public void setEnabled(boolean enabled) { + this.enabled = enabled; + } + + public String getJid() { + return jid; + } + + public void setJid(String jid) { + this.jid = jid; + } +} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppServerClient.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppServerClient.java new file mode 100644 index 000000000..7369f90a4 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/service/impl/xmpp/XmppServerClient.java @@ -0,0 +1,66 @@ +/* + * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. + * + * WSO2 Inc. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.wso2.carbon.device.mgt.iot.virtualfirealarm.service.impl.xmpp; + +import org.jivesoftware.smack.AccountManager; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; + +import java.util.HashMap; +import java.util.Map; + +public class XmppServerClient { + + public static boolean createAccount(XmppAccount xmppAccount) throws VirtualFirealarmXMPPException { + if (XmppConfig.getInstance().isEnabled()) { + if (xmppAccount != null) { + try { + ConnectionConfiguration config = new ConnectionConfiguration(XmppConfig.getInstance().getHost(), + XmppConfig.getInstance().getPort(), + "Accounts"); + XMPPConnection xmppConnection = new XMPPConnection(config); + xmppConnection.connect(); + xmppConnection.login(XmppConfig.getInstance().getUsername(), XmppConfig.getInstance().getPassword()); + AccountManager accountManager = xmppConnection.getAccountManager(); + Map attributes = new HashMap<>(); + attributes.put("username", xmppAccount.getUsername()); + attributes.put("password", xmppAccount.getPassword()); + attributes.put("email", xmppAccount.getEmail()); + attributes.put("name", xmppAccount.getAccountName()); + accountManager.createAccount(xmppAccount.getUsername(), xmppAccount.getPassword(), attributes); + xmppConnection.disconnect(); + return true; + } catch (XMPPException e) { + if (e.getXMPPError().getCode() == 409) { + //AccountAlreadyExist + return true; + } else { + throw new VirtualFirealarmXMPPException( + "XMPP account creation failed. Error: " + e.getLocalizedMessage(), e); + } + } + } else { + throw new VirtualFirealarmXMPPException("Invalid XMPP attributes"); + } + } else { + return true; + } + } +} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml index d250c67de..eb4a397bf 100644 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/web.xml @@ -35,4 +35,6 @@ true + + \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/xmpp.properties b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/xmpp.properties new file mode 100644 index 000000000..3a173cb92 --- /dev/null +++ b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.api/src/main/webapp/WEB-INF/xmpp.properties @@ -0,0 +1,25 @@ +# +# Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. +# +# + +#[XMPP-Configurations] +enabled=false +username=admin +password=admin +host=localhost +port=5222 +serverName=localhost +jid=admin@localhost \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml deleted file mode 100644 index 3c71c1b28..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/pom.xml +++ /dev/null @@ -1,199 +0,0 @@ - - - - - - virtual-fire-alarm-plugin - org.wso2.carbon.devicemgt-plugins - 3.0.5-SNAPSHOT - ../pom.xml - - - 4.0.0 - org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api - war - WSO2 Carbon - IoT Server SCEP Server API - WSO2 Carbon - Virtual FireAlarm SCEP Server API Implementation - http://wso2.org - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.common - provided - - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.core - provided - - - org.apache.axis2.wso2 - axis2-client - - - - - - org.wso2.carbon.devicemgt - org.wso2.carbon.certificate.mgt.core - provided - - - commons-codec - commons-codec - - - - - - - - org.apache.cxf - cxf-rt-frontend-jaxws - provided - - - org.apache.cxf - cxf-rt-frontend-jaxrs - provided - - - org.apache.cxf - cxf-rt-transports-http - provided - - - - - org.codehaus.jackson - jackson-core-asl - - - org.codehaus.jackson - jackson-jaxrs - - - javax - javaee-web-api - provided - - - javax.ws.rs - jsr311-api - provided - - - commons-httpclient.wso2 - commons-httpclient - provided - - - - org.wso2.carbon - org.wso2.carbon.utils - provided - - - org.bouncycastle.wso2 - bcprov-jdk15on - - - org.wso2.carbon - org.wso2.carbon.user.api - - - org.wso2.carbon - org.wso2.carbon.queuing - - - org.wso2.carbon - org.wso2.carbon.base - - - org.apache.axis2.wso2 - axis2 - - - org.igniterealtime.smack.wso2 - smack - - - org.igniterealtime.smack.wso2 - smackx - - - jaxen - jaxen - - - commons-fileupload.wso2 - commons-fileupload - - - org.apache.ant.wso2 - ant - - - org.apache.ant.wso2 - ant - - - commons-httpclient.wso2 - commons-httpclient - - - org.eclipse.equinox - javax.servlet - - - org.wso2.carbon - org.wso2.carbon.registry.api - - - - - - commons-codec - commons-codec - - - - - - - - maven-compiler-plugin - - UTF-8 - ${wso2.maven.compiler.source} - ${wso2.maven.compiler.target} - - - - maven-war-plugin - - virtual_firealarm_scep - - - - - - diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServer.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServer.java deleted file mode 100644 index c5b4676bc..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServer.java +++ /dev/null @@ -1,65 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.Response; -import java.io.InputStream; - - -public interface VirtualFireAlarmScepServer { - - /** - * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. - * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two - * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client - * of the enrolling device. The API supports 2 SCEP Operations [GetCACert] and [GetCACaps]. - *

- * Operation [GetCACert] returns the CA cert of the SCEP-Server for the device to verify its authenticity. - * Operation [GetCACaps] returns the CA Capabilities of the SCEP-Server. - * - * @param operation the SCEP operation requested by the client. [GetCACert] or [GetCACaps] - * @param message any messages pertaining to the requested SCEP Operation. - * @return an HTTP Response object with either the CA-Cert or the CA-Capabilities according to the operation. - */ - @GET - @Path("scep") - Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message); - - - /** - * This is an API called/used by the SCEP Client of the VirtualFirealarm device in its SCEP enrollment process. - * This acts as the endpoint exposed as part of the SCEP-Server for use by a SCEP Client. This is one of the two - * method-signatures that takes different parameters according to the SCEP-Operation executed by the SCEP-Client - * of the enrolling device. This API supports the SCEP Operation [PKIOperation]. - *

- * Operation [PKIOperation] returns a certificate generated by the SCEP-Server for the enrolling device. - * - * @param operation the final SCEP operation executed in the enrollment process - which is [PKIOperation] - * @param inputStream an input stream consisting of the Certificate-Signing-Request (CSR) from the device. - * @return an HTTP Response object with the signed certificate for the device by the CA of the SCEP Server. - */ - @POST - @Path("scep") - Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream); - -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServerImpl.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServerImpl.java deleted file mode 100644 index c2f7a17e6..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/VirtualFireAlarmScepServerImpl.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -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; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.exception.VirtualFireAlarmException; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util.scep.ContentType; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util.scep.SCEPOperation; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util.VirtualFireAlarmServiceUtils; - -import javax.ws.rs.GET; -import javax.ws.rs.POST; -import javax.ws.rs.Path; -import javax.ws.rs.QueryParam; -import javax.ws.rs.core.MediaType; -import javax.ws.rs.core.Response; -import java.io.InputStream; - -@SuppressWarnings("Non-Annoted WebService") -public class VirtualFireAlarmScepServerImpl implements VirtualFireAlarmScepServer { - - private static Log log = LogFactory.getLog(VirtualFireAlarmScepServerImpl.class); - - @GET - @Path("scep") - public Response scepRequest(@QueryParam("operation") String operation, @QueryParam("message") String message) { - if (log.isDebugEnabled()) { - log.debug("Invoking SCEP operation " + operation); - } - if (SCEPOperation.GET_CA_CERT.getValue().equals(operation)) { - if (log.isDebugEnabled()) { - log.debug("Invoking GetCACert"); - } - try { - CertificateManagementService certificateManagementService = - VirtualFireAlarmServiceUtils.getCertificateManagementService(); - SCEPResponse scepResponse = certificateManagementService.getCACertSCEP(); - Response.ResponseBuilder responseBuilder; - switch (scepResponse.getResultCriteria()) { - case CA_CERT_FAILED: - log.error("CA cert failed"); - responseBuilder = Response.serverError(); - break; - case CA_CERT_RECEIVED: - if (log.isDebugEnabled()) { - log.debug("CA certificate received in GetCACert"); - } - responseBuilder = Response.ok(scepResponse.getEncodedResponse(), - ContentType.X_X509_CA_CERT); - break; - case CA_RA_CERT_RECEIVED: - if (log.isDebugEnabled()) { - log.debug("CA and RA certificates received in GetCACert"); - } - responseBuilder = Response.ok(scepResponse.getEncodedResponse(), - ContentType.X_X509_CA_RA_CERT); - break; - default: - log.error("Invalid SCEP request"); - responseBuilder = Response.serverError(); - break; - } - - return responseBuilder.build(); - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the VirtualFireAlarm device", e); - } catch (KeystoreException e) { - log.error("Keystore error occurred while enrolling the VirtualFireAlarm device", e); - } - - } else if (SCEPOperation.GET_CA_CAPS.getValue().equals(operation)) { - - if (log.isDebugEnabled()) { - log.debug("Invoking GetCACaps"); - } - try { - CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. - getCertificateManagementService(); - byte caCaps[] = certificateManagementService.getCACapsSCEP(); - - return Response.ok(caCaps, MediaType.TEXT_PLAIN).build(); - - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the device", e); - } - } else { - log.error("Invalid SCEP operation " + operation); - } - return Response.serverError().build(); - } - - @POST - @Path("scep") - public Response scepRequestPost(@QueryParam("operation") String operation, InputStream inputStream) { - if (log.isDebugEnabled()) { - log.debug("Invoking SCEP operation " + operation); - } - if (SCEPOperation.PKI_OPERATION.getValue().equals(operation)) { - if (log.isDebugEnabled()) { - log.debug("Invoking PKIOperation"); - } - try { - CertificateManagementService certificateManagementService = VirtualFireAlarmServiceUtils. - getCertificateManagementService(); - byte pkiMessage[] = certificateManagementService.getPKIMessageSCEP(inputStream); - return Response.ok(pkiMessage, ContentType.X_PKI_MESSAGE).build(); - } catch (VirtualFireAlarmException e) { - log.error("Error occurred while enrolling the device", e); - } catch (KeystoreException e) { - log.error("Keystore error occurred while enrolling the device", e); - } - } - return Response.serverError().build(); - } - -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/exception/VirtualFireAlarmException.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/exception/VirtualFireAlarmException.java deleted file mode 100644 index 4a81ec6d5..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/exception/VirtualFireAlarmException.java +++ /dev/null @@ -1,31 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.exception; - -public class VirtualFireAlarmException extends Exception { - private static final long serialVersionUID = 118512086957330189L; - - public VirtualFireAlarmException(String errorMessage) { - super(errorMessage); - } - - public VirtualFireAlarmException(String errorMessage, Throwable throwable) { - super(errorMessage, throwable); - } -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/VirtualFireAlarmServiceUtils.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/VirtualFireAlarmServiceUtils.java deleted file mode 100644 index de3d1e6a2..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/VirtualFireAlarmServiceUtils.java +++ /dev/null @@ -1,103 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; -import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService; -import org.wso2.carbon.context.PrivilegedCarbonContext; -import org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.exception.VirtualFireAlarmException; - -import java.lang.*; -import java.security.PublicKey; -import java.security.cert.X509Certificate; - -/** - * - */ -public class VirtualFireAlarmServiceUtils { - private static final Log log = LogFactory.getLog(VirtualFireAlarmServiceUtils.class); - - /** - * - * @return - * @throws VirtualFireAlarmException - */ - public static CertificateManagementService getCertificateManagementService() throws VirtualFireAlarmException { - - PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); - CertificateManagementService certificateManagementService = (CertificateManagementService) - ctx.getOSGiService(CertificateManagementService.class, null); - - if (certificateManagementService == null) { - String msg = "EnrollmentService is not initialized"; - log.error(msg); - throw new VirtualFireAlarmException(msg); - } - - return certificateManagementService; - } - - /** - * - * @param deviceId - * @return - * @throws VirtualFireAlarmException - */ - public static PublicKey getDevicePublicKey(String deviceId) throws VirtualFireAlarmException { - PublicKey clientPublicKey; - String alias = ""; - - try { - alias += deviceId.hashCode(); - - CertificateManagementService certificateManagementService = - VirtualFireAlarmServiceUtils.getCertificateManagementService(); - X509Certificate clientCertificate = (X509Certificate) certificateManagementService.getCertificateByAlias( - alias); - clientPublicKey = clientCertificate.getPublicKey(); - - } catch (VirtualFireAlarmException e) { - String errorMsg = "Could not retrieve CertificateManagementService from the runtime."; - if(log.isDebugEnabled()){ - log.debug(errorMsg); - } - throw new VirtualFireAlarmException(errorMsg, e); - } catch (KeystoreException e) { - String errorMsg; - if (e.getMessage().contains("NULL_CERT")) { - errorMsg = "The Device-View page might have been accessed prior to the device being started."; - if(log.isDebugEnabled()){ - log.debug(errorMsg); - } - throw new VirtualFireAlarmException(errorMsg, e); - } else { - errorMsg = "An error occurred whilst trying to retrieve certificate for deviceId [" + deviceId + - "] with alias: [" + alias + "]"; - if(log.isDebugEnabled()){ - log.debug(errorMsg); - } - throw new VirtualFireAlarmException(errorMsg, e); - } - } - return clientPublicKey; - } - -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/ContentType.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/ContentType.java deleted file mode 100644 index 707ca75fd..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/ContentType.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util.scep; - -public class ContentType { - public static final String X_PKI_MESSAGE = "application/x-pki-message"; - public static final String X_X509_CA_CERT = "application/x-x509-ca-cert"; - public static final String X_X509_CA_RA_CERT = "application/x-x509-ca-ra-cert"; -} - diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/SCEPOperation.java b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/SCEPOperation.java deleted file mode 100644 index b93a99016..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/java/org/wso2/carbon/device/mgt/iot/virtualfirealarm/scep/service/impl/util/scep/SCEPOperation.java +++ /dev/null @@ -1,39 +0,0 @@ -/* - * Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved. - * - * WSO2 Inc. licenses this file to you under the Apache License, - * Version 2.0 (the "License"); you may not use this file except - * in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -package org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.service.impl.util.scep; - -public enum SCEPOperation { - GET_CA_CERT("GetCACert"), - GET_CA_CAPS("GetCACaps"), - PKI_OPERATION("PKIOperation"); - - private String value; - - private SCEPOperation(String value) { - this.setValue(value); - } - - public String getValue() { - return value; - } - - public void setValue(String value) { - this.value = value; - } -} diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/META-INF/webapp-classloading.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/META-INF/webapp-classloading.xml deleted file mode 100644 index fa4461919..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/META-INF/webapp-classloading.xml +++ /dev/null @@ -1,33 +0,0 @@ - - - - - - - - - false - - - CXF,Carbon - diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/cxf-servlet.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/cxf-servlet.xml deleted file mode 100644 index 23280d436..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/cxf-servlet.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/web.xml b/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 2d8392be4..000000000 --- a/components/device-types/virtual-fire-alarm-plugin/org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,38 +0,0 @@ - - - WSO2 IoT Server - WSO2 IoT Server - - - CXFServlet - org.apache.cxf.transport.servlet.CXFServlet - 1 - - - CXFServlet - /* - - - isAdminService - false - - - doAuthentication - false - - - isSharedWithAllTenants - true - - - - - managed-api-enabled - false - - - \ No newline at end of file diff --git a/components/device-types/virtual-fire-alarm-plugin/pom.xml b/components/device-types/virtual-fire-alarm-plugin/pom.xml index 17832867a..afcde9a9b 100644 --- a/components/device-types/virtual-fire-alarm-plugin/pom.xml +++ b/components/device-types/virtual-fire-alarm-plugin/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.advanced.impl org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl org.wso2.carbon.device.mgt.iot.virtualfirealarm.api - org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api + org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/pom.xml b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/pom.xml index d6b111f6f..dd6ffe790 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/pom.xml +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/pom.xml @@ -45,11 +45,6 @@ org.wso2.carbon.device.mgt.iot.virtualfirealarm.api war - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api - war - com.h2database.wso2 h2-database-engine @@ -96,6 +91,18 @@ + + org.wso2.carbon.devicemgt-plugins + org.wso2.carbon.device.mgt.iot.virtualfirealarm.analytics + + ${project.version} + zip + true + + ${project.build.directory}/maven-shared-archive-resources/carbonapps + + **/* + org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.iot.virtualfirealarm.ui @@ -128,15 +135,6 @@ ${project.build.directory}/maven-shared-archive-resources/webapps/ virtual_firealarm.war - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api - - war - true - ${project.build.directory}/maven-shared-archive-resources/webapps/ - virtual_firealarm_scep.war - @@ -227,11 +225,6 @@ org.eclipse.equinox.p2.type.group:true - - - org.wso2.carbon.devicemgt-plugins:org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin:${carbon.devicemgt.plugins.version} - - org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf index 7a18d54a3..f88a8eb2d 100644 --- a/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf +++ b/features/device-types-feature/virtual-fire-alarm-plugin-feature/org.wso2.carbon.device.mgt.iot.virtualfirealarm.feature/src/main/resources/p2.inf @@ -18,7 +18,9 @@ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../reso org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/devicetypes/);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/devicetypes/,target:${installFolder}/../../deployment/server/devicetypes/,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../conf/etc/device-mgt-plugins/);\ -org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/conf/virtual_firealarm.xml,target:${installFolder}/../../conf/etc/device-mgt-plugins/virtual_firealarm.xml,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/carbonapps/);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.iot.virtualfirealarm_${feature.version}/carbonapps/,target:${installFolder}/../../deployment/server/carbonapps/,overwrite:true);\ + instructions.unconfigure = \ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/webapps/virtual_firealarm.war);\ @@ -40,4 +42,4 @@ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../dep org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/jaggeryapps/devicemgt/app/units/cdmf.unit.device.type.virtual_firealarm.policy-wizard);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../resources/security/wso2certs.jks);\ org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/devicetypes/virtual_firealarm.xml);\ -org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../conf/etc/device-mgt-plugins/virtual_firealarm.xml);\ +org.eclipse.equinox.p2.touchpoint.natives.remove(path:${installFolder}/../../deployment/server/carbonapps/virtualfirealarm.car);\ \ No newline at end of file diff --git a/pom.xml b/pom.xml index 096152ebf..172469dd2 100644 --- a/pom.xml +++ b/pom.xml @@ -471,12 +471,6 @@ ${carbon.devicemgt.plugins.version} war - - org.wso2.carbon.devicemgt-plugins - org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api - ${carbon.devicemgt.plugins.version} - war - org.wso2.carbon.devicemgt-plugins org.wso2.carbon.device.mgt.iot.virtualfirealarm.agent.impl