Refactor code

master
Rajitha Kumara 10 months ago
parent 2ad8f54a46
commit 957cb748d7

@ -264,8 +264,8 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
* time to avoid unnecessary device bulks.
* */
List<ActiveSyncDevice> validActiveSyncDevices = isSynced ? DeviceMgtUtil.
getEnrolledActiveSyncDevicesSince(lastSynced) :
DeviceMgtUtil.getEnrolledActiveSyncDevicesPriorTo(new Date());
getEnrolledActiveSyncDevices(lastSynced, false) :
DeviceMgtUtil.getEnrolledActiveSyncDevices(new Date(), true);
List<ActiveSyncDevice> notValidActiveSyncDevices = new ArrayList<>();
List<ActiveSyncDevice> connectedActiveSyncDevices = isSynced ?
@ -286,33 +286,15 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
calendar.add(Calendar.DAY_OF_MONTH, -Constants.MAX_GRACE_PERIOD_IN_DAYS);
List<ActiveSyncDevice> graceExceededNewlyConnectedActiveSyncDevices =
getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
List<ActiveSyncDevice> managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevicesSince(calendar.getTime());
for (ActiveSyncDevice activeSyncDevice : graceExceededNewlyConnectedActiveSyncDevices) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !managedDevices.contains(activeSyncDevice)) {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
} else {
// These devices are managed by UEM, so add to the valid category
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
List<ActiveSyncDevice> managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevices(calendar.getTime(), false);
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
graceExceededNewlyConnectedActiveSyncDevices, managedDevices, gracePeriod, false);
// Block grace offered existing devices if exists
List<ActiveSyncDevice> connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy =
getConnectedActiveSyncDevicesBefore(created, activeSyncServer);
for (ActiveSyncDevice activeSyncDevice: connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !validActiveSyncDevices.contains(activeSyncDevice)) {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
} else {
// These devices are managed by UEM, so add to the valid category
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy, validActiveSyncDevices, gracePeriod, false);
}
if (gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NEW_AND_EXISTING.name()) ||
@ -320,77 +302,27 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
List<ActiveSyncDevice> newlyConnectedActiveSyncDevices =
getConnectedActiveSyncDevicesAfter(isSynced ? lastSynced : created, activeSyncServer);
for (ActiveSyncDevice activeSyncDevice : newlyConnectedActiveSyncDevices) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !validActiveSyncDevices.contains(activeSyncDevice)) {
long timeDiff = Math.abs(new Date().getTime() - activeSyncDevice.getFirstSyncTime().getTime());
// Enforce the grace period if the device not exceeds the grace limit
if (TimeUnit.DAYS.convert(timeDiff, TimeUnit.MILLISECONDS) < gracePeriod.getGracePeriod()) {
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
} else {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
}
} else {
// These devices are managed by UEM, so add to the valid category
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
newlyConnectedActiveSyncDevices, validActiveSyncDevices, gracePeriod, true);
Calendar calendar = Calendar.getInstance();
calendar.add(Calendar.DAY_OF_MONTH, -Constants.MAX_GRACE_PERIOD_IN_DAYS);
List<ActiveSyncDevice> graceExceededNewlyConnectedActiveSyncDevices =
getConnectedActiveSyncDevicesAfter(calendar.getTime(), activeSyncServer);
List<ActiveSyncDevice> managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevicesSince(calendar.getTime());
for (ActiveSyncDevice activeSyncDevice : graceExceededNewlyConnectedActiveSyncDevices) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !managedDevices.contains(activeSyncDevice)) {
long timeDiff = Math.abs(new Date().getTime() - activeSyncDevice.getFirstSyncTime().getTime());
// Enforce the grace period if the device isn't exceeds the current grace limit
if (TimeUnit.DAYS.convert(timeDiff, TimeUnit.MILLISECONDS) < gracePeriod.getGracePeriod()) {
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
} else {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
}
} else {
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
List<ActiveSyncDevice> managedDevices = DeviceMgtUtil.getEnrolledActiveSyncDevices(calendar.getTime(), false);
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
graceExceededNewlyConnectedActiveSyncDevices, managedDevices, gracePeriod, true);
}
if (gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.NEW_AND_EXISTING.name()) ||
gracePeriod.getGraceAllowedPolicy().equalsName(GraceAllowedPolicy.EXISTING_ONLY.name())) {
long timeDiffBetweenCEAPolicyCreatedAndNow = Math.abs(new Date().getTime() - ceaPolicy.getCreated().getTime());
List<ActiveSyncDevice> connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy =
getConnectedActiveSyncDevicesBefore(created, activeSyncServer);
for (ActiveSyncDevice activeSyncDevice: connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !validActiveSyncDevices.contains(activeSyncDevice)) {
// Enforce the grace period if the device not exceeds the grace limit
if(TimeUnit.DAYS.convert(timeDiffBetweenCEAPolicyCreatedAndNow, TimeUnit.MILLISECONDS)
< gracePeriod.getGracePeriod()) {
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
} else {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
}
} else {
// These devices are managed by UEM, so add to the valid category
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
categorizeDevices(validActiveSyncDevices, notValidActiveSyncDevices,
connectedActiveSyncDevicesBeforeTheCreationOfCEAPolicy, validActiveSyncDevices, gracePeriod, true);
}
List<MailboxProfile> mailboxProfiles = generateMailboxPolicies(validActiveSyncDevices,
List<MailboxProfile> mailboxProfiles = generateMailboxProfiles(validActiveSyncDevices,
notValidActiveSyncDevices);
for (MailboxProfile mailboxProfile : mailboxProfiles) {
PowershellCommand powershellCommand = getCommand(Parser.COMMAND_SetCASMailbox.COMMAND, activeSyncServer);
@ -416,6 +348,61 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
}
}
/**
* Categorize active sync devices into valid and not valid
* @param validActiveSyncDevices Valid active sync devices
* @param notValidActiveSyncDevices Not valid active sync devices
* @param deviceList Device list to filter
* @param managedList Already managing devices from UEM
* @param gracePeriod Grace period to consider
* @param allowGrace Whether to allow grace or not
*/
private void categorizeDevices(List<ActiveSyncDevice> validActiveSyncDevices, List<ActiveSyncDevice> notValidActiveSyncDevices,
List<ActiveSyncDevice> deviceList, List<ActiveSyncDevice> managedList, GracePeriod gracePeriod, boolean allowGrace) {
for (ActiveSyncDevice activeSyncDevice : deviceList) {
if (!EASMgtUtil.isManageByUEM(activeSyncDevice.getDeviceId())
&& !managedList.contains(activeSyncDevice)) {
if (allowGrace) {
filterDeviceBasedOnGrace(activeSyncDevice, validActiveSyncDevices, notValidActiveSyncDevices, gracePeriod);
} else {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
}
} else {
// These devices are managed by UEM, so add to the valid category
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
}
}
}
/**
* Filter active sync device based on grace period
* @param activeSyncDevice Active sync device
* @param validActiveSyncDevices Valid active sync device list
* @param notValidActiveSyncDevices Not valid active sync device list
* @param gracePeriod Grace period to consider
*/
private void filterDeviceBasedOnGrace(ActiveSyncDevice activeSyncDevice, List<ActiveSyncDevice> validActiveSyncDevices,
List<ActiveSyncDevice> notValidActiveSyncDevices, GracePeriod gracePeriod) {
long timeDiff = Math.abs(new Date().getTime() - activeSyncDevice.getFirstSyncTime().getTime());
// Enforce the grace period if the device not exceeds the grace limit
if (TimeUnit.DAYS.convert(timeDiff, TimeUnit.MILLISECONDS) < gracePeriod.getGracePeriod()) {
notValidActiveSyncDevices.remove(activeSyncDevice);
validActiveSyncDevices.add(activeSyncDevice);
} else {
validActiveSyncDevices.remove(activeSyncDevice);
notValidActiveSyncDevices.add(activeSyncDevice);
}
}
/**
* Generate powershell command {@link PowershellCommand} from command string
* @param command Powershell command string
* @param activeSyncServer {@link ActiveSyncServer}
* @return {@link PowershellCommand}
* @throws GatewayServiceException Throws when error occurred while retrieving access token
*/
private PowershellCommand getCommand(String command, ActiveSyncServer activeSyncServer)
throws GatewayServiceException {
String[] urlParts = activeSyncServer.getGatewayUrl().split("/");
@ -426,6 +413,13 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return commandBuilder.build();
}
/**
* Wrap powershell command to effect all mailboxes in active sync server
* @param command {@link PowershellCommand} command to wrap
* @param activeSyncServer {@link ActiveSyncServer}
* @return {@link PowershellCommand}
* @throws GatewayServiceException Throws when error occurred while retrieving access token
*/
private PowershellCommand toAllMailboxesCommand(PowershellCommand command,
ActiveSyncServer activeSyncServer) throws GatewayServiceException {
PowershellCommand getEXOMailbox = getCommand(Parser.COMMAND_GetEXOMailbox.COMMAND, activeSyncServer);
@ -438,13 +432,24 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return getEXOMailbox;
}
/**
* Create new powershell request to execute via powershell binaries
* @param command {@link PowershellCommand}
* @return {@link PowershellRequest}
*/
private PowershellRequest getPowershellRequest(PowershellCommand command) {
PowershellRequest powershellRequest = new PowershellRequest();
powershellRequest.setCommand(command);
return powershellRequest;
}
private List<MailboxProfile> generateMailboxPolicies(List<ActiveSyncDevice> activeSyncAllowedDevices,
/**
* Generate mailbox profiles from active sync block and allowed devices
* @param activeSyncAllowedDevices Active sync allowed device list
* @param activeSyncBlockedDevices Active sync blocked device list
* @return List of {@link MailboxProfile}
*/
private List<MailboxProfile> generateMailboxProfiles(List<ActiveSyncDevice> activeSyncAllowedDevices,
List<ActiveSyncDevice> activeSyncBlockedDevices) {
List<MailboxProfile> mailboxProfiles = new ArrayList<>();
MailboxProfile mailboxProfile;
@ -474,6 +479,12 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return mailboxProfiles;
}
/**
* Construct active sync device list from powershell response
* @param powershellResponse Shell response return from powershell binary
* @return List of {@link ActiveSyncDevice}
* @throws CEAEnforcementException Throws when error occurred while generating the device list
*/
private List<ActiveSyncDevice> constructActiveSyncDeviceList(PowershellResponse powershellResponse)
throws CEAEnforcementException {
if (powershellResponse == null) {
@ -514,6 +525,15 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return activeSyncDevices;
}
/**
* Get active sync devices, which are connected with active sync server after a certain timestamp
* @param after Timestamp to retrieve connected devices
* @param activeSyncServer {@link ActiveSyncServer}
* @return List of {@link ActiveSyncDevice}
* @throws GatewayServiceException Throws when error occurred while retrieving access token
* @throws PowershellExecutionException Throws when error occurred while executing the powershell command
* @throws CEAEnforcementException Throws when error occurred while constructing device list
*/
private List<ActiveSyncDevice> getConnectedActiveSyncDevicesAfter(Date after, ActiveSyncServer activeSyncServer)
throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
SimpleDateFormat powershellDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
@ -541,6 +561,15 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return constructActiveSyncDeviceList(powershellResponse);
}
/**
* Get active sync devices, which are connected with active sync server before a certain timestamp
* @param before Timestamp to retrieve connected devices
* @param activeSyncServer {@link ActiveSyncServer}
* @return List of {@link ActiveSyncDevice}
* @throws GatewayServiceException Throws when error occurred while retrieving access token
* @throws PowershellExecutionException Throws when error occurred while executing the powershell command
* @throws CEAEnforcementException Throws when error occurred while constructing device list
*/
private List<ActiveSyncDevice> getConnectedActiveSyncDevicesBefore(Date before, ActiveSyncServer activeSyncServer)
throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
SimpleDateFormat powershellDateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
@ -568,6 +597,14 @@ public class ExchangeOnlineCEAEnforcementServiceImpl implements CEAEnforcementSe
return constructActiveSyncDeviceList(powershellResponse);
}
/**
* Get all connected active sync devices from active sync server
* @param activeSyncServer {@link ActiveSyncServer}
* @return List of {@link ActiveSyncDevice}
* @throws GatewayServiceException Throws when error occurred while retrieving access token
* @throws PowershellExecutionException Throws when error occurred while executing the powershell command
* @throws CEAEnforcementException Throws when error occurred while constructing device list
*/
private List<ActiveSyncDevice> getAllConnectedActiveSyncDevices(ActiveSyncServer activeSyncServer)
throws GatewayServiceException, PowershellExecutionException, CEAEnforcementException {
PowershellCommand getEXOMobileDeviceStatistics = getCommand(Parser.COMMAND_GetEXOMobileDeviceStatistics.COMMAND,

@ -83,6 +83,14 @@ public class ExchangeOnlineGatewayServiceImpl implements GatewayService {
}
}
/**
* Retrieve confidential client application if exists, otherwise create and retrieve
* @param clientId Client ID of the Azure AD application
* @param secret Client Secret of the Azure AD application
* @param authority Authority URL of the tenant which Azure AD application belongs
* @return {@link IConfidentialClientApplication}
* @throws MalformedURLException Throws when trying to set malformed authority URL
*/
private IConfidentialClientApplication getOrCreateConfidentialClientApplication(String clientId, String secret, String authority)
throws MalformedURLException {
IConfidentialClientApplication confidentialClientApplication = confidentialClientApplications.get(clientId);

@ -41,41 +41,31 @@ import java.util.stream.Collectors;
public class DeviceMgtUtil {
private static final Log log = LogFactory.getLog(DeviceMgtUtil.class);
public static List<ActiveSyncDevice> getEnrolledActiveSyncDevicesSince(Date since)
/**
* Retrieve enrolled devices before or after a certain timestamp
* @param date Timestamp to retrieve devices
* @param isPriorTo Whether to retrieve prior devices based on the provided timestamp
* @return List of {@link ActiveSyncDevice}
* @throws DeviceManagementException Throws when error occurred while retrieving devices
* @throws UserStoreException Throws when failed to obtain user details belongs to a device
*/
public static List<ActiveSyncDevice> getEnrolledActiveSyncDevices(Date date, boolean isPriorTo)
throws DeviceManagementException, UserStoreException {
DeviceManagementProviderService deviceManagementProviderService = getDeviceManagementProviderService();
DeviceManagementProviderService deviceManagementProviderService =
EnforcementServiceComponentDataHolder.getInstance().getDeviceManagementProviderService();
if (deviceManagementProviderService == null) {
String msg = "Device management provider service has not initialized";
log.error(msg);
throw new IllegalStateException(msg);
}
List<Device> devices = deviceManagementProviderService.getEnrolledDevicesSince(since);
if (devices == null) {
return new ArrayList<>();
}
return DeviceMgtUtil.constructActiveSyncDeviceList(devices);
}
public static List<ActiveSyncDevice> getEnrolledActiveSyncDevicesPriorTo(Date priorTo)
throws DeviceManagementException, UserStoreException {
DeviceManagementProviderService deviceManagementProviderService = getDeviceManagementProviderService();
if (deviceManagementProviderService == null) {
String msg = "Device management provider service has not initialized";
log.error(msg);
throw new IllegalStateException(msg);
}
List<Device> devices = deviceManagementProviderService.getEnrolledDevicesPriorTo(priorTo);
List<Device> devices = isPriorTo ? deviceManagementProviderService.getEnrolledDevicesPriorTo(date) :
deviceManagementProviderService.getEnrolledDevicesSince(date);
if (devices == null) {
return new ArrayList<>();
}
return DeviceMgtUtil.constructActiveSyncDeviceList(devices);
}
private static DeviceManagementProviderService getDeviceManagementProviderService() {
return EnforcementServiceComponentDataHolder.getInstance().getDeviceManagementProviderService();
}
private static UserStoreManager getUserStoreManager(int tenantId) throws UserStoreException {
RealmService realmService = EnforcementServiceComponentDataHolder.getInstance().getRealmService();
@ -87,11 +77,12 @@ public class DeviceMgtUtil {
return realmService.getTenantUserRealm(tenantId).getUserStoreManager();
}
private static String getIdentity(String owner, UserStoreManager userStoreManager)
throws UserStoreException {
return userStoreManager.getUserClaimValue(owner, Constants.EMAIL_CLAIM_URI, null);
}
/**
* Generate active sync device list from retrieved device list from device management service
* @param devices List of devices retrieved from device management service
* @return List of {@link ActiveSyncDevice}
* @throws UserStoreException Throws when failed to load user details form user store
*/
private static List<ActiveSyncDevice> constructActiveSyncDeviceList(List<Device> devices)
throws UserStoreException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
@ -114,11 +105,19 @@ public class DeviceMgtUtil {
return activeSyncDevices;
}
/**
* Map devices which are retrieved from device management service to active sync devices
* @param device Device list retrieved from device management service
* @param userStoreManager {@link UserStoreManager}
* @return {@link ActiveSyncDevice}
* @throws UserStoreException Throws when failed to load user details form user store
*/
public static ActiveSyncDevice mapToActiveSyncDevice(Device device, UserStoreManager userStoreManager)
throws UserStoreException {
EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo();
ActiveSyncDevice activeSyncDevice = new ActiveSyncDevice();
activeSyncDevice.setUserPrincipalName(DeviceMgtUtil.getIdentity(enrolmentInfo.getOwner(), userStoreManager));
activeSyncDevice.setUserPrincipalName(userStoreManager.
getUserClaimValue(enrolmentInfo.getOwner(), Constants.EMAIL_CLAIM_URI, null));
if (!Objects.equals(device.getType(), Constants.DEVICE_TYPE_ANDROID)) {
for (Device.Property property : device.getProperties()) {
if (property != null && Objects.equals(property.getName(), Constants.DEVICE_PROPERTY_EAS_ID)) {

@ -25,6 +25,8 @@ import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellRequest;
import io.entgra.device.mgt.core.cea.mgt.enforce.bean.PowershellResponse;
import io.entgra.device.mgt.core.cea.mgt.enforce.exception.PowershellExecutionException;
import io.entgra.device.mgt.core.cea.mgt.enforce.util.shell.Powershell;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.BufferedReader;
import java.io.IOException;
@ -36,6 +38,7 @@ import java.util.Arrays;
import java.util.List;
public class AbstractPowershell implements Powershell {
private static final Log log = LogFactory.getLog(AbstractPowershell.class);
protected static final String SYMBOL_SPLITTER = "&";
private static final String PARAMETER_COMMAND = "-Command";
private static final String COMMAND_REDIRECT_WARNINGS = "$WarningPreference = 'SilentlyContinue';";
@ -75,10 +78,12 @@ public class AbstractPowershell implements Powershell {
} catch (IOException e) {
String msg = "IOException occurred while executing powershell command : "
+ powershellRequest.getCommand();
log.error(msg, e);
throw new PowershellExecutionException(msg, e);
} catch (InterruptedException e) {
String msg = "Thread got interrupted while executing powershell command : "
+ powershellRequest.getCommand();
log.error(msg, e);
throw new PowershellExecutionException(msg, e);
}
}

@ -297,7 +297,7 @@ public interface CEAManagementAdminService {
) CEAPolicyWrapper ceaPolicyWrapper);
@GET
@Path("/syncNow")
@Path("/sync-now")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HttpMethod.GET,

@ -1,12 +1,12 @@
/*
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
* Copyright (c) 2018 - 2024, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
*
* Entgra (Pvt) Ltd. 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
* 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
@ -14,6 +14,7 @@
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
*/
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
@ -153,7 +154,7 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
}
@GET
@Path("/syncNow")
@Path("/sync-now")
@Override
public Response sync() {
CEAManagementService ceaManagementService = DeviceMgtAPIUtils.getCEAManagementService();
@ -167,6 +168,11 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
}
}
/**
* Construct {@link CEAPolicy} from {@link CEAPolicyWrapper}
* @param ceaPolicyWrapper {@link CEAPolicyWrapper}
* @return {@link CEAPolicy}
*/
private CEAPolicy constructCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
AccessPolicyWrapper accessPolicyWrapper = ceaPolicyWrapper.getConditionalAccessPolicyEntries();
AccessPolicy accessPolicy = new AccessPolicy();
@ -193,20 +199,4 @@ public class CEAManagementAdminServiceImpl implements CEAManagementAdminService
ceaPolicy.setActiveSyncServer(activeSyncServer);
return ceaPolicy;
}
private List<ActiveSyncServerUIConfiguration> constructActiveSyncServerConfigurations
(List<ServerUIConfiguration> serverUIConfigurations) {
List<ActiveSyncServerUIConfiguration> activeSyncServerUIConfigurations = new ArrayList<>();
if (serverUIConfigurations == null) {
return activeSyncServerUIConfigurations;
}
for (ServerUIConfiguration serverUIConfiguration : serverUIConfigurations) {
ActiveSyncServerUIConfiguration activeSyncServerUIConfiguration = new ActiveSyncServerUIConfiguration();
activeSyncServerUIConfiguration.setName(serverUIConfiguration.getName());
activeSyncServerUIConfiguration.setKey(serverUIConfiguration.getKey());
activeSyncServerUIConfiguration.setDescription(serverUIConfiguration.getDescription());
activeSyncServerUIConfigurations.add(activeSyncServerUIConfiguration);
}
return activeSyncServerUIConfigurations;
}
}

@ -923,6 +923,10 @@ public class RequestValidationUtil {
}
}
/**
* Validate conditional access policy
* @param ceaPolicyWrapper {@link CEAPolicyWrapper}
*/
public static void validateCEAPolicy(CEAPolicyWrapper ceaPolicyWrapper) {
if (ceaPolicyWrapper == null) {
String msg = "CEA policy should not be null";
@ -934,6 +938,10 @@ public class RequestValidationUtil {
validateCEAGracePeriod(ceaPolicyWrapper.getGracePeriodEntries());
}
/**
* Validate active sync server configurations
* @param activeSyncServer {@link ActiveSyncServer}
*/
public static void validateActiveSyncServer(ActiveSyncServer activeSyncServer) {
if (activeSyncServer == null) {
String msg = "Active sync server should not be null";
@ -962,6 +970,10 @@ public class RequestValidationUtil {
}
}
/**
* Validate conditional access policy configurations
* @param accessPolicyWrapper {@link AccessPolicyWrapper}
*/
public static void validateCEAAccessPolicy(AccessPolicyWrapper accessPolicyWrapper) {
if (accessPolicyWrapper == null) {
String msg = "Access policy should not be null";
@ -982,6 +994,10 @@ public class RequestValidationUtil {
}
}
/**
* Validate grace period configurations
* @param gracePeriodWrapper {@link GracePeriodWrapper}
*/
public static void validateCEAGracePeriod(GracePeriodWrapper gracePeriodWrapper) {
if (gracePeriodWrapper == null) {
String msg = "Grace period should not be null";

Loading…
Cancel
Save