Sync with master

pull/306/head
Pasindu Rupasinghe 11 months ago
commit 122f3f16f1

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>grafana-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>analytics-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

@ -21,7 +21,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>apimgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -434,7 +434,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
Scope scope = new Scope();
for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) {
//todo check whether scope is available or not
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
defaultPermission.getScopeMapping().getKey())) {
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
List<String> bindings = new ArrayList<>(
@ -446,6 +447,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
scope.setBindings(bindings);
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
}
}
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
log.error("Error occurred while adding default scopes");
}

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -113,6 +113,11 @@ public class Filter {
*/
private String favouredBy;
/**
* Checking if retired apps needs to be excluded
*/
private boolean isNotRetired;
public int getLimit() {
return limit;
}
@ -208,4 +213,12 @@ public class Filter {
public void setFavouredBy(String favouredBy) {
this.favouredBy = favouredBy;
}
public boolean isNotRetired() {
return isNotRetired;
}
public void setNotRetired(boolean notRetired) {
isNotRetired = notRetired;
}
}

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>application-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -176,6 +176,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (deviceTypeId != -1) {
sql += "AND AP_APP.DEVICE_TYPE_ID = ? ";
}
if (filter.isNotRetired()) {
sql += "AND AP_APP.STATUS != 'RETIRED' ";
}
sql += "GROUP BY AP_APP.ID ORDER BY AP_APP.ID ";
if (StringUtils.isNotEmpty(filter.getSortBy())) {
sql += filter.getSortBy() +" ";
@ -304,6 +307,9 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
if (deviceTypeId != -1) {
sql += " AND AP_APP.DEVICE_TYPE_ID = ?";
}
if (filter.isNotRetired()) {
sql += " AND AP_APP.STATUS != 'RETIRED'";
}
try {
conn = this.getDBConnection();

@ -27,6 +27,7 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
import io.entgra.device.mgt.core.device.mgt.core.dao.util.DeviceManagementDAOUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -56,7 +57,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
try {
Connection conn = this.getDBConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
long currentTime = System.currentTimeMillis();
long currentTime = DeviceManagementDAOUtil.getCurrentUTCTime();
stmt.setString(1, userDTO.getClientUserId());
stmt.setString(2, userDTO.getDmUsername());
stmt.setInt(3, tenantId);
@ -117,7 +118,7 @@ public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements Vp
try {
Connection conn = this.getDBConnection();
long updatedTime = System.currentTimeMillis();
long updatedTime = DeviceManagementDAOUtil.getCurrentUTCTime();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int x = 0;

@ -1332,7 +1332,7 @@ public class ApplicationManagerImpl implements ApplicationManager {
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
String iconPath = APIUtil.createAppIconPath(applicationReleaseDTO, tenantId);
DataHolder.getInstance().getDeviceManagementService().saveApplicationIcon(iconPath,
String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion(), tenantId);
String.valueOf(applicationReleaseDTO.getPackageName()), applicationReleaseDTO.getVersion());
} catch (ApplicationManagementException e) {
String msg = "Error occurred while creating iconPath. Application package name : " + applicationReleaseDTO.getPackageName();
log.error(msg, e);

@ -426,16 +426,10 @@ public class DAOUtil {
vppUserDTO.setDmUsername(rs.getString("DM_USERNAME"));
}
if (rs.getLong("CREATED_TIME") != 0) {
Date date = new Date(rs.getLong("CREATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppUserDTO.setCreatedTime(dateString);
vppUserDTO.setCreatedTime(new Timestamp(rs.getLong("CREATED_TIME") * 1000L).toString());
}
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
String dateString = dateFormat.format(date);
vppUserDTO.setLastUpdatedTime(dateString);
vppUserDTO.setLastUpdatedTime(new Timestamp(rs.getLong("LAST_UPDATED_TIME") * 1000L).toString());
}
vppUserDTOS.add(vppUserDTO);
}

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>certificate-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>certificate-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt-extensions</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -0,0 +1,28 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
@ApiModel(value = "InvitationMailProfile", description = "Holds data related to JIT Enrollment invitation mails")
public class InvitationMailProfile {
@ApiModelProperty(name = "username", value = "Username (same as username in external IDP)", required = true)
private String username;
@ApiModelProperty(name = "mail", value = "Mail will be sent to this mail address", required = true)
private String mail;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getMail() {
return mail;
}
public void setMail(String mail) {
this.mail = mail;
}
}

@ -0,0 +1,50 @@
package io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import java.util.List;
@ApiModel(value = "JITEnrollmentInvitation", description = "Holds data related to JIT enrollment invitations")
public class JITEnrollmentInvitation {
@ApiModelProperty(name = "mailProfiles", value = "Mail profiles to send mail invitations", required = true)
private List<InvitationMailProfile> mailProfiles;
@ApiModelProperty(name = "ownershipType", value = "Ownership type of the enrollment", required = true)
private String ownershipType;
@ApiModelProperty(name = "deviceType", value = "Device type", required = true)
private String deviceType;
@ApiModelProperty(name = "sp", value = "Service provider name", required = true)
private String sp;
public List<InvitationMailProfile> getMailProfiles() {
return mailProfiles;
}
public void setMailProfiles(List<InvitationMailProfile> mailProfiles) {
this.mailProfiles = mailProfiles;
}
public String getOwnershipType() {
return ownershipType;
}
public void setOwnershipType(String ownershipType) {
this.ownershipType = ownershipType;
}
public String getDeviceType() {
return deviceType;
}
public void setDeviceType(String deviceType) {
this.deviceType = deviceType;
}
public String getSp() {
return sp;
}
public void setSp(String sp) {
this.sp = sp;
}
}

@ -0,0 +1,252 @@
/*
* 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.api.jaxrs.service.api;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.swagger.annotations.*;
import org.apache.axis2.transport.http.HTTPConstants;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
/**
* Metadata related REST-API implementation.
*/
@SwaggerDefinition(
info = @Info(
version = "1.0.0",
title = "Device Status Filter Service",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = "name", value = "DeviceStatusManagement"),
@ExtensionProperty(name = "context", value = "/api/device-mgt/v1.0/device-status-filters"),
})
}
),
tags = {
@Tag(name = "device_management")
}
)
@Scopes(
scopes = {
@Scope(
name = "View Device Status Filter",
description = "View device status details",
key = "dm:devicestatusfilter:view",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/device-status-filters/view"}
),
@Scope(
name = "Update Device status filter",
description = "Updating Device status filter",
key = "dm:devicestatusfilter:update",
roles = {"Internal/devicemgt-user"},
permissions = {"/device-mgt/device-status-filters/update"}
),
}
)
@Api(value = "Device Status Management")
@Path("/device-status-filters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public interface DeviceStatusFilterService {
@GET
@Path("/{device-type}")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get device status filters",
notes = "Get device status filters for the tenant of the logged in user",
tags = "Tenant Metadata Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved device status filters.",
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while getting device status filters.",
response = ErrorResponse.class)
})
Response getDeviceStatusFilters( @ApiParam(
name = "deviceType",
value = "The device type.",
required = true) @PathParam ("device-type") String deviceType);
@GET
@Path("/is-enabled")
@ApiOperation(
httpMethod = HTTPConstants.HEADER_GET,
value = "Get device status filter",
notes = "Get device status filter enable or not for the tenant of the logged in user",
tags = "Tenant Metadata Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:view")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully retrieved device status filter.",
response = Response.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while getting device status check.",
response = ErrorResponse.class)
})
Response getDeviceStatusCheck();
@PUT
@Path("/toggle-device-status")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Update Device status check for tenant",
notes = "Update Device status check for the tenant of the logged in user",
tags = "Tenant Metadata Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully updated device status check.",
response = Response.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while updating device status check.",
response = ErrorResponse.class)
})
Response updateDeviceStatusCheck(
@ApiParam(
name = "Device status check",
value = "The device status filtering is enable or not.",
required = true)
@QueryParam("isEnabled") boolean isEnabled);
@PUT
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Update Device status filters for given device type for tenant",
notes = "Update Device status filters for given device type for the tenant of the logged in user",
tags = "Tenant Metadata Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "dm:devicestatusfilter:update")
})
}
)
@ApiResponses(
value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully updated device status filters for given device type..",
response = Response.class,
responseHeaders = {
@ResponseHeader(
name = "Content-Type",
description = "The content type of the body"),
@ResponseHeader(
name = "ETag",
description = "Entity Tag of the response resource.\n" +
"Used by caches, or in conditional requests."),
@ResponseHeader(
name = "Last-Modified",
description = "Date and time the resource was last modified.\n" +
"Used by caches, or in conditional requests."),
}),
@ApiResponse(
code = 500,
message = "Internal Server Error. " +
"\n Server error occurred while updating device status filters for given device type.",
response = ErrorResponse.class)
})
Response updateDeviceStatusFilters(
@ApiParam(
name = "deviceType",
value = "The device type for which you want to update device status filters.",
required = true)
@QueryParam("deviceType") String deviceType,
@ApiParam(
name = "deviceStatus",
value = "A list of device status values to update for the given device type.",
required = true)
@QueryParam("deviceStatus") List<String> deviceStatus);
}

@ -20,14 +20,45 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api;
import com.google.gson.JsonArray;
import io.entgra.device.mgt.core.apimgt.annotations.Scope;
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.Credential;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.EnrollmentInvitation;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.JITEnrollmentInvitation;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OldPasswordResetWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PermissionList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.UserInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.UserStoreList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation;
import io.swagger.annotations.*;
import org.apache.axis2.transport.http.HTTPConstants;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import io.swagger.annotations.Extension;
import io.swagger.annotations.ExtensionProperty;
import io.swagger.annotations.Info;
import io.swagger.annotations.ResponseHeader;
import io.swagger.annotations.SwaggerDefinition;
import io.swagger.annotations.Tag;
import org.apache.axis2.transport.http.HTTPConstants;
import javax.validation.Valid;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
@ -911,6 +942,49 @@ public interface UserManagementService {
required = true)
@Valid EnrollmentInvitation enrollmentInvitation);
@POST
@Path("/jit-enrollment-invite")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = HTTPConstants.HEADER_POST,
value = "Sending Enrollment Invitations to email address",
notes = "Send the a mail inviting recipients to enroll devices.",
tags = "User Management",
extensions = {
@Extension(properties = {
@ExtensionProperty(name = Constants.SCOPE, value = "perm:users:send-invitation")
})
}
)
@ApiResponses(value = {
@ApiResponse(
code = 200,
message = "OK. \n Successfully sent the invitation mail."),
@ApiResponse(
code = 400,
message = "Bad Request. \n Invalid request or validation error.",
response = ErrorResponse.class),
@ApiResponse(
code = 404,
message = "Not Found. \n The specified resource does not exist.\n",
response = ErrorResponse.class),
@ApiResponse(
code = 415,
message = "Unsupported media type. \n The format of the requested entity was not supported.\n",
response = ErrorResponse.class),
@ApiResponse(
code = 500,
message = "Internal Server Error. \n " +
"Server error occurred while updating the user credentials.",
response = ErrorResponse.class)
})
Response inviteExternalUsers(
@ApiParam(
name = "jitEnrollmentInvitation",
value = "List of email address of recipients",
required = true)
@Valid JITEnrollmentInvitation jitEnrollmentInvitation);
@POST
@Path("/validate")
Response validateUser(Credential credential);

@ -0,0 +1,120 @@
/*
* 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.api.jaxrs.service.impl;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.DeviceStatusFilterService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.util.List;
@Path("/device-status-filters")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public class DeviceStatusFilterServiceImpl implements DeviceStatusFilterService {
private static final Log log = LogFactory.getLog(DeviceStatusFilterServiceImpl.class);
@Override
@GET
@Path("/{deviceType}")
public Response getDeviceStatusFilters(@PathParam("deviceType") String deviceType) {
List<String> result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.getDeviceStatusFilters(deviceType, tenantId);
if (result != null) {
return Response.status(Response.Status.OK).entity(result).build();
}
return Response.status(Response.Status.NO_CONTENT).entity(false).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting device status filter of the tenant.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@GET
@Path("/is-enabled")
@Override
public Response getDeviceStatusCheck() {
boolean result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.getDeviceStatusCheck(tenantId);
return Response.status(Response.Status.OK).entity(result).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while getting device status filter of the tenant.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
@Path("/toggle-device-status")
public Response updateDeviceStatusCheck(
@QueryParam("isEnabled")
boolean isEnabled) {
boolean result;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
result = deviceManagementProviderService.updateDefaultDeviceStatusCheck(tenantId, isEnabled);
if (result) {
return Response.status(Response.Status.OK).entity("Successfully updated device status check.").build();
} else {
return Response.status(Response.Status.NO_CONTENT).entity(false).build();
}
} catch (MetadataManagementException e) {
String msg = "Error occurred while updating device status check.";
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
@Override
@PUT
public Response updateDeviceStatusFilters(
@QueryParam("deviceType")
String deviceType,
@QueryParam("deviceStatus")
List<String> deviceStatus
) {
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
try {
DeviceStatusManagementService deviceManagementProviderService = DeviceMgtAPIUtils.getDeviceStatusManagmentService();
deviceManagementProviderService.updateDefaultDeviceStatusFilters(tenantId, deviceType, deviceStatus);
return Response.status(Response.Status.OK).entity("Successfully updated device status filters for " + deviceType).build();
} catch (MetadataManagementException e) {
String msg = "Error occurred while updating device status for " + deviceType;
log.error(msg, e);
return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build();
}
}
}

@ -80,6 +80,9 @@ public class MetadataServiceImpl implements MetadataService {
@PathParam("metaKey") String metaKey) {
Metadata metadata;
try {
if (metaKey.contains("-")) {
metaKey = metaKey.replace('-', '_');
}
metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey);
return Response.status(Response.Status.OK).entity(metadata).build();
} catch (MetadataManagementException e) {
@ -129,6 +132,9 @@ public class MetadataServiceImpl implements MetadataService {
public Response deleteMetadataEntry(
@PathParam("metaKey") String metaKey) {
try {
if (metaKey.contains("-")) {
metaKey = metaKey.replace('-', '_');
}
DeviceMgtAPIUtils.getMetadataManagementService().deleteMetadata(metaKey);
return Response.status(Response.Status.OK).entity("Metadata entry is deleted successfully.").build();
} catch (MetadataKeyNotFoundException e) {

@ -19,7 +19,6 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@ -28,13 +27,6 @@ import org.eclipse.wst.common.uriresolver.internal.util.URIEncoder;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.*;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.UserManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.CredentialManagementResponseBuilder;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException;
@ -45,6 +37,26 @@ import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ActivityList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.BasicUserInfoWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.Credential;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.EnrollmentInvitation;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.InvitationMailProfile;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.JITEnrollmentInvitation;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OldPasswordResetWrapper;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.PermissionList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.UserInfo;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.UserStoreList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.UserManagementService;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.CredentialManagementResponseBuilder;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils;
import org.wso2.carbon.identity.claim.metadata.mgt.ClaimMetadataManagementAdminService;
import org.wso2.carbon.identity.claim.metadata.mgt.dto.AttributeMappingDTO;
import org.wso2.carbon.identity.claim.metadata.mgt.dto.ClaimPropertyDTO;
@ -62,12 +74,22 @@ import org.wso2.carbon.utils.CarbonUtils;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import javax.ws.rs.*;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
import javax.ws.rs.PUT;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.File;
import java.io.UnsupportedEncodingException;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.file.NoSuchFileException;
import java.security.SecureRandom;
import java.text.ParseException;
import java.text.SimpleDateFormat;
@ -318,9 +340,9 @@ public class UserManagementServiceImpl implements UserManagementService {
}
return Response.status(Response.Status.OK).build();
} else {
String msg = "There are enrolled devices for user: " + username + ". Please remove them before deleting the user.";
String msg = "Before deleting this user, ensure there are no devices assigned to the user. You can either remove the devices or change their owner through an update enrollment operation.";
log.error(msg);
return Response.status(400).entity(msg).build();
return Response.status(409).entity(msg).build();
}
} catch (DeviceManagementException | UserStoreException e) {
String msg = "Exception in trying to remove user by user: " + username;
@ -726,6 +748,54 @@ public class UserManagementServiceImpl implements UserManagementService {
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
}
@POST
@Path("jit-enrollment-invite")
@Override
public Response inviteExternalUsers(JITEnrollmentInvitation jitEnrollmentInvitation) {
if (jitEnrollmentInvitation.getMailProfiles() == null || jitEnrollmentInvitation.getMailProfiles().isEmpty()) {
String msg = "Error occurred while validating mail profiles. Mail profiles cannot be empty";
log.error(msg);
throw new BadRequestException(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).setCode(HttpStatus.SC_BAD_REQUEST).
build());
}
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
String inviteBy = DeviceMgtAPIUtils.getAuthenticatedUser();
try {
DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService();
for (InvitationMailProfile mailProfile : jitEnrollmentInvitation.getMailProfiles()) {
Properties props = new Properties();
props.setProperty("username", mailProfile.getUsername());
props.setProperty("tenant-domain", tenantDomain);
props.setProperty("sp", jitEnrollmentInvitation.getSp());
props.setProperty("ownership-type", jitEnrollmentInvitation.getOwnershipType());
props.setProperty("device-type", jitEnrollmentInvitation.getDeviceType());
props.setProperty("invite-by", inviteBy);
Set<String> recipients = new HashSet<>();
recipients.add(mailProfile.getMail());
EmailMetaInfo metaInfo = new EmailMetaInfo(recipients, props);
dms.sendEnrolmentInvitation(getTemplateName(jitEnrollmentInvitation.getDeviceType(),
"jit-enrollment-invitation", "-"), metaInfo);
}
} catch (DeviceManagementException ex) {
String msg = "Error occurred while inviting user to enroll their device";
log.error(msg, ex);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (ConfigurationManagementException ex) {
String msg = "Error occurred while sending the email invitations. Mail server not configured.";
log.error(msg, ex);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
} catch (NoSuchFileException ex) {
String msg = "Error occurred while retrieving email template";
log.error(msg, ex);
return Response.serverError().entity(
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
}
return Response.status(Response.Status.OK).entity("Invitation mails have been sent.").build();
}
@POST
@Path("/validate")
@Override
@ -1148,6 +1218,30 @@ public class UserManagementServiceImpl implements UserManagementService {
return DeviceManagementConstants.EmailAttributes.DEFAULT_ENROLLMENT_TEMPLATE;
}
private String getTemplateName(String deviceType, String prefix, String separator) throws NoSuchFileException {
String templateName = deviceType + separator + prefix + ".vm";
List<String> templatePathSegments =
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", templateName);
File template = new File(String.join(File.separator, templatePathSegments));
if (template.exists()) {
return templateName;
}
String defaultTemplateName = "default" + separator + prefix + ".vm";
List<String> defaultTemplatePathSegments =
Arrays.asList(CarbonUtils.getCarbonHome(), "repository", "resources", "email-templates", defaultTemplateName);
File defaultTemplate = new File(String.join(File.separator, defaultTemplatePathSegments));
if (defaultTemplate.exists()) {
if (log.isDebugEnabled()) {
log.debug("The template that is expected to use is not available. Therefore, using default template.");
}
return defaultTemplateName;
}
throw new NoSuchFileException("Didn't found template file for " + templateName);
}
/**
* Searches users which matches a given filter based on a claim
*

@ -793,6 +793,9 @@ public class RequestValidationUtil {
new ErrorResponse.ErrorResponseBuilder()
.setCode(HttpStatus.SC_BAD_REQUEST).setMessage(msg).build());
}
if (metadata.getMetaKey().contains("-")) {
metadata.setMetaKey(metadata.getMetaKey().replace('-', '_'));
}
String regex = "^[a-zA-Z0-9_.]*$";
if (!metadata.getMetaKey().matches(regex)) {
String msg = "Request parameter metaKey should only contain period, " +

@ -30,6 +30,25 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.OperationStatusBean;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.analytics.EventAttributeList;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.InputValidationException;
import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.util.RequestValidationUtil;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.logging.Log;
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;
import org.wso2.carbon.core.util.Utils;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService;
@ -67,23 +86,6 @@ import io.entgra.device.mgt.core.identity.jwt.client.extension.service.JWTClient
import io.entgra.device.mgt.core.policy.mgt.common.PolicyMonitoringTaskException;
import io.entgra.device.mgt.core.policy.mgt.core.PolicyManagerService;
import io.entgra.device.mgt.core.policy.mgt.core.task.TaskScheduleService;
import org.apache.axis2.AxisFault;
import org.apache.axis2.client.Options;
import org.apache.axis2.java.security.SSLProtocolSocketFactory;
import org.apache.axis2.transport.http.HTTPConstants;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.httpclient.Header;
import org.apache.commons.httpclient.protocol.Protocol;
import org.apache.commons.httpclient.protocol.ProtocolSocketFactory;
import org.apache.commons.logging.Log;
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.base.ServerConfiguration;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.util.Utils;
import org.wso2.carbon.event.processor.stub.EventProcessorAdminServiceStub;
import org.wso2.carbon.event.publisher.core.EventPublisherService;
import org.wso2.carbon.event.publisher.stub.EventPublisherAdminServiceStub;
@ -154,6 +156,8 @@ public class DeviceMgtAPIUtils {
// private static IntegrationClientService integrationClientService;
private static MetadataManagementService metadataManagementService;
private static WhiteLabelManagementService whiteLabelManagementService;
private static DeviceStatusManagementService deviceStatusManagementService;
private static OTPManagementService otpManagementService;
private static volatile SubscriptionManager subscriptionManager;
@ -592,6 +596,28 @@ public class DeviceMgtAPIUtils {
return whiteLabelManagementService;
}
/**
* Initializing and accessing method for DeviceStatusManagementService.
*
* @return WhiteLabelManagementService instance
* @throws IllegalStateException if DeviceStatusManagementService cannot be initialized
*/
public static DeviceStatusManagementService getDeviceStatusManagmentService() {
if (deviceStatusManagementService == null) {
synchronized (DeviceMgtAPIUtils.class) {
if (deviceStatusManagementService == null) {
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
deviceStatusManagementService = (DeviceStatusManagementService) ctx.getOSGiService(
DeviceStatusManagementService.class, null);
if (deviceStatusManagementService == null) {
throw new IllegalStateException("DeviceStatusManagementService Management service not initialized.");
}
}
}
}
return deviceStatusManagementService;
}
/**
* Initializing and accessing method for MetadataManagementService.
*

@ -49,6 +49,7 @@
<ref bean="analyticsArtifactsManagementService"/>
<ref bean="metadataService"/>
<ref bean="whitelabelService"/>
<ref bean="deviceStatusFilterService"/>
</jaxrs:serviceBeans>
<jaxrs:providers>
<ref bean="jsonProvider"/>
@ -99,6 +100,7 @@
<bean id="analyticsArtifactsManagementService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.AnalyticsArtifactsManagementServiceImpl"/>
<bean id="metadataService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.MetadataServiceImpl"/>
<bean id="whitelabelService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.WhiteLabelServiceImpl"/>
<bean id="deviceStatusFilterService" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl.DeviceStatusFilterServiceImpl"/>
<!--<bean id="errorHandler" class="io.entgra.device.mgt.core.device.mgt.api.jaxrs.common.ErrorHandler"/>-->
<cxf:bus>

@ -21,7 +21,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -0,0 +1,60 @@
/*
* 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.common.invitation.mgt;
import java.util.Properties;
public class EnrollmentTypeMail {
private String template;
private String username;
private String recipient;
private Properties properties;
public String getTemplate() {
return template;
}
public void setTemplate(String template) {
this.template = template;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getRecipient() {
return recipient;
}
public void setRecipient(String recipient) {
this.recipient = recipient;
}
public Properties getProperties() {
return properties;
}
public void setProperties(Properties properties) {
this.properties = properties;
}
}

@ -0,0 +1,61 @@
/*
* 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.common.invitation.mgt;
public class UserMailAttributes {
private String username;
private String firstName;
private String email;
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public String getFirstName() {
return firstName;
}
public void setFirstName(String firstName) {
this.firstName = firstName;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getUsernamePlaceholder() {
return "username";
}
public String getEmailPlaceholder() {
return "email";
}
public String getFirstNamePlaceholder() {
return "first-name";
}
}

@ -0,0 +1,43 @@
/*
* 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.common.metadata.mgt;
import java.util.List;
public class AllowedDeviceStatus {
private String type;
private List<String> status;
public String getType() {
return type;
}
public void setType(String type) {
this.type = type;
}
public List<String> getStatus() {
return status;
}
public void setStatus(List<String> status) {
this.status = status;
}
}

@ -0,0 +1,85 @@
/*
* 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.common.metadata.mgt;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import java.util.List;
public interface DeviceStatusManagementService {
/**
* This method is useful to create & persist default device status filter for provided tenant if
* it doesn't exist already
*
* @throws MetadataManagementException if error while adding default device status
*/
void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException;
/**
* This method is useful to reset existing device status to default values in xml
*
* @throws MetadataManagementException if error while resetting default device status
*/
void resetToDefaultDeviceStausFilter() throws MetadataManagementException;
/**
* This method is useful to update existing allowed device status
*
* @throws MetadataManagementException if error while updating existing device status
*/
void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus)
throws MetadataManagementException;
/**
* This method is useful to update existing device status check
*
* @throws MetadataManagementException if error while updating existing device status
*/
boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked)
throws MetadataManagementException;
/**
* This method is useful to get existing device status filters
*
* @throws MetadataManagementException if error while getting existing device status
*/
List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException;
/**
* This method is useful to get existing device status filters by device type and tenant id
*
* @throws MetadataManagementException if error while getting existing device status
*/
List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException;
/**
* This method is useful to get existing device status filters
*
* @throws MetadataManagementException if error while getting existing device status check
*/
boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException;
/**
* This method is useful to check status is valid for device type
*
* @throws MetadataManagementException if error while getting existing device status check
*/
boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException;
}

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>device-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -121,6 +121,9 @@ public final class DeviceManagementConstants {
public static final String USER_WELCOME_TEMPLATE = "user-welcome";
public static final String DEFAULT_ENROLLMENT_TEMPLATE = "default-enrollment-invitation";
public static final String ENROLLMENT_GUIDE_TEMPLATE = "enrollment-guide";
public static final String DEVICE_ENROLLMENT_MAIL_KEY = "enrollment";
public static final String TEMPLATE_NAME_PART_JOINER = "-";
public static final String ENROLLMENT_TYPE_SPLITTER = "_";
}
public static final class OperationAttributes {

@ -0,0 +1,46 @@
/*
* 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.ui;
import javax.xml.bind.annotation.XmlElement;
import java.util.List;
public class DeviceStatusConfigurations {
private List<DeviceStatusItem> deviceStatusItems;
private boolean deviceStatusCheck;
@XmlElement(name = "DeviceStatusItem")
public List<DeviceStatusItem> getDeviceStatusItems() {
return deviceStatusItems;
}
@XmlElement(name = "EnableDeviceStatusCheck")
public boolean isDeviceStatusCheck() {
return deviceStatusCheck;
}
public void setDeviceStatusCheck(boolean deviceStatusCheck) {
this.deviceStatusCheck = deviceStatusCheck;
}
public void setDeviceStatusItems(List<DeviceStatusItem> deviceStatusItems) {
this.deviceStatusItems = deviceStatusItems;
}
}

@ -0,0 +1,48 @@
/*
* 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.ui;
import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import java.util.List;
public class DeviceStatusItem {
private List<String> status;
private String type;
@XmlElement(name = "Type")
public String getType() {
return type;
}
@XmlElementWrapper(name = "AllowedStatus")
@XmlElement(name = "Status")
public List<String> getStatus() {
return status;
}
public void setType(String type) {
this.type = type;
}
public void setStatus(List<String> status) {
this.status = status;
}
}

@ -38,6 +38,8 @@ public class UIConfiguration {
private DeviceInfoConfigurations deviceInfoConfigurations;
private DeviceStatusConfigurations deviceStatusConfigurations;
@XmlElement(name = "AppRegistration", required = true)
public AppRegistration getAppRegistration() {
return appRegistration;
@ -74,6 +76,7 @@ public class UIConfiguration {
public void setHubspotChat(HubspotChat hubspotChat) {
this.hubspotChat = hubspotChat;
}
@XmlElement(name = "Billing", required = true)
public Billing getBilling() {
return billing;
@ -109,4 +112,13 @@ public class UIConfiguration {
public void setDeviceInfoConfigurations(DeviceInfoConfigurations deviceInfoConfigurations) {
this.deviceInfoConfigurations = deviceInfoConfigurations;
}
@XmlElement(name = "DeviceStatusConfigurations", required = true)
public DeviceStatusConfigurations getDeviceStatusConfigurations() {
return deviceStatusConfigurations;
}
public void setDeviceStatusConfigurations(DeviceStatusConfigurations deviceStatusConfigurations) {
this.deviceStatusConfigurations = deviceStatusConfigurations;
}
}

@ -113,4 +113,14 @@ public interface ApplicationDAO {
* @throws DeviceManagementDAOException
*/
String getIconPath(String applicationIdentifier) throws DeviceManagementDAOException;
/**
* This method is used to get the installed application list of a specific device
* @param deviceId ID of the device
* @param enrolmentId Enrolment ID of the device
* @param tenantId tenant ID
* @throws DeviceManagementDAOException If any database error occurred
*/
List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int tenantId)
throws DeviceManagementDAOException;
}

@ -61,4 +61,35 @@ public interface EnrollmentDAO {
boolean updateOwnerOfEnrollment(List<Device> devices, String owner, int tenantId)
throws DeviceManagementDAOException;
/***
*This method is used to add the device status of the enrollment for given set of devices to given user.
*
* @param currentOwner of device.
* @param status going to add
* @param tenantId tenant id.
* @return either (1) true, if device status is succeeded or false.
* @throws DeviceManagementDAOException if an error occurs when updating device owner.
*/
boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException;
/***
*This method is used to add the device status of the enrollment for given set of devices to given user.
*
* @param config of Enrollment.
* @return either (1) true, if device status is succeeded or false.
* @throws DeviceManagementDAOException if an error occurs when updating device owner.
*/
boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException;
/***
*This method is used to add the device status of the enrollment for given set of devices to given user.
*
* @param enrolmentId of device.
* @param status going to add
* @return either (1) true, if device status is succeeded or false.
* @throws DeviceManagementDAOException if an error occurs when updating device owner.
*/
boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException;
}

@ -88,9 +88,6 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
stmt.setInt(4, enrolmentInfo.getId());
stmt.setInt(5, tenantId);
int updatedCount = stmt.executeUpdate();
if (updatedCount == 1){
addDeviceStatus(enrolmentInfo.getId(), enrolmentInfo.getStatus());
}
return updatedCount;
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
@ -126,9 +123,6 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
}
if (updateStatus > 0) {
status = true;
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
addDeviceStatus(enrolmentInfo);
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment status of given device-list.", e);
@ -251,11 +245,11 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
return true;
}
private boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
public boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
return addDeviceStatus(config.getId(), config.getStatus());
}
private boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
public boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){
@ -318,7 +312,7 @@ public abstract class AbstractEnrollmentDAOImpl implements EnrollmentDAO {
return true;
}
private boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
public boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){

@ -285,31 +285,36 @@ public class ApplicationDAOImpl implements ApplicationDAO {
"IS_ACTIVE, " +
"TENANT_ID " +
"FROM DM_APPLICATION " +
"WHERE NOT EXISTS " +
"(SELECT " +
"ID " +
"WHERE PLATFORM = ? AND " +
"TENANT_ID = ? AND " +
"NOT EXISTS (SELECT ID " +
"FROM DM_APPLICATION A " +
"WHERE A.NAME = DM_APPLICATION.NAME " +
"AND A.ID < DM_APPLICATION.ID) " +
"AND PLATFORM = ? " +
"AND TENANT_ID = ? ";
"AND A.ID < DM_APPLICATION.ID AND " +
"PLATFORM = ? AND TENANT_ID = ?) ";
try {
String filter = request.getFilter();
if (filter != null) {
sql = sql + "AND NAME LIKE ? ";
}
if (request != null && request.getRowCount() != -1) {
sql = sql + "LIMIT ? OFFSET ?";
}
Connection conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
int paramIdx = 1;
stmt.setString(paramIdx++, request.getDeviceType());
stmt.setInt(paramIdx++, tenantId);
stmt.setString(paramIdx++, request.getDeviceType());
stmt.setInt(paramIdx++, tenantId);
if (filter != null){
stmt.setString(paramIdx++, filter);
}
if (request != null && request.getRowCount() != -1) {
stmt.setInt(paramIdx++, request.getRowCount());
stmt.setInt(paramIdx, request.getStartIndex());
}
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
application = loadApplication(rs);
@ -569,4 +574,50 @@ public class ApplicationDAOImpl implements ApplicationDAO {
}
return applicationList;
}
public List<Application> getInstalledApplicationListOnDevice(int deviceId, int enrolmentId, int tenantId)
throws DeviceManagementDAOException {
Connection conn;
List<Application> applicationList = new ArrayList<>();
Application application;
String sql = "SELECT " +
"ID, " +
"NAME, " +
"APP_IDENTIFIER, " +
"PLATFORM, " +
"CATEGORY, " +
"VERSION, " +
"TYPE, " +
"LOCATION_URL, " +
"IMAGE_URL, " +
"APP_PROPERTIES, " +
"MEMORY_USAGE, " +
"IS_ACTIVE, " +
"TENANT_ID " +
"FROM DM_APPLICATION " +
"WHERE DEVICE_ID = ? AND " +
"ENROLMENT_ID = ? AND " +
"TENANT_ID = ? ";
try {
conn = this.getConnection();
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(1, deviceId);
stmt.setInt(2, enrolmentId);
stmt.setInt(3, tenantId);
try (ResultSet rs = stmt.executeQuery()) {
while (rs.next()) {
application = loadApplication(rs);
applicationList.add(application);
}
}
}
} catch (SQLException e) {
String msg = "SQL Error occurred while retrieving the list of Applications " +
"installed in device id '" + deviceId;
log.error(msg, e);
throw new DeviceManagementDAOException(msg, e);
}
return applicationList;
}
}

@ -88,9 +88,6 @@ public class GenericEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
stmt.setInt(4, enrolmentInfo.getId());
stmt.setInt(5, tenantId);
int updatedCount = stmt.executeUpdate();
if (updatedCount == 1){
addDeviceStatus(enrolmentInfo.getId(), enrolmentInfo.getStatus());
}
return updatedCount;
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
@ -126,9 +123,6 @@ public class GenericEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
}
if (updateStatus > 0) {
status = true;
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
addDeviceStatus(enrolmentInfo);
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment status of given device-list.", e);
@ -251,11 +245,11 @@ public class GenericEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
return true;
}
private boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
public boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
return addDeviceStatus(config.getId(), config.getStatus());
}
private boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
public boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){
@ -318,7 +312,7 @@ public class GenericEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
return true;
}
private boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
public boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){

@ -88,9 +88,6 @@ public class SQLServerEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
stmt.setInt(4, enrolmentInfo.getId());
stmt.setInt(5, tenantId);
int updatedCount = stmt.executeUpdate();
if (updatedCount == 1){
addDeviceStatus(enrolmentInfo.getId(), enrolmentInfo.getStatus());
}
return updatedCount;
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment configuration", e);
@ -126,9 +123,6 @@ public class SQLServerEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
}
if (updateStatus > 0) {
status = true;
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
addDeviceStatus(enrolmentInfo);
}
}
} catch (SQLException e) {
throw new DeviceManagementDAOException("Error occurred while updating enrolment status of given device-list.", e);
@ -251,11 +245,11 @@ public class SQLServerEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
return true;
}
private boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
public boolean addDeviceStatus(EnrolmentInfo config) throws DeviceManagementDAOException {
return addDeviceStatus(config.getId(), config.getStatus());
}
private boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
public boolean addDeviceStatus(String currentOwner, EnrolmentInfo.Status status, int tenantId) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){
@ -318,7 +312,7 @@ public class SQLServerEnrollmentDAOImpl extends AbstractEnrollmentDAOImpl {
return true;
}
private boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
public boolean addDeviceStatus(int enrolmentId, EnrolmentInfo.Status status) throws DeviceManagementDAOException {
Connection conn;
String changedBy = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername();
if (changedBy == null){

@ -142,7 +142,7 @@ public class GenericGeofenceDAOImpl extends AbstractGeofenceDAOImpl {
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
stmt.setInt(index++, tenantId);
if (isNameProvided) {
stmt.setString(index++, request.getProperty("%" + DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%");
stmt.setString(index++, "%" + request.getProperty(DeviceManagementConstants.GeoServices.FENCE_NAME).toString() + "%");
}
stmt.setInt(index++, request.getRowCount());
stmt.setInt(index, request.getStartIndex());

@ -18,6 +18,9 @@
package io.entgra.device.mgt.core.device.mgt.core.internal;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.DeviceStatusTaskPluginConfig;
import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManager;
@ -44,9 +47,7 @@ import io.entgra.device.mgt.core.device.mgt.core.service.GroupManagementProvider
import io.entgra.device.mgt.core.device.mgt.core.status.task.DeviceStatusTaskManagerService;
import io.entgra.device.mgt.core.device.mgt.core.task.DeviceTaskManagerService;
import io.entgra.device.mgt.core.device.mgt.core.traccar.api.service.DeviceAPIClientService;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import io.entgra.device.mgt.core.transport.mgt.email.sender.core.service.EmailSenderService;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.ntask.core.service.TaskService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@ -93,6 +94,8 @@ public class DeviceManagementDataHolder {
private WhiteLabelManagementService whiteLabelManagementService;
private TraccarManagementService traccarManagementService;
private DeviceStatusManagementService deviceStatusManagementService;
private final Map<DeviceType, DeviceStatusTaskPluginConfig> deviceStatusTaskPluginConfigs = Collections.synchronizedMap(
new HashMap<>());
@ -384,6 +387,14 @@ public class DeviceManagementDataHolder {
this.whiteLabelManagementService = whiteLabelManagementService;
}
public DeviceStatusManagementService getDeviceStatusManagementService() {
return deviceStatusManagementService;
}
public void setDeviceStatusManagementService(DeviceStatusManagementService deviceStatusManagementService) {
this.deviceStatusManagementService = deviceStatusManagementService;
}
public TraccarManagementService getTraccarManagementService() {
TraccarManagementService traccarManagementService;
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();

@ -17,6 +17,15 @@
*/
package io.entgra.device.mgt.core.device.mgt.core.internal;
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.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
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.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.ServerStartupObserver;
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationService;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.PlatformConfigurationManagementService;
@ -79,15 +88,8 @@ import io.entgra.device.mgt.core.device.mgt.core.traccar.api.service.DeviceAPICl
import io.entgra.device.mgt.core.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl;
import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagementSchemaInitializer;
import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import io.entgra.device.mgt.core.transport.mgt.email.sender.core.service.EmailSenderService;
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.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.core.ServerStartupObserver;
import org.wso2.carbon.ndatasource.core.DataSourceService;
import org.wso2.carbon.registry.core.service.RegistryService;
import org.wso2.carbon.user.core.service.RealmService;
@ -327,6 +329,17 @@ public class DeviceManagementServiceComponent {
}
bundleContext.registerService(WhiteLabelManagementService.class.getName(), whiteLabelManagementService, null);
/* Registering DeviceState Filter Service */
DeviceStatusManagementService deviceStatusManagemntService = new DeviceStatusManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagemntService);
try {
deviceStatusManagemntService.addDefaultDeviceStatusFilterIfNotExist(tenantId);
} catch (Throwable e) {
log.error("Error occurred while adding default tenant device status", e);
}
bundleContext.registerService(DeviceStatusManagementService.class.getName(), deviceStatusManagemntService, null);
/* Registering Event Configuration Service */
EventConfigurationProviderService eventConfigurationService = new EventConfigurationProviderServiceImpl();
DeviceManagementDataHolder.getInstance().setEventConfigurationProviderService(eventConfigurationService);

@ -0,0 +1,322 @@
/*
* 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.metadata.mgt;
import com.google.gson.Gson;
import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.AllowedDeviceStatus;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusConfigurations;
import io.entgra.device.mgt.core.device.mgt.core.config.ui.DeviceStatusItem;
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataDAO;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.MetadataManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util.MetadataConstants;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import java.lang.reflect.Type;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class DeviceStatusManagementServiceImpl implements DeviceStatusManagementService {
private static final Log log = LogFactory.getLog(DeviceStatusManagementServiceImpl.class);
private final MetadataDAO metadataDAO;
public DeviceStatusManagementServiceImpl() {
this.metadataDAO = MetadataManagementDAOFactory.getMetadataDAO();
}
@Override
public void addDefaultDeviceStatusFilterIfNotExist(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.beginTransaction();
if (!metadataDAO.isExist(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY) && !metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
Metadata defaultDeviceStatusMetadata = constructDeviceStatusMetadata(getDefaultDeviceStatus());
Metadata defaultDeviceStatusCheckMetadata = constructDeviceStatusCheckMetadata(getDefaultDeviceStatusCheck());
// Add default device status and device status check metadata entries
addMetadataEntry(tenantId, defaultDeviceStatusMetadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
addMetadataEntry(tenantId, defaultDeviceStatusCheckMetadata, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
}
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while inserting default device status metadata entry.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public void resetToDefaultDeviceStausFilter() throws MetadataManagementException {
}
@Override
public void updateDefaultDeviceStatusFilters(int tenantId, String deviceType, List<String> deviceStatus) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.beginTransaction();
// Retrieve the current device status metadata
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
if (metadata != null) {
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> currentStatusList = gson.fromJson(metadata.getMetaValue(), listType);
// Find the status for the specified deviceType
for (AllowedDeviceStatus status : currentStatusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
// Update the status list for the specified deviceType
status.setStatus(deviceStatus);
break;
}
}
metadata.setMetaValue(gson.toJson(currentStatusList));
updateMetadataEntry(tenantId, metadata, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
}
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating device status metadata entry.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public boolean updateDefaultDeviceStatusCheck(int tenantId, boolean isChecked) throws MetadataManagementException {
boolean success = false;
try {
MetadataManagementDAOFactory.beginTransaction();
if (metadataDAO.isExist(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY)) {
Metadata isDeviceStatusChecked = constructDeviceStatusCheckMetadata(isChecked);
// Add default device status check metadata entries
updateMetadataEntry(tenantId, isDeviceStatusChecked, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
success = true;
}
MetadataManagementDAOFactory.commitTransaction();
} catch (MetadataManagementDAOException e) {
MetadataManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating device status check metadata entry.";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
return success;
}
@Override
public List<AllowedDeviceStatus> getDeviceStatusFilters(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
return statusList;
} catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status meta data for tenant:" + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
public List<String> getDeviceStatusFilters(String deviceType, int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
for (AllowedDeviceStatus status : statusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
return status.getStatus();
}
}
// Device type not found in metadata
return Collections.emptyList();
} catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public boolean getDeviceStatusCheck(int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
String metaValue = metadata.getMetaValue();
return Boolean.parseBoolean(metaValue);
} catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status check meta data for tenant:" + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
@Override
public boolean isDeviceStatusValid(String deviceType, String deviceStatus, int tenantId) throws MetadataManagementException {
try {
MetadataManagementDAOFactory.openConnection();
Metadata metadata = metadataDAO.getMetadata(tenantId, MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
Gson gson = new Gson();
Type listType = new TypeToken<List<AllowedDeviceStatus>>() {
}.getType();
List<AllowedDeviceStatus> statusList = gson.fromJson(metadata.getMetaValue(), listType);
for (AllowedDeviceStatus status : statusList) {
if (status.getType().equalsIgnoreCase(deviceType)) {
List<String> allowedStatus = status.getStatus();
return allowedStatus.contains(deviceStatus);
}
}
return false; // Device type not found in metadata
} catch (MetadataManagementDAOException e) {
String msg = "Error occurred while retrieving device status meta data for tenant: " + tenantId;
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new MetadataManagementException(msg, e);
} finally {
MetadataManagementDAOFactory.closeConnection();
}
}
private void addMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
metadataDAO.addMetadata(tenantId, metadata);
if (log.isDebugEnabled()) {
log.debug(key + " metadata entry has been inserted successfully");
}
}
private void updateMetadataEntry(int tenantId, Metadata metadata, String key) throws MetadataManagementDAOException {
metadataDAO.updateMetadata(tenantId, metadata);
if (log.isDebugEnabled()) {
log.debug(key + " metadata entry has been updated successfully");
}
}
private Metadata constructDeviceStatusMetadata(List<DeviceStatusItem> deviceStatusItems) {
Gson gson = new Gson();
String deviceStatusItemsJsonString = gson.toJson(deviceStatusItems);
Metadata metadata = new Metadata();
metadata.setMetaKey(MetadataConstants.ALLOWED_DEVICE_STATUS_META_KEY);
metadata.setMetaValue(deviceStatusItemsJsonString);
return metadata;
}
private Metadata constructDeviceStatusCheckMetadata(boolean deviceStatusCheck) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("deviceStatusCheck", String.valueOf(deviceStatusCheck));
Metadata metadata = new Metadata();
metadata.setMetaKey(MetadataConstants.IS_DEVICE_STATUS_CHECK_META_KEY);
metadata.setMetaValue(String.valueOf(deviceStatusCheck));
return metadata;
}
private List<DeviceStatusItem> getDefaultDeviceStatus() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
List<DeviceStatusItem> deviceStatusItems = new ArrayList<>();
if (deviceStatusConfigurations != null) {
// Access the list of DeviceStatusItem objects
deviceStatusItems = deviceStatusConfigurations.getDeviceStatusItems();
} else {
if (log.isDebugEnabled()) {
log.debug("DeviceStatusConfigurations is null.");
}
}
return deviceStatusItems;
}
private boolean getDefaultDeviceStatusCheck() {
DeviceStatusConfigurations deviceStatusConfigurations = UIConfigurationManager.getInstance().getUIConfig().getDeviceStatusConfigurations();
boolean deviceStatusCheck = false;
if (deviceStatusConfigurations != null) {
// Access the deviceStatusCheck
deviceStatusCheck = deviceStatusConfigurations.isDeviceStatusCheck();
} else {
if (log.isDebugEnabled()) {
log.debug("DeviceStatusConfigurations is null.");
}
}
return deviceStatusCheck;
}
}

@ -20,4 +20,7 @@ package io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.dao.util;
public class MetadataConstants {
public static final String WHITELABEL_META_KEY = "whitelabel";
public static final String ALLOWED_DEVICE_STATUS_META_KEY = "allowed_device_status";
public static final String IS_DEVICE_STATUS_CHECK_META_KEY = "device-status-check";
}

@ -167,12 +167,12 @@ public class SQLServerOperationDAOImpl extends GenericOperationDAOImpl {
operation = new Operation();
operation.setId(rs.getInt("ID"));
operation.setType(Operation.Type.valueOf(rs.getString("TYPE")));
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toString());
operation.setCreatedTimeStamp(new Timestamp(rs.getLong("CREATED_TIMESTAMP") * 1000L).toInstant().toString());
if (rs.getLong("UPDATED_TIMESTAMP") == 0) {
operation.setReceivedTimeStamp("");
} else {
operation.setReceivedTimeStamp(
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toString());
new java.sql.Timestamp((rs.getLong("UPDATED_TIMESTAMP") * 1000)).toInstant().toString());
}
operation.setCode(rs.getString("OPERATION_CODE"));
operation.setStatus(Operation.Status.valueOf(rs.getString("STATUS")));

@ -21,9 +21,9 @@ import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.*;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitation;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentInvitationDetails;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.DeviceEnrollmentType;
import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.EnrollmentTypeMail;
import io.entgra.device.mgt.core.device.mgt.common.invitation.mgt.UserMailAttributes;
import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO;
import io.entgra.device.mgt.core.device.mgt.common.spi.OTPManagementService;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
@ -32,7 +32,6 @@ import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAO;
import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.exception.OTPManagementDAOException;
import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.util.ConnectionManagerUtil;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import io.entgra.device.mgt.core.device.mgt.core.service.EmailMetaInfo;
import io.entgra.device.mgt.core.device.mgt.core.util.DeviceManagerUtil;
import org.apache.commons.lang.StringUtils;
@ -208,53 +207,12 @@ public class OTPManagementServiceImpl implements OTPManagementService {
}
}
@Override
public void sendDeviceEnrollmentInvitationMail(DeviceEnrollmentInvitation deviceEnrollmentInvitation)
throws OTPManagementException {
DeviceManagementProviderService dms = DeviceManagementDataHolder.getInstance().getDeviceManagementProvider();
StringBuilder enrollmentSteps = new StringBuilder();
DeviceEnrollmentInvitationDetails deviceEnrollmentInvitationDetails;
for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentInvitation.getDeviceEnrollmentTypes()) {
deviceEnrollmentInvitationDetails = dms.getDeviceEnrollmentInvitationDetails(
deviceEnrollmentType.getDeviceType());
if (deviceEnrollmentInvitationDetails != null &&
deviceEnrollmentInvitationDetails.getEnrollmentDetails() != null) {
for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) {
deviceEnrollmentInvitationDetails.getEnrollmentDetails().stream()
.filter(details -> enrollmentType.equals(details.getEnrollmentType())).findFirst()
.ifPresent(details -> enrollmentSteps.append(details.getEnrollmentSteps()));
}
}
}
Properties props = new Properties();
props.setProperty("enrollment-steps", enrollmentSteps.toString());
try {
ConnectionManagerUtil.beginDBTransaction();
for (String username : deviceEnrollmentInvitation.getUsernames()) {
String emailAddress = DeviceManagerUtil.getUserClaimValue(
username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS);
props.setProperty("first-name", DeviceManagerUtil.
getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME));
props.setProperty("username", username);
sendMail(props, emailAddress, DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE);
}
ConnectionManagerUtil.commitDBTransaction();
} catch (UserStoreException e) {
String msg = "Error occurred while getting claim values to invite user";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection to add OPT data.";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation.";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
List<EnrollmentTypeMail> enrollmentTypeMails =
getEnrollmentTypeMails(deviceEnrollmentInvitation.getDeviceEnrollmentTypes());
sendEnrollmentTypeMails(deviceEnrollmentInvitation.getUsernames(), enrollmentTypeMails);
}
/**
@ -370,4 +328,113 @@ public class OTPManagementServiceImpl implements OTPManagementService {
ConnectionManagerUtil.closeDBConnection();
}
}
/**
* Send enrollment type mails to users
* @param usernames List of usernames to send enrollment type mails
* @param enrollmentTypeMails List of enrollment types
* @throws OTPManagementException Throws when error occurred while sending emails
*/
private void sendEnrollmentTypeMails(List<String> usernames, List<EnrollmentTypeMail> enrollmentTypeMails)
throws OTPManagementException {
try {
ConnectionManagerUtil.beginDBTransaction();
for (String username : usernames) {
populateUserAttributes(getUserMailAttributes(username), enrollmentTypeMails);
for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) {
sendMail(enrollmentTypeMail);
}
}
ConnectionManagerUtil.commitDBTransaction();
} catch (UserStoreException e) {
String msg = "Error occurred while populating user attributes";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} catch (DBConnectionException e) {
String msg = "Error occurred while getting database connection to add OTP data.";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} catch (TransactionManagementException e) {
String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation.";
log.error(msg, e);
throw new OTPManagementException(msg, e);
} finally {
ConnectionManagerUtil.closeDBConnection();
}
}
/**
* Send enrollment type mail
* @param enrollmentTypeMail Data related to the enrollment mail
* @throws OTPManagementException Throws when error occurred while sending email
*/
private void sendMail(EnrollmentTypeMail enrollmentTypeMail) throws OTPManagementException {
sendMail(enrollmentTypeMail.getProperties(), enrollmentTypeMail.getRecipient(), enrollmentTypeMail.getTemplate());
}
/**
* Get user claims based on the username
* @param username Username
* @return {@link UserMailAttributes}
* @throws UserStoreException Throws when error occurred while retrieving user claims
*/
private UserMailAttributes getUserMailAttributes(String username) throws UserStoreException {
UserMailAttributes userMailAttributes = new UserMailAttributes();
userMailAttributes.setEmail(DeviceManagerUtil.getUserClaimValue(
username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS));
userMailAttributes.setFirstName(DeviceManagerUtil.
getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME));
userMailAttributes.setUsername(username);
return userMailAttributes;
}
/**
* Populate enrollment type mails with provided user attributes
* @param userMailAttributes User attributes
* @param enrollmentTypeMails Enrollment type mails
*/
private void populateUserAttributes(UserMailAttributes userMailAttributes, List<EnrollmentTypeMail> enrollmentTypeMails) {
for (EnrollmentTypeMail enrollmentTypeMail : enrollmentTypeMails) {
Properties properties = new Properties();
properties.setProperty(userMailAttributes.getEmailPlaceholder(), userMailAttributes.getEmail());
properties.setProperty(userMailAttributes.getFirstNamePlaceholder(), userMailAttributes.getFirstName());
properties.setProperty(userMailAttributes.getUsernamePlaceholder(), userMailAttributes.getUsername());
enrollmentTypeMail.setProperties(properties);
enrollmentTypeMail.setUsername(userMailAttributes.getUsername());
enrollmentTypeMail.setRecipient(userMailAttributes.getEmail());
}
}
/**
* Generate enrollment type mail
* @param deviceType Device type of the enrollment type
* @param enrollmentType Enrollment type
* @return {@link EnrollmentTypeMail}
*/
private EnrollmentTypeMail getEnrollmentTypeMail(String deviceType, String enrollmentType) {
EnrollmentTypeMail enrollmentTypeMail = new EnrollmentTypeMail();
enrollmentTypeMail.setUsername(enrollmentTypeMail.getUsername());
enrollmentTypeMail.setTemplate(String.join(DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER,
deviceType.toLowerCase(), enrollmentType.toLowerCase().
replace(DeviceManagementConstants.EmailAttributes.ENROLLMENT_TYPE_SPLITTER,
DeviceManagementConstants.EmailAttributes.TEMPLATE_NAME_PART_JOINER),
DeviceManagementConstants.EmailAttributes.DEVICE_ENROLLMENT_MAIL_KEY));
return enrollmentTypeMail;
}
/**
* Generate enrollment type mails from device enrollment types
* @param deviceEnrollmentTypes List of device enrollment types
* @return List of enrollment type mails
*/
private List<EnrollmentTypeMail> getEnrollmentTypeMails(List<DeviceEnrollmentType> deviceEnrollmentTypes) {
List<EnrollmentTypeMail> enrollmentTypeMails = new ArrayList<>();
for (DeviceEnrollmentType deviceEnrollmentType : deviceEnrollmentTypes) {
String deviceType = deviceEnrollmentType.getDeviceType();
for (String enrollmentType : deviceEnrollmentType.getEnrollmentType()) {
enrollmentTypeMails.add(getEnrollmentTypeMail(deviceType, enrollmentType));
}
}
return enrollmentTypeMails;
}
}

@ -1022,10 +1022,9 @@ public interface DeviceManagementProviderService {
* @param iconPath Icon path of the application
* @param packageName Package name of the application
* @param version Version of the application
* @param tenantId Tenant ID of the application created user
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId)
void saveApplicationIcon(String iconPath, String packageName, String version)
throws DeviceManagementException;
/**
@ -1054,4 +1053,12 @@ public interface DeviceManagementProviderService {
*/
List<Application> getInstalledApplicationsOnDevice(Device device, int offset, int limit)
throws DeviceManagementException;
/**
* This method is for getting the installed application list of a device
* @param device {@link Device}
* @return list of applications {@link Application}
* @throws DeviceManagementException if any service level or DAO level error occurs
*/
List<Application> getInstalledApplicationsOnDevice(Device device) throws DeviceManagementException;
}

@ -20,6 +20,22 @@ 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.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest;
import io.entgra.device.mgt.core.device.mgt.common.Device;
import io.entgra.device.mgt.core.device.mgt.common.DeviceEnrollmentInfoNotification;
@ -125,18 +141,6 @@ import io.entgra.device.mgt.core.notification.logger.DeviceEnrolmentLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceEnrolmentLoggerImpl;
import io.entgra.device.mgt.core.transport.mgt.email.sender.core.*;
import io.entgra.device.mgt.core.transport.mgt.email.sender.core.service.EmailSenderService;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.lang.StringUtils;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.apache.http.protocol.HTTP;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.CarbonContext;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.stratos.common.beans.TenantInfoBean;
import org.wso2.carbon.tenant.mgt.services.TenantMgtAdminService;
import org.wso2.carbon.user.api.UserStoreException;
@ -486,6 +490,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
Device currentDevice = this.getDevice(deviceIdentifier, false);
DeviceManagementDAOFactory.beginTransaction();
device.setId(currentDevice.getId());
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
if (device.getEnrolmentInfo().getId() == 0) {
device.getEnrolmentInfo().setId(currentDevice.getEnrolmentInfo().getId());
}
@ -496,7 +502,14 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.setName(currentDevice.getName());
}
deviceDAO.updateDevice(device, tenantId);
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
int updatedRows = enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
boolean isEnableDeviceStatusCheck = deviceStatusManagementService.getDeviceStatusCheck(tenantId);
boolean isValidState = deviceStatusManagementService.isDeviceStatusValid(device.getType(),device.getEnrolmentInfo().getStatus().name(),tenantId);
if (updatedRows == 1 && !deviceStatusManagementService.getDeviceStatusCheck(tenantId)){
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
} else if (updatedRows ==1 && isEnableDeviceStatusCheck && isValidState ) {
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
}
DeviceManagementDAOFactory.commitTransaction();
log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(currentDevice.getId())).setDeviceType(String.valueOf(currentDevice.getType())).setOwner(currentDevice.getEnrolmentInfo().getOwner()).setOwnership(String.valueOf(currentDevice.getEnrolmentInfo().getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build());
@ -604,7 +617,16 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.getEnrolmentInfo().setDateOfLastUpdate(new Date().getTime());
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
DeviceManagementDAOFactory.beginTransaction();
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
int updatedRows = enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
boolean isEnableDeviceStatusCheck = deviceStatusManagementService.getDeviceStatusCheck(tenantId);
boolean isValidState = deviceStatusManagementService.isDeviceStatusValid(device.getType(),device.getEnrolmentInfo().getStatus().name(),tenantId);
if (updatedRows == 1 && !deviceStatusManagementService.getDeviceStatusCheck(tenantId)){
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
} else if (updatedRows ==1 && isEnableDeviceStatusCheck && isValidState ) {
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
}
deviceDAO.updateDevice(device, tenantId);
DeviceManagementDAOFactory.commitTransaction();
this.removeDeviceFromCache(deviceId);
@ -1094,10 +1116,10 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
public double generateCost(List<Device> allDevices, Timestamp startDate, Timestamp endDate, Cost tenantCost, List<Device> deviceStatusNotAvailable, double totalCost) throws DeviceManagementException {
List<DeviceStatus> deviceStatus;
for (Device device : allDevices) {
long dateDiff = 0;
device.setDeviceStatusInfo(getDeviceStatusHistory(device, null, endDate, true));
List<DeviceStatus> deviceStatus = device.getDeviceStatusInfo();
deviceStatus = getDeviceStatusHistory(device, null, endDate, true);
if (device.getEnrolmentInfo().getDateOfEnrolment() < startDate.getTime()) {
if (!deviceStatus.isEmpty() && (String.valueOf(deviceStatus.get(0).getStatus()).equals("REMOVED")
|| String.valueOf(deviceStatus.get(0).getStatus()).equals("DELETED"))) {
@ -3340,7 +3362,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
isDeviceUpdated = disenrollDevice(deviceIdentifier);
} else {
enrolmentInfo.setStatus(newStatus);
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId);
isDeviceUpdated = updateEnrollment(deviceId, enrolmentInfo, tenantId, deviceIdentifier);
}
this.removeDeviceFromCache(deviceIdentifier);
return isDeviceUpdated;
@ -3371,7 +3393,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
}
private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId)
private boolean updateEnrollment(int deviceId, EnrolmentInfo enrolmentInfo, int tenantId, DeviceIdentifier deviceIdentifier)
throws DeviceManagementException {
if (log.isDebugEnabled()) {
log.debug("Update enrollment of device: " + deviceId);
@ -3380,10 +3402,21 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
try {
DeviceManagementDAOFactory.beginTransaction();
int updatedRows = enrollmentDAO.updateEnrollment(enrolmentInfo, tenantId);
String type = deviceIdentifier.getType();
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
DeviceManagementDAOFactory.commitTransaction();
if (updatedRows > 0) {
isUpdatedEnrollment = true;
}
boolean isEnableDeviceStatusCheck = deviceStatusManagementService.getDeviceStatusCheck(tenantId);
boolean isValidState = deviceStatusManagementService.isDeviceStatusValid(type, enrolmentInfo.getStatus().name(), tenantId);
if (updatedRows == 1 && !deviceStatusManagementService.getDeviceStatusCheck(tenantId)) {
enrollmentDAO.addDeviceStatus(enrolmentInfo.getId(), enrolmentInfo.getStatus());
} else if (updatedRows == 1 && isEnableDeviceStatusCheck && isValidState) {
enrollmentDAO.addDeviceStatus(enrolmentInfo.getId(), enrolmentInfo.getStatus());
}
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while updating the enrollment information device for" +
@ -4412,13 +4445,25 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
device.getEnrolmentInfo().setStatus(EnrolmentInfo.Status.REMOVED);
// different try blocks are used to isolate transactions
try {
enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
String type = device.getType();
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
int updatedRows = enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId);
boolean isEnableDeviceStatusCheck = deviceStatusManagementService.getDeviceStatusCheck(tenantId);
boolean isValidState = deviceStatusManagementService.isDeviceStatusValid(type, String.valueOf(EnrolmentInfo.Status.REMOVED),tenantId);
if (updatedRows == 1 && !deviceStatusManagementService.getDeviceStatusCheck(tenantId)){
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
} else if (updatedRows ==1 && isEnableDeviceStatusCheck && isValidState ) {
enrollmentDAO.addDeviceStatus(device.getEnrolmentInfo().getId(), device.getEnrolmentInfo().getStatus());
}
} catch (DeviceManagementDAOException e) {
DeviceManagementDAOFactory.rollbackTransaction();
String msg = "Error occurred while dis-enrolling device: " +
device.getName();
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (MetadataManagementException e) {
throw new RuntimeException(e);
}
try {
deviceDAO.updateDevice(device, tenantId);
@ -4954,9 +4999,11 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
@Override
public void saveApplicationIcon(String iconPath, String packageName, String version, int tenantId) throws DeviceManagementException{
public void saveApplicationIcon(String iconPath, String packageName, String version) throws DeviceManagementException{
int tenantId = 0;
try{
DeviceManagementDAOFactory.beginTransaction();
tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
if(applicationDAO.getApplicationPackageCount(packageName) == 0){
applicationDAO.saveApplicationIcon(iconPath, packageName, version, tenantId);
}
@ -5078,4 +5125,38 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv
}
return newApplicationList;
}
public List<Application> getInstalledApplicationsOnDevice(Device device) throws DeviceManagementException {
List<Application> applications;
try {
DeviceManagementDAOFactory.openConnection();
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
applications = applicationDAO.getInstalledApplicationListOnDevice(device.getId(),
device.getEnrolmentInfo().getId(), tenantId);
if (applications == null) {
String msg = "Couldn't found applications for device identifier '" + device.getId() + "'";
log.error(msg);
throw new DeviceManagementException(msg);
}
} catch (DeviceManagementDAOException e) {
String msg = "Error occurred while retrieving the application list of android device, " +
"which carries the id '" + device.getId() + "'";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} catch (SQLException e) {
String msg = "Error occurred while opening a connection to the data source";
log.error(msg, e);
throw new DeviceManagementException(msg, e);
} finally {
DeviceManagementDAOFactory.closeConnection();
}
List<Application> newApplicationList;
newApplicationList = this.getInstalledAppIconInfo(applications);
if (newApplicationList == null) {
String msg = "Error occurred while getting app icon info for device identifier '" + device.getId() + "'";
log.error(msg);
throw new DeviceManagementException(msg);
}
return newApplicationList;
}
}

@ -19,6 +19,11 @@
package io.entgra.device.mgt.core.device.mgt.core.status.task.impl;
import com.google.gson.Gson;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
import io.entgra.device.mgt.core.device.mgt.common.DeviceStatusTaskPluginConfig;
import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext;
@ -31,8 +36,7 @@ import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOExceptio
import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory;
import io.entgra.device.mgt.core.device.mgt.core.status.task.DeviceStatusTaskException;
import io.entgra.device.mgt.core.device.mgt.core.task.impl.DynamicPartitionedScheduleTask;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.carbon.context.CarbonContext;
import java.sql.SQLException;
import java.util.ArrayList;
@ -135,11 +139,26 @@ public class DeviceStatusMonitoringTask extends DynamicPartitionedScheduleTask {
private boolean updateDeviceStatus(List<EnrolmentInfo> enrolmentInfos) throws
DeviceStatusTaskException {
boolean updateStatus;
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
try {
DeviceManagementDAOFactory.beginTransaction();
updateStatus = DeviceManagementDAOFactory.getEnrollmentDAO().updateEnrollmentStatus(enrolmentInfos);
boolean isEnableDeviceStatusCheck = deviceStatusManagementService.getDeviceStatusCheck(tenantId);
if (updateStatus) {
for (EnrolmentInfo enrolmentInfo : enrolmentInfos) {
if (isEnableDeviceStatusCheck) {
if (deviceStatusManagementService.isDeviceStatusValid(this.deviceType, enrolmentInfo.getStatus().name(), tenantId)) {
DeviceManagementDAOFactory.getEnrollmentDAO().addDeviceStatus(enrolmentInfo);
}
} else {
DeviceManagementDAOFactory.getEnrollmentDAO().addDeviceStatus(enrolmentInfo);
}
}
}
DeviceManagementDAOFactory.commitTransaction();
} catch (DeviceManagementDAOException e) {
} catch (DeviceManagementDAOException | MetadataManagementException e) {
DeviceManagementDAOFactory.rollbackTransaction();
throw new DeviceStatusTaskException("Error occurred while updating enrollment status of devices of type '"
+ deviceType + "'", e);

@ -19,16 +19,18 @@
package io.entgra.device.mgt.core.device.mgt.core.search;
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 org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import io.entgra.device.mgt.core.device.mgt.core.common.BaseDeviceManagementTest;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.DeviceInformationManager;
import io.entgra.device.mgt.core.device.mgt.core.device.details.mgt.impl.DeviceInformationManagerImpl;
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
public class DeviceDetails extends BaseDeviceManagementTest {
@ -41,6 +43,8 @@ public class DeviceDetails extends BaseDeviceManagementTest {
DeviceManagementProviderService deviceManagementProviderService = new DeviceManagementProviderServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceManagementProvider(deviceManagementProviderService);
DeviceStatusManagementService deviceStatusManagementService = new DeviceStatusManagementServiceImpl();
DeviceManagementDataHolder.getInstance().setDeviceStatusManagementService(deviceStatusManagementService);
}
@Test

@ -20,6 +20,18 @@ package io.entgra.device.mgt.core.device.mgt.core.service;
import io.entgra.device.mgt.core.device.mgt.common.*;
import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.ConfigurationManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.DeviceStatusManagementService;
import io.entgra.device.mgt.core.device.mgt.core.config.ui.UIConfigurationManager;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
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.exceptions.DeviceManagementException;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException;
import io.entgra.device.mgt.core.device.mgt.common.license.mgt.License;
@ -41,13 +53,6 @@ import io.entgra.device.mgt.core.device.mgt.core.mock.MockConnection;
import io.entgra.device.mgt.core.device.mgt.core.mock.MockDataSource;
import io.entgra.device.mgt.core.device.mgt.core.mock.MockResultSet;
import io.entgra.device.mgt.core.device.mgt.core.mock.MockStatement;
import org.apache.commons.collections.map.SingletonMap;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.mockito.Mockito;
import org.testng.Assert;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.registry.core.config.RegistryContext;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.registry.core.internal.RegistryDataHolder;
@ -57,6 +62,7 @@ import org.wso2.carbon.user.api.UserStoreException;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
import java.io.File;
import java.io.InputStream;
import java.lang.reflect.Field;
import java.sql.Timestamp;
@ -69,6 +75,8 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
private static final String ALTERNATE_DEVICE_ID = "1128";
private static final String DEVICE_TYPE = "RANDOM_DEVICE_TYPE";
private final DeviceDetailsDAO deviceDetailsDAO = DeviceManagementDAOFactory.getDeviceDetailsDAO();
private static final String MDM_CONFIG_LOCATION = "src" + File.separator + "test" + File.separator + "resources" +
File.separator + "config" + File.separator + "operation" + File.separator + "mdm-ui-config.xml";
DeviceManagementProviderService deviceMgtService;
@ -87,6 +95,7 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
DeviceManagementDataHolder.getInstance().setDeviceTaskManagerService(null);
deviceMgtService.registerDeviceType(new TestDeviceManagementService(DEVICE_TYPE,
MultitenantConstants.SUPER_TENANT_DOMAIN_NAME));
UIConfigurationManager.getInstance().initConfig(MDM_CONFIG_LOCATION);
}
private RegistryService getRegistryService() throws RegistryException {
@ -195,8 +204,11 @@ public class DeviceManagementProviderServiceTest extends BaseDeviceManagementTes
@Test(dependsOnMethods = {"testSuccessfulDeviceEnrollment"})
public void testReEnrollmentofSameDeviceUnderSameUser() throws DeviceManagementException {
public void testReEnrollmentofSameDeviceUnderSameUser() throws DeviceManagementException, MetadataManagementException {
if (!isMock()) {
DeviceStatusManagementService deviceStatusManagementService = DeviceManagementDataHolder
.getInstance().getDeviceStatusManagementService();
deviceStatusManagementService.addDefaultDeviceStatusFilterIfNotExist(MultitenantConstants.SUPER_TENANT_ID);
Device device = TestDataHolder.generateDummyDeviceData(new DeviceIdentifier(DEVICE_ID, DEVICE_TYPE));
boolean enrollment = deviceMgtService.enrollDevice(device);
Assert.assertTrue(enrollment);

@ -17,6 +17,15 @@
*/
package io.entgra.device.mgt.core.device.mgt.core.task;
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.powermock.api.mockito.PowerMockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
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.exceptions.DeviceManagementException;
@ -38,14 +47,6 @@ import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProvide
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderServiceImpl;
import io.entgra.device.mgt.core.device.mgt.core.task.impl.DeviceDetailsRetrieverTask;
import io.entgra.device.mgt.core.device.mgt.core.task.impl.DeviceTaskManagerImpl;
import io.entgra.device.mgt.core.server.bootup.heartbeat.beacon.service.HeartBeatManagementService;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.powermock.api.mockito.PowerMockito;
import org.testng.Assert;
import org.testng.annotations.AfterClass;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.Test;
import org.wso2.carbon.registry.core.exceptions.RegistryException;
import org.wso2.carbon.utils.multitenancy.MultitenantConstants;
@ -64,7 +65,7 @@ public class DeviceTaskManagerTest extends BaseDeviceManagementTest {
private OperationManager operationManager;
@BeforeClass
public void init() throws DeviceManagementException, RegistryException {
public void init() throws DeviceManagementException, RegistryException, MetadataManagementException {
log.info("Initializing Device Task Manager Test Suite");
this.deviceIds = new ArrayList<>();
for (int i = 0; i < 5; i++) {

@ -0,0 +1,410 @@
<?xml version="1.0" encoding="ISO-8859-1"?>
<!--
~ 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.
-->
<UIConfiguration>
<EnableOAuth>true</EnableOAuth>
<EnableSSO>true</EnableSSO>
<!-- session time out in seconds -->
<SessionTimeOut>3600</SessionTimeOut>
<!-- maximum number of login cache entries -->
<LoginCacheCapacity>10000</LoginCacheCapacity>
<!-- hubspot account info for live chat -->
<HubspotChat>
<EnableHubspot>false</EnableHubspot>
<TrackingUrl>tracking_url</TrackingUrl>
<!-- access token - whenever the access token will be rotated, needs to be changed this with the new token -->
<AccessToken>access_token</AccessToken>
<SenderActorId>sender_actorId</SenderActorId>
</HubspotChat>
<Billing>
<HideBillGenerationInSuperTenant>false</HideBillGenerationInSuperTenant>
<HideBillGenerationInSubTenant>true</HideBillGenerationInSubTenant>
<HideTotalCalculationInSuperTenant>false</HideTotalCalculationInSuperTenant>
<HideTotalCalculationInSubTenant>true</HideTotalCalculationInSubTenant>
<HideDomainSelectionInSuperTenant>false</HideDomainSelectionInSuperTenant>
<HideDomainSelectionInSubTenant>true</HideDomainSelectionInSubTenant>
</Billing>
<DeviceInfoConfigurations>
<DeviceInfoItem>
<DefinedValue>name</DefinedValue>
<DisplayValue>label_device</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>type</DefinedValue>
<DisplayValue>label_type</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>owner</DefinedValue>
<DisplayValue>label_owner</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>serial</DefinedValue>
<DisplayValue>label_serialNumber</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>ownership</DefinedValue>
<DisplayValue>label_ownership</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>status</DefinedValue>
<DisplayValue>label_status</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>dateOfLastUpdate</DefinedValue>
<DisplayValue>label_last_updated</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>actions</DefinedValue>
<DisplayValue>label_actions</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>batteryLevel</DefinedValue>
<DisplayValue>label_battery_leve</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>deviceModel</DefinedValue>
<DisplayValue>label_deviceModel</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>osVersion</DefinedValue>
<DisplayValue>label_os_version</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>vendor</DefinedValue>
<DisplayValue>label_vendor</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>availableRAMMemory</DefinedValue>
<DisplayValue>label_available_ram_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>connectionType</DefinedValue>
<DisplayValue>label_connection_type</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>cpuUsage</DefinedValue>
<DisplayValue>label_cpu_usage</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>externalAvailableMemory</DefinedValue>
<DisplayValue>label_external_available_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>externalTotalMemory</DefinedValue>
<DisplayValue>label_external_tot_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>internalAvailableMemory</DefinedValue>
<DisplayValue>label_internal_available_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>internalTotalMemory</DefinedValue>
<DisplayValue>label_internal_tot_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>osBuildDate</DefinedValue>
<DisplayValue>label_os_build_date</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>pluggedIn</DefinedValue>
<DisplayValue>label_plugged_in</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>ssid</DefinedValue>
<DisplayValue>label_ssid</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>totalRAMMemory</DefinedValue>
<DisplayValue>label_tot_ram_memory</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>updatedTime</DefinedValue>
<DisplayValue>label_updated_time</DisplayValue>
<Type>deviceInfo</Type>
</DeviceInfoItem>
</DeviceInfoConfigurations>
<DeviceStatusConfigurations>
<EnableDeviceStatusCheck>true</EnableDeviceStatusCheck>
<DeviceStatusItem>
<Type>android</Type>
<AllowedStatus>
<Status>ACTIVE</Status>
<Status>CREATED</Status>
<Status>INACTIVE</Status>
<Status>UNREACHABLE</Status>
<Status>UNCLAIMED</Status>
<Status>SUSPENDED</Status>
<Status>BLOCKED</Status>
<Status>REMOVED</Status>
<Status>SUSPENDED</Status>
<Status>DISENROLLMENT_REQUESTED</Status>
</AllowedStatus>
</DeviceStatusItem>
<DeviceStatusItem>
<Type>ios</Type>
<AllowedStatus>
<Status>ACTIVE</Status>
<Status>CREATED</Status>
<Status>INACTIVE</Status>
<Status>UNREACHABLE</Status>
<Status>UNCLAIMED</Status>
<Status>SUSPENDED</Status>
<Status>BLOCKED</Status>
<Status>REMOVED</Status>
<Status>SUSPENDED</Status>
<Status>DISENROLLMENT_REQUESTED</Status>
</AllowedStatus>
</DeviceStatusItem>
<DeviceStatusItem>
<Type>windows</Type>
<AllowedStatus>
<Status>ACTIVE</Status>
<Status>CREATED</Status>
<Status>INACTIVE</Status>
<Status>UNREACHABLE</Status>
<Status>UNCLAIMED</Status>
<Status>SUSPENDED</Status>
<Status>BLOCKED</Status>
<Status>REMOVED</Status>
<Status>SUSPENDED</Status>
<Status>DISENROLLMENT_REQUESTED</Status>
</AllowedStatus>
</DeviceStatusItem>
</DeviceStatusConfigurations>
<AppRegistration>
<Tags>
<Tag>analytics_management</Tag>
<Tag>application_management</Tag>
<Tag>device_management</Tag>
<Tag>subscription_management</Tag>
<Tag>review_management</Tag>
</Tags>
<AllowToAllDomains>true</AllowToAllDomains>
</AppRegistration>
<Scopes>
<Scope>grafana:api:view</Scope>
<Scope>am:store:app:review:view</Scope>
<Scope>am:store:app:review:update</Scope>
<Scope>am:pub:sp:app:view</Scope>
<Scope>am:pub:sp:create</Scope>
<Scope>am:pub:sp:attach</Scope>
<Scope>am:pub:sp:detach</Scope>
<Scope>am:pub:sp:connect</Scope>
<Scope>am:pub:app:view</Scope>
<Scope>am:pub:app:update</Scope>
<Scope>am:store:app:view</Scope>
<Scope>am:store:app:modify</Scope>
<Scope>am:store:app:sub:install</Scope>
<Scope>am:store:app:sub:uninstall</Scope>
<Scope>am:admin:pub:app:review:view</Scope>
<Scope>am:admin:pub:app:update</Scope>
<Scope>am:admin:store:app:review:update</Scope>
<Scope>am:admin:store:app:sub:view</Scope>
<Scope>am:admin:store:app:sub:modify</Scope>
<Scope>dm:device-type:view</Scope>
<Scope>and:enterprise:modify</Scope>
<Scope>and:enterprise:view</Scope>
<Scope>dm:sign-csr</Scope>
<Scope>dm:admin:devices:view</Scope>
<Scope>dm:devices:status:change</Scope>
<Scope>rm:roles:add</Scope>
<Scope>rm:users:add</Scope>
<Scope>rm:roles:update</Scope>
<Scope>rm:roles:permissions:view</Scope>
<Scope>rm:roles:details:view</Scope>
<Scope>rm:roles:view</Scope>
<Scope>rm:roles:combined:add</Scope>
<Scope>rm:roles:delete</Scope>
<Scope>dm:activity:get</Scope>
<Scope>dm:devices:delete</Scope>
<Scope>dm:devices:app:view</Scope>
<Scope>dm:devices:policy:view</Scope>
<Scope>dm:devices:compliance:view</Scope>
<Scope>dm:devices:features:view</Scope>
<Scope>dm:devices:ops:view</Scope>
<Scope>dm:devices:search</Scope>
<Scope>dm:devices:details</Scope>
<Scope>dm:devices:update</Scope>
<Scope>dm:devices:view</Scope>
<Scope>dm:devices:enrollment-guide:view</Scope>
<Scope>dm:conf:view</Scope>
<Scope>dm:conf:manage</Scope>
<Scope>pm:policies:remove</Scope>
<Scope>pm:policies:priorities:update</Scope>
<Scope>pm:policies:deactivate</Scope>
<Scope>pm:policies:details:view</Scope>
<Scope>pm:policies:add</Scope>
<Scope>pm:policies:activate</Scope>
<Scope>pm:policies:update</Scope>
<Scope>pm:policies:change</Scope>
<Scope>dm:policies:view</Scope>
<Scope>um:users:add</Scope>
<Scope>um:users:details:view</Scope>
<Scope>um:users:count</Scope>
<Scope>um:users:delete</Scope>
<Scope>um:roles:view</Scope>
<Scope>um:users:user-details:view</Scope>
<Scope>um:users:cred:change</Scope>
<Scope>um:users:search</Scope>
<Scope>um:users:is-exist</Scope>
<Scope>um:users:update</Scope>
<Scope>um:users:invite</Scope>
<Scope>um:admin:users:view</Scope>
<Scope>dm:admin:enrollment:update</Scope>
<Scope>gm:devices:view</Scope>
<Scope>gm:groups:update</Scope>
<Scope>gm:groups:add</Scope>
<Scope>gm:groups:device:view</Scope>
<Scope>gm:devices:count</Scope>
<Scope>gm:devices-types:view</Scope>
<Scope>gm:groups:remove</Scope>
<Scope>gm:groups:view</Scope>
<Scope>gm:groups:groups-view</Scope>
<Scope>gm:roles:share</Scope>
<Scope>gm:groups:count</Scope>
<Scope>gm:roles:view</Scope>
<Scope>gm:devices:remove</Scope>
<Scope>gm:devices:add</Scope>
<Scope>gm:devices:assign</Scope>
<Scope>dm:device-type:conf:view</Scope>
<Scope>dm:device-type:features:view</Scope>
<Scope>dm:device-type:view</Scope>
<Scope>am:admin:app:install</Scope>
<Scope>am:admin:app:uninstall</Scope>
<Scope>gm:admin:groups:count</Scope>
<Scope>gm:admin:groups:view</Scope>
<Scope>gm:admin:groups:add</Scope>
<Scope>dm:notif:mark-checked</Scope>
<Scope>dm:notifications:view</Scope>
<Scope>cm:cert:delete</Scope>
<Scope>cm:cert:details:get</Scope>
<Scope>cm:cert:view</Scope>
<Scope>cm:cert:add</Scope>
<Scope>cm:cert:verify</Scope>
<Scope>dm:admin</Scope>
<Scope>dm:device-type:deploy</Scope>
<Scope>dm:device-type:event:modify</Scope>
<Scope>dm:device-type:event:view</Scope>
<Scope>dm:admin:device-type:modify</Scope>
<Scope>dm:admin:device-type:view</Scope>
<Scope>dm:admin:device-type:conf:add</Scope>
<Scope>dm:device:enroll</Scope>
<Scope>dm:geo:an:view</Scope>
<Scope>dm:geo:alerts:manage</Scope>
<Scope>dm:admin:devices:permanent-delete</Scope>
<Scope>and:conf:manage</Scope>
<Scope>and:conf:view</Scope>
<Scope>um:users:permission:view</Scope>
<Scope>ios:conf:view</Scope>
<Scope>ios:conf:manage</Scope>
<Scope>ios:dep:view</Scope>
<Scope>ios:dep:add</Scope>
<Scope>win:conf:view</Scope>
<Scope>win:conf:manage</Scope>
<Scope>and:ops:lock-devices</Scope>
<Scope>and:ops:unlock-devices</Scope>
<Scope>and:ops:location</Scope>
<Scope>and:ops:clear-password</Scope>
<Scope>and:ops:control-camera</Scope>
<Scope>and:ops:enterprise-wipe</Scope>
<Scope>and:ops:wipe</Scope>
<Scope>and:ops:ring</Scope>
<Scope>and:ops:app-list</Scope>
<Scope>and:ops:reboot</Scope>
<Scope>and:ops:change-LockTask</Scope>
<Scope>and:ops:mute</Scope>
<Scope>and:ops:conf-display-msg</Scope>
<Scope>and:ops:send-app-restrictions</Scope>
<Scope>and:ops:file-transfer</Scope>
<Scope>and:ops:set-webclip</Scope>
<Scope>and:ops:password-policy</Scope>
<Scope>and:ops:change-lock-code</Scope>
<Scope>and:ops:upgrade-firmware</Scope>
<Scope>and:ops:send-notif</Scope>
<Scope>dm:geo:geo-fence:manage</Scope>
<Scope>dm:whitelable:view</Scope>
<Scope>dm:whitelable:update</Scope>
<Scope>dm:metadata:view</Scope>
<Scope>dm:metadata:create</Scope>
<Scope>dm:metadata:update</Scope>
<Scope>and:ops:add-google-acc</Scope>
<Scope>and:ops:authenticate-acc</Scope>
<Scope>and:ops:update-default-sim</Scope>
<Scope>and:ops:add-google-acc</Scope>
<Scope>and:ops:device-info</Scope>
<Scope>win:ops:lock-devices</Scope>
<Scope>win:devices:enroll</Scope>
<Scope>win:ops:disenroll</Scope>
<Scope>win:ops:wipe</Scope>
<Scope>win:ops:ring</Scope>
<Scope>win:ops:lock-reset</Scope>
<Scope>win:ops:reboot</Scope>
<Scope>win:ops:location</Scope>
<Scope>admin:tenant:view</Scope>
<Scope>dm:admin:devices:usage:view</Scope>
<Scope>and:ops:clear-app</Scope>
<Scope>and:ops:suspend-package</Scope>
<Scope>and:ops:alternate-install</Scope>
<Scope>ios:ops:lock</Scope>
<Scope>ios:ops:location</Scope>
<Scope>ios:ops:ring</Scope>
<Scope>ios:ops:clear-passcode</Scope>
<Scope>ios:ops:enterprise-wipe</Scope>
<Scope>ios:ops:notif</Scope>
<Scope>ios:ops:wipe</Scope>
<Scope>ios:ops:boolean-setting</Scope>
<Scope>ios:ops:wallpaper</Scope>
<Scope>ios:ops:app-attributes</Scope>
<Scope>ios:ops:app-conf</Scope>
<Scope>mac:ops:restart</Scope>
<Scope>mac:ops:shutdown</Scope>
<Scope>am:store:vpp:user:modify</Scope>
<Scope>am:store:vpp:user:view</Scope>
<Scope>am:store:vpp:assets:modify</Scope>
<Scope>am:store:vpp:assets:view</Scope>
<Scope>and:devices:enroll</Scope>
<Scope>ios:devices:enroll</Scope>
</Scopes>
<SSOConfiguration>
<Issuer>device-mgt</Issuer>
</SSOConfiguration>
</UIConfiguration>

@ -654,3 +654,15 @@ CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING (
TRACCAR_USER_ID INT DEFAULT 0
);
-- END OF DM_EXT_PERMISSION_MAPPING TABLE--
-- METADATA TABLE --
CREATE TABLE IF NOT EXISTS DM_METADATA (
METADATA_ID INT AUTO_INCREMENT NOT NULL,
DATA_TYPE VARCHAR(16) NOT NULL,
METADATA_KEY VARCHAR(128) NOT NULL,
METADATA_VALUE TEXT NOT NULL,
TENANT_ID INTEGER NOT NULL,
PRIMARY KEY (METADATA_ID),
CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID)
);
-- END OF METADATA TABLE --

@ -22,7 +22,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<artifactId>device-mgt</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>heartbeat-management</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>identity-extensions</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>identity-extensions</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>logger</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
</parent>
<artifactId>io.entgra.device.mgt.core.notification.logger</artifactId>

@ -22,7 +22,7 @@
<parent>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<groupId>io.entgra.device.mgt.core</groupId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>operation-template-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -21,7 +21,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -22,7 +22,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>policy-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -23,7 +23,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>subtype-mgt</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../pom.xml</relativePath>
</parent>

@ -20,7 +20,7 @@
<parent>
<groupId>io.entgra.device.mgt.core</groupId>
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
<version>5.0.33-SNAPSHOT</version>
<version>5.0.35-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Some files were not shown because too many files have changed in this diff Show More

Loading…
Cancel
Save