forked from community/device-mgt-plugins
Merge branch 'cloud-3.1.0' of https://github.com/wso2/carbon-device-mgt-plugins into cloud-3.1.0
commit
f10e26f0a9
@ -1,72 +0,0 @@
|
|||||||
<?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-plugins</groupId>
|
|
||||||
<artifactId>iot-analytics</artifactId>
|
|
||||||
<version>3.0.3-SNAPSHOT</version>
|
|
||||||
<relativePath>../pom.xml</relativePath>
|
|
||||||
</parent>
|
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
|
||||||
<artifactId>org.wso2.carbon.iot.das.rest.api</artifactId>
|
|
||||||
<name>WSO2 Carbon - IoT Server REST API</name>
|
|
||||||
<packaging>pom</packaging>
|
|
||||||
|
|
||||||
<build>
|
|
||||||
<plugins>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.felix</groupId>
|
|
||||||
<artifactId>maven-scr-plugin</artifactId>
|
|
||||||
<executions>
|
|
||||||
<execution>
|
|
||||||
<id>generate-scr-descriptor</id>
|
|
||||||
<goals>
|
|
||||||
<goal>scr</goal>
|
|
||||||
</goals>
|
|
||||||
</execution>
|
|
||||||
</executions>
|
|
||||||
</plugin>
|
|
||||||
<plugin>
|
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
|
||||||
<artifactId>maven-surefire-plugin</artifactId>
|
|
||||||
</plugin>
|
|
||||||
<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>
|
|
||||||
<Private-Package>
|
|
||||||
</Private-Package>
|
|
||||||
<Export-Package>
|
|
||||||
</Export-Package>
|
|
||||||
<Import-Package>
|
|
||||||
</Import-Package>
|
|
||||||
<DynamicImport-Package>*</DynamicImport-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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
var viewModel = {};
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||||
|
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/admin/devicetype/deploy/arduino/status";
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
url, function (responsePayload) {
|
||||||
|
var responseContent = responsePayload.status;
|
||||||
|
new Log().error(responseContent);
|
||||||
|
if ("204" == responsePayload.status) {
|
||||||
|
viewModel["displayStatus"] = "Display";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
//do nothing.
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return viewModel;
|
||||||
|
}
|
@ -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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
var viewModel = {};
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||||
|
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/admin/devicetype/deploy/raspberrypi/status";
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
url, function (responsePayload) {
|
||||||
|
var responseContent = responsePayload.status;
|
||||||
|
new Log().error(responseContent);
|
||||||
|
if ("204" == responsePayload.status) {
|
||||||
|
viewModel["displayStatus"] = "Display";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
//do nothing.
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return viewModel;
|
||||||
|
}
|
@ -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.
|
||||||
|
*/
|
||||||
|
|
||||||
|
function onRequest(context){
|
||||||
|
var viewModel = {};
|
||||||
|
var devicemgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
||||||
|
var serviceInvokers = require("/app/modules/oauth/token-protected-service-invokers.js")["invokers"];
|
||||||
|
var url = devicemgtProps["httpsURL"] + "/api/device-mgt/v1.0/admin/devicetype/deploy/virtual_firealarm/status";
|
||||||
|
serviceInvokers.XMLHttp.get(
|
||||||
|
url, function (responsePayload) {
|
||||||
|
var responseContent = responsePayload.status;
|
||||||
|
new Log().error(responseContent);
|
||||||
|
if ("204" == responsePayload.status) {
|
||||||
|
viewModel["displayStatus"] = "Display";
|
||||||
|
}
|
||||||
|
},
|
||||||
|
function (responsePayload) {
|
||||||
|
//do nothing.
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return viewModel;
|
||||||
|
}
|
@ -0,0 +1,125 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<!--
|
||||||
|
~ Copyright (c) 2017, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
~
|
||||||
|
~ Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
~ you may not use this file except in compliance with the License.
|
||||||
|
~ You may obtain a copy of the License at
|
||||||
|
~
|
||||||
|
~ http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
~
|
||||||
|
~ Unless required by applicable law or agreed to in writing, software
|
||||||
|
~ distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
~ See the License for the specific language governing permissions and
|
||||||
|
~ limitations under the License.
|
||||||
|
-->
|
||||||
|
<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-plugins</groupId>
|
||||||
|
<artifactId>appm-connector</artifactId>
|
||||||
|
<version>3.0.12-SNAPSHOT</version>
|
||||||
|
<relativePath>../pom.xml</relativePath>
|
||||||
|
</parent>
|
||||||
|
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
<artifactId>org.wso2.carbon.appmgt.mdm.restconnector</artifactId>
|
||||||
|
<packaging>bundle</packaging>
|
||||||
|
<name>WSO2 Carbon - App Manager WSO2 MDM REST Connector Component</name>
|
||||||
|
<url>http://maven.apache.org</url>
|
||||||
|
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<groupId>org.apache.felix</groupId>
|
||||||
|
<artifactId>maven-scr-plugin</artifactId>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<id>generate-scr-scrdescriptor</id>
|
||||||
|
<goals>
|
||||||
|
<goal>scr</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
<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>
|
||||||
|
<Private-Package>org.wso2.carbon.appmgt.mdm.restconnector.internal</Private-Package>
|
||||||
|
<Import-Package>
|
||||||
|
org.osgi.framework,
|
||||||
|
org.osgi.service.component,
|
||||||
|
org.wso2.carbon.appmgt.mobile.utils.*,
|
||||||
|
org.wso2.carbon.appmgt.mobile.mdm.*,
|
||||||
|
org.wso2.carbon.appmgt.mobile.interfaces.*,
|
||||||
|
org.apache.commons.*,
|
||||||
|
org.wso2.carbon.user.core.service,
|
||||||
|
org.wso2.carbon.user.core.tenant,
|
||||||
|
org.wso2.carbon.user.api,
|
||||||
|
feign,
|
||||||
|
feign.auth,
|
||||||
|
feign.codec,
|
||||||
|
feign.gson,
|
||||||
|
org.json.simple.*,
|
||||||
|
org.wso2.carbon.appmgt.mobile.beans,
|
||||||
|
org.wso2.carbon.context
|
||||||
|
</Import-Package>
|
||||||
|
<Export-Package>
|
||||||
|
!org.wso2.carbon.appmgt.mdm.restconnector.internal,
|
||||||
|
org.wso2.carbon.appmgt.mdm.restconnector.*
|
||||||
|
</Export-Package>
|
||||||
|
<Embed-Dependency>
|
||||||
|
jsr311-api,
|
||||||
|
feign-jaxrs
|
||||||
|
</Embed-Dependency>
|
||||||
|
</instructions>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
|
||||||
|
<dependencies>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple.wso2</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.logging</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.devicemgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.identity.jwt.client.extension</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-core</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.github.openfeign</groupId>
|
||||||
|
<artifactId>feign-gson</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>javax.ws.rs</groupId>
|
||||||
|
<artifactId>jsr311-api</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.swagger</groupId>
|
||||||
|
<artifactId>swagger-jaxrs</artifactId>
|
||||||
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.wso2.carbon.appmgt</groupId>
|
||||||
|
<artifactId>org.wso2.carbon.appmgt.mobile</artifactId>
|
||||||
|
</dependency>
|
||||||
|
</dependencies>
|
||||||
|
|
||||||
|
</project>
|
@ -0,0 +1,274 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector;
|
||||||
|
|
||||||
|
import feign.Feign;
|
||||||
|
import feign.gson.GsonDecoder;
|
||||||
|
import feign.gson.GsonEncoder;
|
||||||
|
import feign.jaxrs.JAXRSContract;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.simple.JSONObject;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.OAuthRequestInterceptor;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Activity;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApplicationManagementAdminService;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApplicationWrapper;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.DeviceManagementAdminService;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.MobileApp;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.MobileAppTypes;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.config.AuthorizationConfigurationManager;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationAction;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.beans.ApplicationOperationDevice;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.mdm.App;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.mdm.Device;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.utils.MobileApplicationException;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.utils.MobileConfigurations;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
public class ApplicationOperationsImpl implements ApplicationOperations {
|
||||||
|
private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0";
|
||||||
|
private static DeviceManagementAdminService deviceManagementAdminService;
|
||||||
|
private static final Log log = LogFactory.getLog(ApplicationOperationsImpl.class);
|
||||||
|
private static ApplicationManagementAdminService applicationManagementAdminService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor.
|
||||||
|
*/
|
||||||
|
public ApplicationOperationsImpl() {
|
||||||
|
String authorizationConfigManagerServerURL = AuthorizationConfigurationManager.getInstance().getServerURL();
|
||||||
|
OAuthRequestInterceptor oAuthRequestInterceptor = new OAuthRequestInterceptor();
|
||||||
|
deviceManagementAdminService = Feign.builder()
|
||||||
|
.requestInterceptor(oAuthRequestInterceptor)
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(DeviceManagementAdminService.class,
|
||||||
|
authorizationConfigManagerServerURL + CDMF_SERVER_BASE_CONTEXT);
|
||||||
|
applicationManagementAdminService = Feign.builder()
|
||||||
|
.requestInterceptor(oAuthRequestInterceptor)
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(ApplicationManagementAdminService.class,
|
||||||
|
authorizationConfigManagerServerURL + CDMF_SERVER_BASE_CONTEXT);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install, uninstall, reinstall application in devices.
|
||||||
|
*
|
||||||
|
* @param applicationOperationAction {@link ApplicationOperationAction} object
|
||||||
|
* @return Activity id
|
||||||
|
* @throws MobileApplicationException on errors while trying to perform action in devices
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public String performAction(ApplicationOperationAction applicationOperationAction)
|
||||||
|
throws MobileApplicationException {
|
||||||
|
ApplicationWrapper applicationWrapper = new ApplicationWrapper();
|
||||||
|
MobileApp mobileApp = new MobileApp();
|
||||||
|
|
||||||
|
String type = applicationOperationAction.getType();
|
||||||
|
String[] params = applicationOperationAction.getParams();
|
||||||
|
int tenantId = applicationOperationAction.getTenantId();
|
||||||
|
|
||||||
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(tenantId);
|
||||||
|
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||||
|
List<org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device> deviceList;
|
||||||
|
if (Constants.USER.equals(type)) {
|
||||||
|
String platform = applicationOperationAction.getApp().getPlatform();
|
||||||
|
String userName;
|
||||||
|
for (String param : params) {
|
||||||
|
userName = param;
|
||||||
|
deviceList = deviceManagementAdminService.getDevices(userName, null).getList();
|
||||||
|
|
||||||
|
for (org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device device : deviceList) {
|
||||||
|
if (Constants.WEBAPP.equals(platform) || platform.equalsIgnoreCase(device.getType())) {
|
||||||
|
if (Constants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) {
|
||||||
|
deviceIdentifiers.add(getDeviceIdentifierByDevice(device));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (Constants.ROLE.equals(type)) {
|
||||||
|
String userRole;
|
||||||
|
for (String param : applicationOperationAction.getParams()) {
|
||||||
|
userRole = param;
|
||||||
|
deviceList = deviceManagementAdminService.getDevices(null, userRole).getList();
|
||||||
|
for (org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device device : deviceList) {
|
||||||
|
if (Constants.ACTIVE.equalsIgnoreCase(device.getEnrolmentInfo().getStatus().toString())) {
|
||||||
|
deviceIdentifiers.add(getDeviceIdentifierByDevice(device));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (Constants.DEVICE.equals(type)) {
|
||||||
|
DeviceIdentifier deviceIdentifier;
|
||||||
|
for (String param : params) {
|
||||||
|
deviceIdentifier = new DeviceIdentifier();
|
||||||
|
if (isValidJSON(param)) {
|
||||||
|
JSONParser parser = new JSONParser();
|
||||||
|
try {
|
||||||
|
JSONObject parsedObj = (JSONObject) parser.parse(param);
|
||||||
|
deviceIdentifier.setId((String) parsedObj.get(Constants.ID));
|
||||||
|
String deviceType = (String) parsedObj.get(Constants.TYPE);
|
||||||
|
deviceIdentifier.setType(deviceType);
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
throw new MobileApplicationException("Device Identifier is not valid json object.", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
throw new IllegalStateException("Invalid type is received from app store.");
|
||||||
|
}
|
||||||
|
|
||||||
|
App app = applicationOperationAction.getApp();
|
||||||
|
mobileApp.setId(app.getId());
|
||||||
|
mobileApp.setType(MobileAppTypes.valueOf(app.getType().toUpperCase()));
|
||||||
|
mobileApp.setAppIdentifier(app.getAppIdentifier());
|
||||||
|
mobileApp.setIconImage(app.getIconImage());
|
||||||
|
mobileApp.setIdentifier(app.getIdentifier());
|
||||||
|
mobileApp.setLocation(app.getLocation());
|
||||||
|
mobileApp.setName(app.getName());
|
||||||
|
mobileApp.setPackageName(app.getPackageName());
|
||||||
|
mobileApp.setPlatform(app.getPlatform());
|
||||||
|
mobileApp.setVersion(app.getVersion());
|
||||||
|
Properties mobileAppProperties = new Properties();
|
||||||
|
|
||||||
|
if (Constants.IOS.equals(app.getPlatform())) {
|
||||||
|
if (Constants.ENTERPRISE.equals(app.getType())) {
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_REMOVE_APP, true);
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_PREVENT_BACKUP, true);
|
||||||
|
} else if (Constants.IOSConstants.PUBLIC.equals(app.getType())) {
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.I_TUNES_ID, app.getIdentifier());
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_REMOVE_APP, true);
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_PREVENT_BACKUP, true);
|
||||||
|
} else if (Constants.WEBAPP.equals(app.getType())) {
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.LABEL, app.getName());
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_REMOVE_APP, true);
|
||||||
|
}
|
||||||
|
} else if (Constants.WEBAPP.equals(app.getPlatform())) {
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.LABEL, app.getName());
|
||||||
|
mobileAppProperties.put(Constants.IOSConstants.IS_REMOVE_APP, true);
|
||||||
|
}
|
||||||
|
mobileApp.setProperties(mobileAppProperties);
|
||||||
|
applicationWrapper.setApplication(mobileApp);
|
||||||
|
Activity activity = null;
|
||||||
|
|
||||||
|
if (deviceIdentifiers.size() > 0) {
|
||||||
|
applicationWrapper.setDeviceIdentifiers(deviceIdentifiers);
|
||||||
|
if (Constants.INSTALL.equals(applicationOperationAction.getAction())) {
|
||||||
|
activity = applicationManagementAdminService.installApplication(applicationWrapper);
|
||||||
|
} else if (Constants.UPDATE.equals(applicationOperationAction.getAction())) {
|
||||||
|
activity = applicationManagementAdminService.installApplication(applicationWrapper);
|
||||||
|
} else {
|
||||||
|
activity = applicationManagementAdminService.uninstallApplication(applicationWrapper);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (activity != null) {
|
||||||
|
return activity.getActivityId();
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get devices.
|
||||||
|
*
|
||||||
|
* @param applicationOperationDevice {@link ApplicationOperationAction} object
|
||||||
|
* @return list of {@link Device} objects
|
||||||
|
* @throws MobileApplicationException on errors while trying to get devices list
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public List<Device> getDevices(ApplicationOperationDevice applicationOperationDevice)
|
||||||
|
throws MobileApplicationException {
|
||||||
|
Map<String, String> queryParamsMap = new HashMap<>();
|
||||||
|
String platform = applicationOperationDevice.getPlatform();
|
||||||
|
String platformVersion = applicationOperationDevice.getPlatformVersion();
|
||||||
|
String userName = applicationOperationDevice.getCurrentUser().getUsername();
|
||||||
|
queryParamsMap.put(Constants.PLATFORM, platform);
|
||||||
|
queryParamsMap.put(Constants.PLATFORM_VERSION, platformVersion);
|
||||||
|
queryParamsMap.put(Constants.USER, userName);
|
||||||
|
String type = applicationOperationDevice.getType();
|
||||||
|
queryParamsMap.put(Constants.TYPE, type);
|
||||||
|
List<org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device> deviceList =
|
||||||
|
deviceManagementAdminService.getDevices(userName, null).getList();
|
||||||
|
|
||||||
|
List<Device> processedDevices = new ArrayList<>();
|
||||||
|
for (org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device device : deviceList) {
|
||||||
|
Device processedDevice = new Device();
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(device.getDeviceIdentifier().toString());
|
||||||
|
deviceIdentifier.setType(device.getType().toString());
|
||||||
|
processedDevice.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
processedDevice.setName(device.getName());
|
||||||
|
processedDevice.setModel(device.getName());
|
||||||
|
processedDevice.setType(device.getType());
|
||||||
|
String imgUrl;
|
||||||
|
if (Constants.ANDROID.equalsIgnoreCase((device.getType().toString()))) {
|
||||||
|
imgUrl = String.format(getActiveMDMProperties().get(Constants.PROPERTY_IMAGE_URL), Constants.NEXUS);
|
||||||
|
} else if (Constants.IOS.equalsIgnoreCase((device.getType().toString()))) {
|
||||||
|
imgUrl = String.format(getActiveMDMProperties().get(Constants.PROPERTY_IMAGE_URL), Constants.IPHONE);
|
||||||
|
} else {
|
||||||
|
imgUrl = String.format(getActiveMDMProperties().get(Constants.PROPERTY_IMAGE_URL), Constants.NONE);
|
||||||
|
}
|
||||||
|
processedDevice.setImage(imgUrl);
|
||||||
|
processedDevice.setPlatform(device.getType().toString());
|
||||||
|
processedDevices.add(processedDevice);
|
||||||
|
}
|
||||||
|
return processedDevices;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private HashMap<String, String> getActiveMDMProperties() {
|
||||||
|
MobileConfigurations configurations = MobileConfigurations.getInstance();
|
||||||
|
return configurations.getActiveMDMProperties();
|
||||||
|
}
|
||||||
|
|
||||||
|
private static DeviceIdentifier getDeviceIdentifierByDevice(
|
||||||
|
org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.Device device) {
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(device.getDeviceIdentifier());
|
||||||
|
deviceIdentifier.setType(device.getType());
|
||||||
|
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean isValidJSON(String json) {
|
||||||
|
JSONParser parser = new JSONParser();
|
||||||
|
try {
|
||||||
|
parser.parse(json);
|
||||||
|
} catch (ParseException e) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void logError(String errorMessage, Throwable e) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.error(errorMessage, e);
|
||||||
|
} else {
|
||||||
|
log.error(errorMessage);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,108 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector;
|
||||||
|
|
||||||
|
public class Constants {
|
||||||
|
public static final String PROPERTY_SERVER_URL = "ServerURL";
|
||||||
|
public static final String PROPERTY_TOKEN_API_URL = "TokenApiURL";
|
||||||
|
public static final String PROPERTY_IMAGE_URL = "ImageURL";
|
||||||
|
public static final String PROPERTY_TOKEN_REFRESH_TIME_OFFSET = "TokenRefreshTimeOffset";
|
||||||
|
public static final String PROPERTY_USERNAME = "Username";
|
||||||
|
public static final String PROPERTY_PASSWORD = "Password";
|
||||||
|
|
||||||
|
public static final String USER = "user";
|
||||||
|
public static final String ROLE = "role";
|
||||||
|
public static final String USERS = USER + "s";
|
||||||
|
public static final String ROLES = ROLE + "s";
|
||||||
|
public static final String ANDROID = "android";
|
||||||
|
public static final String IOS = "ios";
|
||||||
|
public static final String WEBAPP = "webapp";
|
||||||
|
public static final String PLATFORM = "platform";
|
||||||
|
public static final String PLATFORM_VERSION = "platformVersion";
|
||||||
|
public static final String PROPERTIES = "properties";
|
||||||
|
public static final String TYPE = "type";
|
||||||
|
public static final String TYPES = TYPE + "s";
|
||||||
|
public static final String ID = "id";
|
||||||
|
public static final String NAME = "name";
|
||||||
|
public static final String USER_LIST = "userList";
|
||||||
|
public static final String DEVICE_IDENTIFIER = "deviceIdentifier";
|
||||||
|
public static final String DEVICE_IDENTIFIERS = DEVICE_IDENTIFIER + "s";
|
||||||
|
public static final String DEVICES = "devices";
|
||||||
|
public static final String APPLICATION = "application";
|
||||||
|
public static final String NEXUS = "nexus";
|
||||||
|
public static final String IPHONE = "iphone";
|
||||||
|
public static final String NONE = "none";
|
||||||
|
public static final String INSTALL = "install";
|
||||||
|
public static final String UPDATE = "update";
|
||||||
|
public static final String MOBILE_DEVICE = "mobileDevice";
|
||||||
|
public static final String ENTERPRISE = "enterprise";
|
||||||
|
public static final String ACTIVE = "active";
|
||||||
|
public static final String DEVICE = "device";
|
||||||
|
|
||||||
|
|
||||||
|
public class IOSConstants {
|
||||||
|
|
||||||
|
private IOSConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String IS_REMOVE_APP = "isRemoveApp";
|
||||||
|
public static final String IS_PREVENT_BACKUP = "isPreventBackup";
|
||||||
|
public static final String I_TUNES_ID = "iTunesId";
|
||||||
|
public static final String LABEL = "label";
|
||||||
|
public static final String PUBLIC = "public";
|
||||||
|
public static final String OPCODE_INSTALL_ENTERPRISE_APPLICATION =
|
||||||
|
"INSTALL_ENTERPRISE_APPLICATION";
|
||||||
|
public static final String OPCODE_INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
|
||||||
|
public static final String OPCODE_INSTALL_WEB_APPLICATION = "WEB_CLIP";
|
||||||
|
public static final String OPCODE_REMOVE_APPLICATION = "REMOVE_APPLICATION";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class AndroidConstants {
|
||||||
|
private AndroidConstants() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String OPCODE_INSTALL_APPLICATION = "INSTALL_APPLICATION";
|
||||||
|
public static final String OPCODE_UPDATE_APPLICATION = "UPDATE_APPLICATION";
|
||||||
|
public static final String OPCODE_UNINSTALL_APPLICATION = "UNINSTALL_APPLICATION";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class WebAppConstants {
|
||||||
|
public static final String WEBAPP = "webapp";
|
||||||
|
public static final String LABEL = "label";
|
||||||
|
public static final String IS_REMOVE_APP = "isRemoveApp";
|
||||||
|
public static final String NAME = "name";
|
||||||
|
}
|
||||||
|
|
||||||
|
public class RestConstants {
|
||||||
|
public static final String USERNAME = "username";
|
||||||
|
public static final String PASSWORD = "password";
|
||||||
|
public static final String AUTHORIZATION = "Authorization";
|
||||||
|
public static final String BEARER = "Bearer ";
|
||||||
|
public static final String BASIC = "Basic ";
|
||||||
|
public static final String COLON = ":";
|
||||||
|
public static final String GRANT_TYPE = "grant_type";
|
||||||
|
public static final String CONTENT_TYPE = "Content-Type";
|
||||||
|
public static final String ACCESS_TOKEN = "accessToken";
|
||||||
|
public static final String ACCEPT = "Accept";
|
||||||
|
public static final String APPLICATION_JSON = "application/json";
|
||||||
|
public static final String APPLICATION_FORM_URL_ENCODED = "application/x-www-form-urlencoded";
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client;
|
||||||
|
|
||||||
|
import feign.Feign;
|
||||||
|
import feign.RequestInterceptor;
|
||||||
|
import feign.RequestTemplate;
|
||||||
|
import feign.auth.BasicAuthRequestInterceptor;
|
||||||
|
import feign.gson.GsonDecoder;
|
||||||
|
import feign.gson.GsonEncoder;
|
||||||
|
import feign.jaxrs.JAXRSContract;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.Constants;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.AccessTokenInfo;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApiApplicationKey;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApiApplicationRegistrationService;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApiRegistrationProfile;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.TokenIssuerService;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.config.AuthorizationConfigurationManager;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.internal.AuthorizationDataHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a request interceptor to add oauth token header.
|
||||||
|
*/
|
||||||
|
public class OAuthRequestInterceptor implements RequestInterceptor {
|
||||||
|
private AccessTokenInfo tokenInfo;
|
||||||
|
private String refreshTimeOffset;
|
||||||
|
private static final String API_APPLICATION_REGISTRATION_CONTEXT = "/api-application-registration";
|
||||||
|
private static final String DEVICE_MANAGEMENT_SERVICE_TAG[] = {"device_management"};
|
||||||
|
private static final String APPLICATION_NAME = "appm_restconnector_application";
|
||||||
|
private static final String PASSWORD_GRANT_TYPE = "password";
|
||||||
|
private static final String REFRESH_GRANT_TYPE = "refresh_token";
|
||||||
|
private ApiApplicationRegistrationService apiApplicationRegistrationService;
|
||||||
|
private TokenIssuerService tokenIssuerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an interceptor that authenticates all requests.
|
||||||
|
*/
|
||||||
|
public OAuthRequestInterceptor() {
|
||||||
|
refreshTimeOffset = AuthorizationConfigurationManager.getInstance().getTokenRefreshTimeOffset();
|
||||||
|
String username = AuthorizationConfigurationManager.getInstance().getUserName();
|
||||||
|
String password = AuthorizationConfigurationManager.getInstance().getPassword();
|
||||||
|
apiApplicationRegistrationService = Feign.builder().requestInterceptor(
|
||||||
|
new BasicAuthRequestInterceptor(username, password))
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(ApiApplicationRegistrationService.class,
|
||||||
|
AuthorizationConfigurationManager.getInstance().getServerURL() +
|
||||||
|
API_APPLICATION_REGISTRATION_CONTEXT);
|
||||||
|
AuthorizationDataHolder.getInstance().setApiApplicationRegistrationService(apiApplicationRegistrationService);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Api create.
|
||||||
|
*
|
||||||
|
* @param template {@link RequestTemplate} object
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void apply(RequestTemplate template) {
|
||||||
|
if (tokenInfo == null) {
|
||||||
|
ApiRegistrationProfile apiRegistrationProfile = new ApiRegistrationProfile();
|
||||||
|
apiRegistrationProfile.setApplicationName(APPLICATION_NAME);
|
||||||
|
apiRegistrationProfile.setIsAllowedToAllDomains(false);
|
||||||
|
apiRegistrationProfile.setIsMappingAnExistingOAuthApp(false);
|
||||||
|
apiRegistrationProfile.setTags(DEVICE_MANAGEMENT_SERVICE_TAG);
|
||||||
|
ApiApplicationKey apiApplicationKey = apiApplicationRegistrationService.register(apiRegistrationProfile);
|
||||||
|
String consumerKey = apiApplicationKey.getConsumerKey();
|
||||||
|
String consumerSecret = apiApplicationKey.getConsumerSecret();
|
||||||
|
String username = AuthorizationConfigurationManager.getInstance().getUserName();
|
||||||
|
String password = AuthorizationConfigurationManager.getInstance().getPassword();
|
||||||
|
tokenIssuerService = Feign.builder().requestInterceptor(
|
||||||
|
new BasicAuthRequestInterceptor(consumerKey, consumerSecret))
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(TokenIssuerService.class, AuthorizationConfigurationManager.getInstance().getTokenApiURL());
|
||||||
|
tokenInfo = tokenIssuerService.getToken(PASSWORD_GRANT_TYPE, username, password);
|
||||||
|
tokenInfo.setExpires_in(System.currentTimeMillis() + tokenInfo.getExpires_in());
|
||||||
|
}
|
||||||
|
synchronized (this) {
|
||||||
|
if (System.currentTimeMillis() + Long.parseLong(refreshTimeOffset) > tokenInfo.getExpires_in()) {
|
||||||
|
tokenInfo = tokenIssuerService.getToken(REFRESH_GRANT_TYPE, tokenInfo.getRefresh_token());
|
||||||
|
tokenInfo.setExpires_in(System.currentTimeMillis() + tokenInfo.getExpires_in());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String headerValue = Constants.RestConstants.BEARER + tokenInfo.getAccess_token();
|
||||||
|
template.header(Constants.RestConstants.AUTHORIZATION, headerValue);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,60 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold access token info that returned from the api call.
|
||||||
|
*/
|
||||||
|
public class AccessTokenInfo {
|
||||||
|
public String token_type;
|
||||||
|
public long expires_in;
|
||||||
|
public String refresh_token;
|
||||||
|
public String access_token;
|
||||||
|
|
||||||
|
public String getToken_type() {
|
||||||
|
return token_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken_type(String token_type) {
|
||||||
|
this.token_type = token_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpires_in() {
|
||||||
|
return expires_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpires_in(long expires_in) {
|
||||||
|
this.expires_in = expires_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRefresh_token() {
|
||||||
|
return refresh_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefresh_token(String refresh_token) {
|
||||||
|
this.refresh_token = refresh_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccess_token() {
|
||||||
|
return access_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccess_token(String access_token) {
|
||||||
|
this.access_token = access_token;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,63 @@
|
|||||||
|
/*
|
||||||
|
* 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
public class Activity {
|
||||||
|
|
||||||
|
public enum Type {
|
||||||
|
CONFIG, MESSAGE, INFO, COMMAND, PROFILE, POLICY
|
||||||
|
}
|
||||||
|
private String activityId;
|
||||||
|
private String code;
|
||||||
|
private Type type;
|
||||||
|
private String createdTimeStamp;
|
||||||
|
|
||||||
|
public String getActivityId() {
|
||||||
|
return activityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActivityId(String activityId) {
|
||||||
|
this.activityId = activityId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCode() {
|
||||||
|
return code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCode(String code) {
|
||||||
|
this.code = code;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Type getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(Type type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTimeStamp() {
|
||||||
|
return createdTimeStamp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTimeStamp(String createdTimeStamp) {
|
||||||
|
this.createdTimeStamp = createdTimeStamp;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds api application consumer key and secret.
|
||||||
|
*/
|
||||||
|
public class ApiApplicationKey {
|
||||||
|
private String client_id;
|
||||||
|
private String client_secret;
|
||||||
|
|
||||||
|
public String getConsumerKey() {
|
||||||
|
return this.client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_id(String consumerKey) {
|
||||||
|
this.client_id = consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return this.client_secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_secret(String consumerSecret) {
|
||||||
|
this.client_secret = consumerSecret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,42 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the application registration service that exposed for apimApplicationRegistration.
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("/register")
|
||||||
|
public interface ApiApplicationRegistrationService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to register api application.
|
||||||
|
*
|
||||||
|
* @param registrationProfile contains the necessary attributes that are needed in order to register an app
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
ApiApplicationKey register(ApiRegistrationProfile registrationProfile);
|
||||||
|
}
|
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the data that are required to register the oauth application.
|
||||||
|
*/
|
||||||
|
public class ApiRegistrationProfile {
|
||||||
|
public String applicationName;
|
||||||
|
public String tags[];
|
||||||
|
public boolean isAllowedToAllDomains;
|
||||||
|
public String consumerKey;
|
||||||
|
public String consumerSecret;
|
||||||
|
public boolean isMappingAnExistingOAuthApp;
|
||||||
|
|
||||||
|
public String getApplicationName() {
|
||||||
|
return applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationName(String applicationName) {
|
||||||
|
this.applicationName = applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getTags() {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTags(String[] tags) {
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllowedToAllDomains() {
|
||||||
|
return isAllowedToAllDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAllowedToAllDomains(boolean isAllowedToAllDomains) {
|
||||||
|
this.isAllowedToAllDomains = isAllowedToAllDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMappingAnExistingOAuthApp() {
|
||||||
|
return isMappingAnExistingOAuthApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsMappingAnExistingOAuthApp(boolean isMappingAnExistingOAuthApp) {
|
||||||
|
this.isMappingAnExistingOAuthApp = isMappingAnExistingOAuthApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerKey() {
|
||||||
|
return consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerKey(String consumerKey) {
|
||||||
|
this.consumerKey = consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return consumerSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerSecret(String consumerSecret) {
|
||||||
|
this.consumerSecret = consumerSecret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/admin/applications")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface provided the definition of the application management service.
|
||||||
|
*/
|
||||||
|
public interface ApplicationManagementAdminService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Install application.
|
||||||
|
*
|
||||||
|
* @param applicationWrapper {@link ApplicationWrapper} object
|
||||||
|
* @return {@link Activity} object
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/install-application")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
Activity installApplication(ApplicationWrapper applicationWrapper);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Uninstall application.
|
||||||
|
*
|
||||||
|
* @param applicationWrapper {@link ApplicationWrapper} object
|
||||||
|
* @return {@link Activity} object
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Path("/uninstall-application")
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
Activity uninstallApplication(ApplicationWrapper applicationWrapper);
|
||||||
|
}
|
@ -0,0 +1,65 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import org.wso2.carbon.appmgt.mobile.beans.DeviceIdentifier;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This DTO class is used to send application details and devices details to installation/uninstallation service.
|
||||||
|
*/
|
||||||
|
public class ApplicationWrapper {
|
||||||
|
private List<String> userNameList;
|
||||||
|
private List<String> roleNameList;
|
||||||
|
private List<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
private MobileApp application;
|
||||||
|
|
||||||
|
public List<String> getUserNameList() {
|
||||||
|
return userNameList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserNameList(List<String> userNameList) {
|
||||||
|
this.userNameList = userNameList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
||||||
|
return deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifiers(
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers) {
|
||||||
|
this.deviceIdentifiers = deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getRoleNameList() {
|
||||||
|
return roleNameList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRoleNameList(List<String> roleNameList) {
|
||||||
|
this.roleNameList = roleNameList;
|
||||||
|
}
|
||||||
|
|
||||||
|
public MobileApp getApplication() {
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplication(MobileApp application) {
|
||||||
|
this.application = application;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,121 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DTO class of device.
|
||||||
|
*/
|
||||||
|
public class Device implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1998101711L;
|
||||||
|
private int id;
|
||||||
|
private String name;
|
||||||
|
private String type;
|
||||||
|
private String description;
|
||||||
|
private String deviceIdentifier;
|
||||||
|
private EnrolmentInfo enrolmentInfo;
|
||||||
|
|
||||||
|
public Device() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceIdentifier() {
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||||
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnrolmentInfo getEnrolmentInfo() {
|
||||||
|
return enrolmentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnrolmentInfo(EnrolmentInfo enrolmentInfo) {
|
||||||
|
this.enrolmentInfo = enrolmentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static class Property {
|
||||||
|
|
||||||
|
private String name;
|
||||||
|
private String value;
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "device [" +
|
||||||
|
"name=" + name + ";" +
|
||||||
|
"type=" + type + ";" +
|
||||||
|
"description=" + description + ";" +
|
||||||
|
"identifier=" + deviceIdentifier + ";" +
|
||||||
|
"EnrolmentInfo[" +
|
||||||
|
"owner=" + enrolmentInfo.getOwner() + ";" +
|
||||||
|
"ownership=" + enrolmentInfo.getOwnership() + ";" +
|
||||||
|
"status=" + enrolmentInfo.getStatus() + ";" +
|
||||||
|
"]" +
|
||||||
|
"]";
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,53 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DeviceList {
|
||||||
|
private List<Device> devices = new ArrayList<>();
|
||||||
|
private int count;
|
||||||
|
|
||||||
|
public int getCount() {
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCount(int count) {
|
||||||
|
this.count = count;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<Device> getList() {
|
||||||
|
return devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setList(List<Device> devices) {
|
||||||
|
this.devices = devices;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
StringBuilder sb = new StringBuilder();
|
||||||
|
sb.append("{\n");
|
||||||
|
|
||||||
|
sb.append(" count: ").append(getCount()).append(",\n");
|
||||||
|
sb.append(" devices: [").append(devices).append("\n");
|
||||||
|
sb.append("]}\n");
|
||||||
|
return sb.toString();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.GET;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/devices")
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This interface provided the definition of the device management service.
|
||||||
|
*/
|
||||||
|
public interface DeviceManagementAdminService {
|
||||||
|
/**
|
||||||
|
* Get devices.
|
||||||
|
*
|
||||||
|
* @param user Username
|
||||||
|
* @param role Role of the user
|
||||||
|
* @return {@link DeviceList} object
|
||||||
|
*/
|
||||||
|
@GET
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
DeviceList getDevices(@QueryParam("user") String user, @QueryParam("role") String role);
|
||||||
|
}
|
@ -0,0 +1,118 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DTO class for enrollment information.
|
||||||
|
*/
|
||||||
|
public class EnrolmentInfo implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1998101712L;
|
||||||
|
|
||||||
|
public enum Status {
|
||||||
|
CREATED, ACTIVE, INACTIVE, UNREACHABLE, UNCLAIMED, SUSPENDED, BLOCKED, REMOVED, DISENROLLMENT_REQUESTED
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum OwnerShip {
|
||||||
|
BYOD, COPE
|
||||||
|
}
|
||||||
|
|
||||||
|
private int id;
|
||||||
|
private OwnerShip ownership;
|
||||||
|
private Status status;
|
||||||
|
private String owner;
|
||||||
|
private Long dateOfEnrolment;
|
||||||
|
private Long dateOfLastUpdate;
|
||||||
|
|
||||||
|
public EnrolmentInfo() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public EnrolmentInfo(String owner, OwnerShip ownership, Status status) {
|
||||||
|
this.owner = owner;
|
||||||
|
this.ownership = ownership;
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDateOfEnrolment() {
|
||||||
|
return dateOfEnrolment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateOfEnrolment(Long dateOfEnrolment) {
|
||||||
|
this.dateOfEnrolment = dateOfEnrolment;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getDateOfLastUpdate() {
|
||||||
|
return dateOfLastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDateOfLastUpdate(Long dateOfLastUpdate) {
|
||||||
|
this.dateOfLastUpdate = dateOfLastUpdate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public OwnerShip getOwnership() {
|
||||||
|
return ownership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwnership(OwnerShip ownership) {
|
||||||
|
this.ownership = ownership;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Status getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(Status status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(String owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object obj) {
|
||||||
|
if (obj instanceof EnrolmentInfo) {
|
||||||
|
EnrolmentInfo tempInfo = (EnrolmentInfo) obj;
|
||||||
|
if (this.owner != null && this.ownership != null) {
|
||||||
|
if (this.owner.equals(tempInfo.getOwner()) && this.ownership.equals(tempInfo.getOwnership())) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return owner.hashCode() ^ ownership.hashCode();
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,126 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.util.Properties;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the generic mobile Application information which is used by AppM.
|
||||||
|
*/
|
||||||
|
public class MobileApp {
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String name;
|
||||||
|
private MobileAppTypes type;
|
||||||
|
private String platform;
|
||||||
|
private String version;
|
||||||
|
private String identifier;
|
||||||
|
private String iconImage;
|
||||||
|
private String packageName;
|
||||||
|
private String appIdentifier;
|
||||||
|
private String location;
|
||||||
|
private Properties properties;
|
||||||
|
|
||||||
|
public MobileAppTypes getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(MobileAppTypes type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPlatform() {
|
||||||
|
return platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPlatform(String platform) {
|
||||||
|
this.platform = platform;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIdentifier() {
|
||||||
|
return identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIdentifier(String identifier) {
|
||||||
|
this.identifier = identifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconImage() {
|
||||||
|
return iconImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIconImage(String iconImage) {
|
||||||
|
this.iconImage = iconImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAppIdentifier() {
|
||||||
|
return appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppIdentifier(String appIdentifier) {
|
||||||
|
this.appIdentifier = appIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLocation() {
|
||||||
|
return location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLocation(String location) {
|
||||||
|
this.location = location;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Properties getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(Properties properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,25 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This enum contains the mobile app types.
|
||||||
|
*/
|
||||||
|
public enum MobileAppTypes {
|
||||||
|
ENTERPRISE, WEBAPP, PUBLIC
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.authorization.client.dto;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold the api definition that is used as a contract with netflix feign.
|
||||||
|
*/
|
||||||
|
@Path("/token")
|
||||||
|
public interface TokenIssuerService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a token for password grant type.
|
||||||
|
* @param grant Token grant type
|
||||||
|
* @param username Username
|
||||||
|
* @param password Password
|
||||||
|
* @return {@link AccessTokenInfo} object
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("username") String username,
|
||||||
|
@QueryParam("password") String password);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a token for refresh grant type.
|
||||||
|
* @param grant Token grant type
|
||||||
|
* @param refreshToken Refresh token
|
||||||
|
* @return {@link AccessTokenInfo} object
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("refreshToken") String refreshToken);
|
||||||
|
}
|
@ -0,0 +1,110 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.config;
|
||||||
|
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.Constants;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.utils.MobileConfigurations;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The DTO class to AuthorizationConfigurationManager.
|
||||||
|
*/
|
||||||
|
public class AuthorizationConfigurationManager {
|
||||||
|
private String tokenApiURL;
|
||||||
|
private String imageURL;
|
||||||
|
private String serverURL;
|
||||||
|
private String userName;
|
||||||
|
private String password;
|
||||||
|
private String tokenRefreshTimeOffset;
|
||||||
|
|
||||||
|
private static AuthorizationConfigurationManager authorizationConfigurationManager = new
|
||||||
|
AuthorizationConfigurationManager();
|
||||||
|
|
||||||
|
private AuthorizationConfigurationManager() {
|
||||||
|
MobileConfigurations configurations = MobileConfigurations.getInstance();
|
||||||
|
HashMap<String, String> configProperties = configurations.getActiveMDMProperties();
|
||||||
|
setTokenApiURL(configProperties.get(Constants.PROPERTY_TOKEN_API_URL));
|
||||||
|
setImageURL(configProperties.get(Constants.PROPERTY_IMAGE_URL));
|
||||||
|
setServerURL(configProperties.get(Constants.PROPERTY_SERVER_URL));
|
||||||
|
setUserName(configProperties.get(Constants.PROPERTY_USERNAME));
|
||||||
|
setPassword(configProperties.get(Constants.PROPERTY_PASSWORD));
|
||||||
|
setTokenRefreshTimeOffset(configProperties.get(Constants.PROPERTY_TOKEN_REFRESH_TIME_OFFSET));
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AuthorizationConfigurationManager getInstance() {
|
||||||
|
return authorizationConfigurationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTokenApiURL() {
|
||||||
|
return tokenApiURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenApiURL(String tokenApiURL) {
|
||||||
|
this.tokenApiURL = tokenApiURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getImageURL() {
|
||||||
|
return imageURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setImageURL(String imageURL) {
|
||||||
|
this.imageURL = imageURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUserName() {
|
||||||
|
return userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserName(String userName) {
|
||||||
|
this.userName = userName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getServerURL() {
|
||||||
|
return serverURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setServerURL(String serverURL) {
|
||||||
|
this.serverURL = serverURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AuthorizationConfigurationManager getAuthorizationConfigurationManager() {
|
||||||
|
return authorizationConfigurationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void setAuthorizationConfigurationManager(
|
||||||
|
AuthorizationConfigurationManager authorizationConfigurationManager) {
|
||||||
|
AuthorizationConfigurationManager.authorizationConfigurationManager = authorizationConfigurationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTokenRefreshTimeOffset() {
|
||||||
|
return tokenRefreshTimeOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenRefreshTimeOffset(String tokenRefreshTimeOffset) {
|
||||||
|
this.tokenRefreshTimeOffset = tokenRefreshTimeOffset;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,43 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.authorization.client.dto.ApiApplicationRegistrationService;
|
||||||
|
|
||||||
|
public class AuthorizationDataHolder {
|
||||||
|
private static AuthorizationDataHolder thisInstance = new AuthorizationDataHolder();
|
||||||
|
|
||||||
|
private ApiApplicationRegistrationService apiApplicationRegistrationService;
|
||||||
|
|
||||||
|
private AuthorizationDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static AuthorizationDataHolder getInstance() {
|
||||||
|
return thisInstance;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ApiApplicationRegistrationService getApiApplicationRegistrationService() {
|
||||||
|
return apiApplicationRegistrationService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiApplicationRegistrationService(
|
||||||
|
ApiApplicationRegistrationService apiApplicationRegistrationService) {
|
||||||
|
this.apiApplicationRegistrationService = apiApplicationRegistrationService;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
*
|
||||||
|
* Copyright (c) 2017, 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.appmgt.mdm.restconnector.internal;
|
||||||
|
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.osgi.framework.BundleContext;
|
||||||
|
import org.osgi.framework.ServiceRegistration;
|
||||||
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import org.wso2.carbon.appmgt.mdm.restconnector.ApplicationOperationsImpl;
|
||||||
|
import org.wso2.carbon.appmgt.mobile.interfaces.ApplicationOperations;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="org.wso2.carbon.appmgt.mdm.restconnector" immediate="true"
|
||||||
|
*/
|
||||||
|
public class MDMComponent {
|
||||||
|
private static final Log log = LogFactory.getLog(MDMComponent.class);
|
||||||
|
private ServiceRegistration mdmServiceRegistration;
|
||||||
|
|
||||||
|
protected void activate(ComponentContext context) {
|
||||||
|
BundleContext bundleContext = context.getBundleContext();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("WSO2MDM MDM Component activated");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
mdmServiceRegistration = bundleContext.registerService(ApplicationOperations.class.getName(), new
|
||||||
|
ApplicationOperationsImpl(), null);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Failed to activate org.wso2.carbon.appmgt.mdm.restconnector.internal." +
|
||||||
|
"MDMComponent : " + e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void deactivate(ComponentContext context) {
|
||||||
|
if (mdmServiceRegistration != null) {
|
||||||
|
mdmServiceRegistration.unregister();
|
||||||
|
mdmServiceRegistration = null;
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("WSO2MDM MDM Component deactivated");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,34 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.input.adapter.extension;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold the input adapter extension service.
|
||||||
|
*/
|
||||||
|
public interface InputAdapterExtensionService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return content validator for the given type.
|
||||||
|
* @param type type of the content validator
|
||||||
|
* @return content validator for the given type.
|
||||||
|
*/
|
||||||
|
ContentValidator getContentValidator(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return default content validator for the given type.
|
||||||
|
* @return default content validator for the given type.
|
||||||
|
*/
|
||||||
|
ContentValidator getDefaultContentValidator();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return content transformer for the given type.
|
||||||
|
* @param type of the content transfomer
|
||||||
|
* @return content transformer for the given type.
|
||||||
|
*/
|
||||||
|
ContentTransformer getContentTransformer(String type);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* return default content transformer for the given type.
|
||||||
|
* @return default content transformer for the given type.
|
||||||
|
*/
|
||||||
|
ContentTransformer getDefaultContentTransformer();
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,31 @@
|
|||||||
|
package org.wso2.carbon.device.mgt.input.adapter.extension;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.internal.InputAdapterServiceDataHolder;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold the input adapter extension service implementation.
|
||||||
|
*/
|
||||||
|
public class InputAdapterExtensionServiceImpl implements InputAdapterExtensionService {
|
||||||
|
private static final String DEFAULT = "default";
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentValidator getContentValidator(String type) {
|
||||||
|
return InputAdapterServiceDataHolder.getInstance().getContentValidatorMap().get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentValidator getDefaultContentValidator() {
|
||||||
|
return InputAdapterServiceDataHolder.getInstance().getContentValidatorMap().get(DEFAULT);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentTransformer getContentTransformer(String type) {
|
||||||
|
return InputAdapterServiceDataHolder.getInstance().getContentTransformerMap().get(type);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentTransformer getDefaultContentTransformer() {
|
||||||
|
return InputAdapterServiceDataHolder.getInstance().getContentTransformerMap().get(DEFAULT);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,96 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.extension.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.input.adapter.extension.ContentTransformer;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionService;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.InputAdapterExtensionServiceImpl;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.transformer.DefaultContentTransformer;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.validator.DefaultContentValidator;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.validator.HTTPContentValidator;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.validator.MQTTContentValidator;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @scr.component name="input.adapter.extension.adapterService.component" immediate="true"
|
||||||
|
* @scr.reference name="InputAdapterServiceComponent.service"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator"
|
||||||
|
* cardinality="0..n"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setContentValidator"
|
||||||
|
* unbind="unsetContentValidator"
|
||||||
|
* * @scr.reference name="InputAdapterServiceComponent.service"
|
||||||
|
* interface="org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer"
|
||||||
|
* cardinality="0..n"
|
||||||
|
* policy="dynamic"
|
||||||
|
* bind="setContentTransformer"
|
||||||
|
* unbind="unsetContentTransformer"
|
||||||
|
*/
|
||||||
|
public class InputAdapterServiceComponent {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(
|
||||||
|
InputAdapterServiceComponent.class);
|
||||||
|
|
||||||
|
protected void activate(ComponentContext context) {
|
||||||
|
try {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Successfully deployed the input adapter extension service");
|
||||||
|
}
|
||||||
|
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentTransformer(new DefaultContentTransformer());
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentValidator(new DefaultContentValidator());
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentValidator(new HTTPContentValidator());
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentValidator(new MQTTContentValidator());
|
||||||
|
|
||||||
|
context.getBundleContext().registerService(InputAdapterExtensionService.class,
|
||||||
|
new InputAdapterExtensionServiceImpl(), null);
|
||||||
|
} catch (RuntimeException e) {
|
||||||
|
log.error("Can not create the input adapter service ", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setContentValidator(ContentValidator contentValidator) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting ContentValidator Service");
|
||||||
|
}
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentValidator(contentValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetContentValidator(ContentValidator contentValidator) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Un-setting ContentValidator Service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setContentTransformer(ContentTransformer contentTransformer) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Setting contentTransformer Service");
|
||||||
|
}
|
||||||
|
InputAdapterServiceDataHolder.getInstance().addContentTransformer(contentTransformer);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetContentValidator(ContentTransformer contentTransformer) {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Un-setting ContentTransformer Service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License"); you may not
|
||||||
|
* use this file except in compliance with the License. You may obtain a copy
|
||||||
|
* of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing, software distributed
|
||||||
|
* under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
|
||||||
|
* CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations under the License.
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.extension.internal;
|
||||||
|
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentTransformer;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* common place to hold some OSGI service references.
|
||||||
|
*/
|
||||||
|
public class InputAdapterServiceDataHolder {
|
||||||
|
|
||||||
|
private static InputAdapterServiceDataHolder inputAdapterServiceDataHolder = new InputAdapterServiceDataHolder();
|
||||||
|
private static Map<String, ContentValidator> contentValidatorMap = new HashMap<>();
|
||||||
|
private static Map<String, ContentTransformer> contentTransformerMap = new HashMap<>();
|
||||||
|
|
||||||
|
private InputAdapterServiceDataHolder() {
|
||||||
|
}
|
||||||
|
|
||||||
|
public static InputAdapterServiceDataHolder getInstance() {
|
||||||
|
return inputAdapterServiceDataHolder;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ContentValidator> getContentValidatorMap() {
|
||||||
|
return contentValidatorMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addContentValidator(ContentValidator contentValidator) {
|
||||||
|
InputAdapterServiceDataHolder.contentValidatorMap.put(contentValidator.getType(), contentValidator);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Map<String, ContentTransformer> getContentTransformerMap() {
|
||||||
|
return contentTransformerMap;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addContentTransformer(ContentTransformer contentTransformer) {
|
||||||
|
InputAdapterServiceDataHolder.contentTransformerMap.put(contentTransformer.getType(), contentTransformer);
|
||||||
|
}
|
||||||
|
}
|
12
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/DefaultContentTransformer.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/DefaultContentTransformer.java
12
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/DefaultContentTransformer.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/transformer/DefaultContentTransformer.java
11
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/DefaultContentValidator.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/DefaultContentValidator.java
11
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/DefaultContentValidator.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/DefaultContentValidator.java
@ -0,0 +1,87 @@
|
|||||||
|
/*
|
||||||
|
* 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.input.adapter.extension.validator;
|
||||||
|
|
||||||
|
import com.jayway.jsonpath.JsonPath;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.simple.JSONArray;
|
||||||
|
import org.json.simple.parser.JSONParser;
|
||||||
|
import org.json.simple.parser.ParseException;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
public class HTTPContentValidator implements ContentValidator {
|
||||||
|
private static final Log log = LogFactory.getLog(HTTPContentValidator.class);
|
||||||
|
private static String JSON_ARRAY_START_CHAR = "[";
|
||||||
|
private static String CDMF_SCOPE_PREFIX = "cdmf";
|
||||||
|
private static String CDMF_SCOPE_SEPERATOR = "/";
|
||||||
|
private static String CDMF_HTTP_CONTENT_VALIDATOR = "iot-http";
|
||||||
|
public static final String DEVICE_ID_JSON_PATH = "event.metaData.deviceId";
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getType() {
|
||||||
|
return CDMF_HTTP_CONTENT_VALIDATOR;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ContentInfo validate(Object msgPayload, Map<String, Object> dynamicParams) {
|
||||||
|
String deviceId = (String) dynamicParams.get("deviceId");
|
||||||
|
String msg = (String) msgPayload;
|
||||||
|
String deviceIdJsonPath = DEVICE_ID_JSON_PATH;
|
||||||
|
boolean status;
|
||||||
|
if (msg.startsWith(JSON_ARRAY_START_CHAR)) {
|
||||||
|
status = processMultipleEvents(msg, deviceId, deviceIdJsonPath);
|
||||||
|
} else {
|
||||||
|
status = processSingleEvent(msg, deviceId, deviceIdJsonPath);
|
||||||
|
}
|
||||||
|
return new ContentInfo(status, msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean processSingleEvent(String msg, String deviceIdFromTopic, String deviceIdJsonPath) {
|
||||||
|
Object res = JsonPath.read(msg, deviceIdJsonPath);
|
||||||
|
String deviceIdFromContent = (res != null) ? res.toString() : "";
|
||||||
|
if (deviceIdFromContent.equals(deviceIdFromTopic)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean processMultipleEvents(String msg, String deviceIdFromTopic, String deviceIdJsonPath) {
|
||||||
|
try {
|
||||||
|
JSONParser jsonParser = new JSONParser();
|
||||||
|
JSONArray jsonArray = (JSONArray) jsonParser.parse(msg);
|
||||||
|
boolean status = false;
|
||||||
|
for (int i = 0; i < jsonArray.size(); i++) {
|
||||||
|
status = processSingleEvent(jsonArray.get(i).toString(), deviceIdFromTopic, deviceIdJsonPath);
|
||||||
|
if (!status) {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return status;
|
||||||
|
} catch (ParseException e) {
|
||||||
|
log.error("Invalid input " + msg, e);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
18
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTContentValidator.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java
18
components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.mqtt/src/main/java/org/wso2/carbon/device/mgt/input/adapter/mqtt/util/MQTTContentValidator.java → components/extensions/cdmf-transport-adapters/input/org.wso2.carbon.device.mgt.input.adapter.extension/src/main/java/org/wso2/carbon/device/mgt/input/adapter/extension/validator/MQTTContentValidator.java
@ -0,0 +1,101 @@
|
|||||||
|
/*
|
||||||
|
* 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.input.adapter.http.authorization;
|
||||||
|
|
||||||
|
import feign.Feign;
|
||||||
|
import feign.FeignException;
|
||||||
|
import feign.gson.GsonDecoder;
|
||||||
|
import feign.gson.GsonEncoder;
|
||||||
|
import feign.jaxrs.JAXRSContract;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.OAuthRequestInterceptor;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.AuthorizationRequest;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.DeviceAccessAuthorizationAdminService;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.DeviceAuthorizationResult;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.DeviceIdentifier;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.util.AuthenticationInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.util.PropertyUtils;
|
||||||
|
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This authorizer crossvalidates the request with device id and device type.
|
||||||
|
*/
|
||||||
|
public class DeviceAuthorizer {
|
||||||
|
|
||||||
|
private static DeviceAccessAuthorizationAdminService deviceAccessAuthorizationAdminService;
|
||||||
|
private static final String CDMF_SERVER_BASE_CONTEXT = "/api/device-mgt/v1.0";
|
||||||
|
private static final String DEVICE_MGT_SERVER_URL = "deviceMgtServerUrl";
|
||||||
|
private static Log logger = LogFactory.getLog(DeviceAuthorizer.class);
|
||||||
|
|
||||||
|
public DeviceAuthorizer(Map<String, String> globalProperties) {
|
||||||
|
try {
|
||||||
|
deviceAccessAuthorizationAdminService = Feign.builder()
|
||||||
|
.requestInterceptor(new OAuthRequestInterceptor(globalProperties))
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(DeviceAccessAuthorizationAdminService.class, getDeviceMgtServerUrl(globalProperties)
|
||||||
|
+ CDMF_SERVER_BASE_CONTEXT);
|
||||||
|
} catch (InputEventAdapterException e) {
|
||||||
|
logger.error("Invalid value for deviceMgtServerUrl in globalProperties.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public boolean isAuthorized(AuthenticationInfo authenticationInfo, String deviceId, String deviceType) {
|
||||||
|
|
||||||
|
if (deviceId != null && !deviceId.isEmpty() && deviceType != null && !deviceType.isEmpty()) {
|
||||||
|
|
||||||
|
AuthorizationRequest authorizationRequest = new AuthorizationRequest();
|
||||||
|
authorizationRequest.setTenantDomain(authenticationInfo.getTenantDomain());
|
||||||
|
authorizationRequest.setUsername(authenticationInfo.getUsername());
|
||||||
|
DeviceIdentifier deviceIdentifier = new DeviceIdentifier();
|
||||||
|
deviceIdentifier.setId(deviceId);
|
||||||
|
deviceIdentifier.setType(deviceType);
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers = new ArrayList<>();
|
||||||
|
deviceIdentifiers.add(deviceIdentifier);
|
||||||
|
authorizationRequest.setDeviceIdentifiers(deviceIdentifiers);
|
||||||
|
try {
|
||||||
|
DeviceAuthorizationResult deviceAuthorizationResult =
|
||||||
|
deviceAccessAuthorizationAdminService.isAuthorized(authorizationRequest);
|
||||||
|
List<DeviceIdentifier> devices = deviceAuthorizationResult.getAuthorizedDevices();
|
||||||
|
if (devices != null && devices.size() > 0) {
|
||||||
|
DeviceIdentifier authorizedDevice = devices.get(0);
|
||||||
|
if (authorizedDevice.getId().equals(deviceId) && authorizedDevice.getType().equals(deviceType)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (FeignException e) {
|
||||||
|
logger.error(e.getMessage(), e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDeviceMgtServerUrl(Map<String, String> properties) throws InputEventAdapterException {
|
||||||
|
String deviceMgtServerUrl = PropertyUtils.replaceProperty(properties.get(DEVICE_MGT_SERVER_URL));
|
||||||
|
if (deviceMgtServerUrl == null || deviceMgtServerUrl.isEmpty()) {
|
||||||
|
logger.error("deviceMgtServerUrl can't be empty ");
|
||||||
|
}
|
||||||
|
return deviceMgtServerUrl;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,161 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client;
|
||||||
|
|
||||||
|
import feign.Feign;
|
||||||
|
import feign.RequestInterceptor;
|
||||||
|
import feign.RequestTemplate;
|
||||||
|
import feign.auth.BasicAuthRequestInterceptor;
|
||||||
|
import feign.gson.GsonDecoder;
|
||||||
|
import feign.gson.GsonEncoder;
|
||||||
|
import feign.jaxrs.JAXRSContract;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.AccessTokenInfo;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.ApiApplicationKey;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.ApiApplicationRegistrationService;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.ApiRegistrationProfile;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto.TokenIssuerService;
|
||||||
|
import org.wso2.carbon.device.mgt.input.adapter.http.util.PropertyUtils;
|
||||||
|
import org.wso2.carbon.event.input.adapter.core.exception.InputEventAdapterException;
|
||||||
|
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is a request interceptor to add oauth token header.
|
||||||
|
*/
|
||||||
|
public class OAuthRequestInterceptor implements RequestInterceptor {
|
||||||
|
|
||||||
|
private AccessTokenInfo tokenInfo;
|
||||||
|
private long refreshTimeOffset;
|
||||||
|
private static final String API_APPLICATION_REGISTRATION_CONTEXT = "/api-application-registration";
|
||||||
|
private static final String DEVICE_MANAGEMENT_SERVICE_TAG[] = {"device_management"};
|
||||||
|
private static final String APPLICATION_NAME = "websocket-app";
|
||||||
|
private static final String PASSWORD_GRANT_TYPE = "password";
|
||||||
|
private static final String REFRESH_GRANT_TYPE = "refresh_token";
|
||||||
|
private static final String REQUIRED_SCOPE = "perm:authorization:verify";
|
||||||
|
private ApiApplicationRegistrationService apiApplicationRegistrationService;
|
||||||
|
private TokenIssuerService tokenIssuerService;
|
||||||
|
|
||||||
|
private static Log logger = LogFactory.getLog(OAuthRequestInterceptor.class);
|
||||||
|
|
||||||
|
private static final String CONNECTION_USERNAME = "username";
|
||||||
|
private static final String CONNECTION_PASSWORD = "password";
|
||||||
|
private static final String TOKEN_REFRESH_TIME_OFFSET = "tokenRefreshTimeOffset";
|
||||||
|
private static final String TOKEN_SCOPES = "scopes";
|
||||||
|
private static final String DEVICE_MGT_SERVER_URL = "deviceMgtServerUrl";
|
||||||
|
private static final String TOKEN_ENDPOINT_CONTEXT = "tokenUrl";
|
||||||
|
private static String username;
|
||||||
|
private static String password;
|
||||||
|
private static String tokenEndpoint;
|
||||||
|
private static String deviceMgtServerUrl;
|
||||||
|
private static String scopes;
|
||||||
|
private static Map<String, String> globalProperties;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an interceptor that authenticates all requests.
|
||||||
|
*/
|
||||||
|
public OAuthRequestInterceptor(Map<String, String> globalProperties) {
|
||||||
|
this.globalProperties = globalProperties;
|
||||||
|
try {
|
||||||
|
deviceMgtServerUrl = getDeviceMgtServerUrl(globalProperties);
|
||||||
|
refreshTimeOffset = getRefreshTimeOffset(globalProperties) * 1000;
|
||||||
|
username = getUsername(globalProperties);
|
||||||
|
password = getPassword(globalProperties);
|
||||||
|
tokenEndpoint = getTokenEndpoint(globalProperties);
|
||||||
|
apiApplicationRegistrationService = Feign.builder().requestInterceptor(
|
||||||
|
new BasicAuthRequestInterceptor(username, password))
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(ApiApplicationRegistrationService.class,
|
||||||
|
deviceMgtServerUrl + API_APPLICATION_REGISTRATION_CONTEXT);
|
||||||
|
} catch (InputEventAdapterException e) {
|
||||||
|
logger.error("Invalid url: deviceMgtServerUrl" + deviceMgtServerUrl + " or tokenEndpoint:" + tokenEndpoint,
|
||||||
|
e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void apply(RequestTemplate template) {
|
||||||
|
if (tokenInfo == null) {
|
||||||
|
//had to do on demand initialization due to start up error.
|
||||||
|
ApiRegistrationProfile apiRegistrationProfile = new ApiRegistrationProfile();
|
||||||
|
apiRegistrationProfile.setApplicationName(APPLICATION_NAME);
|
||||||
|
apiRegistrationProfile.setIsAllowedToAllDomains(false);
|
||||||
|
apiRegistrationProfile.setIsMappingAnExistingOAuthApp(false);
|
||||||
|
apiRegistrationProfile.setTags(DEVICE_MANAGEMENT_SERVICE_TAG);
|
||||||
|
ApiApplicationKey apiApplicationKey = apiApplicationRegistrationService.register(apiRegistrationProfile);
|
||||||
|
String consumerKey = apiApplicationKey.getConsumerKey();
|
||||||
|
String consumerSecret = apiApplicationKey.getConsumerSecret();
|
||||||
|
tokenIssuerService = Feign.builder().requestInterceptor(
|
||||||
|
new BasicAuthRequestInterceptor(consumerKey, consumerSecret))
|
||||||
|
.contract(new JAXRSContract()).encoder(new GsonEncoder()).decoder(new GsonDecoder())
|
||||||
|
.target(TokenIssuerService.class, tokenEndpoint);
|
||||||
|
tokenInfo = tokenIssuerService.getToken(PASSWORD_GRANT_TYPE, username, password, REQUIRED_SCOPE);
|
||||||
|
tokenInfo.setExpires_in(System.currentTimeMillis() + (tokenInfo.getExpires_in() * 1000));
|
||||||
|
}
|
||||||
|
synchronized(this) {
|
||||||
|
if (System.currentTimeMillis() + refreshTimeOffset > tokenInfo.getExpires_in()) {
|
||||||
|
tokenInfo = tokenIssuerService.getToken(REFRESH_GRANT_TYPE, tokenInfo.getRefresh_token());
|
||||||
|
tokenInfo.setExpires_in(System.currentTimeMillis() + tokenInfo.getExpires_in());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
String headerValue = "Bearer " + tokenInfo.getAccess_token();
|
||||||
|
template.header("Authorization", headerValue);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getUsername(Map<String, String> globalProperties) {
|
||||||
|
String username = globalProperties.get(CONNECTION_USERNAME);
|
||||||
|
if (username == null || username.isEmpty()) {
|
||||||
|
logger.error("username can't be empty ");
|
||||||
|
}
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getPassword(Map<String, String> globalProperties) {
|
||||||
|
String password = globalProperties.get(CONNECTION_PASSWORD);;
|
||||||
|
if (password == null || password.isEmpty()) {
|
||||||
|
logger.error("password can't be empty ");
|
||||||
|
}
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getDeviceMgtServerUrl(Map<String, String> globalProperties) throws InputEventAdapterException {
|
||||||
|
String deviceMgtServerUrl = globalProperties.get(DEVICE_MGT_SERVER_URL);
|
||||||
|
if (deviceMgtServerUrl == null || deviceMgtServerUrl.isEmpty()) {
|
||||||
|
logger.error("deviceMgtServerUrl can't be empty ");
|
||||||
|
}
|
||||||
|
return PropertyUtils.replaceProperty(deviceMgtServerUrl);
|
||||||
|
}
|
||||||
|
|
||||||
|
private String getTokenEndpoint(Map<String, String> globalProperties) throws InputEventAdapterException {
|
||||||
|
String tokenEndpoint = globalProperties.get(TOKEN_ENDPOINT_CONTEXT);
|
||||||
|
if ( tokenEndpoint.isEmpty()) {
|
||||||
|
logger.error("tokenEndpoint can't be empty ");
|
||||||
|
}
|
||||||
|
return PropertyUtils.replaceProperty(tokenEndpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private long getRefreshTimeOffset(Map<String, String> globalProperties) {
|
||||||
|
long refreshTimeOffset = 100;
|
||||||
|
try {
|
||||||
|
refreshTimeOffset = Long.parseLong(globalProperties.get(TOKEN_REFRESH_TIME_OFFSET));
|
||||||
|
} catch (NumberFormatException e) {
|
||||||
|
logger.error("refreshTimeOffset should be a number", e);
|
||||||
|
}
|
||||||
|
return refreshTimeOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,57 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold access token info that returned from the api call
|
||||||
|
*/
|
||||||
|
public class AccessTokenInfo {
|
||||||
|
public String token_type;
|
||||||
|
public long expires_in;
|
||||||
|
public String refresh_token;
|
||||||
|
public String access_token;
|
||||||
|
|
||||||
|
public String getToken_type() {
|
||||||
|
return token_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setToken_type(String token_type) {
|
||||||
|
this.token_type = token_type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public long getExpires_in() {
|
||||||
|
return expires_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExpires_in(long expires_in) {
|
||||||
|
this.expires_in = expires_in;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRefresh_token() {
|
||||||
|
return refresh_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRefresh_token(String refresh_token) {
|
||||||
|
this.refresh_token = refresh_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccess_token() {
|
||||||
|
return access_token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccess_token(String access_token) {
|
||||||
|
this.access_token = access_token;
|
||||||
|
}
|
||||||
|
}
|
@ -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.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds api application consumer key and secret.
|
||||||
|
*/
|
||||||
|
public class ApiApplicationKey {
|
||||||
|
private String client_id;
|
||||||
|
private String client_secret;
|
||||||
|
|
||||||
|
public String getConsumerKey() {
|
||||||
|
return this.client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_id(String consumerKey) {
|
||||||
|
this.client_id = consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return this.client_secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_secret(String consumerSecret) {
|
||||||
|
this.client_secret = consumerSecret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,38 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This is the application registration service that exposed for apimApplicationRegistration
|
||||||
|
*/
|
||||||
|
|
||||||
|
@Path("/register")
|
||||||
|
public interface ApiApplicationRegistrationService {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is used to register api application
|
||||||
|
*
|
||||||
|
* @param registrationProfile contains the necessary attributes that are needed in order to register an app.
|
||||||
|
*/
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
ApiApplicationKey register(ApiRegistrationProfile registrationProfile);
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the data that are required to register
|
||||||
|
* the oauth application.
|
||||||
|
*/
|
||||||
|
public class ApiRegistrationProfile {
|
||||||
|
|
||||||
|
public String applicationName;
|
||||||
|
public String tags[];
|
||||||
|
public boolean isAllowedToAllDomains;
|
||||||
|
public String consumerKey;
|
||||||
|
public String consumerSecret;
|
||||||
|
public boolean isMappingAnExistingOAuthApp;
|
||||||
|
|
||||||
|
public String getApplicationName() {
|
||||||
|
return applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationName(String applicationName) {
|
||||||
|
this.applicationName = applicationName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String[] getTags() {
|
||||||
|
return tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTags(String[] tags) {
|
||||||
|
this.tags = tags;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAllowedToAllDomains() {
|
||||||
|
return isAllowedToAllDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsAllowedToAllDomains(boolean isAllowedToAllDomains) {
|
||||||
|
this.isAllowedToAllDomains = isAllowedToAllDomains;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isMappingAnExistingOAuthApp() {
|
||||||
|
return isMappingAnExistingOAuthApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsMappingAnExistingOAuthApp(boolean isMappingAnExistingOAuthApp) {
|
||||||
|
this.isMappingAnExistingOAuthApp = isMappingAnExistingOAuthApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerKey() {
|
||||||
|
return consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerKey(String consumerKey) {
|
||||||
|
this.consumerKey = consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return consumerSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerSecret(String consumerSecret) {
|
||||||
|
this.consumerSecret = consumerSecret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,59 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DTO of the authorization request
|
||||||
|
*/
|
||||||
|
public class AuthorizationRequest {
|
||||||
|
|
||||||
|
String tenantDomain;
|
||||||
|
String username;
|
||||||
|
List<DeviceIdentifier> deviceIdentifiers;
|
||||||
|
List<String> permissions;
|
||||||
|
|
||||||
|
public String getTenantDomain() {
|
||||||
|
return tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantDomain(String tenantDomain) {
|
||||||
|
this.tenantDomain = tenantDomain;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUsername() {
|
||||||
|
return username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsername(String username) {
|
||||||
|
this.username = username;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DeviceIdentifier> getDeviceIdentifiers() {
|
||||||
|
return deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifiers(List<DeviceIdentifier> deviceIdentifiers) {
|
||||||
|
this.deviceIdentifiers = deviceIdentifiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getPermissions() {
|
||||||
|
return permissions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPermissions(List<String> permissions) {
|
||||||
|
this.permissions = permissions;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,41 @@
|
|||||||
|
/*
|
||||||
|
* 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.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Path;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
@Path("/admin/authorization")
|
||||||
|
/**
|
||||||
|
* This interface provided the definition of the device - user access verification service.
|
||||||
|
*/
|
||||||
|
public interface DeviceAccessAuthorizationAdminService {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_JSON)
|
||||||
|
DeviceAuthorizationResult isAuthorized(AuthorizationRequest authorizationRequest);
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2015, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* WSO2 Inc. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* you may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Represents a DeviceAuthorizationResult including a list of authorized devices and a list of unauthorized devices.
|
||||||
|
*/
|
||||||
|
public class DeviceAuthorizationResult {
|
||||||
|
|
||||||
|
private List<DeviceIdentifier> authorizedDevices = new ArrayList<>();
|
||||||
|
private List<DeviceIdentifier> unauthorizedDevices = new ArrayList<>();
|
||||||
|
|
||||||
|
public List<DeviceIdentifier> getAuthorizedDevices() {
|
||||||
|
return authorizedDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthorizedDevices(List<DeviceIdentifier> authorizedDevices) {
|
||||||
|
this.authorizedDevices = authorizedDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUnauthorizedDevices(
|
||||||
|
List<DeviceIdentifier> unauthorizedDevices) {
|
||||||
|
this.unauthorizedDevices = unauthorizedDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAuthorizedDevice(DeviceIdentifier deviceIdentifier) {
|
||||||
|
authorizedDevices.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<DeviceIdentifier> getUnauthorizedDevices() {
|
||||||
|
return unauthorizedDevices;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUnauthorizedDevice(DeviceIdentifier deviceIdentifier) {
|
||||||
|
unauthorizedDevices.add(deviceIdentifier);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,51 @@
|
|||||||
|
/*
|
||||||
|
* 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.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* DTO of the device identifier
|
||||||
|
*/
|
||||||
|
public class DeviceIdentifier implements Serializable{
|
||||||
|
|
||||||
|
private String id;
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
public DeviceIdentifier() {}
|
||||||
|
|
||||||
|
public DeviceIdentifier(String id, String type) {
|
||||||
|
this.id = id;
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type.toLowerCase();
|
||||||
|
}
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,58 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents an OAuth application populated with necessary data.
|
||||||
|
*/
|
||||||
|
public class OAuthApplicationInfo {
|
||||||
|
|
||||||
|
public String client_id;
|
||||||
|
public String client_name;
|
||||||
|
public String callback_url;
|
||||||
|
public String client_secret;
|
||||||
|
|
||||||
|
public String getClient_id() {
|
||||||
|
return client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_id(String client_id) {
|
||||||
|
this.client_id = client_id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClient_name() {
|
||||||
|
return client_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_name(String client_name) {
|
||||||
|
this.client_name = client_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCallback_url() {
|
||||||
|
return callback_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallback_url(String callback_url) {
|
||||||
|
this.callback_url = callback_url;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClient_secret() {
|
||||||
|
return client_secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClient_secret(String client_secret) {
|
||||||
|
this.client_secret = client_secret;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,40 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This holds the data related to registration.
|
||||||
|
*/
|
||||||
|
public class RegisterInfo {
|
||||||
|
|
||||||
|
private boolean isRegistered;
|
||||||
|
private String msg;
|
||||||
|
|
||||||
|
public boolean isRegistered() {
|
||||||
|
return isRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIsRegistered(boolean isRegistered) {
|
||||||
|
this.isRegistered = isRegistered;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMsg() {
|
||||||
|
return msg;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMsg(String msg) {
|
||||||
|
this.msg = msg;
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,78 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This class represents the data that are required to register
|
||||||
|
* the oauth application.
|
||||||
|
*/
|
||||||
|
public class RegistrationProfile {
|
||||||
|
|
||||||
|
public String callbackUrl;
|
||||||
|
public String clientName;
|
||||||
|
public String tokenScope;
|
||||||
|
public String owner;
|
||||||
|
public String grantType;
|
||||||
|
public String applicationType;
|
||||||
|
|
||||||
|
public String getCallbackUrl() {
|
||||||
|
return callbackUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCallbackUrl(String callBackUrl) {
|
||||||
|
this.callbackUrl = callBackUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientName() {
|
||||||
|
return clientName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientName(String clientName) {
|
||||||
|
this.clientName = clientName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTokenScope() {
|
||||||
|
return tokenScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenScope(String tokenScope) {
|
||||||
|
this.tokenScope = tokenScope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOwner() {
|
||||||
|
return owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOwner(String owner) {
|
||||||
|
this.owner = owner;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getGrantType() {
|
||||||
|
return grantType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGrantType(String grantType) {
|
||||||
|
this.grantType = grantType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplicationType() {
|
||||||
|
return applicationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicationType(String applicationType) {
|
||||||
|
this.applicationType = applicationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,56 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
|
* you may not use this file except in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
* Unless required by applicable law or agreed to in writing, software
|
||||||
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||||
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||||
|
* See the License for the specific language governing permissions and limitations under the License.
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
package org.wso2.carbon.device.mgt.input.adapter.http.authorization.client.dto;
|
||||||
|
|
||||||
|
import javax.ws.rs.Consumes;
|
||||||
|
import javax.ws.rs.POST;
|
||||||
|
import javax.ws.rs.Produces;
|
||||||
|
import javax.ws.rs.QueryParam;
|
||||||
|
import javax.ws.rs.core.MediaType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold the api defintion that is used as a contract with netflix feign.
|
||||||
|
*/
|
||||||
|
public interface TokenIssuerService {
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("username") String username,
|
||||||
|
@QueryParam("password") String password);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("username") String username,
|
||||||
|
@QueryParam("password") String password, @QueryParam("scope") String scopes);
|
||||||
|
|
||||||
|
@POST
|
||||||
|
@Produces(MediaType.APPLICATION_JSON)
|
||||||
|
@Consumes(MediaType.APPLICATION_FORM_URLENCODED)
|
||||||
|
AccessTokenInfo getToken(@QueryParam("grant_type") String grant, @QueryParam("refresh_token") String refreshToken);
|
||||||
|
}
|
@ -1,99 +0,0 @@
|
|||||||
/*
|
|
||||||
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
|
|
||||||
*
|
|
||||||
* WSO2 Inc. licenses this file to you under the Apache License,
|
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
|
||||||
* in compliance with the License.
|
|
||||||
* You may obtain a copy of the License at
|
|
||||||
*
|
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
*
|
|
||||||
* Unless required by applicable law or agreed to in writing,
|
|
||||||
* software distributed under the License is distributed on an
|
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
||||||
* KIND, either express or implied. See the License for the
|
|
||||||
* specific language governing permissions and limitations
|
|
||||||
* under the License.
|
|
||||||
*/
|
|
||||||
|
|
||||||
package org.wso2.carbon.device.mgt.input.adapter.http.util;
|
|
||||||
|
|
||||||
import com.jayway.jsonpath.JsonPath;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.json.simple.JSONArray;
|
|
||||||
import org.json.simple.parser.JSONParser;
|
|
||||||
import org.json.simple.parser.ParseException;
|
|
||||||
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentInfo;
|
|
||||||
import org.wso2.carbon.device.mgt.input.adapter.extension.ContentValidator;
|
|
||||||
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
public class HTTPContentValidator implements ContentValidator {
|
|
||||||
private static final Log log = LogFactory.getLog(HTTPContentValidator.class);
|
|
||||||
private static String JSON_ARRAY_START_CHAR = "[";
|
|
||||||
private static String CDMF_SCOPE_PREFIX = "cdmf";
|
|
||||||
private static String CDMF_SCOPE_SEPERATOR = "/";
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public ContentInfo validate(Object msgPayload, Map<String, Object> dynamicParams) {
|
|
||||||
String deviceId = (String) dynamicParams.get("deviceId");
|
|
||||||
String deviceType = (String) dynamicParams.get("deviceType");
|
|
||||||
String msg = (String) msgPayload;
|
|
||||||
String deviceIdJsonPath = HTTPEventAdapterConstants.DEVICE_ID_JSON_PATH;
|
|
||||||
boolean status;
|
|
||||||
if (status = isValidDevice(deviceId, deviceType, dynamicParams)) {
|
|
||||||
if (msg.startsWith(JSON_ARRAY_START_CHAR)) {
|
|
||||||
status = processMultipleEvents(msg, deviceId, deviceIdJsonPath);
|
|
||||||
} else {
|
|
||||||
status = processSingleEvent(msg, deviceId, deviceIdJsonPath);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new ContentInfo(status, msg);
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean processSingleEvent(String msg, String deviceIdFromTopic, String deviceIdJsonPath) {
|
|
||||||
Object res = JsonPath.read(msg, deviceIdJsonPath);
|
|
||||||
String deviceIdFromContent = (res != null) ? res.toString() : "";
|
|
||||||
if (deviceIdFromContent.equals(deviceIdFromTopic)) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean processMultipleEvents(String msg, String deviceIdFromTopic, String deviceIdJsonPath) {
|
|
||||||
try {
|
|
||||||
JSONParser jsonParser = new JSONParser();
|
|
||||||
JSONArray jsonArray = (JSONArray) jsonParser.parse(msg);
|
|
||||||
boolean status = false;
|
|
||||||
for (int i = 0; i < jsonArray.size(); i++) {
|
|
||||||
status = processSingleEvent(jsonArray.get(i).toString(), deviceIdFromTopic, deviceIdJsonPath);
|
|
||||||
if (!status) {
|
|
||||||
return status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return status;
|
|
||||||
} catch (ParseException e) {
|
|
||||||
log.error("Invalid input " + msg, e);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private boolean isValidDevice(String deviceId, String deviceType, Map<String, Object> dynamicParams) {
|
|
||||||
List<String> scopes = (List<String>) dynamicParams.get(HTTPEventAdapterConstants.SCOPE_TAG);
|
|
||||||
if (scopes != null) {
|
|
||||||
for (String scope : scopes) {
|
|
||||||
if (scope.startsWith(CDMF_SCOPE_PREFIX)) {
|
|
||||||
String deviceIdInfo[] = scope.split(CDMF_SCOPE_SEPERATOR);
|
|
||||||
if (deviceIdInfo.length == 3) {
|
|
||||||
if (deviceId.equals(deviceIdInfo[2]) && deviceType.equals(deviceIdInfo[1])) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue