Merge branch 'master' into 'master'

Retrieve enrollment config from general config and support serilnumber based config with user based

See merge request entgra/carbon-device-mgt!578
revert-70ac1926
Dharmakeerthi Lasantha 4 years ago
commit b3f395b284

@ -231,8 +231,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
} }
return false; return false;
} }
EnrollmentConfiguration enrollmentConfiguration = DeviceManagerUtil.getEnrollmentConfigurationEntry( EnrollmentConfiguration enrollmentConfiguration = DeviceManagerUtil.getEnrollmentConfigurationEntry();
this.getConfiguration(device.getType()));
String deviceSerialNumber = null; String deviceSerialNumber = null;
if (enrollmentConfiguration != null) { if (enrollmentConfiguration != null) {
deviceSerialNumber = DeviceManagerUtil.getPropertyString(device.getProperties(), deviceSerialNumber = DeviceManagerUtil.getPropertyString(device.getProperties(),

@ -19,7 +19,6 @@ package org.wso2.carbon.device.mgt.core.util;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import com.google.gson.Gson; import com.google.gson.Gson;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log; import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory; import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
@ -887,20 +886,14 @@ public final class DeviceManagerUtil {
/** /**
* Retrieve the Enrollment Configuration entry added to the Platform Configuration * Retrieve the Enrollment Configuration entry added to the Platform Configuration
* @param platformConfiguration which has all the platform configurations added to the tenant
* @return enrollment configuration * @return enrollment configuration
*/ */
public static EnrollmentConfiguration getEnrollmentConfigurationEntry(PlatformConfiguration platformConfiguration) { public static EnrollmentConfiguration getEnrollmentConfigurationEntry() {
if (platformConfiguration != null) { Object enrollmentConfigEntry = DeviceManagerUtil.getConfiguration(
String enrollmentConfigEntry = platformConfiguration.getConfiguration().stream() DeviceManagementConstants.Common.ENROLLMENT_CONFIGURATION);
.filter(configurationEntry -> DeviceManagementConstants.Common.ENROLLMENT_CONFIGURATION if (enrollmentConfigEntry != null) {
.equals(configurationEntry.getName()))
.findFirst()
.map(configurationEntry -> configurationEntry.getValue().toString()).orElse(null);
if (!StringUtils.isBlank(enrollmentConfigEntry)) {
Gson gson = new Gson(); Gson gson = new Gson();
return gson.fromJson(enrollmentConfigEntry, EnrollmentConfiguration.class); return gson.fromJson(enrollmentConfigEntry.toString(), EnrollmentConfiguration.class);
}
} }
return null; return null;
} }
@ -911,8 +904,9 @@ public final class DeviceManagerUtil {
* Validation happens in two ways, * Validation happens in two ways,
* 1. List of Serial Numbers - If this is available checks if the device to be enrolled serial number is * 1. List of Serial Numbers - If this is available checks if the device to be enrolled serial number is
* in the given list of serial numbers * in the given list of serial numbers
* 2. List of Serial Numbers against a User - If [1] is missing and this is available checks if the device * 2. List of Serial Numbers against a User - If [1] is not configured or the device serial number is not
* to be enrolled serial number is in the list of serial numbers which are against a User * in the [1] then this checks if the device to be enrolled serial number is in the list of serial numbers
* which are against a User
* @param enrollmentConfiguration which has the enrollment configurations of a tenant * @param enrollmentConfiguration which has the enrollment configurations of a tenant
* @param deviceSerialNumber device serial number to be validated * @param deviceSerialNumber device serial number to be validated
* @return a boolean value if the device can be enrolled * @return a boolean value if the device can be enrolled
@ -928,14 +922,18 @@ public final class DeviceManagerUtil {
return true; return true;
} else { } else {
List<String> enrollmentConfigSerialNumbers = enrollmentConfiguration.getSerialNumbers(); List<String> enrollmentConfigSerialNumbers = enrollmentConfiguration.getSerialNumbers();
boolean isDeviceEnrollable = false;
if (enrollmentConfigSerialNumbers != null && !enrollmentConfigSerialNumbers.isEmpty()) { if (enrollmentConfigSerialNumbers != null && !enrollmentConfigSerialNumbers.isEmpty()) {
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("List of serial numbers '" + enrollmentConfigSerialNumbers.toString() + "' has been" log.debug("List of serial numbers '" + enrollmentConfigSerialNumbers.toString() + "' has been"
+ " added for enrollment configuration under platform configuration to validate " + " added for enrollment configuration under platform configuration to validate "
+ "the serial number '" + deviceSerialNumber + "'."); + "the serial number '" + deviceSerialNumber + "'.");
} }
return enrollmentConfigSerialNumbers.stream().anyMatch(deviceSerialNumber::equals); isDeviceEnrollable = enrollmentConfigSerialNumbers.stream().anyMatch(deviceSerialNumber::equals);
} else { }
if (isDeviceEnrollable) {
return true;
}
String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
List<EnrollmentConfiguration.UserConfiguration> userConfigurations = enrollmentConfiguration List<EnrollmentConfiguration.UserConfiguration> userConfigurations = enrollmentConfiguration
.getUserConfigurations(); .getUserConfigurations();
@ -949,6 +947,11 @@ public final class DeviceManagerUtil {
.filter(userConfiguration -> userConfiguration.getSerialNumbers().stream() .filter(userConfiguration -> userConfiguration.getSerialNumbers().stream()
.anyMatch(deviceSerialNumber::equals)).isPresent(); .anyMatch(deviceSerialNumber::equals)).isPresent();
} else { } else {
if (enrollmentConfigSerialNumbers != null && !enrollmentConfigSerialNumbers.isEmpty()) {
// serial number of the device is not in the serial number based configuration nor in the serial
// numbers against user based configuration
return false;
}
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Enrollment configuration has been but configuration does not contain any " log.debug("Enrollment configuration has been but configuration does not contain any "
+ "serial number based validation. It may be having the configuration to push " + "serial number based validation. It may be having the configuration to push "
@ -960,7 +963,6 @@ public final class DeviceManagerUtil {
} }
} }
} }
}
/** /**

Loading…
Cancel
Save