Compare commits

Invalid templates have been ignored

1 invalid template(s) found pull_request_template.md: frontmatter must start with a separator line

...

11 Commits

Author SHA1 Message Date
Thilina Sandaruwan 44c7d324de Fix: delete group with GeoFence references issue
1 year ago
Pahansith Gunathilake 0fbe062e49 Fix the SSL error when invoking internal API via HttpClient (#215)
1 year ago
Inosh Perara 320d012f5a Merge pull request 'Fix the API to check if a device is enrolled' (#222) from arshana790/device-mgt-core-fork:status into master
1 year ago
Arshana d20c95a55c Merge branch 'master' of ssh://repository.entgra.net:222/community/device-mgt-core into status
1 year ago
Arshana 9c7fd9027e Fix the API to check if a device is enrolled
1 year ago
Charitha Goonetilleke b761bdd5ea Merge pull request 'URL permission issue fixes (Removed * from root URLs)' (#221) from thameera/device-mgt-core:permission_issue into master
1 year ago
Thameera 680f57ade5 URL permission issue fixes (Removed * from root URLs)
1 year ago
Lasantha Dharmakeerthi 693e3a51d5 Remove custom properties from device table column selection
1 year ago
shamalka 203475f87d Remove custom properties from device table column selection
1 year ago
Pahansith Gunathilake 913f6175af Merge pull request 'Change location publishing logic' (#218) from shamalka1/device-mgt-core:location-fix into master
1 year ago
shamalka dc40351293 Change location publishing logic
1 year ago

@ -63,7 +63,7 @@ public class AnnotationProcessor {
private static final String PACKAGE_ORG_APACHE = "org.apache";
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
public static final String WILD_CARD = "/*";
public static final String WILD_CARD = "/";
private static final String SWAGGER_ANNOTATIONS_INFO = "info";
private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";
private static final String SWAGGER_ANNOTATIONS_EXTENSIONS = "extensions";

@ -112,6 +112,11 @@
</build>
<dependencies>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
<dependency>
<groupId>org.eclipse.osgi</groupId>
<artifactId>org.eclipse.osgi</artifactId>

@ -26,18 +26,20 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
import io.entgra.device.mgt.core.application.mgt.core.util.VppHttpUtil;
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpException;
import org.apache.commons.httpclient.HttpMethodBase;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.methods.StringRequestEntity;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.http.HttpResponse;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.ssl.SSLContextBuilder;
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClients;
import org.json.JSONArray;
import org.json.JSONObject;
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
@ -106,6 +108,9 @@ import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
@ -1297,38 +1302,37 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
}
}
private int invokeIOTCoreAPI(HttpMethodBase request) throws UserStoreException, APIManagerException, IOException {
HttpClient httpClient;
private int invokeIOTCoreAPI(HttpPost request) throws UserStoreException, APIManagerException, IOException,
ApplicationManagementException {
CloseableHttpClient httpClient = getHttpClient();
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain);
String username =
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
.getAdminUserName() + Constants.ApplicationInstall.AT + tenantDomain;
AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username);
request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION,
request.addHeader(Constants.ApplicationInstall.AUTHORIZATION,
Constants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken());
httpClient = new HttpClient();
httpClient.executeMethod(request);
return request.getStatusCode();
HttpResponse response = httpClient.execute(request);
return response.getStatusLine().getStatusCode();
}
public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO)
throws ApplicationManagementException {
PostMethod request;
String requestUrl =null;
try {
String requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
.getProperty(Constants.ApplicationInstall.IOT_CORE_HOST) + Constants.ApplicationInstall.COLON
requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
.getProperty(Constants.ApplicationInstall.IOT_GATEWAY_HOST) + Constants.ApplicationInstall.COLON
+ System.getProperty(Constants.ApplicationInstall.IOT_CORE_PORT)
+ Constants.ApplicationInstall.GOOGLE_APP_INSTALL_URL;
Gson gson = new Gson();
String payload = gson.toJson(applicationPolicyDTO);
HttpPost httpPost = new HttpPost(requestUrl);
StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON,
Constants.ApplicationInstall.ENCODING);
request = new PostMethod(requestUrl);
request.setRequestEntity(requestEntity);
return invokeIOTCoreAPI(request);
StringEntity stringEntity = new StringEntity(payload, Constants.ApplicationInstall.ENCODING);
httpPost.addHeader("Content-Type",MediaType.APPLICATION_JSON);
httpPost.setEntity(stringEntity);
return invokeIOTCoreAPI(httpPost);
} catch (UserStoreException e) {
String msg = "Error while accessing user store for user with Android device.";
log.error(msg, e);
@ -1337,18 +1341,38 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
String msg = "Error while retrieving access token for Android device";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (HttpException e) {
String msg = "Error while calling the app store to install enrollment app with id: " + applicationPolicyDTO
.getApplicationDTO().getId() + " on device";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (IOException e) {
String msg =
"Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId()
+ " on device";
+ " on device: request URL: " + requestUrl;
log.error(msg + "request url: " + requestUrl, e);
throw new ApplicationManagementException(msg, e);
}
}
private CloseableHttpClient getHttpClient() throws ApplicationManagementException {
try {
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
return HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build();
} catch (NoSuchAlgorithmException e) {
String msg = "Failed while building the http client for EntApp installation. " +
"Used SSL algorithm not available";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (KeyStoreException e) {
String msg = "Failed while building the http client for EntApp installation. " +
"Failed to load required key stores";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
} catch (KeyManagementException e) {
String msg = "Failed while building the http client for EntApp installation. " +
"Failed while building SSL context";
log.error(msg, e);
throw new ApplicationManagementException(msg, e);
}
}
private String getIOTCoreBaseUrl() {

@ -178,6 +178,8 @@ public class Constants {
public static final String DEVICE_TYPE_ANDROID = "android";
public static final String COLON = ":";
public static final String IOT_CORE_HOST = "iot.core.host";
public static final String IOT_GATEWAY_HOST = "iot.gateway.host";
public static final String IOT_CORE_PORT = "iot.core.https.port";
public static final String ENROLLMENT_APP_INSTALL_PROTOCOL = "https://";
public static final String GOOGLE_APP_INSTALL_URL = "/api/device-mgt/android/v1.0/enterprise/change-app";

@ -838,9 +838,9 @@ public interface DeviceManagementService {
Response getDeviceByIdList(List<String> deviceIds);
@PUT
@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{type}/{id}")
@Path("/{type}/{id}/status")
@ApiOperation(
produces = MediaType.APPLICATION_JSON,
httpMethod = "GET",

@ -526,6 +526,14 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO {
stmt.setInt(1, groupId);
stmt.setInt(2, tenantId);
stmt.executeUpdate();
sql = "DELETE FROM DM_DEVICE_EVENT_GROUP_MAPPING WHERE GROUP_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, groupId);
stmt.executeUpdate();
sql = "DELETE FROM DM_GEOFENCE_GROUP_MAPPING WHERE GROUP_ID = ?";
stmt = conn.prepareStatement(sql);
stmt.setInt(1, groupId);
stmt.executeUpdate();
} catch (SQLException e) {
throw new GroupManagementDAOException("Error occurred while removing mappings for group.'", e);
} finally {

@ -363,13 +363,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceManagementDAOFactory.beginTransaction();
DeviceLocation previousLocation = deviceDetailsDAO.getDeviceLocation(device.getId(),
device.getEnrolmentInfo().getId());
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.updateDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationInfo(device, deviceLocation,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
if (DeviceManagerUtil.isPublishLocationResponseEnabled()) {
Object[] metaData = {device.getDeviceIdentifier(), device.getEnrolmentInfo().getOwner(), device.getType()};
Object[] payload = new Object[]{
@ -382,11 +375,17 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
deviceLocation.getDistance()
};
}
//Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation);
} else {
if (previousLocation == null) {
deviceDetailsDAO.addDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.updateDeviceLocation(deviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationInfo(device, deviceLocation,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
if(!HttpReportingUtil.isLocationPublishing()) {
if (log.isDebugEnabled()) {
log.debug("Location publishing is disabled");
@ -453,19 +452,20 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
DeviceManagementDAOFactory.beginTransaction();
boolean previousLocation = deviceDetailsDAO.hasLocations(device.getId(),
device.getEnrolmentInfo().getId());
if(!HttpReportingUtil.isTrackerEnabled()) {
if (previousLocation) {
deviceDetailsDAO.updateDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
} else {
deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId());
}
deviceDetailsDAO.addDeviceLocationsInfo(device, deviceLocations,
CarbonContext.getThreadLocalCarbonContext().getTenantId());
}
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
for (DeviceLocation deviceLocation: deviceLocations) {
//Tracker update GPS Location
if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) {
DeviceManagementDataHolder.getInstance().getTraccarManagementService().updateLocation(device, deviceLocation);
}
} else {
if(!HttpReportingUtil.isLocationPublishing()) {
if (log.isDebugEnabled()) {
@ -478,7 +478,6 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager {
}
}
}
}
DeviceManagementDAOFactory.commitTransaction();
} catch (TransactionManagementException e) {

@ -73,6 +73,65 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP (
REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
-- DM_GEOFENCE TABLE--
CREATE TABLE IF NOT EXISTS DM_GEOFENCE
(
ID INT NOT NULL AUTO_INCREMENT,
FENCE_NAME VARCHAR(255) NOT NULL,
DESCRIPTION TEXT DEFAULT NULL,
LATITUDE DOUBLE DEFAULT NULL,
LONGITUDE DOUBLE DEFAULT NULL,
RADIUS DOUBLE DEFAULT NULL,
GEO_JSON TEXT DEFAULT NULL,
FENCE_SHAPE VARCHAR(100) DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
OWNER VARCHAR(255) NOT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_GEOFENCE TABLE--
-- DM_GEOFENCE_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
FENCE_ID INT NOT NULL,
GROUP_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_geofence_group_mapping_geofence FOREIGN KEY (FENCE_ID) REFERENCES
DM_GEOFENCE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_geofence_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES
DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- END OF DM_GEOFENCE_GROUP_MAPPING TABLE--
-- DM_DEVICE_EVENT TABLE --
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT
(
ID INT NOT NULL AUTO_INCREMENT,
EVENT_SOURCE VARCHAR(100) NOT NULL,
EVENT_LOGIC VARCHAR(100) NOT NULL,
ACTIONS TEXT DEFAULT NULL,
CREATED_TIMESTAMP TIMESTAMP NOT NULL,
TENANT_ID INTEGER DEFAULT 0,
PRIMARY KEY (ID)
);
-- END OF DM_DEVICE_EVENT TABLE --
-- DM_DEVICE_EVENT_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING
(
ID INT NOT NULL AUTO_INCREMENT,
EVENT_ID INT NOT NULL,
GROUP_ID INT NOT NULL,
PRIMARY KEY (ID),
CONSTRAINT fk_dm_event_group_mapping_event FOREIGN KEY (EVENT_ID) REFERENCES
DM_DEVICE_EVENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION,
CONSTRAINT fk_dm_event_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES
DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION
);
-- END OF DM_DEVICE_EVENT_GROUP_MAPPING TABLE--
CREATE TABLE IF NOT EXISTS DM_OPERATION (
ID INTEGER AUTO_INCREMENT NOT NULL,
TYPE VARCHAR(50) NOT NULL,

@ -81,21 +81,6 @@
<DisplayValue>label_actions</DisplayValue>
<Type>default</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>FIRMWARE_VERSION</DefinedValue>
<DisplayValue>label_firmware_version</DisplayValue>
<Type>deviceDetailsMap</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>FIRMWARE_APP_VERSION</DefinedValue>
<DisplayValue>label_app_version</DisplayValue>
<Type>deviceDetailsMap</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>FIRMWARE_SYSTEM_VERSION</DefinedValue>
<DisplayValue>label_firmware_system_version</DisplayValue>
<Type>deviceDetailsMap</Type>
</DeviceInfoItem>
<DeviceInfoItem>
<DefinedValue>batteryLevel</DefinedValue>
<DisplayValue>label_battery_leve</DisplayValue>

@ -2145,7 +2145,7 @@
<github.openfeign.version>9.3.1</github.openfeign.version>
<jsr311.version>1.1.1</jsr311.version>
<commons.logging.version>1.2</commons.logging.version>
<apache.http.client.version>4.5.6</apache.http.client.version>
<apache.http.client.version>4.5.13</apache.http.client.version>
<!-- apache http components core -->
<apache.http.core.version>4.4.10</apache.http.core.version>
<apache.http.mime.version>4.5.8</apache.http.mime.version>

Loading…
Cancel
Save