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

Loading…
Cancel
Save