forked from community/device-mgt-core
commit
968cb00f35
@ -0,0 +1,118 @@
|
|||||||
|
package org.wso2.carbon.apimgt.application.extension.api.filter;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.apimgt.application.extension.api.util.APIUtil;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
|
import javax.servlet.*;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import javax.xml.bind.JAXBContext;
|
||||||
|
import javax.xml.bind.JAXBException;
|
||||||
|
import javax.xml.bind.Unmarshaller;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStream;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* this filter check for permission for the request
|
||||||
|
*/
|
||||||
|
public class ApiPermissionFilter implements Filter{
|
||||||
|
private static final Log log = LogFactory.getLog(ApiPermissionFilter.class);
|
||||||
|
private static final String UI_EXECUTE = "ui.execute";
|
||||||
|
private static final String PERMISSION_CONFIG_PATH = File.separator + "META-INF" + File.separator
|
||||||
|
+ "permissions.xml";
|
||||||
|
private static final String PERMISSION_PREFIX = "/permission/admin";
|
||||||
|
private static List<Permission> permissions;
|
||||||
|
private static final String WEBAPP_CONTEXT = "/api-application-registration";
|
||||||
|
@Override
|
||||||
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
|
InputStream permissionStream = filterConfig.getServletContext().getResourceAsStream(PERMISSION_CONFIG_PATH);
|
||||||
|
if (permissionStream != null) {
|
||||||
|
try {
|
||||||
|
JAXBContext cdmContext = JAXBContext.newInstance(PermissionConfiguration.class);
|
||||||
|
Unmarshaller unmarshaller = cdmContext.createUnmarshaller();
|
||||||
|
PermissionConfiguration permissionConfiguration = (PermissionConfiguration)
|
||||||
|
unmarshaller.unmarshal(permissionStream);
|
||||||
|
permissions = permissionConfiguration.getPermissions();
|
||||||
|
} catch (JAXBException e) {
|
||||||
|
log.error("invalid permissions.xml", e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain)
|
||||||
|
throws IOException, ServletException {
|
||||||
|
if (servletRequest instanceof HttpServletRequest) {
|
||||||
|
String uri = ((HttpServletRequest)servletRequest).getRequestURI();
|
||||||
|
boolean status = false;
|
||||||
|
if (uri.contains("register/tenants")) {
|
||||||
|
String urlPermission = getPermission("/register/tenants/*");
|
||||||
|
if (urlPermission != null) {
|
||||||
|
status = isUserAuthorized(PERMISSION_PREFIX + urlPermission, UI_EXECUTE);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
String urlPermission = getPermission(uri);
|
||||||
|
if (urlPermission != null) {
|
||||||
|
status = isUserAuthorized(PERMISSION_PREFIX + urlPermission, UI_EXECUTE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (status) {
|
||||||
|
filterChain.doFilter(servletRequest, servletResponse);
|
||||||
|
} else {
|
||||||
|
HttpServletResponse res = (HttpServletResponse) servletResponse;
|
||||||
|
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
HttpServletResponse res = (HttpServletResponse) servletResponse;
|
||||||
|
res.setStatus(HttpServletResponse.SC_FORBIDDEN);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void destroy() {
|
||||||
|
//do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getPermission(String url) {
|
||||||
|
if (permissions != null) {
|
||||||
|
for (int i = 0; i < permissions.size(); i++) {
|
||||||
|
Permission permission = permissions.get(i);
|
||||||
|
if ((WEBAPP_CONTEXT + permission.getUrl()).equals(url)) {
|
||||||
|
return permission.getPath();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check whether the client is authorized with the given permission and action.
|
||||||
|
* @param permission Carbon permission that requires for the use
|
||||||
|
* @param action Carbon permission action that requires for the given permission.
|
||||||
|
* @return boolean - true if user is authorized else return false.
|
||||||
|
*/
|
||||||
|
private boolean isUserAuthorized(String permission, String action) {
|
||||||
|
PrivilegedCarbonContext context = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
String username = context.getUsername();
|
||||||
|
try {
|
||||||
|
UserRealm userRealm = APIUtil.getRealmService().getTenantUserRealm(PrivilegedCarbonContext
|
||||||
|
.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
return userRealm.getAuthorizationManager().isUserAuthorized(username, permission, action);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String errorMsg = String.format("Unable to authorize the user : %s", username, e);
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.apimgt.application.extension.api.filter;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the information related to permission.
|
||||||
|
*/
|
||||||
|
@XmlRootElement (name = "Permission")
|
||||||
|
public class Permission {
|
||||||
|
|
||||||
|
private String path; // permission string
|
||||||
|
private String url; // url of the resource
|
||||||
|
private String method; // http method
|
||||||
|
|
||||||
|
public String getPath() {
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement (name = "path", required = true)
|
||||||
|
public void setPath(String path) {
|
||||||
|
this.path = path;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUrl() {
|
||||||
|
return url;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement (name = "url", required = true)
|
||||||
|
public void setUrl(String url) {
|
||||||
|
this.url = url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMethod() {
|
||||||
|
return method;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement (name = "method", required = true)
|
||||||
|
public void setMethod(String method) {
|
||||||
|
this.method = method;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.apimgt.application.extension.api.filter;
|
||||||
|
|
||||||
|
import javax.xml.bind.annotation.XmlElement;
|
||||||
|
import javax.xml.bind.annotation.XmlRootElement;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the information related to permission configuration.
|
||||||
|
*/
|
||||||
|
@XmlRootElement (name = "PermissionConfiguration")
|
||||||
|
public class PermissionConfiguration {
|
||||||
|
|
||||||
|
private List<Permission> permissions;
|
||||||
|
|
||||||
|
public List<Permission> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
@XmlElement (name = "Permission", required = true)
|
||||||
|
public void setPermissions(List<Permission> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,147 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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>device-mgt-extensions</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - GCM Based Push Notification Provider Implementation</name>
|
||||||
|
<description>WSO2 Carbon - GCM Based Push Notification Provider Implementation</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.governance</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.governance.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.core</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.apache.ws.commons.axiom</groupId>
|
||||||
|
<artifactId>axiom-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.orbit.org.scannotation</groupId>
|
||||||
|
<artifactId>scannotation</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.tomcat</groupId>
|
||||||
|
<artifactId>tomcat</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang.wso2</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json.wso2</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>GCM Based Push Notification Provider Bundle</Bundle-Description>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal,
|
||||||
|
org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.*
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
com.google.gson,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt,
|
||||||
|
org.wso2.carbon.device.mgt.common.push.notification,
|
||||||
|
org.apache.commons.logging,
|
||||||
|
org.wso2.carbon.device.mgt.common,
|
||||||
|
org.wso2.carbon.device.mgt.core.service
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,39 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.gcm;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
|
|
||||||
|
public class GCMBasedPushNotificationProvider implements PushNotificationProvider {
|
||||||
|
|
||||||
|
private static final String PS_PROVIDER_GCM = "GCM";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return PS_PROVIDER_GCM;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
|
||||||
|
return new GCMNotificationStrategy(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,134 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.gcm;
|
||||||
|
|
||||||
|
import com.google.gson.JsonArray;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonPrimitive;
|
||||||
|
import org.wso2.carbon.device.mgt.common.Device;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMDataHolder;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.OutputStream;
|
||||||
|
import java.net.HttpURLConnection;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GCMNotificationStrategy implements NotificationStrategy {
|
||||||
|
|
||||||
|
private static final String GCM_TOKEN = "GCM_TOKEN";
|
||||||
|
private final static String GCM_ENDPOINT = "https://gcm-http.googleapis.com/gcm/send";
|
||||||
|
private static final String GCM_API_KEY = "gcmAPIKey";
|
||||||
|
private static final int TIME_TO_LIVE = 60;
|
||||||
|
private static final int HTTP_STATUS_CODE_OK = 200;
|
||||||
|
private PushNotificationConfig config;
|
||||||
|
|
||||||
|
public GCMNotificationStrategy(PushNotificationConfig config) {
|
||||||
|
this.config = config;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||||
|
try {
|
||||||
|
Device device =
|
||||||
|
GCMDataHolder.getInstance().getDeviceManagementProviderService().getDevice(ctx.getDeviceId());
|
||||||
|
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new PushNotificationExecutionFailedException("Error occurred while retrieving device information", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new PushNotificationExecutionFailedException("Error occurred while sending push notification", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationContext buildContext() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void sendWakeUpCall(String message,
|
||||||
|
Device device) throws IOException, PushNotificationExecutionFailedException {
|
||||||
|
OutputStream os = null;
|
||||||
|
byte[] bytes = getGCMRequest(message, getGCMToken(device.getProperties())).getBytes();
|
||||||
|
|
||||||
|
HttpURLConnection conn = null;
|
||||||
|
try {
|
||||||
|
conn = (HttpURLConnection) (new URL(config.getProperty(GCM_ENDPOINT)).openConnection());
|
||||||
|
conn.setDoOutput(true);
|
||||||
|
conn.setUseCaches(false);
|
||||||
|
conn.setFixedLengthStreamingMode(bytes.length);
|
||||||
|
conn.setRequestMethod("POST");
|
||||||
|
conn.setRequestProperty("Content-Type", "application/json");
|
||||||
|
conn.setRequestProperty("Authorization", "key=" + config.getProperty(GCM_API_KEY));
|
||||||
|
|
||||||
|
os = conn.getOutputStream();
|
||||||
|
os.write(bytes);
|
||||||
|
} finally {
|
||||||
|
if (os != null) {
|
||||||
|
os.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
int status = conn.getResponseCode();
|
||||||
|
if (status != HTTP_STATUS_CODE_OK) {
|
||||||
|
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
|
||||||
|
"error code '" + status + "'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getGCMRequest(String message, String registrationId) {
|
||||||
|
JsonObject gcmRequest = new JsonObject();
|
||||||
|
gcmRequest.addProperty("delay_while_idle", false);
|
||||||
|
gcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
|
||||||
|
|
||||||
|
//Add message to GCM request
|
||||||
|
JsonObject data = new JsonObject();
|
||||||
|
if (message != null && !message.isEmpty()) {
|
||||||
|
data.addProperty("data", message);
|
||||||
|
gcmRequest.add("data", data);
|
||||||
|
}
|
||||||
|
|
||||||
|
//Set device reg-id
|
||||||
|
JsonArray regIds = new JsonArray();
|
||||||
|
regIds.add(new JsonPrimitive(registrationId));
|
||||||
|
|
||||||
|
gcmRequest.add("registration_ids", regIds);
|
||||||
|
return gcmRequest.toString();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getGCMToken(List<Device.Property> properties) {
|
||||||
|
String gcmToken = null;
|
||||||
|
for (Device.Property property : properties) {
|
||||||
|
if (GCM_TOKEN.equals(property.getName())) {
|
||||||
|
gcmToken = property.getValue();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gcmToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.gcm.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
|
||||||
|
public class GCMDataHolder {
|
||||||
|
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
private static GCMDataHolder thisInstance = new GCMDataHolder();
|
||||||
|
|
||||||
|
public static GCMDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceManagementProviderService getDeviceManagementProviderService() {
|
||||||
|
return deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
this.deviceManagementProviderService = deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.gcm.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.GCMPushNotificationServiceComponent" immediate="true"
|
||||||
|
* @scr.reference name="carbon.device.mgt.provider"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setDeviceManagementProviderService"
|
||||||
|
* unbind="unsetDeviceManagementProviderService"
|
||||||
|
*/
|
||||||
|
public class GCMPushNotificationServiceComponent {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(GCMPushNotificationServiceComponent.class);
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing GCM based push notification provider implementation bundle");
|
||||||
|
}
|
||||||
|
//Do nothing
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("GCM based push notification provider implementation bundle has been successfully " +
|
||||||
|
"initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while initializing GCM based push notification provider " +
|
||||||
|
"implementation bundle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
GCMDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,148 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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>device-mgt-extensions</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</name>
|
||||||
|
<description>WSO2 Carbon - MQTT Based Push Notification Provider Implementation</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.governance</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.governance.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.core</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.apache.ws.commons.axiom</groupId>
|
||||||
|
<artifactId>axiom-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.orbit.org.scannotation</groupId>
|
||||||
|
<artifactId>scannotation</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.tomcat</groupId>
|
||||||
|
<artifactId>tomcat</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang.wso2</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json.wso2</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>MQTT Based Push Notification Provider Bundle</Bundle-Description>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal,
|
||||||
|
org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.*
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.apache.commons.logging,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.wso2.carbon.context,
|
||||||
|
org.wso2.carbon.device.mgt.common.operation.mgt,
|
||||||
|
org.wso2.carbon.device.mgt.common.push.notification,
|
||||||
|
org.wso2.carbon.device.mgt.core.service,
|
||||||
|
org.wso2.carbon.event.output.adapter.core,
|
||||||
|
org.wso2.carbon.event.output.adapter.core.exception
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
|
|
||||||
|
public class MQTTBasedPushNotificationProvider implements PushNotificationProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "MQTT";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
|
||||||
|
return new MQTTNotificationStrategy(config);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.MQTTDataHolder;
|
||||||
|
import org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.internal.util.MQTTAdapterConstants;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.MessageType;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterConfiguration;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.exception.OutputEventAdapterException;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class MQTTNotificationStrategy implements NotificationStrategy {
|
||||||
|
|
||||||
|
private static final String MQTT_ADAPTER_PROPERTY_NAME = "mqtt.adapter.name";
|
||||||
|
private static final String MQTT_ADAPTER_TOPIC = "mqtt.adapter.topic";
|
||||||
|
private static final String MQTT_ADAPTER_NAME = "mqtt.push.notification.publisher";
|
||||||
|
|
||||||
|
public MQTTNotificationStrategy(PushNotificationConfig config) {
|
||||||
|
OutputEventAdapterConfiguration adapterConfig = new OutputEventAdapterConfiguration();
|
||||||
|
adapterConfig.setType(MQTTAdapterConstants.MQTT_ADAPTER_TYPE);
|
||||||
|
adapterConfig.setName(MQTT_ADAPTER_NAME);
|
||||||
|
adapterConfig.setMessageFormat(MessageType.JSON);
|
||||||
|
|
||||||
|
Map<String, String> configProperties = new HashMap<String, String>();
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_BROKER_URL));
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_USERNAME));
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_DCR_URL,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_DCR_URL));
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_CLEAR_SESSION));
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_SCOPES));
|
||||||
|
configProperties.put(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS,
|
||||||
|
config.getProperty(MQTTAdapterConstants.MQTT_ADAPTER_PROPERTY_MESSAGE_QOS));
|
||||||
|
adapterConfig.setStaticProperties(configProperties);
|
||||||
|
try {
|
||||||
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().create(adapterConfig);
|
||||||
|
} catch (OutputEventAdapterException e) {
|
||||||
|
throw new RuntimeException("Error occurred while initializing MQTT output event adapter", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||||
|
Map<String, String> dynamicProperties = ctx.getProperties();
|
||||||
|
dynamicProperties.put("topic", (String) ctx.getOperation().getProperties().get(MQTT_ADAPTER_TOPIC));
|
||||||
|
MQTTDataHolder.getInstance().getOutputEventAdapterService().publish(MQTT_ADAPTER_NAME, dynamicProperties,
|
||||||
|
ctx.getOperation().getPayLoad());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationContext buildContext() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||||
|
|
||||||
|
public class MQTTPushNotificationStrategyUtil {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MQTTPushNotificationStrategyUtil.class);
|
||||||
|
|
||||||
|
public static String getAuthenticatedUser() {
|
||||||
|
CarbonContext carbonContext = CarbonContext.getThreadLocalCarbonContext();
|
||||||
|
String username = carbonContext.getUsername();
|
||||||
|
String tenantDomain = carbonContext.getTenantDomain();
|
||||||
|
if (username.endsWith(tenantDomain)) {
|
||||||
|
return username.substring(0, username.lastIndexOf("@"));
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static String getAuthenticatedUserTenantDomain() {
|
||||||
|
return CarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,50 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||||
|
|
||||||
|
public class MQTTDataHolder {
|
||||||
|
|
||||||
|
private OutputEventAdapterService outputEventAdapterService;
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
private static MQTTDataHolder thisInstance = new MQTTDataHolder();
|
||||||
|
|
||||||
|
public static MQTTDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceManagementProviderService getDeviceManagementProviderService() {
|
||||||
|
return deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
this.deviceManagementProviderService = deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService) {
|
||||||
|
this.outputEventAdapterService = outputEventAdapterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public OutputEventAdapterService getOutputEventAdapterService() {
|
||||||
|
return outputEventAdapterService;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,83 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
import org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.MQTTPushNotificationServiceComponent" immediate="true"
|
||||||
|
* @scr.reference name="carbon.device.mgt.provider"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setDeviceManagementProviderService"
|
||||||
|
* unbind="unsetDeviceManagementProviderService"
|
||||||
|
* @scr.reference name="event.output.adapter.service"
|
||||||
|
* interface="org.wso2.carbon.event.output.adapter.core.OutputEventAdapterService"
|
||||||
|
* cardinality="1..1" policy="dynamic" bind="setOutputEventAdapterService"
|
||||||
|
* unbind="unsetOutputEventAdapterService"
|
||||||
|
*/
|
||||||
|
public class MQTTPushNotificationServiceComponent {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(MQTTPushNotificationServiceComponent.class);
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing MQTT based push notification provider implementation bundle");
|
||||||
|
}
|
||||||
|
//Do nothing
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("MQTT based push notification provider implementation bundle has been successfully " +
|
||||||
|
"initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while initializing MQTT based push notification provider " +
|
||||||
|
"implementation bundle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
MQTTDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
MQTTDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService){
|
||||||
|
MQTTDataHolder.getInstance().setOutputEventAdapterService(outputEventAdapterService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetOutputEventAdapterService(OutputEventAdapterService outputEventAdapterService){
|
||||||
|
MQTTDataHolder.getInstance().setOutputEventAdapterService(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.mqtt.internal.util;
|
||||||
|
|
||||||
|
public final class MQTTAdapterConstants {
|
||||||
|
|
||||||
|
private MQTTAdapterConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String MQTT_ADAPTER_TYPE = "oauth-mqtt";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_BROKER_URL = "url";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_USERNAME = "username";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_DCR_URL = "dcrUrl";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_SCOPES = "scopes";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_PASSWORD = "password";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_CLIENT_ID = "clientId";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_CLEAR_SESSION = "cleanSession";
|
||||||
|
public static final String MQTT_ADAPTER_PROPERTY_MESSAGE_QOS = "qos";
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,144 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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>device-mgt-extensions</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</name>
|
||||||
|
<description>WSO2 Carbon - XMPP Based Push Notification Provider Implementation</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.governance</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.governance.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.registry.core</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.apache.ws.commons.axiom</groupId>
|
||||||
|
<artifactId>axiom-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.utils</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.orbit.org.scannotation</groupId>
|
||||||
|
<artifactId>scannotation</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.tomcat</groupId>
|
||||||
|
<artifactId>tomcat</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.tomcat</groupId>
|
||||||
|
<artifactId>tomcat-servlet-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.axis2.wso2</groupId>
|
||||||
|
<artifactId>axis2</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-lang.wso2</groupId>
|
||||||
|
<artifactId>commons-lang</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.eclipse.paho</groupId>
|
||||||
|
<artifactId>org.eclipse.paho.client.mqttv3</artifactId>
|
||||||
|
<scope>provided</scope>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.google.code.gson</groupId>
|
||||||
|
<artifactId>gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.json.wso2</groupId>
|
||||||
|
<artifactId>json</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.analytics-common</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-bundle-plugin</artifactId>
|
||||||
|
<extensions>true</extensions>
|
||||||
|
<configuration>
|
||||||
|
<instructions>
|
||||||
|
<Bundle-SymbolicName>${project.artifactId}</Bundle-SymbolicName>
|
||||||
|
<Bundle-Name>${project.artifactId}</Bundle-Name>
|
||||||
|
<Bundle-Version>${carbon.device.mgt.version}</Bundle-Version>
|
||||||
|
<Bundle-Description>XMPP Based Push Notification Provider Bundle</Bundle-Description>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.internal,
|
||||||
|
org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.*
|
||||||
|
</Export-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.apache.commons.logging,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.wso2.carbon.device.mgt.common.push.notification,
|
||||||
|
org.wso2.carbon.device.mgt.core.service
|
||||||
|
</Import-Package>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,37 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.xmpp;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
|
|
||||||
|
public class XMPPBasedPushNotificationProvider implements PushNotificationProvider {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return "XMPP";
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationStrategy getNotificationStrategy(PushNotificationConfig pushNotificationConfig) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.xmpp;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||||
|
|
||||||
|
public class XMPPNotificationStrategy implements NotificationStrategy {
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void init() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public NotificationContext buildContext() {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.xmpp.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
|
||||||
|
public class XMPPDataHolder {
|
||||||
|
|
||||||
|
private DeviceManagementProviderService deviceManagementProviderService;
|
||||||
|
private static XMPPDataHolder thisInstance = new XMPPDataHolder();
|
||||||
|
|
||||||
|
public static XMPPDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceManagementProviderService getDeviceManagementProviderService() {
|
||||||
|
return deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
this.deviceManagementProviderService = deviceManagementProviderService;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,70 @@
|
|||||||
|
/*
|
||||||
|
* 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.extensions.push.notification.provider.xmpp.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.internal.XMPPPushNotificationServiceComponent" immediate="true"
|
||||||
|
* @scr.reference name="carbon.device.mgt.provider"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService"
|
||||||
|
* cardinality="1..1"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setDeviceManagementProviderService"
|
||||||
|
* unbind="unsetDeviceManagementProviderService"
|
||||||
|
*/
|
||||||
|
public class XMPPPushNotificationServiceComponent {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(XMPPPushNotificationServiceComponent.class);
|
||||||
|
|
||||||
|
@SuppressWarnings("unused")
|
||||||
|
protected void activate(ComponentContext componentContext) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Initializing XMPP based push notification provider implementation bundle");
|
||||||
|
}
|
||||||
|
//Do nothing
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("XMPP based push notification provider implementation bundle has been successfully " +
|
||||||
|
"initialized");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while initializing XMPP based push notification provider " +
|
||||||
|
"implementation bundle", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext componentContext) {
|
||||||
|
//Do nothing
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
XMPPDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetDeviceManagementProviderService(
|
||||||
|
DeviceManagementProviderService deviceManagementProviderService) {
|
||||||
|
XMPPDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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>carbon-devicemgt</artifactId>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>device-mgt-extensions</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - Device Management Extensions</name>
|
||||||
|
<description>WSO2 Carbon - Device Management Extensions</description>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,55 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.push.notification;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class NotificationContext {
|
||||||
|
|
||||||
|
private DeviceIdentifier deviceId;
|
||||||
|
|
||||||
|
private Operation operation;
|
||||||
|
|
||||||
|
private Map<String, String> properties;
|
||||||
|
|
||||||
|
public NotificationContext(DeviceIdentifier deviceId) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public NotificationContext(DeviceIdentifier deviceId, Operation operation) {
|
||||||
|
this.deviceId = deviceId;
|
||||||
|
this.operation = operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DeviceIdentifier getDeviceId() {
|
||||||
|
return deviceId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Operation getOperation() {
|
||||||
|
return operation;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,29 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.push.notification;
|
||||||
|
|
||||||
|
public interface NotificationStrategy {
|
||||||
|
|
||||||
|
void init();
|
||||||
|
|
||||||
|
void execute(NotificationContext ctx) throws PushNotificationExecutionFailedException;
|
||||||
|
|
||||||
|
NotificationContext buildContext();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.push.notification;
|
||||||
|
|
||||||
|
public class PushNotificationExecutionFailedException extends Exception {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3151279311923070297L;
|
||||||
|
|
||||||
|
public PushNotificationExecutionFailedException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationExecutionFailedException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationExecutionFailedException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationExecutionFailedException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationExecutionFailedException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,27 @@
|
|||||||
|
/*
|
||||||
|
* 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.common.push.notification;
|
||||||
|
|
||||||
|
public interface PushNotificationProvider {
|
||||||
|
|
||||||
|
String getType();
|
||||||
|
|
||||||
|
NotificationStrategy getNotificationStrategy(PushNotificationConfig config);
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.operation.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.operation.mgt.OperationManager;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class OperationManagerRepository {
|
||||||
|
|
||||||
|
private Map<String, OperationManager> operationManagers;
|
||||||
|
|
||||||
|
public OperationManagerRepository() {
|
||||||
|
operationManagers = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addOperationManager(String type, OperationManager operationManager) {
|
||||||
|
operationManagers.put(type, operationManager);
|
||||||
|
}
|
||||||
|
|
||||||
|
public OperationManager getOperationManager(String type) {
|
||||||
|
return operationManagers.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeOperationManager(String type) {
|
||||||
|
operationManagers.remove(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,120 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.common.PaginationResult;
|
||||||
|
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.common.operation.mgt.OperationManager;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class PushNotificationBasedOperationManager implements OperationManager {
|
||||||
|
|
||||||
|
private OperationManager operationManager;
|
||||||
|
private NotificationStrategy notificationProvider;
|
||||||
|
|
||||||
|
public PushNotificationBasedOperationManager(
|
||||||
|
OperationManager operationManager, NotificationStrategy notificationProvider) {
|
||||||
|
this.operationManager = operationManager;
|
||||||
|
this.notificationProvider = notificationProvider;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addOperation(Operation operation,
|
||||||
|
List<DeviceIdentifier> devices) throws OperationManagementException {
|
||||||
|
int operationId = this.operationManager.addOperation(operation, devices);
|
||||||
|
for (DeviceIdentifier deviceId : devices) {
|
||||||
|
try {
|
||||||
|
this.notificationProvider.execute(new NotificationContext(deviceId));
|
||||||
|
} catch (PushNotificationExecutionFailedException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while sending push notification to device", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return operationId;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperations(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||||
|
return this.operationManager.getOperations(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public PaginationResult getOperations(DeviceIdentifier deviceId,
|
||||||
|
PaginationRequest request) throws OperationManagementException {
|
||||||
|
return this.operationManager.getOperations(deviceId, request);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getPendingOperations(
|
||||||
|
DeviceIdentifier deviceId) throws OperationManagementException {
|
||||||
|
return this.operationManager.getPendingOperations(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getNextPendingOperation(DeviceIdentifier deviceId) throws OperationManagementException {
|
||||||
|
return this.operationManager.getNextPendingOperation(deviceId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateOperation(DeviceIdentifier deviceId,
|
||||||
|
Operation operation) throws OperationManagementException {
|
||||||
|
this.operationManager.updateOperation(deviceId, operation);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void deleteOperation(int operationId) throws OperationManagementException {
|
||||||
|
this.operationManager.deleteOperation(operationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperationByDeviceAndOperationId(
|
||||||
|
DeviceIdentifier deviceId, int operationId) throws OperationManagementException {
|
||||||
|
return this.operationManager.getOperationByDeviceAndOperationId(deviceId, operationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<? extends Operation> getOperationsByDeviceAndStatus(
|
||||||
|
DeviceIdentifier deviceId,
|
||||||
|
Operation.Status status) throws OperationManagementException {
|
||||||
|
try {
|
||||||
|
return this.operationManager.getOperationsByDeviceAndStatus(deviceId, status);
|
||||||
|
} catch (DeviceManagementException e) {
|
||||||
|
throw new OperationManagementException("Error occurred while retrieving the list of operations by " +
|
||||||
|
"device and status", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperation(int operationId) throws OperationManagementException {
|
||||||
|
return this.operationManager.getOperation(operationId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Operation getOperationByActivityId(String activity) throws OperationManagementException {
|
||||||
|
return this.operationManager.getOperationByActivityId(activity);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class PushNotificationConfigRepository {
|
||||||
|
|
||||||
|
private Map<Integer, PushNotificationConfig> configs;
|
||||||
|
|
||||||
|
public PushNotificationConfigRepository() {
|
||||||
|
configs = new HashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addConfig(PushNotificationConfig config) {
|
||||||
|
configs.put(CarbonContext.getThreadLocalCarbonContext().getTenantId(), config);
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationConfig getConfig() {
|
||||||
|
return configs.get(CarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.NotificationStrategy;
|
||||||
|
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
|
||||||
|
|
||||||
|
public class PushNotificationEnabledDeviceManagementService {
|
||||||
|
|
||||||
|
public PushNotificationEnabledDeviceManagementService(
|
||||||
|
DeviceManagementService provider, NotificationStrategy strategy) {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,36 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
|
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
|
||||||
|
public class PushNotificationProviderFactory {
|
||||||
|
|
||||||
|
public static PushNotificationProvider getPushNotificationFactory(String type) {
|
||||||
|
PushNotificationProvider provider =
|
||||||
|
DeviceManagementDataHolder.getInstance().getPushNotificationProviderRepository().getProvider(type);
|
||||||
|
if (provider == null) {
|
||||||
|
throw new UnsupportedPushNotificationProviderException("Push notification type '" + type +
|
||||||
|
"' is not supported");
|
||||||
|
}
|
||||||
|
return provider;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationProvider;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.concurrent.ConcurrentHashMap;
|
||||||
|
|
||||||
|
public class PushNotificationProviderRepository {
|
||||||
|
|
||||||
|
private Map<String, PushNotificationProvider> providers;
|
||||||
|
private static final Log log = LogFactory.getLog(PushNotificationProviderRepository.class);
|
||||||
|
|
||||||
|
public PushNotificationProviderRepository() {
|
||||||
|
this.providers = new ConcurrentHashMap<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProvider(PushNotificationProvider provider) {
|
||||||
|
providers.put(provider.getType(), provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addProvider(String className) {
|
||||||
|
try {
|
||||||
|
Class<?> clz = Class.forName(className);
|
||||||
|
PushNotificationProvider provider = (PushNotificationProvider) clz.newInstance();
|
||||||
|
providers.put(provider.getType(), provider);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.error("Provided push notification provider implementation '" + className + "' cannot be found", e);
|
||||||
|
} catch (InstantiationException e) {
|
||||||
|
log.error("Error occurred while instantiating push notification provider implementation '" +
|
||||||
|
className + "'", e);
|
||||||
|
} catch (IllegalAccessException e) {
|
||||||
|
log.error("Error occurred while adding push notification provider implementation '" + className + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public PushNotificationProvider getProvider(String type) {
|
||||||
|
return providers.get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,45 @@
|
|||||||
|
/*
|
||||||
|
* 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.core.push.notification.mgt;
|
||||||
|
|
||||||
|
public class UnsupportedPushNotificationProviderException extends RuntimeException {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = -3151279321923070297L;
|
||||||
|
|
||||||
|
public UnsupportedPushNotificationProviderException(String msg, Exception nestedEx) {
|
||||||
|
super(msg, nestedEx);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPushNotificationProviderException(String message, Throwable cause) {
|
||||||
|
super(message, cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPushNotificationProviderException(String msg) {
|
||||||
|
super(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPushNotificationProviderException() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UnsupportedPushNotificationProviderException(Throwable cause) {
|
||||||
|
super(cause);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2014, 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.email.sender.core.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.io.FileUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.email.sender.core.EmailSenderConfigurationFailedException;
|
||||||
|
import org.wso2.carbon.registry.api.Collection;
|
||||||
|
import org.wso2.carbon.registry.api.Registry;
|
||||||
|
import org.wso2.carbon.registry.api.RegistryException;
|
||||||
|
import org.wso2.carbon.registry.api.Resource;
|
||||||
|
import org.wso2.carbon.utils.CarbonUtils;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FilenameFilter;
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
class EmailUtils {
|
||||||
|
|
||||||
|
private static final String EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH = "/email-templates";
|
||||||
|
private static Log log = LogFactory.getLog(EmailSenderServiceComponent.class);
|
||||||
|
|
||||||
|
static void setupEmailTemplates() throws EmailSenderConfigurationFailedException {
|
||||||
|
File templateDir =
|
||||||
|
new File(CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator +
|
||||||
|
"resources" + File.separator + "email-templates");
|
||||||
|
if (!templateDir.exists()) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("The directory that is expected to use as the container for all email templates is not " +
|
||||||
|
"available. Therefore, no template is uploaded to the registry");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (templateDir.canRead()) {
|
||||||
|
File[] templates = templateDir.listFiles(new FilenameFilter() {
|
||||||
|
@Override
|
||||||
|
public boolean accept(File dir, String name) {
|
||||||
|
name = name.toLowerCase();
|
||||||
|
return name.endsWith(".vm");
|
||||||
|
}
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
Registry registry =
|
||||||
|
EmailSenderDataHolder.getInstance().getRegistryService().getConfigSystemRegistry(tenantId);
|
||||||
|
if (!registry.resourceExists(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH)) {
|
||||||
|
Collection collection = registry.newCollection();
|
||||||
|
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH, collection);
|
||||||
|
for (File template : templates) {
|
||||||
|
Resource resource = registry.newResource();
|
||||||
|
resource.setMediaType("text/plain");
|
||||||
|
String contents = FileUtils.readFileToString(template);
|
||||||
|
resource.setContent(contents);
|
||||||
|
registry.put(EMAIL_TEMPLATE_DIR_RELATIVE_REGISTRY_PATH + "/"
|
||||||
|
+ template.getName().replace(".vm", ""), resource);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (RegistryException e) {
|
||||||
|
throw new EmailSenderConfigurationFailedException("Error occurred while setting up email templates", e);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
throw new EmailSenderConfigurationFailedException("Error occurred while writing template file " +
|
||||||
|
"contents as an input stream of a resource", e);
|
||||||
|
} catch (IOException e) {
|
||||||
|
throw new EmailSenderConfigurationFailedException("Error occurred while serializing file " +
|
||||||
|
"contents to a string", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>device-mgt-extensions-feature</artifactId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - GCM Based Push Notification Provider Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
@ -0,0 +1 @@
|
|||||||
|
instructions.configure = \
|
@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>device-mgt-extensions-feature</artifactId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - MQTT Based Push Notification Provider Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>WSO2 Carbon - MQTT Based Push Notification Provider Feature</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
@ -0,0 +1 @@
|
|||||||
|
instructions.configure = \
|
@ -0,0 +1,106 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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/maven-v4_0_0.xsd">
|
||||||
|
|
||||||
|
<parent>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>device-mgt-extensions-feature</artifactId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<name>WSO2 Carbon - XMPP Based Push Notification Provider Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
<description>WSO2 Carbon - XMPP Based Push Notification Provider Feature</description>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-resources-plugin</artifactId>
|
||||||
|
<version>2.6</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>copy-resources</id>
|
||||||
|
<phase>generate-resources</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>copy-resources</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<outputDirectory>src/main/resources</outputDirectory>
|
||||||
|
<resources>
|
||||||
|
<resource>
|
||||||
|
<directory>resources</directory>
|
||||||
|
<includes>
|
||||||
|
<include>build.properties</include>
|
||||||
|
<include>p2.inf</include>
|
||||||
|
</includes>
|
||||||
|
</resource>
|
||||||
|
</resources>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.wso2.maven</groupId>
|
||||||
|
<artifactId>carbon-p2-plugin</artifactId>
|
||||||
|
<version>${carbon.p2.plugin.version}</version>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>p2-feature-generation</id>
|
||||||
|
<phase>package</phase>
|
||||||
|
<goals>
|
||||||
|
<goal>p2-feature-gen</goal>
|
||||||
|
</goals>
|
||||||
|
<configuration>
|
||||||
|
<id>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp</id>
|
||||||
|
<propertiesFile>../../../features/etc/feature.properties</propertiesFile>
|
||||||
|
<adviceFile>
|
||||||
|
<properties>
|
||||||
|
<propertyDef>org.wso2.carbon.p2.category.type:server</propertyDef>
|
||||||
|
<propertyDef>org.eclipse.equinox.p2.type.group:false</propertyDef>
|
||||||
|
</properties>
|
||||||
|
</adviceFile>
|
||||||
|
<bundles>
|
||||||
|
<bundleDef>
|
||||||
|
org.wso2.carbon.devicemgt:org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp:${carbon.device.mgt.version}
|
||||||
|
</bundleDef>
|
||||||
|
</bundles>
|
||||||
|
<importFeatures>
|
||||||
|
<importFeatureDef>org.wso2.carbon.core.server:${carbon.kernel.version}</importFeatureDef>
|
||||||
|
<importFeatureDef>org.wso2.carbon.device.mgt.server:${carbon.device.mgt.version}</importFeatureDef>
|
||||||
|
</importFeatures>
|
||||||
|
</configuration>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</project>
|
@ -0,0 +1 @@
|
|||||||
|
custom = true
|
@ -0,0 +1 @@
|
|||||||
|
instructions.configure = \
|
@ -0,0 +1,41 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ 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.
|
||||||
|
-->
|
||||||
|
|
||||||
|
<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>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>carbon-devicemgt</artifactId>
|
||||||
|
<version>1.1.0-SNAPSHOT</version>
|
||||||
|
<relativePath>../../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>device-mgt-extensions-feature</artifactId>
|
||||||
|
<packaging>pom</packaging>
|
||||||
|
<name>WSO2 Carbon - Device Management Extensions Feature</name>
|
||||||
|
<url>http://wso2.org</url>
|
||||||
|
|
||||||
|
<modules>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.gcm.feature</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature</module>
|
||||||
|
<module>org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature</module>
|
||||||
|
</modules>
|
||||||
|
|
||||||
|
</project>
|
Loading…
Reference in new issue