Sync with master

master
tcdlpds 4 months ago
commit 3d5f4004d0

@ -25,16 +25,52 @@ public class ApplicationArtifact {
private String installerName;
private InputStream installerStream;
private String installerPath;
private String bannerName;
private InputStream bannerStream;
private String bannerPath;
private String iconName;
private InputStream iconStream;
private String iconPath;
private Map<String , InputStream> screenshots;
private Map<String, String> screenshotPaths;
public String getInstallerPath() {
return installerPath;
}
public void setInstallerPath(String installerPath) {
this.installerPath = installerPath;
}
public String getBannerPath() {
return bannerPath;
}
public void setBannerPath(String bannerPath) {
this.bannerPath = bannerPath;
}
public String getIconPath() {
return iconPath;
}
public void setIconPath(String iconPath) {
this.iconPath = iconPath;
}
public Map<String, String> getScreenshotPaths() {
return screenshotPaths;
}
public void setScreenshotPaths(Map<String, String> screenshotPaths) {
this.screenshotPaths = screenshotPaths;
}
public String getInstallerName() {
return installerName;

@ -547,5 +547,20 @@ public interface ApplicationManager {
* @throws ApplicationManagementException thrown if an error occurs when deleting data
*/
void deleteApplicationDataOfTenant(int tenantId) throws ApplicationManagementException;
/**
* Delete all application related data of a tenant by tenant Domain
*
* @param tenantDomain Domain of the Tenant
* @throws ApplicationManagementException thrown if an error occurs when deleting data
*/
void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException;
/**
* Delete all Application artifacts related to a tenant by Tenant Domain
*
* @param tenantDomain Domain of the Tenant
* @throws ApplicationManagementException thrown if an error occurs when deleting app folders
*/
void deleteApplicationArtifactsByTenantDomain(String tenantDomain) throws ApplicationManagementException;
}

@ -140,4 +140,14 @@ public interface ApplicationStorageManager {
* @throws ApplicationStorageManagementException thrown if
*/
void deleteAppFolderOfTenant(int tenantId) throws ApplicationStorageManagementException;
/**
* Get absolute path of a file describe by hashVal, folder, file name and tenantId
* @param hashVal Hash value of the application release.
* @param folderName Folder name file resides.
* @param fileName File name of the file.
* @param tenantId Tenant ID
* @return Absolute path
*/
String getAbsolutePathOfFile(String hashVal, String folderName, String fileName, int tenantId);
}

@ -293,12 +293,10 @@ public interface SubscriptionManager {
*
* @param deviceId the deviceId of the device that need to get operation details.
* @param uuid the UUID of the application release.
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
* @throws SubscriptionManagementException if there is an error while fetching the details.
*/
List<DeviceOperationDTO> getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid, int offset, int limit)
List<DeviceOperationDTO> getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid)
throws ApplicationManagementException;
/**

@ -99,6 +99,7 @@
io.entgra.device.mgt.core.identity.jwt.client.extension.dto;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.exception;version="[5.0,6)",
io.entgra.device.mgt.core.identity.jwt.client.extension.service;version="[5.0,6)",
io.entgra.device.mgt.core.tenant.mgt.common.*;version="[5.0,6)",
javax.annotation;version="[1.0,2)",
javax.naming,
javax.sql,
@ -443,6 +444,11 @@
<artifactId>org.wso2.carbon.tenant.mgt</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.tenant.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>

@ -378,12 +378,10 @@ public interface SubscriptionDAO {
* @param appReleaseId the appReleaseId of the application release.
* @param deviceId the deviceId of the device that need to get operation details.
* @param tenantId id of the current tenant.
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link DeviceOperationDTO} which contains the details of device subscriptions.
* @throws ApplicationManagementDAOException if connection establishment or SQL execution fails.
*/
List<DeviceOperationDTO> getSubscriptionOperationsByAppReleaseIDAndDeviceID(int appReleaseId, int deviceId, int tenantId, int offset, int limit)
List<DeviceOperationDTO> getSubscriptionOperationsByAppReleaseIDAndDeviceID(int appReleaseId, int deviceId, int tenantId)
throws ApplicationManagementDAOException;
/**

@ -1858,7 +1858,7 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
@Override
public List<DeviceOperationDTO> getSubscriptionOperationsByAppReleaseIDAndDeviceID(
int appReleaseId, int deviceId, int tenantId, int offset, int limit) throws ApplicationManagementDAOException {
int appReleaseId, int deviceId, int tenantId) throws ApplicationManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get device subscriptions related to the given AppReleaseID and DeviceID.");
}
@ -1878,13 +1878,12 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
"WHERE ads.AP_APP_RELEASE_ID = ? " +
"AND ads.DM_DEVICE_ID = ? " +
"AND ads.TENANT_ID = ? " +
"LIMIT ? OFFSET ?";
"ORDER BY aasom.OPERATION_ID DESC " +
"LIMIT 1";
try (PreparedStatement ps = conn.prepareStatement(sql)) {
ps.setInt(1, appReleaseId);
ps.setInt(2, deviceId);
ps.setInt(3, tenantId);
ps.setInt(4, limit);
ps.setInt(5, offset);
try (ResultSet rs = ps.executeQuery()) {
DeviceOperationDTO deviceSubscription;
while (rs.next()) {

@ -19,28 +19,11 @@
package io.entgra.device.mgt.core.application.mgt.core.impl;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileDownloaderServiceException;
import io.entgra.device.mgt.core.application.mgt.common.exception.FileTransferServiceException;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.application.mgt.core.dao.*;
import io.entgra.device.mgt.core.application.mgt.core.exception.*;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstaller;
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
@ -91,21 +74,35 @@ import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateMa
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagementException;
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringEscapeUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.validator.routines.UrlValidator;
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.json.JSONObject;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.user.api.UserRealm;
import org.wso2.carbon.user.api.UserStoreException;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
@ -722,24 +719,29 @@ public class ApplicationManagerImpl implements ApplicationManager {
* @throws ResourceManagementException if error occurred while uploading
*/
private ApplicationReleaseDTO uploadCustomAppReleaseArtifacts(ApplicationReleaseDTO releaseDTO, ApplicationArtifact applicationArtifact,
String deviceType)
String deviceType)
throws ResourceManagementException, ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
ApplicationStorageManager applicationStorageManager = APIUtil.getApplicationStorageManager();
byte[] content = getByteContentOfApp(applicationArtifact);
String md5OfApp = generateMD5OfApp(applicationArtifact, content);
validateReleaseBinaryFileHash(md5OfApp);
releaseDTO.setUuid(UUID.randomUUID().toString());
releaseDTO.setAppHashValue(md5OfApp);
releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try {
String md5OfApp = applicationStorageManager.
getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
validateReleaseBinaryFileHash(md5OfApp);
releaseDTO.setUuid(UUID.randomUUID().toString());
releaseDTO.setAppHashValue(md5OfApp);
releaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager.uploadReleaseArtifact(releaseDTO, deviceType,
binaryDuplicate, tenantId);
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
} catch (IOException e) {
String msg = "Error occurred when uploading release artifact into the server";
log.error(msg);
throw new ApplicationManagementException(msg, e);
} catch (StorageManagementException e) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ releaseDTO.getUuid();
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
return addImageArtifacts(releaseDTO, applicationArtifact, tenantId);
}
@ -768,6 +770,8 @@ public class ApplicationManagerImpl implements ApplicationManager {
return Constants.GOOGLE_PLAY_STORE_URL;
} else if (DeviceTypes.IOS.toString().equalsIgnoreCase(deviceType)) {
return Constants.APPLE_STORE_URL;
} else if (DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
return Constants.MICROSOFT_STORE_URL;
} else {
throw new IllegalArgumentException("No such device with the name " + deviceType);
}
@ -855,82 +859,77 @@ public class ApplicationManagerImpl implements ApplicationManager {
String uuid = UUID.randomUUID().toString();
applicationReleaseDTO.setUuid(uuid);
// The application executable artifacts such as apks are uploaded.
try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(binary, deviceType);
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
} else {
String windowsInstallerName = applicationArtifact.getInstallerName();
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
if (!extension.equalsIgnoreCase(Constants.MSI) &&
!extension.equalsIgnoreCase(Constants.APPX)) {
String msg = "Application Type doesn't match with supporting application types of " +
deviceType + "platform which are APPX and MSI";
log.error(msg);
throw new BadRequestException(msg);
}
if (!DeviceTypes.WINDOWS.toString().equalsIgnoreCase(deviceType)) {
ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(applicationInstaller.getPackageName());
} else {
String windowsInstallerName = applicationArtifact.getInstallerName();
String extension = windowsInstallerName.substring(windowsInstallerName.lastIndexOf(".") + 1);
if (!extension.equalsIgnoreCase(Constants.MSI) &&
!extension.equalsIgnoreCase(Constants.APPX)) {
String msg = "Application Type doesn't match with supporting application types of " +
deviceType + "platform which are APPX and MSI";
log.error(msg);
throw new BadRequestException(msg);
}
}
String packageName = applicationReleaseDTO.getPackageName();
try {
ConnectionManagerUtil.openDBConnection();
if (!isNewRelease && applicationReleaseDAO
.isActiveReleaseExisitForPackageName(packageName, tenantId,
lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packageName
+ ". Either you can delete all application releases for package " + packageName + " or "
+ "you can add this app release as an new application release, under the existing "
+ "application.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
String md5OfApp = applicationStorageManager.getMD5(new ByteArrayInputStream(content));
if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg =
"Application release exists for the uploaded binary file. Device Type: " + deviceType;
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate, tenantId);
}
} catch (StorageManagementException e) {
String packageName = applicationReleaseDTO.getPackageName();
try {
ConnectionManagerUtil.openDBConnection();
if (!isNewRelease && applicationReleaseDAO
.isActiveReleaseExisitForPackageName(packageName, tenantId,
lifecycleStateManager.getEndState())) {
String msg = "Application release is already exist for the package name: " + packageName
+ ". Either you can delete all application releases for package " + packageName + " or "
+ "you can add this app release as an new application release, under the existing "
+ "application.";
log.error(msg);
throw new ApplicationManagementException(msg);
}
String md5OfApp = applicationStorageManager.
getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
if (md5OfApp == null) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying app release data.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg =
"Error occurred when executing the query for verifying application release existence for "
+ "the package.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
"Application release exists for the uploaded binary file. Device Type: " + deviceType;
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO.setAppHashValue(md5OfApp);
applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType,
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
} catch (StorageManagementException e) {
String msg = "Error occurred while md5sum value retrieving process: application UUID "
+ applicationReleaseDTO.getUuid();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying app release data.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred when executing the query for verifying application release existence for "
+ "the package.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
} catch (IOException e) {
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
@ -956,73 +955,64 @@ public class ApplicationManagerImpl implements ApplicationManager {
// The application executable artifacts such as apks are uploaded.
try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
if (md5OfApp == null) {
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
+ "release UUID " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
try (ByteArrayInputStream binary = new ByteArrayInputStream(content)) {
ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(binary, deviceType);
String packageName = applicationInstaller.getPackageName();
String md5OfApp = applicationStorageManager.getMD5(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
if (md5OfApp == null) {
String msg = "Error occurred while retrieving md5sum value from the binary file for application "
+ "release UUID " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
try {
ConnectionManagerUtil.getDBConnection();
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg = "Same binary file is in the server. Hence you can't add same file into the "
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
if (applicationReleaseDTO.getPackageName() == null){
String msg = "Found null value for application release package name for application "
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationManagementException(msg);
}
if (!applicationReleaseDTO.getPackageName().equals(packageName)){
String msg = "Package name of the new artifact does not match with the package name of "
+ "the exiting application release. Package name of the existing app release "
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
+ "application release " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
if (!applicationReleaseDTO.getAppHashValue().equals(md5OfApp)) {
applicationReleaseDTO.setInstallerName(applicationArtifact.getInstallerName());
ApplicationInstaller applicationInstaller = applicationStorageManager
.getAppInstallerData(Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), deviceType);
String packageName = applicationInstaller.getPackageName();
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packageName);
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
applicationReleaseDTO.setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO, deviceType, binaryDuplicate,
tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO, tenantId);
}
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application "
+ "release existing for new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when executing the query for verifying application release "
+ "existence for the new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
try {
ConnectionManagerUtil.getDBConnection();
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg = "Same binary file is in the server. Hence you can't add same file into the "
+ "server. Device Type: " + deviceType + " and package name: " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
if (applicationReleaseDTO.getPackageName() == null) {
String msg = "Found null value for application release package name for application "
+ "release which has UUID: " + applicationReleaseDTO.getUuid();
log.error(msg);
throw new ApplicationManagementException(msg);
}
if (!applicationReleaseDTO.getPackageName().equals(packageName)) {
String msg = "Package name of the new artifact does not match with the package name of "
+ "the exiting application release. Package name of the existing app release "
+ applicationReleaseDTO.getPackageName() + " and package name of the new "
+ "application release " + packageName;
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO.setVersion(applicationInstaller.getVersion());
applicationReleaseDTO.setPackageName(packageName);
String deletingAppHashValue = applicationReleaseDTO.getAppHashValue();
applicationReleaseDTO.setAppHashValue(md5OfApp);
applicationStorageManager.uploadReleaseArtifact(applicationReleaseDTO, deviceType,
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())),
tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO, tenantId);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application "
+ "release existing for new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg = "Error occurred when executing the query for verifying application release "
+ "existence for the new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
} catch (StorageManagementException e) {
@ -1031,7 +1021,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
} catch (IOException e) {
String msg = "Error occurred when getting byte array of binary file. Installer name: " + applicationArtifact
String msg = "Error occurred when getting file input stream. Installer name: " + applicationArtifact
.getInstallerName();
log.error(msg, e);
throw new ApplicationStorageManagementException(msg, e);
@ -3605,52 +3595,49 @@ public class ApplicationManagerImpl implements ApplicationManager {
DeviceType deviceTypeObj = APIUtil.getDeviceTypeData(applicationDTO.getDeviceTypeId());
// The application executable artifacts such as deb are uploaded.
try {
byte[] content = IOUtils.toByteArray(applicationArtifact.getInstallerStream());
try (ByteArrayInputStream binaryClone = new ByteArrayInputStream(content)) {
String md5OfApp = applicationStorageManager.getMD5(binaryClone);
if (md5OfApp == null) {
String msg = "Error occurred while retrieving md5sum value from the binary file for "
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
try {
ConnectionManagerUtil.getDBConnection();
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg =
"Same binary file is in the server. Hence you can't add same file into the "
+ "server. Device Type: " + deviceTypeObj.getName()
+ " and package name: " + applicationDTO.getApplicationReleaseDTOs()
.get(0).getPackageName();
log.error(msg);
throw new BadRequestException(msg);
}
String md5OfApp = applicationStorageManager.getMD5(
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())));
if (md5OfApp == null) {
String msg = "Error occurred while retrieving md5sum value from the binary file for "
+ "application release UUID " + applicationReleaseDTO.get().getUuid();
log.error(msg);
throw new ApplicationStorageManagementException(msg);
}
applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
applicationReleaseDTO.get().setAppHashValue(md5OfApp);
try (ByteArrayInputStream binaryDuplicate = new ByteArrayInputStream(content)) {
applicationStorageManager
.uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
binaryDuplicate, tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO.get(), tenantId);
}
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application"
+ " release existing for new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
if (!applicationReleaseDTO.get().getAppHashValue().equals(md5OfApp)) {
try {
ConnectionManagerUtil.getDBConnection();
if (this.applicationReleaseDAO.verifyReleaseExistenceByHash(md5OfApp, tenantId)) {
String msg =
"Error occurred when executing the query for verifying application release "
+ "existence for the new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
"Same binary file is in the server. Hence you can't add same file into the "
+ "server. Device Type: " + deviceTypeObj.getName()
+ " and package name: " + applicationDTO.getApplicationReleaseDTOs()
.get(0).getPackageName();
log.error(msg);
throw new BadRequestException(msg);
}
applicationReleaseDTO.get().setInstallerName(applicationArtifact.getInstallerName());
String deletingAppHashValue = applicationReleaseDTO.get().getAppHashValue();
applicationReleaseDTO.get().setAppHashValue(md5OfApp);
applicationStorageManager.
uploadReleaseArtifact(applicationReleaseDTO.get(), deviceTypeObj.getName(),
Files.newInputStream(Paths.get(applicationArtifact.getInstallerPath())), tenantId);
applicationStorageManager.copyImageArtifactsAndDeleteInstaller(deletingAppHashValue,
applicationReleaseDTO.get(), tenantId);
} catch (DBConnectionException e) {
String msg = "Error occurred when getting database connection for verifying application"
+ " release existing for new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
String msg =
"Error occurred when executing the query for verifying application release "
+ "existence for the new app hash value.";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
} catch (StorageManagementException e) {
@ -4422,7 +4409,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
@ -4447,12 +4433,6 @@ public class ApplicationManagerImpl implements ApplicationManager {
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting App folder of tenant"
+ " of tenant ID: " + tenantId ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
@ -4461,19 +4441,9 @@ public class ApplicationManagerImpl implements ApplicationManager {
@Override
public void deleteApplicationDataByTenantDomain(String tenantDomain) throws ApplicationManagementException {
int tenantId;
try{
TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
TenantInfoBean tenantInfoBean = tenantMgtAdminService.getTenant(tenantDomain);
tenantId = tenantInfoBean.getTenantId();
} catch (Exception e) {
String msg = "Error getting tenant ID from domain: "
+ tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
try {
tenantId = DataHolder.getInstance().getTenantManagerAdminService().getTenantId(tenantDomain);
ConnectionManagerUtil.beginDBTransaction();
vppApplicationDAO.deleteAssociationByTenant(tenantId);
@ -4497,40 +4467,54 @@ public class ApplicationManagerImpl implements ApplicationManager {
spApplicationDAO.deleteSPApplicationMappingByTenant(tenantId);
spApplicationDAO.deleteIdentityServerByTenant(tenantId);
applicationDAO.deleteApplicationsByTenant(tenantId);
APIUtil.getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
ConnectionManagerUtil.commitDBTransaction();
} catch (DBConnectionException e) {
String msg = "Error occurred while observing the database connection to delete applications for tenant with ID: "
+ tenantId;
String msg = "Error occurred while observing the database connection to delete applications for tenant with " +
"domain: " + tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Database access error is occurred when getting applications for tenant with ID: " + tenantId;
String msg = "Database access error is occurred when getting applications for tenant with domain: "
+ tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (LifeCycleManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting life-cycle state data of application releases of the tenant"
+ " of ID: " + tenantId ;
+ " of domain: " + tenantDomain ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ReviewManagementDAOException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting reviews of application releases of the applications"
+ " of tenant ID: " + tenantId ;
+ " of tenant of domain: " + tenantDomain ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (ApplicationStorageManagementException e) {
ConnectionManagerUtil.rollbackDBTransaction();
String msg = "Error occurred while deleting App folder of tenant"
+ " of tenant ID: " + tenantId ;
} catch (Exception e) {
String msg = "Error getting tenant ID from domain: "
+ tenantDomain;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
@Override
public void deleteApplicationArtifactsByTenantDomain(String tenantDomain) throws ApplicationManagementException {
int tenantId;
try {
tenantId = DataHolder.getInstance().getTenantManagerAdminService().getTenantId(tenantDomain);
DataHolder.getInstance().getApplicationStorageManager().deleteAppFolderOfTenant(tenantId);
} catch (ApplicationStorageManagementException e) {
String msg = "Error deleting app artifacts of tenant of domain: " + tenantDomain ;
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (TenantMgtException e) {
String msg = "Error getting tenant ID from domain: "
+ tenantDomain + " when trying to delete application artifacts of tenant";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
}

@ -32,14 +32,13 @@ import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagem
import io.entgra.device.mgt.core.device.mgt.core.common.util.StorageManagementUtil;
import net.dongliu.apk.parser.bean.ApkMeta;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.io.IOUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Paths;
import java.util.List;
import static io.entgra.device.mgt.core.device.mgt.core.common.util.StorageManagementUtil.saveFile;
@ -158,13 +157,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
public void uploadReleaseArtifact(ApplicationReleaseDTO applicationReleaseDTO,
String deviceType, InputStream binaryFile, int tenantId) throws ResourceManagementException {
try {
byte [] content = IOUtils.toByteArray(binaryFile);
String artifactDirectoryPath =
storagePath + tenantId + File.separator + applicationReleaseDTO.getAppHashValue() + File.separator
+ Constants.APP_ARTIFACT;
StorageManagementUtil.createArtifactDirectory(artifactDirectoryPath);
String artifactPath = artifactDirectoryPath + File.separator + applicationReleaseDTO.getInstallerName();
saveFile(new ByteArrayInputStream(content), artifactPath);
saveFile(binaryFile, artifactPath);
} catch (IOException e) {
String msg = "IO Exception while saving the release artifacts in the server for the application UUID "
+ applicationReleaseDTO.getUuid();
@ -327,4 +325,12 @@ public class ApplicationStorageManagerImpl implements ApplicationStorageManager
}
}
}
@Override
public String getAbsolutePathOfFile(String hashVal, String folderName, String fileName, int tenantId) {
String filePath =
storagePath + tenantId + File.separator + hashVal + File.separator + folderName + File.separator
+ fileName;
return Paths.get(filePath).toAbsolutePath().toString();
}
}

@ -31,6 +31,7 @@ import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.nio.file.FileSystems;
@ -103,8 +104,13 @@ public class FileTransferServiceImpl implements FileTransferService {
@Override
public boolean isExistsOnLocal(URL downloadUrl) throws FileTransferServiceException {
try {
return FileTransferServiceHelperUtil.resolve(downloadUrl) != null;
} catch (FileTransferServiceHelperUtilException e) {
FileDescriptor fileDescriptor = FileTransferServiceHelperUtil.resolve(downloadUrl);
if (fileDescriptor != null && fileDescriptor.getFile() != null) {
fileDescriptor.getFile().close();
return true;
}
return false;
} catch (FileTransferServiceHelperUtilException | IOException e) {
String msg = "Error occurred while checking the existence of artifact on the local environment";
log.error(msg, e);
throw new FileTransferServiceException(msg, e);

@ -1750,8 +1750,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
int appReleaseId = applicationReleaseDTO.getId();
List<SubscriptionsDTO> groupDetailsWithDevices = new ArrayList<>();
List<GroupSubscriptionDTO> groupDetails =
@ -1767,7 +1767,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
// Retrieve group details and device IDs for the group using the service layer
GroupDetailsDTO groupDetailWithDevices =
groupManagementProviderService.getGroupDetailsWithDevices(groupName, offset, limit);
groupManagementProviderService.getGroupDetailsWithDevices(groupName, applicationDTO.getDeviceTypeId(),
offset, limit);
SubscriptionsDTO groupDetailDTO = new SubscriptionsDTO();
groupDetailDTO.setId(groupDetailWithDevices.getGroupId());
@ -1940,8 +1941,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
int appReleaseId = applicationReleaseDTO.getId();
List<SubscriptionsDTO> userSubscriptionsWithDevices = new ArrayList<>();
List<SubscriptionsDTO> userSubscriptions =
@ -1957,7 +1958,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
// Retrieve owner details and device IDs for the user using the service layer
OwnerWithDeviceDTO ownerDetailsWithDevices =
deviceManagementProviderService.getOwnersWithDeviceIds(userName);
deviceManagementProviderService.getOwnersWithDeviceIds(userName, applicationDTO.getDeviceTypeId());
SubscriptionsDTO userSubscriptionDTO = new SubscriptionsDTO();
userSubscriptionDTO.setName(userSubscription.getName());
@ -1994,15 +1995,20 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for (Integer deviceId : deviceIds) {
List<DeviceSubscriptionDTO> deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
userSubscription.getAppReleaseId(), unsubscribe, tenantId, deviceIds);
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
if (ownerWithDeviceByDeviceId == null) {
continue;
}
boolean isNewDevice = true;
for (DeviceSubscriptionDTO subscription : deviceSubscriptions) {
if (subscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(subscription.getDeviceId());
deviceDetail.setSubId(subscription.getId());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
deviceDetail.setStatus(subscription.getStatus());
deviceDetail.setActionType(subscription.getActionTriggeredFrom());
@ -2011,8 +2017,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(subscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(subscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(subscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = subscription.getStatus();
switch (status) {
@ -2042,16 +2048,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true;
@ -2061,11 +2067,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -2127,8 +2133,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
int appReleaseId = applicationReleaseDTO.getId();
List<SubscriptionsDTO> roleSubscriptionsWithDevices = new ArrayList<>();
List<SubscriptionsDTO> roleSubscriptions =
@ -2169,7 +2175,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
for (String user : users) {
OwnerWithDeviceDTO ownerDetailsWithDevices;
try {
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user);
ownerDetailsWithDevices = deviceManagementProviderService.getOwnersWithDeviceIds(user, applicationDTO.getDeviceTypeId());
} catch (DeviceManagementDAOException e) {
throw new ApplicationManagementException("Error retrieving owner details with devices for user: " + user, e);
}
@ -2182,7 +2188,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
subscribedDeviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
appReleaseId, !unsubscribe, tenantId, deviceIds);
}
OwnerWithDeviceDTO ownerWithDeviceByDeviceId =
deviceManagementProviderService.getOwnerWithDeviceByDeviceId(deviceId);
if (ownerWithDeviceByDeviceId == null) {
continue;
}
List<DeviceSubscriptionDTO> deviceSubscriptions;
try {
deviceSubscriptions = subscriptionDAO.getSubscriptionDetailsByDeviceIds(
@ -2196,9 +2206,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (deviceSubscription.getDeviceId() == deviceId) {
DeviceSubscriptionData deviceDetail = new DeviceSubscriptionData();
deviceDetail.setDeviceId(deviceSubscription.getDeviceId());
deviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
deviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
deviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
deviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
deviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
deviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
deviceDetail.setStatus(deviceSubscription.getStatus());
deviceDetail.setActionType(deviceSubscription.getActionTriggeredFrom());
@ -2208,8 +2218,8 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
deviceDetail.setUnsubscribed(deviceSubscription.isUnsubscribed());
deviceDetail.setUnsubscribedBy(deviceSubscription.getUnsubscribedBy());
deviceDetail.setUnsubscribedTimestamp(deviceSubscription.getUnsubscribedTimestamp());
deviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
deviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
deviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
status = deviceSubscription.getStatus();
switch (status) {
@ -2239,16 +2249,16 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (subscribedDevice.getDeviceId() == deviceId) {
DeviceSubscriptionData subscribedDeviceDetail = new DeviceSubscriptionData();
subscribedDeviceDetail.setDeviceId(subscribedDevice.getDeviceId());
subscribedDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
subscribedDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
subscribedDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
subscribedDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
subscribedDeviceDetail.setSubId(subscribedDevice.getId());
subscribedDeviceDetail.setActionTriggeredBy(subscribedDevice.getSubscribedBy());
subscribedDeviceDetail.setActionTriggeredTimestamp(subscribedDevice.getSubscribedTimestamp());
subscribedDeviceDetail.setActionType(subscribedDevice.getActionTriggeredFrom());
subscribedDeviceDetail.setStatus(subscribedDevice.getStatus());
subscribedDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
subscribedDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
subscribedDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
subscribedDevices.add(subscribedDeviceDetail);
statusCounts.put("SUBSCRIBED", statusCounts.get("SUBSCRIBED") + 1);
isSubscribedDevice = true;
@ -2258,11 +2268,11 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
if (!isSubscribedDevice) {
DeviceSubscriptionData newDeviceDetail = new DeviceSubscriptionData();
newDeviceDetail.setDeviceId(deviceId);
newDeviceDetail.setDeviceName(ownerDetailsWithDevices.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerDetailsWithDevices.getUserName());
newDeviceDetail.setDeviceStatus(ownerDetailsWithDevices.getDeviceStatus());
newDeviceDetail.setType(ownerDetailsWithDevices.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerDetailsWithDevices.getDeviceIdentifiers());
newDeviceDetail.setDeviceName(ownerWithDeviceByDeviceId.getDeviceNames());
newDeviceDetail.setDeviceOwner(ownerWithDeviceByDeviceId.getUserName());
newDeviceDetail.setDeviceStatus(ownerWithDeviceByDeviceId.getDeviceStatus());
newDeviceDetail.setType(ownerWithDeviceByDeviceId.getDeviceTypes());
newDeviceDetail.setDeviceIdentifier(ownerWithDeviceByDeviceId.getDeviceIdentifiers());
newDevices.add(newDeviceDetail);
statusCounts.put("NEW", statusCounts.get("NEW") + 1);
}
@ -2295,7 +2305,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
return roleSubscriptionsWithDevices;
} catch (ApplicationManagementDAOException e) {
} catch (ApplicationManagementDAOException | DeviceManagementDAOException e) {
String msg = "Error occurred in retrieving role subscriptions with devices";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
@ -2337,6 +2347,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
int appReleaseId = applicationReleaseDTO.getId();
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
@ -2351,7 +2362,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
List<DeviceDetailsDTO> allDevices =
deviceManagementProviderService.getDevicesByTenantId(tenantId);
deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId());
List<Integer> deviceIds = allDevices.stream()
.map(DeviceDetailsDTO::getDeviceId)
@ -2523,6 +2534,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
log.error(msg);
throw new NotFoundException(msg);
}
ApplicationDTO applicationDTO = this.applicationDAO.getAppWithRelatedRelease(uuid, tenantId);
int appReleaseId = applicationReleaseDTO.getId();
List<DeviceSubscriptionDTO> allSubscriptions =
@ -2552,7 +2564,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
statusCounts.put("NEW", 0);
List<DeviceDetailsDTO> allDevices =
deviceManagementProviderService.getDevicesByTenantId(tenantId);
deviceManagementProviderService.getDevicesByTenantId(tenantId, applicationDTO.getDeviceTypeId());
for (DeviceDetailsDTO device : allDevices) {
Integer deviceId = device.getDeviceId();
@ -2642,7 +2654,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
@Override
public List<DeviceOperationDTO> getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid, int offset, int limit)
public List<DeviceOperationDTO> getSubscriptionOperationsByUUIDAndDeviceID(int deviceId, String uuid)
throws ApplicationManagementException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
if (uuid == null || uuid.isEmpty()) {
@ -2661,7 +2673,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
DeviceManagementProviderService deviceManagementProviderService = HelperUtil.getDeviceManagementProviderService();
List<DeviceOperationDTO> deviceSubscriptions =
subscriptionDAO.getSubscriptionOperationsByAppReleaseIDAndDeviceID(appReleaseId, deviceId, tenantId, offset, limit);
subscriptionDAO.getSubscriptionOperationsByAppReleaseIDAndDeviceID(appReleaseId, deviceId, tenantId);
for (DeviceOperationDTO deviceSubscription : deviceSubscriptions) {
Integer operationId = deviceSubscription.getOperationId();
if (operationId != null) {

@ -26,7 +26,6 @@ import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.*;
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
import io.entgra.device.mgt.core.application.mgt.core.impl.AppmDataHandlerImpl;
@ -35,11 +34,15 @@ import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateMa
import io.entgra.device.mgt.core.application.mgt.core.task.ScheduledAppSubscriptionTaskManager;
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.osgi.framework.BundleContext;
import org.osgi.service.component.ComponentContext;
import org.osgi.service.component.annotations.*;
import org.osgi.service.component.annotations.Reference;
import org.osgi.service.component.annotations.ReferenceCardinality;
import org.osgi.service.component.annotations.ReferencePolicy;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.user.core.service.RealmService;
@ -109,7 +112,7 @@ public class ApplicationManagementServiceComponent {
bundleContext.registerService(FileTransferService.class.getName(), fileTransferService, null);
ScheduledAppSubscriptionTaskManager taskManager = new ScheduledAppSubscriptionTaskManager();
// todo: taskManager.scheduleCleanupTask();
taskManager.scheduleCleanupTask();
log.info("ApplicationManagement core bundle has been successfully initialized");
} catch (Throwable e) {
@ -200,4 +203,25 @@ public class ApplicationManagementServiceComponent {
}
DataHolder.getInstance().setTaskService(null);
}
@Reference(
name = "io.entgra.device.mgt.core.tenant.manager",
service = io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService.class,
cardinality = ReferenceCardinality.MANDATORY,
policy = ReferencePolicy.DYNAMIC,
unbind = "unsetTenantManagementAdminService")
protected void setTenantManagementAdminService(TenantManagerAdminService tenantManagerAdminService) {
if (log.isDebugEnabled()) {
log.debug("Setting Tenant management admin Service");
}
DataHolder.getInstance().setTenantManagerAdminService(tenantManagerAdminService);
}
@SuppressWarnings("unused")
protected void unsetTenantManagementAdminService(TenantManagerAdminService tenantManagerAdminService) {
if (log.isDebugEnabled()) {
log.debug("Un setting Tenant management admin service");
}
DataHolder.getInstance().setTenantManagerAdminService(null);
}
}

@ -25,9 +25,9 @@ import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationMa
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
import io.entgra.device.mgt.core.application.mgt.common.services.*;
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.user.core.service.RealmService;
@ -58,6 +58,7 @@ public class DataHolder {
private TaskService taskService;
private FileTransferService fileTransferService;
private TenantManagerAdminService tenantManagerAdminService;
private static final DataHolder applicationMgtDataHolder = new DataHolder();
@ -164,4 +165,12 @@ public class DataHolder {
public void setFileTransferService(FileTransferService fileTransferService) {
this.fileTransferService = fileTransferService;
}
public TenantManagerAdminService getTenantManagerAdminService() {
return tenantManagerAdminService;
}
public void setTenantManagerAdminService(TenantManagerAdminService tenantManagerAdminService) {
this.tenantManagerAdminService = tenantManagerAdminService;
}
}

@ -180,6 +180,7 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(artifactLinkUrl).download(artifactLinkUrl);
applicationArtifact.setInstallerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setInstallerStream(fileDescriptor.getFile());
applicationArtifact.setInstallerPath(fileDescriptor.getAbsolutePath());
}
if (iconLink != null) {
@ -187,6 +188,7 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(iconLinkUrl).download(iconLinkUrl);
applicationArtifact.setIconName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setIconStream(fileDescriptor.getFile());
applicationArtifact.setIconPath(fileDescriptor.getAbsolutePath());
}
if (bannerLink != null) {
@ -194,10 +196,12 @@ public class ApplicationManagementUtil {
fileDescriptor = FileDownloaderServiceProvider.getFileDownloaderService(bannerLinkUrl).download(bannerLinkUrl);
applicationArtifact.setBannerName(fileDescriptor.getFullQualifiedName());
applicationArtifact.setBannerStream(fileDescriptor.getFile());
applicationArtifact.setBannerPath(fileDescriptor.getAbsolutePath());
}
if (screenshotLinks != null) {
Map<String, InputStream> screenshotData = new TreeMap<>();
Map<String, String> screenshotPaths = new TreeMap<>();
// This is to handle cases in which multiple screenshots have the same name
Map<String, Integer> screenshotNameCount = new HashMap<>();
URL screenshotLinkUrl;
@ -208,6 +212,7 @@ public class ApplicationManagementUtil {
screenshotNameCount.put(screenshotName, screenshotNameCount.getOrDefault(screenshotName, 0) + 1);
screenshotName = FileUtil.generateDuplicateFileName(screenshotName, screenshotNameCount.get(screenshotName));
screenshotData.put(screenshotName, fileDescriptor.getFile());
screenshotPaths.put(screenshotName, fileDescriptor.getAbsolutePath());
}
applicationArtifact.setScreenshots(screenshotData);
}

@ -74,6 +74,7 @@ public class Constants {
public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles";
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
public static final String MICROSOFT_STORE_URL = "https://apps.microsoft.com/detail/";
public static final String GOOGLE_PLAY_SYNCED_APP = "GooglePlaySyncedApp";
// Subscription task related constants

@ -23,7 +23,9 @@ import com.google.gson.Gson;
import io.entgra.device.mgt.core.application.mgt.common.ChunkDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileDescriptor;
import io.entgra.device.mgt.core.application.mgt.common.FileMetaEntry;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationStorageManagementException;
import io.entgra.device.mgt.core.application.mgt.core.exception.FileTransferServiceHelperUtilException;
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.NotFoundException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -175,6 +177,12 @@ public class FileTransferServiceHelperUtil {
}
String []urlPathSegments = downloadUrl.getPath().split("/");
FileDescriptor fileDescriptorResolvedFromRelease = resolve(urlPathSegments);
if (fileDescriptorResolvedFromRelease != null) {
return fileDescriptorResolvedFromRelease;
}
if (urlPathSegments.length < 2) {
if (log.isDebugEnabled()) {
log.debug("URL patch segments contain less than 2 segments");
@ -234,4 +242,54 @@ public class FileTransferServiceHelperUtil {
throw new FileTransferServiceHelperUtilException("Error encountered while creating artifact file", e);
}
}
private static FileDescriptor resolve(String []urlSegments) throws FileTransferServiceHelperUtilException {
// check the possibility of url is pointing to a file resides in the default storage path
if (urlSegments.length < 4) {
if (log.isDebugEnabled()) {
log.debug("URL path segments contain less than 4 segments");
}
return null;
}
int tenantId;
try {
tenantId = Integer.parseInt(urlSegments[urlSegments.length - 4]);
} catch (NumberFormatException e) {
if (log.isDebugEnabled()) {
log.debug("URL isn't pointing to a file resides in the default storage path");
}
return null;
}
String fileName = urlSegments[urlSegments.length - 1];
String folderName = urlSegments[urlSegments.length - 2];
String appHash = urlSegments[urlSegments.length - 3];
try {
InputStream fileStream = DataHolder.getInstance().
getApplicationStorageManager().getFileStream(appHash, folderName, fileName, tenantId);
if (fileStream == null) {
if (log.isDebugEnabled()) {
log.debug("Could not found the file " + fileName);
}
return null;
}
String []fileNameSegments = fileName.split("\\.(?=[^.]+$)");
if (fileNameSegments.length < 2) {
throw new FileTransferServiceHelperUtilException("Invalid full qualified name encountered :" + fileName);
}
FileDescriptor fileDescriptor = new FileDescriptor();
fileDescriptor.setFile(fileStream);
fileDescriptor.setFullQualifiedName(fileName);
fileDescriptor.setExtension(fileNameSegments[fileNameSegments.length - 1]);
fileDescriptor.setFileName(fileNameSegments[fileNameSegments.length - 2]);
fileDescriptor.setAbsolutePath(DataHolder.getInstance().
getApplicationStorageManager().getAbsolutePathOfFile(appHash, folderName, fileName, tenantId));
return fileDescriptor;
} catch (ApplicationStorageManagementException e) {
throw new FileTransferServiceHelperUtilException("Error encountered while getting file input stream", e);
}
}
}

@ -329,7 +329,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED
DEVICE_ID INT NOT NULL,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL,
POLICY_CONTENT BLOB NULL,
POLICY_CONTENT TEXT NULL,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL,
CREATED_TIME TIMESTAMP NULL,

@ -336,7 +336,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT(1) NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -108,6 +108,46 @@
<groupId>org.wso2.carbon.analytics-common</groupId>
<artifactId>org.wso2.carbon.event.output.adapter.core</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.google.auth-library-oauth2-http</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.io.opencensus</groupId>
<artifactId>opencensus</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-http-util</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.orbit.io.grpc</groupId>
<artifactId>grpc-context</artifactId>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
<dependency>
<groupId>org.wso2.carbon</groupId>
<artifactId>org.wso2.carbon.utils</artifactId>
</dependency>
</dependencies>
<build>
@ -135,15 +175,30 @@
io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.*
</Export-Package>
<Import-Package>
com.google.gson;version="[2.9,3)",
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.operation.mgt;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.common.push.notification;version="[5.0,6)",
io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",
org.apache.commons.logging;version="[1.2,2)",
org.osgi.service.*;version="${imp.package.version.osgi.service}"
com.google.gson,
org.osgi.framework.*;version="${imp.package.version.osgi.framework}",
org.osgi.service.*;version="${imp.package.version.osgi.service}",
org.wso2.carbon.utils.*,
io.entgra.device.mgt.core.device.mgt.common.operation.mgt,
io.entgra.device.mgt.core.device.mgt.common.push.notification,
org.apache.commons.logging,
io.entgra.device.mgt.core.device.mgt.common.*,
io.entgra.device.mgt.core.device.mgt.core.service,
io.entgra.device.mgt.core.device.mgt.core.config.*,
io.entgra.device.mgt.core.device.mgt.core.config.push.notification.*,
io.entgra.device.mgt.core.device.mgt.extensions.logger.spi,
io.entgra.device.mgt.core.notification.logger.*,
com.google.auth.oauth2.*
</Import-Package>
<Embed-Dependency>
google-auth-library-oauth2-http;scope=compile|runtime,
google-http-client;scope=compile|runtime,
grpc-context;scope=compile|runtime,
guava;scope=compile|runtime,
opencensus;scope=compile|runtime,
failureaccess;scope=compile|runtime
</Embed-Dependency>
<Embed-Transitive>true</Embed-Transitive>
</instructions>
</configuration>
</plugin>

@ -32,7 +32,9 @@ public class FCMBasedPushNotificationProvider implements PushNotificationProvide
@Override
public NotificationStrategy getNotificationStrategy(PushNotificationConfig config) {
return new FCMNotificationStrategy(config);
FCMNotificationStrategy fcmNotificationStrategy = new FCMNotificationStrategy(config);
fcmNotificationStrategy.init();
return fcmNotificationStrategy;
}
}

@ -17,9 +17,7 @@
*/
package io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.push.notification.NotificationContext;
@ -27,6 +25,7 @@ import io.entgra.device.mgt.core.device.mgt.common.push.notification.Notificatio
import io.entgra.device.mgt.core.device.mgt.common.push.notification.PushNotificationConfig;
import io.entgra.device.mgt.core.device.mgt.common.push.notification.PushNotificationExecutionFailedException;
import io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.internal.FCMDataHolder;
import io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.util.FCMUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -39,14 +38,13 @@ import java.util.List;
public class FCMNotificationStrategy implements NotificationStrategy {
private static final Log log = LogFactory.getLog(FCMNotificationStrategy.class);
private static final String NOTIFIER_TYPE_FCM = "FCM";
private static final String FCM_TOKEN = "FCM_TOKEN";
private static final String FCM_ENDPOINT = "https://fcm.googleapis.com/fcm/send";
private static final String FCM_API_KEY = "fcmAPIKey";
private static final int TIME_TO_LIVE = 2419199; // 1 second less that 28 days
private static final int TIME_TO_LIVE = 2419199; // 1 second less than 28 days
private static final int HTTP_STATUS_CODE_OK = 200;
private final PushNotificationConfig config;
private static final String FCM_ENDPOINT_KEY = "FCM_SERVER_ENDPOINT";
public FCMNotificationStrategy(PushNotificationConfig config) {
this.config = config;
@ -64,12 +62,14 @@ public class FCMNotificationStrategy implements NotificationStrategy {
Device device = FCMDataHolder.getInstance().getDeviceManagementProviderService()
.getDeviceWithTypeProperties(ctx.getDeviceId());
if(device.getProperties() != null && getFCMToken(device.getProperties()) != null) {
this.sendWakeUpCall(ctx.getOperation().getCode(), device);
FCMUtil.getInstance().getDefaultApplication().refresh();
sendWakeUpCall(FCMUtil.getInstance().getDefaultApplication().getAccessToken().getTokenValue(),
getFCMToken(device.getProperties()));
}
} else {
if (log.isDebugEnabled()) {
log.debug("Not using FCM notifier as notifier type is set to " + config.getType() +
" in Platform Configurations.");
" in Platform Configurations.");
}
}
} catch (DeviceManagementException e) {
@ -79,71 +79,75 @@ public class FCMNotificationStrategy implements NotificationStrategy {
}
}
@Override
public NotificationContext buildContext() {
return null;
}
@Override
public void undeploy() {
}
/**
* Send FCM message to the FCM server to initiate the push notification
* @param accessToken Access token to authenticate with the FCM server
* @param registrationId Registration ID of the device
* @throws IOException If an error occurs while sending the request
* @throws PushNotificationExecutionFailedException If an error occurs while sending the push notification
*/
private void sendWakeUpCall(String accessToken, String registrationId) throws IOException,
PushNotificationExecutionFailedException {
HttpURLConnection conn = null;
String fcmServerEndpoint = FCMUtil.getInstance().getContextMetadataProperties()
.getProperty(FCM_ENDPOINT_KEY);
if(fcmServerEndpoint == null) {
String msg = "Encountered configuration issue. " + FCM_ENDPOINT_KEY + " is not defined";
log.error(msg);
throw new PushNotificationExecutionFailedException(msg);
}
private void sendWakeUpCall(String message, Device device) throws IOException,
PushNotificationExecutionFailedException {
if (device.getProperties() != null) {
OutputStream os = null;
byte[] bytes = getFCMRequest(message, getFCMToken(device.getProperties())).getBytes();
HttpURLConnection conn = null;
try {
conn = (HttpURLConnection) new URL(FCM_ENDPOINT).openConnection();
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "key=" + config.getProperty(FCM_API_KEY));
conn.setRequestMethod("POST");
conn.setDoOutput(true);
os = conn.getOutputStream();
try {
byte[] bytes = getFCMRequest(registrationId).getBytes();
URL url = new URL(fcmServerEndpoint);
conn = (HttpURLConnection) url.openConnection();
conn.setRequestProperty("Content-Type", "application/json");
conn.setRequestProperty("Authorization", "Bearer " + accessToken);
conn.setRequestMethod("POST");
conn.setDoOutput(true);
try (OutputStream os = conn.getOutputStream()) {
os.write(bytes);
} finally {
if (os != null) {
os.close();
}
if (conn != null) {
conn.disconnect();
}
}
int status = conn.getResponseCode();
if (log.isDebugEnabled()) {
log.debug("Result code: " + status + ", Message: " + conn.getResponseMessage());
if (status != 200) {
log.error("Response Status: " + status + ", Response Message: " + conn.getResponseMessage());
}
if (status != HTTP_STATUS_CODE_OK) {
throw new PushNotificationExecutionFailedException("Push notification sending failed with the HTTP " +
"error code '" + status + "'");
} finally {
if (conn != null) {
conn.disconnect();
}
}
}
private static String getFCMRequest(String message, String registrationId) {
JsonObject fcmRequest = new JsonObject();
fcmRequest.addProperty("delay_while_idle", false);
fcmRequest.addProperty("time_to_live", TIME_TO_LIVE);
fcmRequest.addProperty("priority", "high");
//Add message to FCM request
JsonObject data = new JsonObject();
if (message != null && !message.isEmpty()) {
data.addProperty("data", message);
fcmRequest.add("data", data);
}
/**
* Get the FCM request as a JSON string
* @param registrationId Registration ID of the device
* @return FCM request as a JSON string
*/
private static String getFCMRequest(String registrationId) {
JsonObject messageObject = new JsonObject();
messageObject.addProperty("token", registrationId);
//Set device reg-id
JsonArray regIds = new JsonArray();
regIds.add(new JsonPrimitive(registrationId));
JsonObject fcmRequest = new JsonObject();
fcmRequest.add("message", messageObject);
fcmRequest.add("registration_ids", regIds);
return fcmRequest.toString();
}
@Override
public NotificationContext buildContext() {
return null;
}
@Override
public void undeploy() {
}
private static String getFCMToken(List<Device.Property> properties) {
String fcmToken = null;
for (Device.Property property : properties) {
@ -159,5 +163,4 @@ public class FCMNotificationStrategy implements NotificationStrategy {
public PushNotificationConfig getConfig() {
return config;
}
}

@ -0,0 +1,108 @@
/*
* 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
*
* 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 io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.util;
import com.google.auth.oauth2.GoogleCredentials;
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
import io.entgra.device.mgt.core.device.mgt.core.config.push.notification.ContextMetadata;
import io.entgra.device.mgt.core.device.mgt.core.config.push.notification.PushNotificationConfiguration;
import io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.FCMNotificationStrategy;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.utils.CarbonUtils;
import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
import java.util.Properties;
public class FCMUtil {
private static final Log log = LogFactory.getLog(FCMUtil.class);
private static volatile FCMUtil instance;
private static GoogleCredentials defaultApplication;
private static final String FCM_SERVICE_ACCOUNT_PATH = CarbonUtils.getCarbonHome() + File.separator +
"repository" + File.separator + "resources" + File.separator + "service-account.json";
private static final String[] FCM_SCOPES = { "https://www.googleapis.com/auth/firebase.messaging" };
private Properties contextMetadataProperties;
private FCMUtil() {
initContextConfigs();
initDefaultOAuthApplication();
}
private void initDefaultOAuthApplication() {
if (defaultApplication == null) {
Path serviceAccountPath = Paths.get(FCM_SERVICE_ACCOUNT_PATH);
try {
defaultApplication = GoogleCredentials.
fromStream(Files.newInputStream(serviceAccountPath)).
createScoped(FCM_SCOPES);
} catch (IOException e) {
String msg = "Fail to initialize default OAuth application for FCM communication";
log.error(msg);
throw new IllegalStateException(msg, e);
}
}
}
/**
* Initialize the context metadata properties from the cdm-config.xml. This file includes the fcm server URL
* to be invoked when sending the wakeup call to the device.
*/
private void initContextConfigs() {
PushNotificationConfiguration pushNotificationConfiguration = DeviceConfigurationManager.getInstance().
getDeviceManagementConfig().getPushNotificationConfiguration();
List<ContextMetadata> contextMetadata = pushNotificationConfiguration.getContextMetadata();
Properties properties = new Properties();
if (contextMetadata != null) {
for (ContextMetadata metadata : contextMetadata) {
properties.setProperty(metadata.getKey(), metadata.getValue());
}
}
contextMetadataProperties = properties;
}
/**
* Get the instance of FCMUtil. FCMUtil is a singleton class which should not be
* instantiating more than once. Instantiating the class requires to read the service account file from
* the filesystem and instantiation of the GoogleCredentials object which are costly operations.
* @return FCMUtil instance
*/
public static FCMUtil getInstance() {
if (instance == null) {
synchronized (FCMUtil.class) {
if (instance == null) {
instance = new FCMUtil();
}
}
}
return instance;
}
public GoogleCredentials getDefaultApplication() {
return defaultApplication;
}
public Properties getContextMetadataProperties() {
return contextMetadataProperties;
}
}

@ -468,5 +468,10 @@
<artifactId>jaxb-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.tenant.mgt.common</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
</project>

@ -916,6 +916,12 @@ public interface PolicyManagementService {
required = false)
@QueryParam("status")
String status,
@ApiParam(
name = "deviceType",
value = "The device type of the policy that needs filtering.",
required = false)
@QueryParam("deviceType")
String deviceType,
@ApiParam(
name = "If-Modified-Since",
value = "Checks if the requested variant was modified, since the specified date-time. \n" +

@ -298,8 +298,13 @@ public interface UserManagementAdminService {
name = "tenantDomain",
value = "The domain of the tenant to be deleted.",
required = true)
@PathParam("tenantDomain")
String tenantDomain);
String tenantDomain,
@ApiParam(
name = "deleteAppArtifacts",
value = "Flag to indicate whether to delete application artifacts.",
required = false)
@QueryParam("deleteAppArtifacts")
@DefaultValue("false")
boolean deleteAppArtifacts);
}

@ -566,22 +566,49 @@ public class DeviceManagementServiceImpl implements DeviceManagementService {
@Path("/type/{deviceType}/id/{deviceId}/rename")
public Response renameDevice(Device device, @PathParam("deviceType") String deviceType,
@PathParam("deviceId") String deviceId) {
if (device == null) {
String msg = "Required values are not set to rename device";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
if (StringUtils.isEmpty(device.getName())) {
String msg = "Device name is not set to rename device";
log.error(msg);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
}
DeviceManagementProviderService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceManagementService();
try {
Device persistedDevice = deviceManagementProviderService.getDevice(new DeviceIdentifier
(deviceId, deviceType), true);
persistedDevice.setName(device.getName());
System.out.println("This is rename device");
boolean responseOfmodifyEnrollment = deviceManagementProviderService.modifyEnrollment(persistedDevice);
boolean responseOfDeviceNameChanged = deviceManagementProviderService.sendDeviceNameChangedNotification(
persistedDevice);
boolean response = responseOfmodifyEnrollment && responseOfDeviceNameChanged;
return Response.status(Response.Status.CREATED).entity(response).build();
} catch (DeviceManagementException e) {
String msg = "Error encountered while updating requested device of type : " + deviceType ;
Device updatedDevice = deviceManagementProviderService.updateDeviceName(device, deviceType, deviceId);
if (updatedDevice != null) {
boolean notificationResponse = deviceManagementProviderService.sendDeviceNameChangedNotification(updatedDevice);
if (notificationResponse) {
return Response.status(Response.Status.CREATED).entity(updatedDevice).build();
} else {
String msg = "Device updated successfully, but failed to send notification.";
log.warn(msg);
return Response.status(Response.Status.CREATED).entity(updatedDevice).header("Warning", msg).build();
}
} else {
String msg = "Device update failed for device of type : " + deviceType;
log.error(msg);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
} catch (BadRequestException e) {
String msg = "Bad request: " + e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.BAD_REQUEST).entity(msg).build();
} catch (DeviceNotFoundException e) {
String msg = "Device not found: " + e.getMessage();
log.error(msg, e);
return Response.status(Response.Status.NOT_FOUND).entity(msg).build();
} catch (DeviceManagementException e) {
String msg = "Error encountered while updating requested device of type : " + deviceType;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
} catch (ConflictException e) {
String msg = "Conflict encountered while updating requested device of type : " + deviceType;
log.error(msg, e);
return Response.status(Response.Status.CONFLICT).entity(msg).build();
}
}

@ -499,6 +499,7 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
@QueryParam("name") String name,
@QueryParam("type") String type,
@QueryParam("status") String status,
@QueryParam("deviceType") String deviceType,
@HeaderParam("If-Modified-Since") String ifModifiedSince,
@QueryParam("offset") int offset,
@QueryParam("limit") int limit) {
@ -516,6 +517,9 @@ public class PolicyManagementServiceImpl implements PolicyManagementService {
if (status != null){
request.setStatus(status);
}
if (deviceType != null) {
request.setDeviceType(deviceType);
}
try {
PolicyAdministratorPoint policyAdministratorPoint = policyManagementService.getPAP();
policies = policyAdministratorPoint.getPolicyList(request);

@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.admin;
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
@ -29,9 +30,6 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.CredentialManagementR
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.base.MultitenantConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.stratos.common.exception.StratosException;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserStoreException;
import javax.validation.constraints.Size;
import javax.ws.rs.*;
@ -91,7 +89,7 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
@DELETE
@Path("/domain/{tenantDomain}")
@Override
public Response deleteTenantByDomain(@PathParam("tenantDomain") String tenantDomain) {
public Response deleteTenantByDomain(@PathParam("tenantDomain") String tenantDomain, @QueryParam("deleteAppArtifacts") boolean deleteAppArtifacts) {
try {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if (tenantId != MultitenantConstants.SUPER_TENANT_ID){
@ -99,15 +97,20 @@ public class UserManagementAdminServiceImpl implements UserManagementAdminServic
log.error(msg);
return Response.status(Response.Status.UNAUTHORIZED).entity(msg).build();
} else {
if (deleteAppArtifacts) {
DeviceMgtAPIUtils.getApplicationManager().deleteApplicationArtifactsByTenantDomain(tenantDomain);
}
DeviceMgtAPIUtils.getApplicationManager().deleteApplicationDataByTenantDomain(tenantDomain);
DeviceMgtAPIUtils.getDeviceManagementService().deleteDeviceDataByTenantDomain(tenantDomain);
TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
tenantMgtAdminService.deleteTenant(tenantDomain);
DeviceMgtAPIUtils.getTenantManagerAdminService().deleteTenant(tenantDomain);
String msg = "Tenant Deletion process has been initiated for tenant:" + tenantDomain;
if (log.isDebugEnabled()) {
log.debug(msg);
}
return Response.status(Response.Status.OK).entity(msg).build();
}
} catch (StratosException | UserStoreException e) {
} catch (TenantMgtException e) {
String msg = "Error deleting tenant: " + tenantDomain;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();

@ -33,6 +33,7 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestV
import io.entgra.device.mgt.core.device.mgt.common.authorization.GroupAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.permission.mgt.PermissionManagerServiceImpl;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
@ -46,7 +47,6 @@ import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.analytics.api.AnalyticsDataAPI;
import org.wso2.carbon.analytics.stream.persistence.stub.EventStreamPersistenceAdminServiceStub;
import org.wso2.carbon.authenticator.stub.AuthenticationAdminStub;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
@ -167,6 +167,7 @@ public class DeviceMgtAPIUtils {
private static volatile ConsumerRESTAPIServices consumerRESTAPIServices;
private static volatile APIManagementProviderService apiManagementProviderService;
private static volatile APIPublisherService apiPublisher;
private static volatile TenantManagerAdminService tenantManagerAdminService;
static {
String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password");
@ -1304,4 +1305,21 @@ public class DeviceMgtAPIUtils {
}
return isPermitted;
}
public static TenantManagerAdminService getTenantManagerAdminService(){
if(tenantManagerAdminService == null) {
synchronized (DeviceMgtAPIUtils.class) {
if (tenantManagerAdminService == null) {
tenantManagerAdminService = (TenantManagerAdminService) PrivilegedCarbonContext.getThreadLocalCarbonContext().
getOSGiService(TenantManagerAdminService.class, null);
if (tenantManagerAdminService == null) {
String msg = "Tenant Manager Admin Service is null";
log.error(msg);
throw new IllegalStateException(msg);
}
}
}
}
return tenantManagerAdminService;
}
}

@ -58,6 +58,8 @@ public class MDMAppConstants {
}
public static final String INSTALL_ENTERPRISE_APPLICATION = "INSTALL_ENTERPRISE_APPLICATION";
public static final String UNINSTALL_ENTERPRISE_APPLICATION = "UNINSTALL_ENTERPRISE_APPLICATION";
public static final String INSTALL_STORE_APPLICATION = "INSTALL_STORE_APPLICATION";
public static final String UNINSTALL_STORE_APPLICATION = "UNINSTALL_STORE_APPLICATION";
public static final String INSTALL_WEB_CLIP_APPLICATION = "INSTALL_WEB_CLIP";
public static final String UNINSTALL_WEB_CLIP_APPLICATION = "UNINSTALL_WEB_CLIP";
//App type constants related to window device type

@ -24,6 +24,7 @@ public class PolicyPaginationRequest {
private String name;
private String type;
private String status;
private String deviceType;
public PolicyPaginationRequest(int start, int rowCount) {
this.startIndex = start;
@ -70,6 +71,14 @@ public class PolicyPaginationRequest {
this.status = status;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
@Override
public String toString() {
return "Group Name '" + this.name + "' num of rows: " + this.rowCount + " start index: " + this.startIndex;

@ -0,0 +1,49 @@
/*
* 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
*
* 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 io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows;
import com.google.gson.Gson;
import java.io.Serializable;
public class AppStoreApplication implements Serializable {
private String type;
private String packageIdentifier;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public String getPackageIdentifier() {
return packageIdentifier;
}
public void setPackageIdentifier(String packageIdentifier) {
this.packageIdentifier = packageIdentifier;
}
public String toJSON() {
Gson gson = new Gson();
return gson.toJson(this);
}
}

@ -0,0 +1,32 @@
/*
* 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
*
* 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 io.entgra.device.mgt.core.device.mgt.common.exceptions;
public class ConflictException extends Exception {
private static final long serialVersionUID = -4998775497944307646L;
public ConflictException(String message) {
super(message);
}
public ConflictException(String message, Throwable cause) {
super(message, cause);
}
}

@ -23,8 +23,15 @@ import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagem
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
import java.nio.file.Paths;
/**
* This is a util class that handles Storage Management related tasks.
@ -81,13 +88,14 @@ public class StorageManagementUtil {
* @param path Path the file need to be saved in.
*/
public static void saveFile(InputStream inputStream, String path) throws IOException {
try (OutputStream outStream = new FileOutputStream(new File(path))) {
byte[] buffer = new byte[inputStream.available()];
if (inputStream.read(buffer) != -1) {
outStream.write(buffer);
try (BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(Files.newOutputStream(Paths.get(path)));
BufferedInputStream bufferedInputStream = new BufferedInputStream(inputStream)) {
byte []buffer = new byte[8192];
int n;
while ((n = bufferedInputStream.read(buffer)) != -1) {
bufferedOutputStream.write(buffer, 0, n);
}
} finally {
inputStream.close();
bufferedOutputStream.flush();
}
}

@ -0,0 +1,47 @@
/*
* Copyright (c) 2018 - 2023, 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
*
* 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 io.entgra.device.mgt.core.device.mgt.core.config.push.notification;
import javax.xml.bind.annotation.XmlAttribute;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlValue;
@XmlRootElement(name = "ContextMetadata")
public class ContextMetadata {
private String key;
private String value;
@XmlAttribute(name = "key")
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
@XmlValue
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
}

@ -33,6 +33,7 @@ public class PushNotificationConfiguration {
private int schedulerTaskInitialDelay;
private boolean schedulerTaskEnabled;
private List<String> pushNotificationProviders;
private List<ContextMetadata> contextMetadata;
@XmlElement(name = "SchedulerBatchSize", required = true)
public int getSchedulerBatchSize() {
@ -79,4 +80,14 @@ public class PushNotificationConfiguration {
public void setPushNotificationProviders(List<String> pushNotificationProviders) {
this.pushNotificationProviders = pushNotificationProviders;
}
@XmlElementWrapper(name = "ProviderContextMetadata")
@XmlElement(name = "ContextMetadata", required = true)
public List<ContextMetadata> getContextMetadata() {
return contextMetadata;
}
public void setContextMetadata(List<ContextMetadata> contextMetadata) {
this.contextMetadata = contextMetadata;
}
}

@ -100,11 +100,13 @@ public interface EnrollmentDAO {
* Retrieves owners and the list of device IDs related to an owner.
*
* @param owner the owner whose device IDs need to be retrieved
* @param allowingDeviceStatuses statuses of devices need to be retrieved
* @param tenantId the ID of the tenant
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
* @throws DeviceManagementDAOException if an error occurs while fetching the data
*/
OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId) throws DeviceManagementDAOException;
OwnerWithDeviceDTO getOwnersWithDevices(String owner, List<String> allowingDeviceStatuses, int tenantId, int deviceTypeId)
throws DeviceManagementDAOException;
/**
* Retrieves a list of device IDs with owners and device status.
@ -121,8 +123,11 @@ public interface EnrollmentDAO {
* Retrieves owners and the list of device IDs with device status.
*
* @param tenantId the ID of the tenant
* @param allowingDeviceStatuses the allowed device statuses of devices
* @param deviceTypeId the device type id
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user
* @throws DeviceManagementDAOException if an error occurs while fetching the data
*/
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException;
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, List<String> allowingDeviceStatuses, int deviceTypeId)
throws DeviceManagementDAOException;
}

@ -473,13 +473,16 @@ public interface GroupDAO {
* Get group details and list of device IDs related to the group.
*
* @param groupName Group name
* @param allowingDeviceStatuses the statuses of devices
* @param deviceTypeId the device type id
* @param tenantId Tenant ID
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
* @throws GroupManagementDAOException if an error occurs while retrieving the group details and devices
*/
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit)
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List<String> allowingDeviceStatuses, int deviceTypeId,
int tenantId, int offset, int limit)
throws GroupManagementDAOException;
}

@ -982,7 +982,7 @@ public abstract class AbstractDeviceDAOImpl implements DeviceDAO {
+ "e.TENANT_ID = ? AND "
+ "LOWER(e.OWNER) = LOWER(?) AND "
+ "e.STATUS IN (",
")) e1 ORDER BY e1.DATE_OF_LAST_UPDATE DESC");
")) e1 WHERE d.ID = e1.DEVICE_ID ORDER BY e1.DATE_OF_LAST_UPDATE DESC");
deviceStatuses.stream().map(ignored -> "?").forEach(joiner::add);
String query = joiner.toString();

@ -563,30 +563,44 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
}
@Override
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, int tenantId)
public OwnerWithDeviceDTO getOwnersWithDevices(String owner, List<String> allowingDeviceStatuses, int tenantId, int deviceTypeId)
throws DeviceManagementDAOException {
Connection conn = null;
OwnerWithDeviceDTO ownerDetails = new OwnerWithDeviceDTO();
List<Integer> deviceIds = new ArrayList<>();
int deviceCount = 0;
StringBuilder deviceFilters = new StringBuilder();
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
deviceFilters.append("?");
if (i < allowingDeviceStatuses.size() - 1) {
deviceFilters.append(",");
}
}
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS AS DEVICE_STATUS, d.NAME AS DEVICE_NAME, e.DEVICE_TYPE AS DEVICE_TYPE, e.DEVICE_IDENTIFICATION AS DEVICE_IDENTIFICATION " +
"FROM DM_ENROLMENT e " +
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE e.OWNER = ? AND e.TENANT_ID = ?";
"WHERE e.OWNER = ? AND e.TENANT_ID = ? AND d.DEVICE_TYPE_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ")";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, owner);
stmt.setInt(2, tenantId);
stmt.setInt(3, deviceTypeId);
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
stmt.setString(4 + i, allowingDeviceStatuses.get(i));
}
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
if (ownerDetails.getUserName() == null) {
ownerDetails.setUserName(rs.getString("OWNER"));
ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
}
ownerDetails.setDeviceStatus(rs.getString("DEVICE_STATUS"));
ownerDetails.setDeviceNames(rs.getString("DEVICE_NAME"));
ownerDetails.setDeviceTypes("DEVICE_TYPE");
ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION");
deviceIds.add(rs.getInt("DEVICE_ID"));
deviceCount++;
}
@ -597,10 +611,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
ownerDetails.setDeviceIds(deviceIds);
ownerDetails.setDeviceTypes("DEVICE_TYPE");
ownerDetails.setDeviceIdentifiers("DEVICE_IDENTIFICATION");
ownerDetails.setDeviceCount(deviceCount);
return ownerDetails;
}
@ -642,18 +653,36 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
}
@Override
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId)
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, List<String> allowingDeviceStatuses, int deviceTypeId)
throws DeviceManagementDAOException {
List<DeviceDetailsDTO> devices = new ArrayList<>();
String sql = "SELECT DEVICE_ID, OWNER, STATUS, DEVICE_TYPE, DEVICE_IDENTIFICATION " +
"FROM DM_ENROLMENT " +
"WHERE TENANT_ID = ?";
if (allowingDeviceStatuses.isEmpty()) {
return devices;
}
StringBuilder deviceFilters = new StringBuilder();
for (int i = 0; i < allowingDeviceStatuses.size(); i++) {
deviceFilters.append("?");
if (i < allowingDeviceStatuses.size() - 1) {
deviceFilters.append(",");
}
}
String sql = "SELECT e.DEVICE_ID, e.OWNER, e.STATUS, e.DEVICE_TYPE, e.DEVICE_IDENTIFICATION " +
"FROM DM_ENROLMENT e " +
"JOIN DM_DEVICE d ON e.DEVICE_ID = d.ID " +
"WHERE e.TENANT_ID = ? AND e.STATUS IN (" + deviceFilters.toString() + ") AND d.DEVICE_TYPE_ID = ?";
Connection conn = null;
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, tenantId);
int index = 1;
stmt.setInt(index++, tenantId);
for (String status : allowingDeviceStatuses) {
stmt.setString(index++, status);
}
stmt.setInt(index++, deviceTypeId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
@ -674,5 +703,4 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
}
return devices;
}
}

@ -1441,7 +1441,8 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
}
@Override
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int tenantId, int offset, int limit)
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, List<String> allowedStatuses, int deviceTypeId,
int tenantId, int offset, int limit)
throws GroupManagementDAOException {
if (log.isDebugEnabled()) {
log.debug("Request received in DAO Layer to get group details and device IDs for group: " + groupName);
@ -1454,6 +1455,14 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
Map<Integer, String> deviceTypes = new HashMap<>();
Map<Integer, String> deviceIdentifiers = new HashMap<>();
StringBuilder deviceFilters = new StringBuilder();
for (int i = 0; i < allowedStatuses.size(); i++) {
deviceFilters.append("?");
if (i < allowedStatuses.size() - 1) {
deviceFilters.append(",");
}
}
String sql =
"SELECT " +
" g.ID AS GROUP_ID, " +
@ -1473,16 +1482,23 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
"WHERE " +
" g.GROUP_NAME = ? " +
" AND g.TENANT_ID = ? " +
" AND d.DEVICE_TYPE_ID = ? " +
" AND e.STATUS IN (" + deviceFilters.toString() + ") " +
"LIMIT ? OFFSET ?";
Connection conn = null;
try {
conn = GroupManagementDAOFactory.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setString(1, groupName);
stmt.setInt(2, tenantId);
stmt.setInt(3, limit);
stmt.setInt(4, offset);
int index = 1;
stmt.setString(index++, groupName);
stmt.setInt(index++, tenantId);
stmt.setInt(index++, deviceTypeId);
for (String status : allowedStatuses) {
stmt.setString(index++, status);
}
stmt.setInt(index++, limit);
stmt.setInt(index++, offset);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
@ -1500,19 +1516,19 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
deviceIdentifiers.put(deviceId, rs.getString("DEVICE_IDENTIFICATION"));
}
}
groupDetails.setDeviceIds(deviceIds);
groupDetails.setDeviceCount(deviceIds.size());
groupDetails.setDeviceOwners(deviceOwners);
groupDetails.setDeviceStatuses(deviceStatuses);
groupDetails.setDeviceNames(deviceNames);
groupDetails.setDeviceTypes(deviceTypes);
groupDetails.setDeviceIdentifiers(deviceIdentifiers);
return groupDetails;
groupDetails.setDeviceIds(deviceIds);
groupDetails.setDeviceCount(deviceIds.size());
groupDetails.setDeviceOwners(deviceOwners);
groupDetails.setDeviceStatuses(deviceStatuses);
groupDetails.setDeviceNames(deviceNames);
groupDetails.setDeviceTypes(deviceTypes);
groupDetails.setDeviceIdentifiers(deviceIdentifiers);
return groupDetails;
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
log.error(msg, e);
throw new GroupManagementDAOException(msg, e);
}
} catch (SQLException e) {
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
log.error(msg, e);
throw new GroupManagementDAOException(msg, e);
}
}
}

@ -19,6 +19,7 @@
package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.ConflictException;
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceDetailsDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OperationDTO;
import io.entgra.device.mgt.core.device.mgt.core.dto.OwnerWithDeviceDTO;
@ -1073,10 +1074,11 @@ public interface DeviceManagementProviderService {
* Get owner details and device IDs for a given owner and tenant.
*
* @param owner the name of the owner.
* @param deviceTypeId the device type id
* @return {@link OwnerWithDeviceDTO} which contains a list of devices related to a user.
* @throws DeviceManagementException if an error occurs while fetching owner details.
*/
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException;
OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException;
/**
* Get owner details and device IDs for a given owner and tenant.
@ -1090,10 +1092,11 @@ public interface DeviceManagementProviderService {
/**
* Get owner details and device IDs for a given owner and tenant.
* @param tenantId the tenant id which devices need to be retried
* @param deviceTypeId the device type id
* @return {@link DeviceDetailsDTO} which contains devices details.
* @throws DeviceManagementException if an error occurs while fetching owner details.
*/
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException;
List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException;
/**
* Get operation details by operation code.
@ -1117,4 +1120,17 @@ public interface DeviceManagementProviderService {
*/
PaginationResult getDevicesNotInGroup(PaginationRequest request, boolean requireDeviceInfo)
throws DeviceManagementException;
/**
* This method is to update devices names
* @param device {@link Device}
* @param deviceType the type of the device.
* @param deviceId ID of the device.
* @return boolean value of the update status.
* @throws DeviceManagementException if any service level or DAO level error occurs.
* @throws DeviceManagementException if service level null device error occurs.
* @throws ConflictException if service level data conflicts occurs.
*/
Device updateDeviceName(Device device, String deviceType, String deviceId)
throws DeviceManagementException, DeviceNotFoundException, ConflictException;
}

@ -20,6 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.core.service;
import com.google.common.reflect.TypeToken;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.ConflictException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.dao.TenantDAO;
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceDetailsDTO;
@ -3925,6 +3926,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceIdentifier, this.getTenantId());
}
private void updateDeviceInCache(DeviceIdentifier deviceIdentifier, Device device) {
DeviceCacheManagerImpl.getInstance().updateDeviceInCache(deviceIdentifier, device, this.getTenantId());
}
/***
* This method removes a given list of devices from the cache
* @param deviceList list of DeviceCacheKey objects
@ -5357,13 +5362,18 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner) throws DeviceManagementDAOException {
public OwnerWithDeviceDTO getOwnersWithDeviceIds(String owner, int deviceTypeId) throws DeviceManagementDAOException {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
OwnerWithDeviceDTO ownerWithDeviceDTO;
List<String> allowingDeviceStatuses = new ArrayList<>();
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
try {
DeviceManagementDAOFactory.openConnection();
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, tenantId);
ownerWithDeviceDTO = this.enrollmentDAO.getOwnersWithDevices(owner, allowingDeviceStatuses, tenantId, deviceTypeId);
if (ownerWithDeviceDTO == null) {
String msg = "No data found for owner: " + owner;
log.error(msg);
@ -5414,11 +5424,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId) throws DeviceManagementDAOException {
public List<DeviceDetailsDTO> getDevicesByTenantId(int tenantId, int deviceTypeId) throws DeviceManagementDAOException {
List<DeviceDetailsDTO> devices;
List<String> allowingDeviceStatuses = new ArrayList<>();
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
try {
DeviceManagementDAOFactory.openConnection();
devices = enrollmentDAO.getDevicesByTenantId(tenantId);
devices = enrollmentDAO.getDevicesByTenantId(tenantId, allowingDeviceStatuses, deviceTypeId);
if (devices == null || devices.isEmpty()) {
String msg = "No devices found for tenant ID: " + tenantId;
log.error(msg);
@ -5511,4 +5525,52 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
paginationResult.setRecordsTotal(count);
return paginationResult;
}
@Override
public Device updateDeviceName(Device device, String deviceType, String deviceId)
throws DeviceManagementException, DeviceNotFoundException, ConflictException {
Device persistedDevice = this.getDevice(new DeviceIdentifier(deviceId, deviceType), true);
if (persistedDevice == null) {
String msg = "Device not found for the given deviceId and deviceType";
log.error(msg);
throw new DeviceNotFoundException(msg);
}
if (persistedDevice.getName().equals(device.getName())) {
String msg = "Device names are the same.";
log.info(msg);
throw new ConflictException(msg);
}
persistedDevice.setName(device.getName());
if (log.isDebugEnabled()) {
log.debug("Rename Device name of: " + persistedDevice.getId() + " of type '" + persistedDevice.getType() + "'");
}
DeviceManager deviceManager = this.getDeviceManager(persistedDevice.getType());
if (deviceManager == null) {
String msg = "Device Manager associated with the device type '" + persistedDevice.getType() + "' is null. " +
"Therefore, not attempting method 'modifyEnrolment'";
log.error(msg);
throw new DeviceManagementException(msg);
}
DeviceIdentifier deviceIdentifier = new DeviceIdentifier(persistedDevice.getDeviceIdentifier(), persistedDevice.getType());
try {
DeviceManagementDAOFactory.beginTransaction();
int tenantId = this.getTenantId();
deviceDAO.updateDevice(persistedDevice, tenantId);
DeviceManagementDAOFactory.commitTransaction();
this.updateDeviceInCache(deviceIdentifier, persistedDevice);
return persistedDevice;
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while renaming the device '" + persistedDevice.getId() + "'";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (TransactionManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while initiating transaction to rename device: " + persistedDevice.getId();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
}
}

@ -377,11 +377,12 @@ public interface GroupManagementProviderService {
* Get group details and device IDs for a given group name.
*
* @param groupName the name of the group.
* @param deviceTypeId the device type id
* @param offset the offset for the data set
* @param limit the limit for the data set
* @return {@link GroupDetailsDTO} which containing group details and a list of device IDs
* @throws GroupManagementException if an error occurs while fetching group details.
*/
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit) throws GroupManagementException;
GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit) throws GroupManagementException;
}

@ -17,16 +17,10 @@
*/
package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*;
import io.entgra.device.mgt.core.device.mgt.core.dao.*;
import io.entgra.device.mgt.core.device.mgt.core.event.config.GroupAssignmentEventOperationExecutor;
import io.entgra.device.mgt.core.device.mgt.core.geo.task.GeoFenceEventOperationManager;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
@ -59,7 +53,14 @@ import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.api.UserStoreManager;
import java.sql.SQLException;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.concurrent.ExecutorService;
import java.util.stream.Collectors;
@ -1689,17 +1690,22 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid
}
@Override
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int offset, int limit)
public GroupDetailsDTO getGroupDetailsWithDevices(String groupName, int deviceTypeId, int offset, int limit)
throws GroupManagementException {
if (log.isDebugEnabled()) {
log.debug("Retrieving group details and device IDs for group: " + groupName);
}
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
GroupDetailsDTO groupDetailsWithDevices;
List<String> allowingDeviceStatuses = new ArrayList<>();
allowingDeviceStatuses.add(EnrolmentInfo.Status.ACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.INACTIVE.toString());
allowingDeviceStatuses.add(EnrolmentInfo.Status.UNREACHABLE.toString());
try {
GroupManagementDAOFactory.openConnection();
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, tenantId, offset, limit);
groupDetailsWithDevices = this.groupDAO.getGroupDetailsWithDevices(groupName, allowingDeviceStatuses,
deviceTypeId, tenantId, offset, limit);
} catch (GroupManagementDAOException | SQLException e) {
String msg = "Error occurred while retrieving group details and device IDs for group: " + groupName;
log.error(msg, e);

@ -25,6 +25,7 @@ import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.AppStoreApplication;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.EnterpriseApplication;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedAppxApplication;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.windows.HostedMSIApplication;
@ -62,64 +63,26 @@ public class MDMWindowsOperationUtil {
switch (application.getType()) {
case ENTERPRISE:
operation.setCode(MDMAppConstants.WindowsConstants.INSTALL_ENTERPRISE_APPLICATION);
EnterpriseApplication enterpriseApplication = new EnterpriseApplication();
if (appType.equalsIgnoreCase(MDMAppConstants.WindowsConstants.APPX)) {
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication();
List<String> dependencyPackageList = new ArrayList<>();
for (int i = 0; i < metaJsonArray.size(); i++) {
JsonElement metaElement = metaJsonArray.get(i);
JsonObject metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_URI.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageUri(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_FAMILY_NAME.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageFamilyName(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_DEPENDENCY_PACKAGE_URL.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
dependencyPackageList.add(metaObject.get("value").getAsString().trim());
hostedAppxApplication.setDependencyPackageUri(dependencyPackageList);
}
else if (MDMAppConstants.WindowsConstants.APPX_CERTIFICATE_HASH.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setCertificateHash(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_ENCODED_CERT_CONTENT.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setEncodedCertificate(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedAppxApplication(hostedAppxApplication);
} else if (appType.equalsIgnoreCase(MDMAppConstants.WindowsConstants.MSI)) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication();
for (int i = 0; i < metaJsonArray.size(); i++) {
JsonElement metaElement = metaJsonArray.get(i);
JsonObject metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.MSI_PRODUCT_ID.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setProductId(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_CONTENT_URI.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setContentUrl(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_FILE_HASH.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setFileHash(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedMSIApplication(hostedMSIApplication);
}
createEnterpriseAppPayload(appType, metaJsonArray, enterpriseApplication);
operation.setCode(MDMAppConstants.WindowsConstants.INSTALL_ENTERPRISE_APPLICATION);
operation.setPayLoad(enterpriseApplication.toJSON());
break;
case PUBLIC:
AppStoreApplication appStoreApplication = new AppStoreApplication();
appStoreApplication.setType(application.getType().toString());
appStoreApplication.setPackageIdentifier(application.getIdentifier());
operation.setCode(MDMAppConstants.WindowsConstants.INSTALL_STORE_APPLICATION);
operation.setPayLoad(appStoreApplication.toJSON());
break;
case WEB_CLIP:
operation.setCode(MDMAppConstants.WindowsConstants.INSTALL_WEB_CLIP_APPLICATION);
WebClipApplication webClipApplication = new WebClipApplication();
webClipApplication.setUrl(application.getLocation());
webClipApplication.setName(application.getName());
webClipApplication.setIcon(application.getIconImage());
webClipApplication.setProperties(application.getProperties());
webClipApplication.setType(application.getType().toString());
operation.setCode(MDMAppConstants.WindowsConstants.INSTALL_WEB_CLIP_APPLICATION);
operation.setPayLoad(webClipApplication.toJSON());
break;
default:
@ -148,64 +111,26 @@ public class MDMWindowsOperationUtil {
switch (application.getType()) {
case ENTERPRISE:
operation.setCode(MDMAppConstants.WindowsConstants.UNINSTALL_ENTERPRISE_APPLICATION);
EnterpriseApplication enterpriseApplication = new EnterpriseApplication();
if (appType.equalsIgnoreCase(MDMAppConstants.WindowsConstants.APPX)) {
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication();
List<String> dependencyPackageList = new ArrayList<>();
for (int i = 0; i < metaJsonArray.size(); i++) {
JsonElement metaElement = metaJsonArray.get(i);
JsonObject metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_URI.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageUri(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_FAMILY_NAME.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageFamilyName(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_DEPENDENCY_PACKAGE_URL.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
dependencyPackageList.add(metaObject.get("value").getAsString().trim());
hostedAppxApplication.setDependencyPackageUri(dependencyPackageList);
}
else if (MDMAppConstants.WindowsConstants.APPX_CERTIFICATE_HASH.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setCertificateHash(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_ENCODED_CERT_CONTENT.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setEncodedCertificate(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedAppxApplication(hostedAppxApplication);
} else if (appType.equalsIgnoreCase(MDMAppConstants.WindowsConstants.MSI)) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication();
for (int i = 0; i < metaJsonArray.size(); i++) {
JsonElement metaElement = metaJsonArray.get(i);
JsonObject metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.MSI_PRODUCT_ID.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setProductId(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_CONTENT_URI.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setContentUrl(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_FILE_HASH.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setFileHash(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedMSIApplication(hostedMSIApplication);
}
createEnterpriseAppPayload(appType, metaJsonArray, enterpriseApplication);
operation.setCode(MDMAppConstants.WindowsConstants.UNINSTALL_ENTERPRISE_APPLICATION);
operation.setPayLoad(enterpriseApplication.toJSON());
break;
case PUBLIC:
AppStoreApplication appStoreApplication = new AppStoreApplication();
appStoreApplication.setType(application.getType().toString());
appStoreApplication.setPackageIdentifier(application.getIdentifier());
operation.setCode(MDMAppConstants.WindowsConstants.UNINSTALL_STORE_APPLICATION);
operation.setPayLoad(appStoreApplication.toJSON());
break;
case WEB_CLIP:
operation.setCode(MDMAppConstants.WindowsConstants.UNINSTALL_WEB_CLIP_APPLICATION);
WebClipApplication webClipApplication = new WebClipApplication();
webClipApplication.setUrl(application.getLocation());
webClipApplication.setName(application.getName());
webClipApplication.setIcon(application.getIconImage());
webClipApplication.setProperties(application.getProperties());
webClipApplication.setType(application.getType().toString());
operation.setCode(MDMAppConstants.WindowsConstants.UNINSTALL_WEB_CLIP_APPLICATION);
operation.setPayLoad(webClipApplication.toJSON());
default:
String msg = "Application type " + application.getType() + " is not supported";
@ -216,6 +141,67 @@ public class MDMWindowsOperationUtil {
return operation;
}
/**
* Helper method to create enterprise APPX and MSI app payloads for both install and uninstall operations
* @param appType contains whether the app type is APPX or MSI
* @param metaJsonArray JSON array containing metadata of APPX and MSI apps
* @param enterpriseApplication {@link EnterpriseApplication} contains operation payload content that will be sent to the device
*/
private static void createEnterpriseAppPayload(String appType, JsonArray metaJsonArray, EnterpriseApplication enterpriseApplication) {
JsonElement metaElement;
JsonObject metaObject;
if (MDMAppConstants.WindowsConstants.APPX.equalsIgnoreCase(appType)) {
HostedAppxApplication hostedAppxApplication = new HostedAppxApplication();
List<String> dependencyPackageList = new ArrayList<>();
for (int i = 0; i < metaJsonArray.size(); i++) {
metaElement = metaJsonArray.get(i);
metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_URI.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageUri(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_PACKAGE_FAMILY_NAME.equals(metaObject.get("key").getAsString())) {
hostedAppxApplication.setPackageFamilyName(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_DEPENDENCY_PACKAGE_URL.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
dependencyPackageList.add(metaObject.get("value").getAsString().trim());
hostedAppxApplication.setDependencyPackageUri(dependencyPackageList);
}
else if (MDMAppConstants.WindowsConstants.APPX_CERTIFICATE_HASH.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setCertificateHash(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.APPX_ENCODED_CERT_CONTENT.equals(metaObject.get("key").getAsString())
&& metaObject.has("value")) {
hostedAppxApplication.setEncodedCertificate(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedAppxApplication(hostedAppxApplication);
} else if (MDMAppConstants.WindowsConstants.MSI.equalsIgnoreCase(appType)) {
HostedMSIApplication hostedMSIApplication = new HostedMSIApplication();
for (int i = 0; i < metaJsonArray.size(); i++) {
metaElement = metaJsonArray.get(i);
metaObject = metaElement.getAsJsonObject();
if (MDMAppConstants.WindowsConstants.MSI_PRODUCT_ID.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setProductId(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_CONTENT_URI.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setContentUrl(metaObject.get("value").getAsString().trim());
}
else if (MDMAppConstants.WindowsConstants.MSI_FILE_HASH.equals(metaObject.get("key").getAsString())) {
hostedMSIApplication.setFileHash(metaObject.get("value").getAsString().trim());
}
}
enterpriseApplication.setHostedMSIApplication(hostedMSIApplication);
}
}
/**
* Method to get the installer file extension type for windows type apps(either appx or msi)
*
@ -223,8 +209,7 @@ public class MDMWindowsOperationUtil {
* @return string extension of the windows app types(either appx or msi)
*/
public static String windowsAppType(String installerName) {
String extension = installerName.substring(installerName.lastIndexOf(".") + 1);
return extension;
return installerName.substring(installerName.lastIndexOf(".") + 1);
}
/**
@ -234,8 +219,7 @@ public class MDMWindowsOperationUtil {
* @return the metaData Json String as Json Array
*/
public static JsonArray jsonStringToArray(String metaData) {
JsonArray metaJsonArray = new JsonParser().parse(metaData).getAsJsonArray();
return metaJsonArray;
return new JsonParser().parse(metaData).getAsJsonArray();
}

@ -338,7 +338,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -242,7 +242,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -300,7 +300,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -209,6 +209,10 @@
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.policy.mgt.common</artifactId>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
</dependency>
<dependency>
<groupId>io.entgra.device.mgt.core</groupId>

@ -18,11 +18,13 @@
package io.entgra.device.mgt.core.policy.mgt.core.dao.impl.policy;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.CorrectiveAction;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.DeviceGroupWrapper;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Policy;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.PolicyCriterion;
import io.entgra.device.mgt.core.device.mgt.common.policy.mgt.Profile;
import io.entgra.device.mgt.core.policy.mgt.common.Criterion;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyDAO;
import io.entgra.device.mgt.core.policy.mgt.core.dao.PolicyManagementDAOFactory;
@ -37,14 +39,24 @@ import org.wso2.carbon.context.PrivilegedCarbonContext;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.sql.*;
import java.util.*;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Properties;
/**
* Abstract implementation of PolicyDAO which holds generic SQL queries.
*/
public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
private static final Gson gson = new Gson();
private static final Log log = LogFactory.getLog(AbstractPolicyDAOImpl.class);
@Override
@ -1178,13 +1190,13 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
stmt = conn.prepareStatement(query);
stmt.setInt(1, deviceId);
stmt.setInt(2, policy.getId());
stmt.setBytes(3, PolicyManagerUtil.getBytes(policy));
stmt.setString(3, PolicyManagerUtil.convertToJson(policy));
stmt.setTimestamp(4, currentTimestamp);
stmt.setTimestamp(5, currentTimestamp);
stmt.setInt(6, tenantId);
stmt.setInt(7, enrolmentId);
stmt.executeUpdate();
} catch (SQLException | IOException e) {
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while adding the evaluated feature list to device", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, null);
@ -1231,7 +1243,7 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
"APPLIED = ? WHERE DEVICE_ID = ? AND TENANT_ID = ? AND ENROLMENT_ID = ?";
stmt = conn.prepareStatement(query);
stmt.setInt(1, policy.getId());
stmt.setBytes(2, PolicyManagerUtil.getBytes(policy));
stmt.setString(2, PolicyManagerUtil.convertToJson(policy));
stmt.setTimestamp(3, currentTimestamp);
stmt.setBoolean(4, false);
stmt.setInt(5, deviceId);
@ -1239,7 +1251,7 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
stmt.setInt(7, enrolmentId);
stmt.executeUpdate();
} catch (SQLException | IOException e) {
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while updating the evaluated feature list " +
"to device", e);
} finally {
@ -1690,39 +1702,12 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
resultSet = stmt.executeQuery();
while (resultSet.next()) {
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
byte[] contentBytes;
try {
contentBytes = resultSet.getBytes("POLICY_CONTENT");
bais = new ByteArrayInputStream(contentBytes);
ois = new ObjectInputStream(bais);
policy = (Policy) ois.readObject();
} finally {
if (bais != null) {
try {
bais.close();
} catch (IOException e) {
log.warn("Error occurred while closing ByteArrayOutputStream", e);
}
}
if (ois != null) {
try {
ois.close();
} catch (IOException e) {
log.warn("Error occurred while closing ObjectOutputStream", e);
}
}
}
String contentString = resultSet.getString("POLICY_CONTENT");
policy = gson.fromJson(contentString, Policy.class);
}
} catch (SQLException e) {
throw new PolicyManagerDAOException("Error occurred while getting the applied policy", e);
} catch (IOException e) {
throw new PolicyManagerDAOException("Unable to read the byte stream for content", e);
} catch (ClassNotFoundException e) {
throw new PolicyManagerDAOException("Class not found while converting the object", e);
} finally {
PolicyManagementDAOUtil.cleanupResources(stmt, resultSet);
}
@ -1835,4 +1820,66 @@ public abstract class AbstractPolicyDAOImpl implements PolicyDAO {
}
return policies;
}
/**
* Extracts a list of Policy objects with associated Profile objects from the given ResultSet
*
* @param resultSet The ResultSet containing the policy and profile data
* @param tenantId The tenant ID
* @return A list of Policy objects populated with data from the ResultSet
* @throws SQLException If an SQL error occurs while processing the ResultSet
*/
protected List<Policy> extractPolicyListWithProfileFromDbResult(ResultSet resultSet, int tenantId) throws SQLException {
List<Policy> policies = new ArrayList<>();
while (resultSet.next()) {
Policy policy = createPolicyFromResultSet(resultSet, tenantId);
Profile profile = createProfileFromResultSet(resultSet, tenantId);
policy.setProfile(profile);
policies.add(policy);
}
return policies;
}
/**
* Creates a Policy object from the current row in the given ResultSet
*
* @param resultSet The ResultSet containing the policy data
* @param tenantId The tenant ID
* @return A Policy object populated with data from the ResultSet
* @throws SQLException If an SQL error occurs while processing the ResultSet
*/
private Policy createPolicyFromResultSet(ResultSet resultSet, int tenantId) throws SQLException {
Policy policy = new Policy();
policy.setId(resultSet.getInt("ID"));
policy.setProfileId(resultSet.getInt("PROFILE_ID"));
policy.setPolicyName(resultSet.getString("NAME"));
policy.setTenantId(tenantId);
policy.setPriorityId(resultSet.getInt("PRIORITY"));
policy.setCompliance(resultSet.getString("COMPLIANCE"));
policy.setOwnershipType(resultSet.getString("OWNERSHIP_TYPE"));
policy.setUpdated(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("UPDATED")));
policy.setActive(PolicyManagerUtil.convertIntToBoolean(resultSet.getInt("ACTIVE")));
policy.setDescription(resultSet.getString("DESCRIPTION"));
policy.setPolicyType(resultSet.getString("POLICY_TYPE"));
policy.setPolicyPayloadVersion(resultSet.getString("PAYLOAD_VERSION"));
return policy;
}
/**
* Creates a Profile object from the current row in the given ResultSet
*
* @param resultSet The ResultSet containing the profile data
* @param tenantId The tenant ID
* @return A Profile object populated with data from the ResultSet
* @throws SQLException If an SQL error occurs while processing the ResultSet
*/
private Profile createProfileFromResultSet(ResultSet resultSet, int tenantId) throws SQLException {
Profile profile = new Profile();
profile.setProfileId(resultSet.getInt("PROFILE_ID"));
profile.setProfileName(resultSet.getString("PROFILE_NAME"));
profile.setTenantId(tenantId);
profile.setDeviceType(resultSet.getString("DEVICE_TYPE"));
return profile;
}
}

@ -48,24 +48,27 @@ public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl {
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
String deviceType = request.getDeviceType();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
boolean isDeviceTypeProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
"WHERE TENANT_ID = ? ";
"FROM DM_POLICY P " +
"LEFT JOIN DM_PROFILE PR ON P.PROFILE_ID = PR.ID " +
"WHERE P.TENANT_ID = ? ";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
query += "AND P.NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
query += "AND P.POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
@ -73,11 +76,16 @@ public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
query += "AND P.ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID LIMIT ?,?";
if (deviceType != null && !deviceType.isEmpty()) {
query += "AND PR.DEVICE_TYPE = ? ";
isDeviceTypeProvided = true;
}
query += "ORDER BY P.ID LIMIT ?,?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;
@ -91,10 +99,13 @@ public class GenericPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, deviceType);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
return this.extractPolicyListWithProfileFromDbResult(resultSet, tenantId);
}
}
} catch (SQLException e) {

@ -47,24 +47,27 @@ public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl {
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
String deviceType = request.getDeviceType();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
boolean isDeviceTypeProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
"WHERE TENANT_ID = ? ";
"FROM DM_POLICY P " +
"LEFT JOIN DM_PROFILE PR ON P.PROFILE_ID = PR.ID " +
"WHERE P.TENANT_ID = ? ";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
query += "AND P.NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
query += "AND P.POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
@ -72,11 +75,16 @@ public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
query += "AND P.ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
if (deviceType != null && !deviceType.isEmpty()) {
query += "AND PR.DEVICE_TYPE = ? ";
isDeviceTypeProvided = true;
}
query += "ORDER BY P.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;
@ -90,10 +98,13 @@ public class OraclePolicyDAOImpl extends AbstractPolicyDAOImpl {
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, deviceType);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
return this.extractPolicyListWithProfileFromDbResult(resultSet, tenantId);
}
}
} catch (SQLException e) {

@ -47,24 +47,27 @@ public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl {
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
String deviceType = request.getDeviceType();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
boolean isDeviceTypeProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
"WHERE TENANT_ID = ? ";
"FROM DM_POLICY P " +
"LEFT JOIN DM_PROFILE PR ON P.PROFILE_ID = PR.ID " +
"WHERE P.TENANT_ID = ? ";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
query += "AND P.NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
query += "AND P.POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
@ -72,11 +75,16 @@ public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
query += "AND P.ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID LIMIT ? OFFSET ?";
if (deviceType != null && !deviceType.isEmpty()) {
query += "AND PR.DEVICE_TYPE = ?";
isDeviceTypeProvided = true;
}
query += "ORDER BY P.ID LIMIT ? OFFSET ?";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;
@ -90,10 +98,13 @@ public class PostgreSQLPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, deviceType);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
return this.extractPolicyListWithProfileFromDbResult(resultSet, tenantId);
}
}
} catch (SQLException e) {

@ -47,24 +47,27 @@ public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl {
String name = request.getName();
String type = request.getType();
String status = request.getStatus();
String deviceType = request.getDeviceType();
int statusValue = 0;
boolean isPolicyNameProvided = false;
boolean isPolicyTypeProvided = false;
boolean isPolicyStatusProvided = false;
boolean isDeviceTypeProvided = false;
try {
conn = this.getConnection();
String query = "SELECT * " +
"FROM DM_POLICY " +
"WHERE TENANT_ID = ? ";
"FROM DM_POLICY P " +
"LEFT JOIN DM_PROFILE PR ON P.PROFILE_ID = PR.ID " +
"WHERE P.TENANT_ID = ? ";
if (name != null && !name.isEmpty()) {
query += "AND NAME LIKE ? " ;
query += "AND P.NAME LIKE ? " ;
isPolicyNameProvided = true;
}
if (type != null && !type.isEmpty()) {
query += "AND POLICY_TYPE = ? " ;
query += "AND P.POLICY_TYPE = ? " ;
isPolicyTypeProvided = true;
}
@ -72,11 +75,16 @@ public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (status.equals("ACTIVE")) {
statusValue = 1;
}
query += "AND ACTIVE = ? " ;
query += "AND P.ACTIVE = ? " ;
isPolicyStatusProvided = true;
}
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
if (deviceType != null && !deviceType.isEmpty()) {
query += "AND PR.DEVICE_TYPE = ?";
isDeviceTypeProvided = true;
}
query += "ORDER BY P.ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
try (PreparedStatement stmt = conn.prepareStatement(query)) {
int paramIdx = 1;
@ -90,10 +98,13 @@ public class SQLServerPolicyDAOImpl extends AbstractPolicyDAOImpl {
if (isPolicyStatusProvided) {
stmt.setInt(paramIdx++, statusValue);
}
if (isDeviceTypeProvided) {
stmt.setString(paramIdx++, deviceType);
}
stmt.setInt(paramIdx++, request.getStartIndex());
stmt.setInt(paramIdx++, request.getRowCount());
try (ResultSet resultSet = stmt.executeQuery()) {
return this.extractPolicyListFromDbResult(resultSet, tenantId);
return this.extractPolicyListWithProfileFromDbResult(resultSet, tenantId);
}
}
} catch (SQLException e) {

@ -1530,6 +1530,8 @@ public class PolicyManagerImpl implements PolicyManager {
for (Policy policy : policyList) {
policy.setRoles(policyDAO.getPolicyAppliedRoles(policy.getId()));
policy.setUsers(policyDAO.getPolicyAppliedUsers(policy.getId()));
policy.setProfile(profileDAO.getProfile(policy.getId()));
List<DeviceGroupWrapper> deviceGroupWrappers = policyDAO.getDeviceGroupsOfPolicy(policy.getId());
if (!deviceGroupWrappers.isEmpty()) {
deviceGroupWrappers = this.getDeviceGroupNames(deviceGroupWrappers);
@ -1549,6 +1551,10 @@ public class PolicyManagerImpl implements PolicyManager {
String msg = "Error occurred while getting device groups.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} catch (ProfileManagerDAOException e) {
String msg = "Error occurred while getting profiles.";
log.error(msg, e);
throw new PolicyManagementException(msg, e);
} finally {
PolicyManagementDAOFactory.closeConnection();
}

@ -59,7 +59,7 @@ import java.io.ObjectOutputStream;
import java.util.*;
public class PolicyManagerUtil {
private static final Gson gson = new Gson();
public static final String GENERAL_CONFIG_RESOURCE_PATH = "general";
public static final String MONITORING_FREQUENCY = "notifierFrequency";
private static final Log log = LogFactory.getLog(PolicyManagerUtil.class);
@ -352,6 +352,15 @@ public class PolicyManagerUtil {
return data;
}
/**
* Using for converting policy objects into Json strings
* @param obj
* @return
*/
public static String convertToJson(Object obj) {
return gson.toJson(obj);
}
public static boolean convertIntToBoolean(int x) {
return x == 1;

@ -376,7 +376,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -161,7 +161,7 @@ CREATE TABLE IF NOT EXISTS `WSO2CDM`.`DM_DEVICE_POLICY_APPLIED` (
`ID` INT(11) NOT NULL AUTO_INCREMENT,
`DEVICE_ID` INT(11) NOT NULL,
`POLICY_ID` INT(11) NOT NULL,
`POLICY_CONTENT` BLOB NULL DEFAULT NULL,
`POLICY_CONTENT` TEXT NULL DEFAULT NULL,
`APPLIED` TINYINT(1) NULL DEFAULT NULL,
`CREATED_TIME` TIMESTAMP NULL DEFAULT NULL,
`UPDATED_TIME` TIMESTAMP NULL DEFAULT NULL,

@ -301,7 +301,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -0,0 +1,27 @@
/*
* 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
*
* 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 io.entgra.device.mgt.core.tenant.mgt.common.spi;
import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
public interface TenantManagerAdminService {
void deleteTenant(String tenantDomain) throws TenantMgtException;
int getTenantId(String tenantDomain) throws TenantMgtException;
}

@ -74,6 +74,7 @@
org.wso2.carbon.stratos.common.beans;version="[4.9,5)",
org.wso2.carbon.stratos.common.exception;version="[4.9,5)",
org.wso2.carbon.stratos.common.listeners;version="[4.9,5)",
org.wso2.carbon.tenant.mgt.services,
org.wso2.carbon.user.api;version="[1.0,2)",
org.wso2.carbon.user.core.service;version="[4.8,5)"
</Import-Package>

@ -57,4 +57,5 @@ public interface TenantManager {
* @throws TenantMgtException Throws when deleting Tenant related device data
*/
void deleteTenantDeviceData(int tenantId) throws TenantMgtException;
}

@ -0,0 +1,57 @@
/*
* 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
*
* 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 io.entgra.device.mgt.core.tenant.mgt.core.impl;
import io.entgra.device.mgt.core.tenant.mgt.common.exception.TenantMgtException;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.stratos.common.exception.StratosException;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserStoreException;
public class TenantManagerAdminServiceImpl implements TenantManagerAdminService {
private static final Log log = LogFactory.getLog(TenantManagerAdminServiceImpl.class);
private static final TenantMgtAdminService tenantMgtAdminService = new TenantMgtAdminService();
@Override
public void deleteTenant(String tenantDomain) throws TenantMgtException {
try {
tenantMgtAdminService.deleteTenant(tenantDomain);
} catch (StratosException | UserStoreException e) {
String msg = "Error occurred while deleting tenant of domain: " + tenantDomain;
log.error(msg, e);
throw new TenantMgtException(msg, e);
}
}
@Override
public int getTenantId(String tenantDomain) throws TenantMgtException {
try {
return tenantMgtAdminService.getTenant(tenantDomain).getTenantId();
} catch (Exception e){
String msg = "Error occurred while getting tenant ID of domain: " + tenantDomain;
log.error(msg, e);
throw new TenantMgtException(msg, e);
}
}
}

@ -22,8 +22,10 @@ import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.WhiteLabelManage
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.WhiteLabelManagementServiceImpl;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.DeviceStatusManagementServiceImpl;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerAdminService;
import io.entgra.device.mgt.core.tenant.mgt.common.spi.TenantManagerService;
import io.entgra.device.mgt.core.tenant.mgt.core.TenantManager;
import io.entgra.device.mgt.core.tenant.mgt.core.impl.TenantManagerAdminServiceImpl;
import io.entgra.device.mgt.core.tenant.mgt.core.impl.TenantManagerImpl;
import io.entgra.device.mgt.core.tenant.mgt.core.impl.TenantManagerServiceImpl;
import io.entgra.device.mgt.core.tenant.mgt.core.listener.DeviceMgtTenantListener;
@ -48,11 +50,14 @@ public class TenantMgtServiceComponent {
try {
TenantManagerService tenantManagerService = new TenantManagerServiceImpl();
componentContext.getBundleContext().
registerService(TenantManagerServiceImpl.class.getName(), tenantManagerService, null);
registerService(TenantManagerService.class.getName(), tenantManagerService, null);
TenantManagerAdminService tenantManagerAdminService = new TenantManagerAdminServiceImpl();
componentContext.getBundleContext().
registerService(TenantManagerAdminService.class.getName(), tenantManagerAdminService, null);
TenantManager tenantManager = new TenantManagerImpl();
TenantMgtDataHolder.getInstance().setTenantManager(tenantManager);
WhiteLabelManagementService whiteLabelManagementService = new WhiteLabelManagementServiceImpl();
componentContext.getBundleContext().registerService(WhiteLabelManagementServiceImpl.class.getName(),
componentContext.getBundleContext().registerService(WhiteLabelManagementService.class.getName(),
whiteLabelManagementService, null);
TenantMgtDataHolder.getInstance().setWhiteLabelManagementService(whiteLabelManagementService);
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl();

@ -88,13 +88,5 @@ public class DeviceMgtTenantListener implements TenantMgtListener {
@Override
public void onPreDelete(int i) throws StratosException {
// Any work to be performed before a tenant is deleted
TenantManager tenantManager = TenantMgtDataHolder.getInstance().getTenantManager();
try{
tenantManager.deleteTenantDeviceData(i);
tenantManager.deleteTenantApplicationData(i);
} catch (TenantMgtException e) {
String msg = "Error occurred while deleting tenant data";
log.error(msg, e);
}
}
}

@ -387,6 +387,7 @@
<Scope>win:ops:device-info</Scope>
<Scope>win:ops:security-info</Scope>
<Scope>win:ops:firewall-info</Scope>
<Scope>win:microsoft-store:search</Scope>
<Scope>admin:tenant:view</Scope>
<Scope>dm:admin:devices:usage:view</Scope>
<Scope>and:ops:clear-app</Scope>

@ -48,6 +48,11 @@
{% endfor %}
{% endif %}
</PushNotificationProviders>
{% if device_mgt_conf.push_notification_conf.fcm_server_endpoint is defined %}
<ProviderContextMetadata>
<ContextMetadata key="FCM_SERVER_ENDPOINT">{{device_mgt_conf.push_notification_conf.fcm_server_endpoint}}</ContextMetadata>
</ProviderContextMetadata>
{% endif %}
</PushNotificationConfiguration>
<PullNotificationConfiguration>
{% if device_mgt_conf.pull_notification_conf is defined %}

@ -304,7 +304,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -369,7 +369,7 @@ IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[D
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL ,
POLICY_CONTENT VARBINARY(MAX) NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INTEGER NOT NULL,
APPLIED BIT NULL ,
CREATED_TIME DATETIME2 NULL ,

@ -355,7 +355,7 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY (
DEVICE_ID INT NOT NULL ,
ENROLMENT_ID INT(11) NOT NULL,
POLICY_ID INT NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INT NOT NULL,
APPLIED TINYINT(1) NULL ,
CREATED_TIME TIMESTAMP NULL ,

@ -509,7 +509,7 @@ CREATE TABLE DM_DEVICE_POLICY_APPLIED (
DEVICE_ID NUMBER(10) NOT NULL ,
ENROLMENT_ID NUMBER(10) NOT NULL,
POLICY_ID NUMBER(10) NOT NULL ,
POLICY_CONTENT BLOB NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID NUMBER(10) NOT NULL,
APPLIED NUMBER(1) DEFAULT 0,
CREATED_TIME TIMESTAMP(0) NULL ,

@ -365,7 +365,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED (
DEVICE_ID INTEGER NOT NULL ,
ENROLMENT_ID INTEGER NOT NULL,
POLICY_ID INTEGER NOT NULL ,
POLICY_CONTENT BYTEA NULL ,
POLICY_CONTENT TEXT NULL ,
TENANT_ID INTEGER NOT NULL,
APPLIED SMALLINT NULL ,
CREATED_TIME TIMESTAMP(0) NULL ,

@ -1833,6 +1833,51 @@
<artifactId>mockito-inline</artifactId>
<version>${mokito.version}</version>
</dependency>
<dependency>
<groupId>com.google.auth</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>${com.google.auth.library.auth2.http.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.google.http-client</groupId>
<artifactId>google-http-client</artifactId>
<version>${com.google.http.client.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.orbit.com.google.auth-library-oauth2-http</groupId>
<artifactId>google-auth-library-oauth2-http</artifactId>
<version>${com.google.auth.library.wso2.auth2.http.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.orbit.io.opencensus</groupId>
<artifactId>opencensus</artifactId>
<version>${io.opencensus.version}</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-api</artifactId>
<version>${io.opencensus.api.version}</version>
</dependency>
<dependency>
<groupId>io.opencensus</groupId>
<artifactId>opencensus-contrib-http-util</artifactId>
<version>${io.opencensus.contrib.http.util.version}</version>
</dependency>
<dependency>
<groupId>org.wso2.orbit.io.grpc</groupId>
<artifactId>grpc-context</artifactId>
<version>${io.grpc.context.version}</version>
</dependency>
<dependency>
<groupId>com.google.http-client</groupId>
<artifactId>google-http-client-gson</artifactId>
<version>${com.google.http.client.gson.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>failureaccess</artifactId>
<version>${com.google.failureaccess.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
@ -2250,6 +2295,16 @@
<orbit.h2.version>2.1.214.wso2v1</orbit.h2.version>
<securevault.version>1.1.3</securevault.version>
<com.google.auth.library.wso2.auth2.http.version>1.20.0.wso2v1</com.google.auth.library.wso2.auth2.http.version>
<com.google.auth.library.auth2.http.version>1.20.0</com.google.auth.library.auth2.http.version>
<com.google.http.client.version>1.41.2.wso2v2</com.google.http.client.version>
<com.google.failureaccess.version>1.0.1</com.google.failureaccess.version>
<com.google.http.client.gson.version>1.43.3</com.google.http.client.gson.version>
<io.grpc.context.version>1.27.2.wso2v1</io.grpc.context.version>
<io.opencensus.version>0.30.0.wso2v1</io.opencensus.version>
<io.opencensus.api.version>0.30.0</io.opencensus.api.version>
<io.opencensus.contrib.http.util.version>0.30.0</io.opencensus.contrib.http.util.version>
<pax.logging.api.version>1.11.2</pax.logging.api.version>
<version.org.wso2.orbit.javax.xml.bind>2.3.1.wso2v1</version.org.wso2.orbit.javax.xml.bind>
<commons-lang.version>2.4</commons-lang.version>

Loading…
Cancel
Save