Wrapping all device provisioning related info in ProvisioningConfig

4.x.x
prabathabey 9 years ago
parent 779ed5eac2
commit f5f177a858

@ -0,0 +1,39 @@
/*
* Copyright (c) 2016, WSO2 Inc. (http://www.wso2.org) All Rights Reserved.
*
* WSO2 Inc. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package org.wso2.carbon.device.mgt.common;
public class ProvisioningConfig {
private String providerTenantDomain;
private boolean isSharedWithAllTenants;
public ProvisioningConfig(String providerTenantDomain, boolean sharedWithAllTenants) {
this.providerTenantDomain = providerTenantDomain;
isSharedWithAllTenants = sharedWithAllTenants;
}
public String getProviderTenantDomain() {
return providerTenantDomain;
}
public boolean isSharedWithAllTenants() {
return isSharedWithAllTenants;
}
}

@ -18,13 +18,11 @@
*/
package org.wso2.carbon.device.mgt.common.spi;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import java.util.List;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
/**
* Composite interface that acts as the SPI exposing all device management as well as application management
@ -32,33 +30,16 @@ import java.util.List;
*/
public interface DeviceManagementService {
/**
* Method to retrieve the provider type that implements DeviceManager interface.
*
* @return Returns provider type
*/
String getType();
/**
* This returns the tenant domain of the provider.
* @return
*/
String getProviderTenantDomain();
/**
* returns true if the device type is shared between all tenants and false if its not.
*
* @return
*/
boolean isSharedWithAllTenants();
void init() throws DeviceManagementException;
String getType();
DeviceManager getDeviceManager();
ApplicationManager getApplicationManager();
void notifyOperationToDevices(Operation operation,
List<DeviceIdentifier> deviceIds) throws DeviceManagementException;
ProvisioningConfig getProvisioningConfig();
PushNotificationConfig getPushNotificationConfig();
}

@ -21,6 +21,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceTypeIdentifier;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementDataHolder;
import org.wso2.carbon.device.mgt.core.internal.DeviceManagementServiceComponent;
@ -44,8 +45,10 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
public void addDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceType = provider.getType();
String tenantDomain = provider.getProviderTenantDomain();
boolean isSharedWithAllTenants = provider.isSharedWithAllTenants();
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
String tenantDomain = provisioningConfig.getProviderTenantDomain();
boolean isSharedWithAllTenants = provisioningConfig.isSharedWithAllTenants();
int tenantId = DeviceManagerUtil.getTenantId(tenantDomain);
if (tenantId == -1) {
throw new DeviceManagementException("No tenant available for tenant domain " + tenantDomain);
@ -57,7 +60,7 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
provider.init();
DeviceManagerUtil.registerDeviceType(deviceType, tenantId, isSharedWithAllTenants);
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(deviceType,
provider.getDeviceManager().requireDeviceAuthorization());
provider.getDeviceManager().requireDeviceAuthorization());
}
} catch (DeviceManagementException e) {
@ -75,13 +78,15 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
}
public void removeDeviceManagementProvider(DeviceManagementService provider) throws DeviceManagementException {
String deviceTypeName=provider.getType();
if(provider.isSharedWithAllTenants()){
DeviceTypeIdentifier deviceTypeIdentifier =new DeviceTypeIdentifier(deviceTypeName);
String deviceTypeName = provider.getType();
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
if (provisioningConfig.isSharedWithAllTenants()) {
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName);
providers.remove(deviceTypeIdentifier);
}else{
int providerTenantId=DeviceManagerUtil.getTenantId(provider.getProviderTenantDomain());
DeviceTypeIdentifier deviceTypeIdentifier =new DeviceTypeIdentifier(deviceTypeName, providerTenantId);
} else {
int providerTenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
DeviceTypeIdentifier deviceTypeIdentifier = new DeviceTypeIdentifier(deviceTypeName, providerTenantId);
providers.remove(deviceTypeIdentifier);
}
}
@ -113,15 +118,17 @@ public class DeviceManagementPluginRepository implements DeviceManagerStartupLis
for (DeviceManagementService provider : providers.values()) {
try {
provider.init();
int tenantId=DeviceManagerUtil.getTenantId(provider.getProviderTenantDomain());
DeviceManagerUtil.registerDeviceType(provider.getType(), tenantId, provider.isSharedWithAllTenants());
ProvisioningConfig provisioningConfig = provider.getProvisioningConfig();
int tenantId = DeviceManagerUtil.getTenantId(provisioningConfig.getProviderTenantDomain());
DeviceManagerUtil.registerDeviceType(provider.getType(), tenantId, provisioningConfig.isSharedWithAllTenants());
//TODO:
//This is a temporory fix.
//windows and IOS cannot resolve user info by extracting certs
//until fix that, use following variable to enable and disable of checking user authorization.
DeviceManagementDataHolder.getInstance().setRequireDeviceAuthorization(provider.getType(),
provider.getDeviceManager().requireDeviceAuthorization());
provider.getDeviceManager().requireDeviceAuthorization());
} catch (Throwable e) {
/* Throwable is caught intentionally as failure of one plugin - due to invalid start up parameters,
etc - should not block the initialization of other device management providers */

@ -753,17 +753,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
public void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws DeviceManagementException {
try {
for (DeviceIdentifier deviceId : deviceIds) {
DeviceManagementService dms =
getPluginRepository().getDeviceManagementService(deviceId.getType(), this.getTenantId());
dms.notifyOperationToDevices(operation, deviceIds);
}
} catch (DeviceManagementException deviceMgtEx) {
String errorMsg = "Error in notify operations to plugins for app installation:" +
deviceMgtEx.getErrorMessage();
log.error(errorMsg, deviceMgtEx);
throw new DeviceManagementException(errorMsg, deviceMgtEx);
for (DeviceIdentifier deviceId : deviceIds) {
DeviceManagementService dms =
getPluginRepository().getDeviceManagementService(deviceId.getType(), this.getTenantId());
//TODO FIX THIS WITH PUSH NOTIFICATIONS
//dms.notifyOperationToDevices(operation, deviceIds);
}
}

@ -20,8 +20,10 @@ package org.wso2.carbon.device.mgt.core;
import org.wso2.carbon.device.mgt.common.DeviceIdentifier;
import org.wso2.carbon.device.mgt.common.DeviceManagementException;
import org.wso2.carbon.device.mgt.common.DeviceManager;
import org.wso2.carbon.device.mgt.common.ProvisioningConfig;
import org.wso2.carbon.device.mgt.common.app.mgt.ApplicationManager;
import org.wso2.carbon.device.mgt.common.operation.mgt.Operation;
import org.wso2.carbon.device.mgt.common.push.notification.PushNotificationConfig;
import org.wso2.carbon.device.mgt.common.spi.DeviceManagementService;
import java.util.List;
@ -40,14 +42,6 @@ public class TestDeviceManagementService implements DeviceManagementService {
return providerType;
}
@Override
public String getProviderTenantDomain() { return tenantDomain;}
@Override
public boolean isSharedWithAllTenants() {
return true;
}
@Override
public void init() throws DeviceManagementException {
@ -64,9 +58,13 @@ public class TestDeviceManagementService implements DeviceManagementService {
}
@Override
public void notifyOperationToDevices(Operation operation, List<DeviceIdentifier> deviceIds)
throws DeviceManagementException {
public ProvisioningConfig getProvisioningConfig() {
return new ProvisioningConfig(tenantDomain, false);
}
@Override
public PushNotificationConfig getPushNotificationConfig() {
return null;
}
}

Loading…
Cancel
Save