forked from community/device-mgt-plugins
parent
4f1f1a3e7e
commit
8b5dd4d811
@ -1,167 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
|
|
||||||
<parent>
|
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<version>3.0.9-SNAPSHOT</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin</artifactId>
|
|
||||||
<packaging>bundle</packaging>
|
|
||||||
<name>WSO2 Carbon - IoT Server VirtualFireAlarm Management Plugin</name>
|
|
||||||
<description>WSO2 Carbon - Virtual FireAlarm Management/Control Plugin Implementation</description>
|
|
||||||
<url>http://wso2.org</url>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.felix</groupId>
|
|
||||||
<artifactId>maven-scr-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<source>1.7</source>
|
|
||||||
<target>1.7</target>
|
|
||||||
</configuration>
|
|
||||||
<version>2.3.2</version>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.felix</groupId>
|
|
||||||
<artifactId>maven-bundle-plugin</artifactId>
|
|
||||||
<version>1.4.0</version>
|
|
||||||
<extensions>true</extensions>
|
|
||||||
<configuration>
|
|
||||||
<instructions>
|
|
||||||
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
|
||||||
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
|
||||||
<Bundle-Version>${carbon.devicemgt.plugins.version}</Bundle-Version>
|
|
||||||
<Bundle-Description>IoT Server Virtual Firealarm Impl Bundle</Bundle-Description>
|
|
||||||
<Private-Package>org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal</Private-Package>
|
|
||||||
<Import-Package>
|
|
||||||
org.osgi.framework,
|
|
||||||
org.osgi.service.component,
|
|
||||||
org.apache.commons.logging,
|
|
||||||
javax.naming;resolution:=optional,
|
|
||||||
javax.sql;resolution:=optional,
|
|
||||||
org.wso2.carbon.device.mgt.common.*,
|
|
||||||
org.wso2.carbon.device.mgt.common,
|
|
||||||
org.wso2.carbon.device.mgt.input.adapter.extension.*,
|
|
||||||
org.wso2.carbon.device.mgt.extensions.feature.mgt.*,
|
|
||||||
org.wso2.carbon.utils.*,
|
|
||||||
org.wso2.carbon.context,
|
|
||||||
org.wso2.carbon.core,
|
|
||||||
javax.crypto,
|
|
||||||
org.apache.commons.codec.binary,
|
|
||||||
org.json.*;version="${commons-json.version.range}",
|
|
||||||
org.wso2.carbon.certificate.mgt.core.*,
|
|
||||||
org.wso2.carbon.device.mgt.analytics.data.publisher.exception,
|
|
||||||
org.wso2.carbon.device.mgt.analytics.data.publisher.service,
|
|
||||||
org.wso2.carbon.event.input.adapter.core,
|
|
||||||
org.wso2.carbon.event.input.adapter.core.exception,
|
|
||||||
org.jivesoftware.smack.*,
|
|
||||||
javax.xml,
|
|
||||||
javax.xml.bind,
|
|
||||||
javax.xml.bind.annotation,
|
|
||||||
javax.xml.parsers; version="${javax.xml.parsers.import.pkg.version}",
|
|
||||||
org.w3c.dom
|
|
||||||
</Import-Package>
|
|
||||||
<Export-Package>
|
|
||||||
!org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal,
|
|
||||||
org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.*,
|
|
||||||
</Export-Package>
|
|
||||||
</instructions>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.osgi</groupId>
|
|
||||||
<artifactId>org.eclipse.osgi</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.eclipse.osgi</groupId>
|
|
||||||
<artifactId>org.eclipse.osgi.services</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.logging</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.ndatasource.core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.extensions</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.analytics-common</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.event.input.adapter.core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.input.adapter.extension</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.json.wso2</groupId>
|
|
||||||
<artifactId>json</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.analytics.data.publisher</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
|
||||||
<artifactId>smack</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
|
||||||
<artifactId>smackx</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
</project>
|
|
@ -1,45 +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.plugin.config;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
|
|
||||||
@XmlRootElement(name = "DeviceManagementConfiguration")
|
|
||||||
public class DeviceManagementConfiguration {
|
|
||||||
|
|
||||||
private EventListenerConfiguration eventListenerConfiguration;
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(DeviceManagementConfiguration.class);
|
|
||||||
|
|
||||||
private DeviceManagementConfiguration() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement(name = "EventListenerConfiguration", required = false)
|
|
||||||
public EventListenerConfiguration getEventListenerConfiguration() {
|
|
||||||
return eventListenerConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEventListenerConfiguration(EventListenerConfiguration eventListenerConfiguration) {
|
|
||||||
this.eventListenerConfiguration = eventListenerConfiguration;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,79 +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.plugin.config;
|
|
||||||
|
|
||||||
import javax.xml.bind.annotation.XmlAttribute;
|
|
||||||
import javax.xml.bind.annotation.XmlElement;
|
|
||||||
import javax.xml.bind.annotation.XmlElementWrapper;
|
|
||||||
import javax.xml.bind.annotation.XmlRootElement;
|
|
||||||
import javax.xml.bind.annotation.XmlValue;
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
@XmlRootElement(name = "EventListenerConfiguration")
|
|
||||||
public class EventListenerConfiguration {
|
|
||||||
|
|
||||||
private String eventListenerProvider;
|
|
||||||
private List<Property> properties;
|
|
||||||
|
|
||||||
@XmlElementWrapper(name = "Properties", required = true)
|
|
||||||
@XmlElement(name = "Property", required = true)
|
|
||||||
public List<Property> getProperties() {
|
|
||||||
return properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProperties(List<Property> properties) {
|
|
||||||
this.properties = properties;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlElement(name = "EventListenerProvider", required = true)
|
|
||||||
public String getEventListenerProvider() {
|
|
||||||
return eventListenerProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEventListenerProvider(String eventListenerProvider) {
|
|
||||||
this.eventListenerProvider = eventListenerProvider;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlRootElement(name = "Property")
|
|
||||||
public static class Property {
|
|
||||||
|
|
||||||
private String name;
|
|
||||||
private String value;
|
|
||||||
|
|
||||||
@XmlAttribute(name = "Name", required = true)
|
|
||||||
public String getName() {
|
|
||||||
return name;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setName(String name) {
|
|
||||||
this.name = name;
|
|
||||||
}
|
|
||||||
|
|
||||||
@XmlValue
|
|
||||||
public String getValue() {
|
|
||||||
return value;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setValue(String value) {
|
|
||||||
this.value = value;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,62 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.w3c.dom.Document;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.exception.VirtualFirealarmConfigurationException;
|
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
|
||||||
|
|
||||||
import javax.xml.XMLConstants;
|
|
||||||
import javax.xml.bind.JAXBContext;
|
|
||||||
import javax.xml.bind.JAXBException;
|
|
||||||
import javax.xml.bind.Unmarshaller;
|
|
||||||
import javax.xml.parsers.DocumentBuilder;
|
|
||||||
import javax.xml.parsers.DocumentBuilderFactory;
|
|
||||||
import java.io.File;
|
|
||||||
public class VirtualFirealarmConfig {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(VirtualFirealarmConfig.class);
|
|
||||||
private static final String DEVICE_TYPE_CONFIG_PATH =
|
|
||||||
CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + "device-mgt-plugins" + File.separator
|
|
||||||
+ "virtual_firealarm.xml";
|
|
||||||
private static VirtualFirealarmConfig virtualFirealarmConfig = new VirtualFirealarmConfig();
|
|
||||||
private static DeviceManagementConfiguration deviceManagementConfiguration;
|
|
||||||
|
|
||||||
public static VirtualFirealarmConfig getInstance() {
|
|
||||||
return virtualFirealarmConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initialize() throws VirtualFirealarmConfigurationException {
|
|
||||||
File configFile = new File(DEVICE_TYPE_CONFIG_PATH);
|
|
||||||
try {
|
|
||||||
Document doc = convertToDocument(configFile);
|
|
||||||
|
|
||||||
/* Un-marshaling Webapp Authenticator configuration */
|
|
||||||
JAXBContext ctx = JAXBContext.newInstance(DeviceManagementConfiguration.class);
|
|
||||||
Unmarshaller unmarshaller = ctx.createUnmarshaller();
|
|
||||||
//unmarshaller.setSchema(getSchema());
|
|
||||||
deviceManagementConfiguration = (DeviceManagementConfiguration) unmarshaller.unmarshal(doc);
|
|
||||||
} catch (JAXBException e) {
|
|
||||||
throw new VirtualFirealarmConfigurationException("Error occurred while un-marshalling the file " +
|
|
||||||
DEVICE_TYPE_CONFIG_PATH, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
public DeviceManagementConfiguration getDeviceTypeConfiguration() {
|
|
||||||
return deviceManagementConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static Document convertToDocument(File file) throws VirtualFirealarmConfigurationException {
|
|
||||||
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
|
|
||||||
factory.setNamespaceAware(true);
|
|
||||||
try {
|
|
||||||
factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
|
|
||||||
DocumentBuilder docBuilder = factory.newDocumentBuilder();
|
|
||||||
return docBuilder.parse(file);
|
|
||||||
} catch (Exception e) {
|
|
||||||
throw new VirtualFirealarmConfigurationException("Error occurred while parsing file, while converting " +
|
|
||||||
"to a org.w3c.dom.Document", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,53 +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.plugin.config.exception;
|
|
||||||
|
|
||||||
public class VirtualFirealarmConfigurationException extends Exception {
|
|
||||||
|
|
||||||
private static final long serialVersionUID = -3151279431229070297L;
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(int errorCode, String message) {
|
|
||||||
super(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(int errorCode, String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(String msg, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmConfigurationException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,88 +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.plugin.constants;
|
|
||||||
|
|
||||||
import org.wso2.carbon.utils.CarbonUtils;
|
|
||||||
|
|
||||||
import java.io.File;
|
|
||||||
|
|
||||||
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";
|
|
||||||
}
|
|
@ -1,56 +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.plugin.exception;
|
|
||||||
|
|
||||||
|
|
||||||
public class VirtualFirealarmDeviceMgtPluginException extends Exception{
|
|
||||||
|
|
||||||
private String errorMessage;
|
|
||||||
|
|
||||||
public String getErrorMessage() {
|
|
||||||
return errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setErrorMessage(String errorMessage) {
|
|
||||||
this.errorMessage = errorMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmDeviceMgtPluginException(String msg, Exception nestedEx) {
|
|
||||||
super(msg, nestedEx);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmDeviceMgtPluginException(String message, Throwable cause) {
|
|
||||||
super(message, cause);
|
|
||||||
setErrorMessage(message);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmDeviceMgtPluginException(String msg) {
|
|
||||||
super(msg);
|
|
||||||
setErrorMessage(msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmDeviceMgtPluginException() {
|
|
||||||
super();
|
|
||||||
}
|
|
||||||
|
|
||||||
public VirtualFirealarmDeviceMgtPluginException(Throwable cause) {
|
|
||||||
super(cause);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,223 +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.plugin.impl;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
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.analytics.data.publisher.exception.DataPublisherConfigurationException;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
|
||||||
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.internal.VirtualFirealarmManagementDataHolder;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.mqtt.MqttConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.xmpp.XmppConfig;
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterConfiguration;
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.MessageType;
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.cert.X509Certificate;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Contains utility methods used by FireAlarm plugin.
|
|
||||||
*/
|
|
||||||
public class VirtualFireAlarmUtils {
|
|
||||||
|
|
||||||
private static Log log = LogFactory.getLog(VirtualFireAlarmUtils.class);
|
|
||||||
|
|
||||||
public static void setupMqttInputAdapter() throws IOException {
|
|
||||||
if (!MqttConfig.getInstance().isEnabled()) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
InputEventAdapterConfiguration inputEventAdapterConfiguration =
|
|
||||||
createMqttInputEventAdapterConfiguration(VirtualFireAlarmConstants.MQTT_ADAPTER_NAME,
|
|
||||||
VirtualFireAlarmConstants.MQTT_ADAPTER_TYPE, MessageType.TEXT);
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
||||||
VirtualFireAlarmConstants.DEVICE_TYPE_PROVIDER_DOMAIN, true);
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().getInputEventAdapterService()
|
|
||||||
.create(inputEventAdapterConfiguration, new VirtualFirealarmEventAdapterSubscription());
|
|
||||||
} catch (InputEventAdapterException e) {
|
|
||||||
log.error("Unable to create Input Event Adapter : " + VirtualFireAlarmConstants.MQTT_ADAPTER_NAME, e);
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create Output Event Adapter Configuration for given configuration.
|
|
||||||
*
|
|
||||||
* @param name Input Event Adapter name
|
|
||||||
* @param type Input Event Adapter type
|
|
||||||
* @param msgFormat Input Event Adapter message format
|
|
||||||
* @return InputEventAdapterConfiguration instance for given configuration
|
|
||||||
*/
|
|
||||||
private static InputEventAdapterConfiguration createMqttInputEventAdapterConfiguration(String name, String type,
|
|
||||||
String msgFormat) throws IOException {
|
|
||||||
InputEventAdapterConfiguration inputEventAdapterConfiguration = new InputEventAdapterConfiguration();
|
|
||||||
inputEventAdapterConfiguration.setName(name);
|
|
||||||
inputEventAdapterConfiguration.setType(type);
|
|
||||||
inputEventAdapterConfiguration.setMessageFormat(msgFormat);
|
|
||||||
Map<String, String> mqttAdapterProperties = new HashMap<>();
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.USERNAME_PROPERTY_KEY, MqttConfig.getInstance().getUsername());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.DCR_PROPERTY_KEY, MqttConfig.getInstance().getDcrUrl());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.BROKER_URL_PROPERTY_KEY, MqttConfig.getInstance().getUrl());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.SCOPES_PROPERTY_KEY, MqttConfig.getInstance().getScopes());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.CLEAR_SESSION_PROPERTY_KEY, MqttConfig.getInstance()
|
|
||||||
.getClearSession());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.QOS_PROPERTY_KEY, MqttConfig.getInstance().getQos());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.CLIENT_ID_PROPERTY_KEY, "");
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.TOPIC, VirtualFireAlarmConstants.SUBSCRIBED_TOPIC);
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_TRANSFORMATION,
|
|
||||||
VirtualFirealarmMqttContentTransformer.class.getName());
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_VALIDATION, "default");
|
|
||||||
mqttAdapterProperties.put(VirtualFireAlarmConstants.RESOURCE, "input-event");
|
|
||||||
inputEventAdapterConfiguration.setProperties(mqttAdapterProperties);
|
|
||||||
|
|
||||||
return inputEventAdapterConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String extractMessageFromPayload(String message, PublicKey verifySignatureKey)
|
|
||||||
throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
String actualMessage;
|
|
||||||
|
|
||||||
JSONObject jsonPayload = new JSONObject(message);
|
|
||||||
Object encodedMessage = jsonPayload.get(VirtualFireAlarmConstants.JSON_MESSAGE_KEY);
|
|
||||||
Object signedPayload = jsonPayload.get(VirtualFireAlarmConstants.JSON_SIGNATURE_KEY);
|
|
||||||
|
|
||||||
if (encodedMessage != null && signedPayload != null) {
|
|
||||||
if (VirtualFirealarmSecurityManager.verifySignature(
|
|
||||||
encodedMessage.toString(), signedPayload.toString(), verifySignatureKey)) {
|
|
||||||
actualMessage = new String(Base64.decodeBase64(encodedMessage.toString()));
|
|
||||||
//VirtualFirealarmSecurityManager.decryptMessage(encryptedMessage.toString(), decryptionKey);
|
|
||||||
} else {
|
|
||||||
String errorMsg = "The message was not signed by a valid client. Could not verify signature on payload";
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
String errorMsg = "The received message is in an INVALID format. " +
|
|
||||||
"Need to be JSON - {\"Msg\":\"<ENCRYPTED_MSG>\", \"Sig\":\"<SIGNED_MSG>\"}.";
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg);
|
|
||||||
}
|
|
||||||
|
|
||||||
return actualMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PublicKey getDevicePublicKey(String alias) throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
PublicKey clientPublicKey;
|
|
||||||
try {
|
|
||||||
CertificateManagementService certificateManagementService =
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().getCertificateManagementService();
|
|
||||||
X509Certificate clientCertificate = (X509Certificate) certificateManagementService.getCertificateByAlias(
|
|
||||||
alias);
|
|
||||||
clientPublicKey = clientCertificate.getPublicKey();
|
|
||||||
} 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 VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} else {
|
|
||||||
errorMsg = "An error occurred whilst trying to retrieve certificate for alias [" + alias +
|
|
||||||
"] with alias: [" + alias + "]";
|
|
||||||
if(log.isDebugEnabled()){
|
|
||||||
log.debug(errorMsg);
|
|
||||||
}
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return clientPublicKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean publishToDAS(String deviceId, float temperature) {
|
|
||||||
EventsPublisherService deviceAnalyticsService =
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().getEventsPublisherService();
|
|
||||||
if (deviceAnalyticsService != null) {
|
|
||||||
String owner = "";
|
|
||||||
Object metdaData[] = {owner, VirtualFireAlarmConstants.DEVICE_TYPE, deviceId, System.currentTimeMillis()};
|
|
||||||
Object payloadData[] = {temperature};
|
|
||||||
try {
|
|
||||||
deviceAnalyticsService.publishEvent(VirtualFireAlarmConstants.TEMPERATURE_STREAM_DEFINITION,
|
|
||||||
"1.0.0", metdaData, new Object[0], payloadData);
|
|
||||||
} catch (DataPublisherConfigurationException e) {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void setupXmppInputAdapter() throws IOException {
|
|
||||||
if (!XmppConfig.getInstance().isEnabled()) return;
|
|
||||||
InputEventAdapterConfiguration inputEventAdapterConfiguration =
|
|
||||||
createXmppInputEventAdapterConfiguration(VirtualFireAlarmConstants.XMPP_ADAPTER_NAME,
|
|
||||||
VirtualFireAlarmConstants.XMPP_ADAPTER_TYPE, MessageType.TEXT);
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(
|
|
||||||
VirtualFireAlarmConstants.DEVICE_TYPE_PROVIDER_DOMAIN, true);
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().getInputEventAdapterService()
|
|
||||||
.create(inputEventAdapterConfiguration, new VirtualFirealarmEventAdapterSubscription());
|
|
||||||
} catch (InputEventAdapterException e) {
|
|
||||||
log.error("Unable to create Input Event Adapter : " + VirtualFireAlarmConstants.MQTT_ADAPTER_NAME, e);
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Create Input Event Adapter Configuration for given configuration.
|
|
||||||
*
|
|
||||||
* @param name Input Event Adapter name
|
|
||||||
* @param type Input Event Adapter type
|
|
||||||
* @param msgFormat Input Event Adapter message format
|
|
||||||
* @return InputEventAdapterConfiguration instance for given configuration
|
|
||||||
*/
|
|
||||||
private static InputEventAdapterConfiguration createXmppInputEventAdapterConfiguration(String name, String type,
|
|
||||||
String msgFormat) throws IOException {
|
|
||||||
InputEventAdapterConfiguration inputEventAdapterConfiguration = new InputEventAdapterConfiguration();
|
|
||||||
inputEventAdapterConfiguration.setName(name);
|
|
||||||
inputEventAdapterConfiguration.setType(type);
|
|
||||||
inputEventAdapterConfiguration.setMessageFormat(msgFormat);
|
|
||||||
Map<String, String> xmppAdapterProperties = new HashMap<>();
|
|
||||||
XmppConfig xmppConfig = XmppConfig.getInstance();
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.HOST_KEY, xmppConfig.getHost());
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.PORT_KEY, String.valueOf(xmppConfig.getPort()));
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.USERNAME_PROPERTY_KEY, xmppConfig.getUsername());
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.PASSWORD_PROPERTY_KEY, xmppConfig.getPassword());
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.JID_PROPERTY_KEY, xmppConfig.getJid());
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_TRANSFORMATION,
|
|
||||||
VirtualFirealarmXmppContentTransformer.class.getName());
|
|
||||||
xmppAdapterProperties.put(VirtualFireAlarmConstants.CONTENT_VALIDATION, "default");
|
|
||||||
inputEventAdapterConfiguration.setProperties(xmppAdapterProperties);
|
|
||||||
return inputEventAdapterConfiguration;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,23 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl;
|
|
||||||
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterSubscription;
|
|
||||||
|
|
||||||
public class VirtualFirealarmEventAdapterSubscription implements InputEventAdapterSubscription {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onEvent(Object o) {
|
|
||||||
String msg = (String) o;
|
|
||||||
if (msg != null && !msg.isEmpty()) {
|
|
||||||
String[] messages = (msg).split(",");
|
|
||||||
String deviceId = messages[0];
|
|
||||||
String actualMessage = messages[1];
|
|
||||||
if (actualMessage.contains("PUBLISHER")) {
|
|
||||||
float temperature = Float.parseFloat(actualMessage.split(":")[2]);
|
|
||||||
VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
|
|
||||||
} else {
|
|
||||||
float temperature = Float.parseFloat(actualMessage.split(":")[1]);
|
|
||||||
VirtualFireAlarmUtils.publishToDAS(deviceId, temperature);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,39 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
|
||||||
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class VirtualFirealarmMqttContentTransformer implements ContentTransformer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object transform(Object message, Map<String, Object> dynamicProperties) {
|
|
||||||
String topic = (String) dynamicProperties.get("topic");
|
|
||||||
String[] topicParams = topic.split("/");
|
|
||||||
String tenantDomain = topicParams[0];
|
|
||||||
String deviceId = topicParams[2];
|
|
||||||
JSONObject jsonPayload = new JSONObject((String) message);
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
ctx.setTenantDomain(tenantDomain, true);
|
|
||||||
Integer serialNo = (Integer) jsonPayload.get(VirtualFireAlarmConstants.JSON_SERIAL_KEY);
|
|
||||||
// the hash-code of the deviceId is used as the alias for device certificates during SCEP enrollment.
|
|
||||||
// hence, the same is used here to fetch the device-specific-certificate from the key store.
|
|
||||||
PublicKey clientPublicKey = VirtualFireAlarmUtils.getDevicePublicKey("" + serialNo);
|
|
||||||
|
|
||||||
// the MQTT-messages from VirtualFireAlarm devices are in the form {"Msg":<MESSAGE>, "Sig":<SIGNATURE>}
|
|
||||||
String actualMessage = VirtualFireAlarmUtils.extractMessageFromPayload((String) message, clientPublicKey);
|
|
||||||
return deviceId + "," + actualMessage;
|
|
||||||
} catch (VirtualFirealarmDeviceMgtPluginException e) {
|
|
||||||
return "";
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,256 +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.plugin.impl;
|
|
||||||
|
|
||||||
import org.apache.commons.codec.binary.Base64;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.config.CertificateConfigurationManager;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.config.CertificateKeystoreConfig;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.exception.CertificateManagementException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
|
||||||
|
|
||||||
import javax.crypto.BadPaddingException;
|
|
||||||
import javax.crypto.Cipher;
|
|
||||||
import javax.crypto.IllegalBlockSizeException;
|
|
||||||
import javax.crypto.NoSuchPaddingException;
|
|
||||||
import java.io.FileInputStream;
|
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.InputStream;
|
|
||||||
import java.nio.charset.StandardCharsets;
|
|
||||||
import java.security.InvalidKeyException;
|
|
||||||
import java.security.Key;
|
|
||||||
import java.security.KeyStore;
|
|
||||||
import java.security.KeyStoreException;
|
|
||||||
import java.security.NoSuchAlgorithmException;
|
|
||||||
import java.security.PrivateKey;
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.security.Signature;
|
|
||||||
import java.security.SignatureException;
|
|
||||||
import java.security.UnrecoverableKeyException;
|
|
||||||
import java.security.cert.CertificateException;
|
|
||||||
|
|
||||||
public class VirtualFirealarmSecurityManager {
|
|
||||||
private static final Log log = LogFactory.getLog(VirtualFirealarmSecurityManager.class);
|
|
||||||
|
|
||||||
private static PrivateKey serverPrivateKey;
|
|
||||||
private static final String SHA_512 = "SHA-512";
|
|
||||||
private static final String CIPHER_PADDING = "RSA/ECB/PKCS1Padding";
|
|
||||||
private static CertificateKeystoreConfig certificateKeystoreConfig;
|
|
||||||
private VirtualFirealarmSecurityManager() {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static CertificateKeystoreConfig getCertKeyStoreConfig() throws CertificateManagementException {
|
|
||||||
if (certificateKeystoreConfig == null) {
|
|
||||||
certificateKeystoreConfig = CertificateConfigurationManager.getInstance().getCertificateKeyStoreConfig();
|
|
||||||
}
|
|
||||||
return certificateKeystoreConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static void initVerificationManager() {
|
|
||||||
serverPrivateKey = retrievePrivateKey();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PrivateKey retrievePrivateKey() {
|
|
||||||
PrivateKey privateKey = null;
|
|
||||||
InputStream inputStream = null;
|
|
||||||
KeyStore keyStore;
|
|
||||||
try {
|
|
||||||
CertificateKeystoreConfig certificateKeystoreConfig = getCertKeyStoreConfig();
|
|
||||||
keyStore = KeyStore.getInstance(certificateKeystoreConfig.getCertificateKeystoreType());
|
|
||||||
inputStream = new FileInputStream(certificateKeystoreConfig.getCertificateKeystoreLocation());
|
|
||||||
|
|
||||||
keyStore.load(inputStream, certificateKeystoreConfig.getCertificateKeystorePassword().toCharArray());
|
|
||||||
|
|
||||||
privateKey = (PrivateKey) (keyStore.getKey(certificateKeystoreConfig.getCACertAlias(),
|
|
||||||
certificateKeystoreConfig.getCAPrivateKeyPassword().toCharArray()));
|
|
||||||
|
|
||||||
} catch (KeyStoreException e) {
|
|
||||||
String errorMsg = "Could not load KeyStore of given type in [certificate-config.xml] file." ;
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (FileNotFoundException e) {
|
|
||||||
String errorMsg = "KeyStore file could not be loaded from path given in [certificate-config.xml] file.";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
String errorMsg = "Algorithm not found when loading KeyStore";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (CertificateException e) {
|
|
||||||
String errorMsg = "CertificateException when loading KeyStore";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (IOException e) {
|
|
||||||
String errorMsg = "Input output issue occurred when loading KeyStore";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (UnrecoverableKeyException e) {
|
|
||||||
String errorMsg = "Key is unrecoverable when retrieving CA private key";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} catch (CertificateManagementException e) {
|
|
||||||
String errorMsg = "Failed to load the certificate";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
} finally {
|
|
||||||
try {
|
|
||||||
if (inputStream != null) {
|
|
||||||
inputStream.close();
|
|
||||||
}
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Error closing KeyStore input stream", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return privateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static PrivateKey getServerPrivateKey() {
|
|
||||||
return serverPrivateKey;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String encryptMessage(String message, Key encryptionKey) throws
|
|
||||||
VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
Cipher encrypter;
|
|
||||||
byte[] cipherData;
|
|
||||||
|
|
||||||
try {
|
|
||||||
encrypter = Cipher.getInstance(CIPHER_PADDING);
|
|
||||||
encrypter.init(Cipher.ENCRYPT_MODE, encryptionKey);
|
|
||||||
cipherData = encrypter.doFinal(message.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (NoSuchPaddingException e) {
|
|
||||||
String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + encryptionKey + "\n]\n";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (BadPaddingException e) {
|
|
||||||
String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (IllegalBlockSizeException e) {
|
|
||||||
String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Base64.encodeBase64String(cipherData);
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String signMessage(String encryptedData, PrivateKey signatureKey) throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
|
|
||||||
Signature signature;
|
|
||||||
String signedEncodedString;
|
|
||||||
|
|
||||||
try {
|
|
||||||
signature = Signature.getInstance(SHA_512);
|
|
||||||
signature.initSign(signatureKey);
|
|
||||||
signature.update(Base64.decodeBase64(encryptedData));
|
|
||||||
|
|
||||||
byte[] signatureBytes = signature.sign();
|
|
||||||
signedEncodedString = Base64.encodeBase64String(signatureBytes);
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (SignatureException e) {
|
|
||||||
String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + signatureKey + "\n]\n";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return signedEncodedString;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static boolean verifySignature(String data, String signedData, PublicKey verificationKey)
|
|
||||||
throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
|
|
||||||
Signature signature;
|
|
||||||
boolean verified;
|
|
||||||
|
|
||||||
try {
|
|
||||||
signature = Signature.getInstance(SHA_512);
|
|
||||||
signature.initVerify(verificationKey);
|
|
||||||
signature.update(Base64.decodeBase64(data));
|
|
||||||
|
|
||||||
verified = signature.verify(Base64.decodeBase64(signedData));
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
String errorMsg = "Algorithm not found exception occurred for Signature instance of [" + SHA_512 + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (SignatureException e) {
|
|
||||||
String errorMsg = "Signature exception occurred for Signature instance of [" + SHA_512 + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
String errorMsg = "InvalidKey exception occurred for signatureKey \n[\n" + verificationKey + "\n]\n";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return verified;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static String decryptMessage(String encryptedMessage, Key decryptKey) throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
|
|
||||||
Cipher decrypter;
|
|
||||||
String decryptedMessage;
|
|
||||||
|
|
||||||
try {
|
|
||||||
|
|
||||||
decrypter = Cipher.getInstance(CIPHER_PADDING);
|
|
||||||
decrypter.init(Cipher.DECRYPT_MODE, decryptKey);
|
|
||||||
decryptedMessage = new String(decrypter.doFinal(Base64.decodeBase64(encryptedMessage)), StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
} catch (NoSuchAlgorithmException e) {
|
|
||||||
String errorMsg = "Algorithm not found exception occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (NoSuchPaddingException e) {
|
|
||||||
String errorMsg = "No Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (InvalidKeyException e) {
|
|
||||||
String errorMsg = "InvalidKey exception occurred for encryptionKey \n[\n" + decryptKey + "\n]\n";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (BadPaddingException e) {
|
|
||||||
String errorMsg = "Bad Padding error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
} catch (IllegalBlockSizeException e) {
|
|
||||||
String errorMsg = "Illegal blockSize error occurred for Cipher instance of [" + CIPHER_PADDING + "]";
|
|
||||||
log.error(errorMsg);
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException(errorMsg, e);
|
|
||||||
}
|
|
||||||
|
|
||||||
return decryptedMessage;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +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.plugin.impl;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.core.ServerStartupObserver;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal.VirtualFirealarmManagementDataHolder;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
public class VirtualFirealarmStartupListener implements ServerStartupObserver {
|
|
||||||
private static final Log log = LogFactory.getLog(VirtualFirealarmStartupListener.class);
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void completingServerStartup() {
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void completedServerStartup() {
|
|
||||||
try {
|
|
||||||
VirtualFireAlarmUtils.setupMqttInputAdapter();
|
|
||||||
VirtualFireAlarmUtils.setupXmppInputAdapter();
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().getInputEventAdapterService().start();
|
|
||||||
} catch (IOException e) {
|
|
||||||
log.error("Failed to intilaize the virtual firealarm input adapter", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,46 +0,0 @@
|
|||||||
package org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl;
|
|
||||||
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.constants.VirtualFireAlarmConstants;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
|
||||||
|
|
||||||
import java.security.PublicKey;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class VirtualFirealarmXmppContentTransformer implements ContentTransformer {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object transform(Object message, Map<String, Object> dynamicProperties) {
|
|
||||||
String from = (String) dynamicProperties.get("from");
|
|
||||||
String subject = (String) dynamicProperties.get("subject");
|
|
||||||
|
|
||||||
int indexOfAt = from.indexOf("@");
|
|
||||||
int indexOfSlash = from.indexOf("/");
|
|
||||||
|
|
||||||
if (indexOfAt != -1 && indexOfSlash != -1) {
|
|
||||||
String deviceId = from.substring(0, indexOfAt);
|
|
||||||
JSONObject jsonPayload = new JSONObject((String) message);
|
|
||||||
try {
|
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
|
||||||
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
|
||||||
ctx.setTenantDomain(subject, true);
|
|
||||||
Integer serialNo = (Integer) jsonPayload.get(VirtualFireAlarmConstants.JSON_SERIAL_KEY);
|
|
||||||
// the hash-code of the deviceId is used as the alias for device certificates during SCEP enrollment.
|
|
||||||
// hence, the same is used here to fetch the device-specific-certificate from the key store.
|
|
||||||
PublicKey clientPublicKey = VirtualFireAlarmUtils.getDevicePublicKey("" + serialNo);
|
|
||||||
|
|
||||||
// the MQTT-messages from VirtualFireAlarm devices are in the form {"Msg":<MESSAGE>, "Sig":<SIGNATURE>}
|
|
||||||
String actualMessage = VirtualFireAlarmUtils.extractMessageFromPayload((String) message,
|
|
||||||
clientPublicKey);
|
|
||||||
return deviceId + "," + actualMessage;
|
|
||||||
} catch (VirtualFirealarmDeviceMgtPluginException e) {
|
|
||||||
return "";
|
|
||||||
} finally {
|
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +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.plugin.internal;
|
|
||||||
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* DataHolder class of virtual firealarm plugins component.
|
|
||||||
*/
|
|
||||||
public class VirtualFirealarmManagementDataHolder {
|
|
||||||
|
|
||||||
private InputEventAdapterService inputEventAdapterService;
|
|
||||||
private EventsPublisherService eventsPublisherService;
|
|
||||||
private CertificateManagementService certificateManagementService;
|
|
||||||
|
|
||||||
private static VirtualFirealarmManagementDataHolder thisInstance = new VirtualFirealarmManagementDataHolder();
|
|
||||||
|
|
||||||
private VirtualFirealarmManagementDataHolder() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public static VirtualFirealarmManagementDataHolder getInstance() {
|
|
||||||
return thisInstance;
|
|
||||||
}
|
|
||||||
|
|
||||||
public InputEventAdapterService getInputEventAdapterService() {
|
|
||||||
return inputEventAdapterService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
|
|
||||||
this.inputEventAdapterService = inputEventAdapterService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public EventsPublisherService getEventsPublisherService() {
|
|
||||||
return eventsPublisherService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEventsPublisherService(
|
|
||||||
EventsPublisherService eventsPublisherService) {
|
|
||||||
this.eventsPublisherService = eventsPublisherService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public CertificateManagementService getCertificateManagementService() {
|
|
||||||
return certificateManagementService;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setCertificateManagementService(CertificateManagementService certificateManagementService) {
|
|
||||||
this.certificateManagementService = certificateManagementService;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,117 +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.plugin.internal;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.osgi.framework.BundleContext;
|
|
||||||
import org.osgi.framework.ServiceRegistration;
|
|
||||||
import org.osgi.service.component.ComponentContext;
|
|
||||||
import org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService;
|
|
||||||
import org.wso2.carbon.core.ServerStartupObserver;
|
|
||||||
import org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.VirtualFirealarmConfig;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFirealarmSecurityManager;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.impl.VirtualFirealarmStartupListener;
|
|
||||||
import org.wso2.carbon.event.input.adapter.core.InputEventAdapterService;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @scr.component name="org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.internal
|
|
||||||
* .VirtualFirealarmManagementServiceComponent"
|
|
||||||
* immediate="true"
|
|
||||||
* @scr.reference name="event.input.adapter.service"
|
|
||||||
* interface="org.wso2.carbon.event.input.adapter.core.InputEventAdapterService"
|
|
||||||
* cardinality="1..1"
|
|
||||||
* policy="dynamic"
|
|
||||||
* bind="setInputEventAdapterService"
|
|
||||||
* unbind="unsetInputEventAdapterService"
|
|
||||||
* @scr.reference name="certificate.management.service"
|
|
||||||
* interface="org.wso2.carbon.certificate.mgt.core.service.CertificateManagementService"
|
|
||||||
* cardinality="1..1"
|
|
||||||
* policy="dynamic"
|
|
||||||
* bind="setCertificateManagementService"
|
|
||||||
* unbind="unsetCertificateManagementService"
|
|
||||||
* @scr.reference name="event.publisher.service"
|
|
||||||
* interface="org.wso2.carbon.device.mgt.analytics.data.publisher.service.EventsPublisherService"
|
|
||||||
* cardinality="1..1"
|
|
||||||
* policy="dynamic"
|
|
||||||
* bind="setEventsPublisherService"
|
|
||||||
* unbind="unsetEventsPublisherService"
|
|
||||||
*/
|
|
||||||
public class VirtualFirealarmManagementServiceComponent {
|
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(VirtualFirealarmManagementServiceComponent.class);
|
|
||||||
private ServiceRegistration firealarmServiceRegRef;
|
|
||||||
|
|
||||||
protected void activate(ComponentContext ctx) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Activating Virtual Firealarm Device Management Service Component");
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
VirtualFirealarmConfig.initialize();
|
|
||||||
BundleContext bundleContext = ctx.getBundleContext();
|
|
||||||
bundleContext.registerService(ServerStartupObserver.class.getName(), new VirtualFirealarmStartupListener(),
|
|
||||||
null);
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Virtual Firealarm Device Management Service Component has been successfully activated");
|
|
||||||
}
|
|
||||||
VirtualFirealarmSecurityManager.initVerificationManager();
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error("Error occurred while activating Virtual Firealarm Device Management Service Component", e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void deactivate(ComponentContext ctx) {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("De-activating Virtual Firealarm Device Management Service Component");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Initialize the Input EventAdapter Service dependency
|
|
||||||
*
|
|
||||||
* @param inputEventAdapterService Input EventAdapter Service reference
|
|
||||||
*/
|
|
||||||
protected void setInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setInputEventAdapterService(inputEventAdapterService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* De-reference the Input EventAdapter Service dependency.
|
|
||||||
*/
|
|
||||||
protected void unsetInputEventAdapterService(InputEventAdapterService inputEventAdapterService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setInputEventAdapterService(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setCertificateManagementService(CertificateManagementService certificateManagementService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setCertificateManagementService(certificateManagementService);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void unsetCertificateManagementService(CertificateManagementService certificateManagementService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setCertificateManagementService(null);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void setEventsPublisherService(EventsPublisherService eventsPublisherService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setEventsPublisherService(eventsPublisherService);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void unsetEventsPublisherService(EventsPublisherService eventsPublisherService) {
|
|
||||||
VirtualFirealarmManagementDataHolder.getInstance().setEventsPublisherService(null);
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,108 +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.plugin.mqtt;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.DeviceManagementConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.EventListenerConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.VirtualFirealarmConfig;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
public class MqttConfig {
|
|
||||||
|
|
||||||
private static MqttConfig mqttConfig = new MqttConfig();
|
|
||||||
private static final Log log = LogFactory.getLog(MqttConfig.class);
|
|
||||||
|
|
||||||
private boolean enabled;
|
|
||||||
private String url;
|
|
||||||
private String username;
|
|
||||||
private String dcrUrl;
|
|
||||||
private String qos;
|
|
||||||
private String scopes;
|
|
||||||
private String clearSession;
|
|
||||||
|
|
||||||
private MqttConfig() {
|
|
||||||
DeviceManagementConfiguration deviceManagementConfiguration = VirtualFirealarmConfig.getInstance()
|
|
||||||
.getDeviceTypeConfiguration();
|
|
||||||
List<EventListenerConfiguration.Property> properties = deviceManagementConfiguration
|
|
||||||
.getEventListenerConfiguration().getProperties();
|
|
||||||
String provider = deviceManagementConfiguration.getEventListenerConfiguration().getEventListenerProvider();
|
|
||||||
if (provider.equals("MQTT")) {
|
|
||||||
enabled = true;
|
|
||||||
}
|
|
||||||
if (enabled) {
|
|
||||||
for (EventListenerConfiguration.Property property : properties) {
|
|
||||||
switch (property.getName()) {
|
|
||||||
case "url":
|
|
||||||
url = property.getValue();
|
|
||||||
break;
|
|
||||||
case "username":
|
|
||||||
username = property.getValue();
|
|
||||||
break;
|
|
||||||
case "dcrUrl":
|
|
||||||
dcrUrl = property.getValue();
|
|
||||||
break;
|
|
||||||
case "qos":
|
|
||||||
qos = property.getValue();
|
|
||||||
break;
|
|
||||||
case "scopes":
|
|
||||||
scopes = property.getValue();
|
|
||||||
break;
|
|
||||||
case "clearSession":
|
|
||||||
clearSession = property.getValue();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public static MqttConfig getInstance() {
|
|
||||||
return mqttConfig;
|
|
||||||
}
|
|
||||||
|
|
||||||
public boolean isEnabled() {
|
|
||||||
return enabled;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUrl() {
|
|
||||||
return url;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getUsername() {
|
|
||||||
return username;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getDcrUrl() {
|
|
||||||
return dcrUrl;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getQos() {
|
|
||||||
return qos;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getScopes() {
|
|
||||||
return scopes;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getClearSession() {
|
|
||||||
return clearSession;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,63 +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.plugin.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;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,136 +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.plugin.xmpp;
|
|
||||||
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.DeviceManagementConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.EventListenerConfiguration;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.config.VirtualFirealarmConfig;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
|
|
||||||
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 XmppConfig() {
|
|
||||||
DeviceManagementConfiguration deviceManagementConfiguration = VirtualFirealarmConfig.getInstance()
|
|
||||||
.getDeviceTypeConfiguration();
|
|
||||||
List<EventListenerConfiguration.Property> properties = deviceManagementConfiguration.getEventListenerConfiguration()
|
|
||||||
.getProperties();
|
|
||||||
String provider = deviceManagementConfiguration.getEventListenerConfiguration().getEventListenerProvider();
|
|
||||||
if ("XMPP".equals(provider)) {
|
|
||||||
enabled = true;
|
|
||||||
}
|
|
||||||
if (enabled) {
|
|
||||||
for (EventListenerConfiguration.Property property : properties) {
|
|
||||||
switch (property.getName()) {
|
|
||||||
case "host":
|
|
||||||
host = property.getValue();
|
|
||||||
break;
|
|
||||||
case "port":
|
|
||||||
port = Integer.parseInt(property.getValue());
|
|
||||||
break;
|
|
||||||
case "username":
|
|
||||||
username = property.getValue();
|
|
||||||
break;
|
|
||||||
case "password":
|
|
||||||
password = property.getValue();
|
|
||||||
break;
|
|
||||||
case "server.name":
|
|
||||||
serverName = property.getValue();
|
|
||||||
break;
|
|
||||||
case "jid":
|
|
||||||
jid = property.getValue();
|
|
||||||
break;
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
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;
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,67 +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.plugin.xmpp;
|
|
||||||
|
|
||||||
import org.jivesoftware.smack.AccountManager;
|
|
||||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
|
||||||
import org.jivesoftware.smack.XMPPConnection;
|
|
||||||
import org.jivesoftware.smack.XMPPException;
|
|
||||||
import org.wso2.carbon.device.mgt.iot.virtualfirealarm.plugin.exception.VirtualFirealarmDeviceMgtPluginException;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class XmppServerClient {
|
|
||||||
|
|
||||||
public static boolean createAccount(XmppAccount xmppAccount) throws VirtualFirealarmDeviceMgtPluginException {
|
|
||||||
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<String, String> 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 VirtualFirealarmDeviceMgtPluginException(
|
|
||||||
"XMPP account creation failed. Error: " + e.getLocalizedMessage(), e);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
throw new VirtualFirealarmDeviceMgtPluginException("Invalid XMPP attributes");
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,199 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<!--
|
|
||||||
~ 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.
|
|
||||||
-->
|
|
||||||
|
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
|
||||||
<parent>
|
|
||||||
<artifactId>virtual-fire-alarm-plugin</artifactId>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt-plugins</groupId>
|
|
||||||
<version>3.0.6-SNAPSHOT</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.iot.virtualfirealarm.scep.api</artifactId>
|
|
||||||
<packaging>war</packaging>
|
|
||||||
<name>WSO2 Carbon - IoT Server SCEP Server API</name>
|
|
||||||
<description>WSO2 Carbon - Virtual FireAlarm SCEP Server API Implementation</description>
|
|
||||||
<url>http://wso2.org</url>
|
|
||||||
|
|
||||||
<dependencies>
|
|
||||||
<!-- CDM -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.common</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.device.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.axis2.wso2</groupId>
|
|
||||||
<artifactId>axis2-client</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon.devicemgt</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.certificate.mgt.core</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
|
|
||||||
<!--CXF -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxws</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-frontend-jaxrs</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.apache.cxf</groupId>
|
|
||||||
<artifactId>cxf-rt-transports-http</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<!--JAX-RS -->
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-core-asl</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.codehaus.jackson</groupId>
|
|
||||||
<artifactId>jackson-jaxrs</artifactId>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax</groupId>
|
|
||||||
<artifactId>javaee-web-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>javax.ws.rs</groupId>
|
|
||||||
<artifactId>jsr311-api</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-httpclient.wso2</groupId>
|
|
||||||
<artifactId>commons-httpclient</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.utils</artifactId>
|
|
||||||
<scope>provided</scope>
|
|
||||||
<exclusions>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.bouncycastle.wso2</groupId>
|
|
||||||
<artifactId>bcprov-jdk15on</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.user.api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.queuing</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.base</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.axis2.wso2</groupId>
|
|
||||||
<artifactId>axis2</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
|
||||||
<artifactId>smack</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.igniterealtime.smack.wso2</groupId>
|
|
||||||
<artifactId>smackx</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>jaxen</groupId>
|
|
||||||
<artifactId>jaxen</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-fileupload.wso2</groupId>
|
|
||||||
<artifactId>commons-fileupload</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.ant.wso2</groupId>
|
|
||||||
<artifactId>ant</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.apache.ant.wso2</groupId>
|
|
||||||
<artifactId>ant</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>commons-httpclient.wso2</groupId>
|
|
||||||
<artifactId>commons-httpclient</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.eclipse.equinox</groupId>
|
|
||||||
<artifactId>javax.servlet</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
<exclusion>
|
|
||||||
<groupId>org.wso2.carbon</groupId>
|
|
||||||
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
|
||||||
</exclusion>
|
|
||||||
</exclusions>
|
|
||||||
</dependency>
|
|
||||||
|
|
||||||
<dependency>
|
|
||||||
<groupId>commons-codec</groupId>
|
|
||||||
<artifactId>commons-codec</artifactId>
|
|
||||||
</dependency>
|
|
||||||
</dependencies>
|
|
||||||
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-compiler-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<encoding>UTF-8</encoding>
|
|
||||||
<source>${wso2.maven.compiler.source}</source>
|
|
||||||
<target>${wso2.maven.compiler.target}</target>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<artifactId>maven-war-plugin</artifactId>
|
|
||||||
<configuration>
|
|
||||||
<warName>virtual_firealarm_scep</warName>
|
|
||||||
</configuration>
|
|
||||||
</plugin>
|
|
||||||
</plugins>
|
|
||||||
</build>
|
|
||||||
|
|
||||||
</project>
|
|
Loading…
Reference in new issue