diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml index 82f30811ab1..c198c72364e 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core grafana-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -295,7 +295,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java index 6121f78ddd5..23128fc5278 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java +++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/GrafanaAPIProxyServiceImpl.java @@ -22,6 +22,7 @@ import com.google.gson.JsonObject; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.GrafanaAPIProxyService; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.bean.ErrorResponse; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.exception.RefererNotValid; +import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.impl.util.GrafanaMgtAPIUtils; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.impl.util.GrafanaRequestHandlerUtil; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common.exception.GrafanaManagementException; import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.bean.GrafanaPanelIdentifier; @@ -49,8 +50,8 @@ public class GrafanaAPIProxyServiceImpl implements GrafanaAPIProxyService { public Response queryDatasource(JsonObject body, @Context HttpHeaders headers, @Context UriInfo requestUriInfo) { try { GrafanaPanelIdentifier panelIdentifier = GrafanaRequestHandlerUtil.getPanelIdentifier(headers); - GrafanaMgtDataHolder.getInstance().getGrafanaQueryService(). - buildSafeQuery(body, panelIdentifier.getDashboardId(), panelIdentifier.getPanelId(), requestUriInfo.getRequestUri()); + GrafanaMgtAPIUtils.getGrafanaQueryService().buildSafeQuery(body, panelIdentifier.getDashboardId(), + panelIdentifier.getPanelId(), requestUriInfo.getRequestUri()); return GrafanaRequestHandlerUtil.proxyPassPostRequest(body, requestUriInfo, panelIdentifier.getOrgId()); } catch (MaliciousQueryAttempt e) { return Response.status(Response.Status.BAD_REQUEST).entity( diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaMgtAPIUtils.java b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaMgtAPIUtils.java new file mode 100644 index 00000000000..07a4293b49f --- /dev/null +++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api/src/main/java/io/entgra/device/mgt/core/analytics/mgt/grafana/proxy/api/impl/util/GrafanaMgtAPIUtils.java @@ -0,0 +1,52 @@ +/* + * 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.analytics.mgt.grafana.proxy.api.impl.util; + +import io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core.service.GrafanaQueryService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +public class GrafanaMgtAPIUtils { + + private static final Log log = LogFactory.getLog(GrafanaMgtAPIUtils.class); + private static volatile GrafanaQueryService grafanaQueryService; + + /** + * Accessing GrafanaQueryService from OSGI service context + * @return GrafanaQueryService instance + */ + public static GrafanaQueryService getGrafanaQueryService() { + if (grafanaQueryService == null) { + synchronized (GrafanaMgtAPIUtils.class) { + if (grafanaQueryService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + grafanaQueryService = + (GrafanaQueryService) ctx.getOSGiService(GrafanaQueryService.class, null); + if (grafanaQueryService == null) { + String msg = "Grafana Query service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + } + } + return grafanaQueryService; + } +} diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml index a05f1959a3b..3cbdb071e59 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core grafana-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml index 2e2888b88ae..fcf8b4bf98b 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core grafana-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -211,7 +211,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 org.wso2.carbon diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index 0b495a83a89..110c64f5533 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core analytics-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index abf63392136..6482bc57daa 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml index e647b5f2dc5..d2e2ca34c7f 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml @@ -20,7 +20,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml index 1732b475853..5dc407ca23a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml index 37082c6fc63..022d3a8a51b 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml index 7434c58e547..f62fd9c2ee7 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -143,6 +143,14 @@ org.wso2.carbon.apimgt.impl;version="[9.28,10)", org.wso2.carbon.apimgt.impl.utils;version="[9.28,10)", org.wso2.carbon.context;version="[4.8,5)", + org.wso2.carbon.apimgt.impl;version="${carbon.api.mgt.version.range}", + org.wso2.carbon.apimgt.impl.utils;version="${carbon.api.mgt.version.range}", + org.wso2.carbon.context;version="${carbon.kernel.version.range}", + io.entgra.device.mgt.core.identity.jwt.client.extension, + io.entgra.device.mgt.core.identity.jwt.client.extension.dto, + io.entgra.device.mgt.core.identity.jwt.client.extension.exception, + io.entgra.device.mgt.core.identity.jwt.client.extension.service, + io.entgra.device.mgt.core.apimgt.extension.rest.api, org.wso2.carbon.registry.core.exceptions;version="[1.0,2)", org.wso2.carbon.registry.core.service;version="[1.0,2)", org.wso2.carbon.registry.indexing.service;version="[4.8,5)", diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java index 0808f11963e..b4a1f11e140 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/APIManagementProviderServiceImpl.java @@ -41,16 +41,19 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.App import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.ApiApplicationInfo; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.RegistrationProfile; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.eclipse.jetty.http.MetaData; import org.wso2.carbon.apimgt.api.APIAdmin; import org.wso2.carbon.apimgt.api.APIConsumer; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.dto.KeyManagerConfigurationDTO; +import org.wso2.carbon.apimgt.api.model.*; import org.wso2.carbon.apimgt.api.model.API; import org.wso2.carbon.apimgt.api.model.APIKey; import org.wso2.carbon.apimgt.api.model.ApiTypeWrapper; @@ -119,6 +122,108 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe return generateAndRetrieveApplicationKeys(applicationName, tags ,keyType, isAllowedAllDomains, validityTime, tokenInfo); } + @Override + public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String tags[], + String keyType, String username, + boolean isAllowedAllDomains, + String validityTime, String password) throws APIManagerException { + + APIApplicationServices apiApplicationServices = APIApplicationManagerExtensionDataHolder.getInstance().getApiApplicationServices(); + + ConsumerRESTAPIServices consumerRESTAPIServices = + APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices(); + + try { + io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application[] applications = + consumerRESTAPIServices.getAllApplications(null, null, applicationName); + + List uniqueApiList = new ArrayList<>(); + + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(true); + + for (String tag : tags) { + Map queryParams = new HashMap<>(); + queryParams.put("tag", tag); + if ("carbon.super".equals(tenantDomain)) { + consumerRESTAPIServices.getAllApis(null, null, queryParams); + } else { + //call All API getting call with carbon super header param + APIInfo[] apiInfos; + if (!"carbon.super".equals(tenantDomain)) { + headerParams.put("X-WSO2-Tenant", "carbon.super"); + } + apiInfos = consumerRESTAPIServices.getAllApis(null, null, queryParams, headerParams); + + uniqueApiList.addAll(List.of(apiInfos)); + Set taggedAPISet = new HashSet<>(uniqueApiList); + uniqueApiList.clear(); + uniqueApiList.addAll(taggedAPISet); + } + + if (applications.length == 0) { + io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application application = + new io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application(); + + application.setName(applicationName); + application = consumerRESTAPIServices.createApplication(null, null, application); + List subscriptions = new ArrayList<>(); + for (APIInfo apiInfo : uniqueApiList) { + Subscription subscription = new Subscription(); + subscription.setApiId(apiInfo.getId()); + subscription.setApplicationId(application.getApplicationId()); + subscriptions.add(subscription); + } + consumerRESTAPIServices.createSubscriptions(null, null, subscriptions); + } else { + if (applications.length == 1) { + Optional application = + Arrays.stream(applications).findFirst(); + Subscription[] subscriptions = consumerRESTAPIServices.getAllSubscriptions(null, null, + application.get().getApplicationId()); + for (Subscription subscription : subscriptions) { + if (uniqueApiList.contains(subscription.getApiInfo())) { + uniqueApiList.remove(subscription.getApiInfo()); + } else { + uniqueApiList.add(subscription.getApiInfo()); + } + } + + + //duplicate code block + List subscriptionList = new ArrayList<>(); + for (APIInfo apiInfo : uniqueApiList) { + Subscription subscription = new Subscription(); + subscription.setApiId(apiInfo.getId()); + subscription.setApplicationId(application.get().getApplicationId()); + subscriptionList.add(subscription); + } + consumerRESTAPIServices.createSubscriptions(null, null, subscriptionList); + } else { + String msg = "Found more than one application for application name: " + applicationName; + log.error(msg); + throw new APIManagerException(msg); + } + + } + + + } catch (APIServicesException e) { + e.printStackTrace(); + } catch (BadRequestException e) { + e.printStackTrace(); + } catch (UnexpectedResponseException e) { + e.printStackTrace(); + } + + return null; + + + } + + + /** + * {@inheritDoc} + */ @Override public synchronized ApiApplicationKey generateAndRetrieveApplicationKeys(String applicationName, String[] tags, String keyType, String username, @@ -139,9 +244,11 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe boolean isAllowedAllDomains, String validityTime, TokenInfo tokenInfo) throws APIManagerException { + ConsumerRESTAPIServices consumerRESTAPIServices = APIApplicationManagerExtensionDataHolder.getInstance().getConsumerRESTAPIServices(); + ApiApplicationInfo applicationInfo = getApplicationInfo(username, password); try { List uniqueApiList = new ArrayList<>(); @@ -208,6 +315,50 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe throw new APIManagerException(msg); } } + + MetadataManagementService metadataManagementService = APIApplicationManagerExtensionDataHolder.getInstance().getMetadataManagementService(); + if (isNewApplication) { + ApplicationKey applicationKey = consumerRESTAPIServices.generateApplicationKeys(applicationInfo, application); + ApiApplicationKey apiApplicationKey = new ApiApplicationKey(); + apiApplicationKey.setConsumerKey(applicationKey.getConsumerKey()); + apiApplicationKey.setConsumerSecret(applicationKey.getConsumerSecret()); + + Metadata metaData = new Metadata(); + metaData.setMetaKey(applicationName); + String metaValue = application.getApplicationId() + ":" + applicationKey.getKeyMappingId(); + metaData.setMetaValue(metaValue); + try { + metadataManagementService.createMetadata(metaData); + return apiApplicationKey; + } catch (MetadataManagementException e) { + String msg = "Error occurred while creating the meta data entry for mata key: " + applicationName; + log.error(msg, e); + throw new APIManagerException(msg, e); + } catch (MetadataKeyAlreadyExistsException e) { + String msg = "Found duplicate meta value entry for meta key: " + applicationName; + log.error(msg, e); + throw new APIManagerException(msg, e); + } + } else { + try { + Metadata metaData = metadataManagementService.retrieveMetadata(applicationName); + if (metaData == null) { + String msg = + "Couldn't find application key data from meta data mgt service. Meta key: " + applicationName; + log.error(msg); + throw new APIManagerException(msg); + } + String[] metaValues = metaData.getMetaValue().split(":"); + String applicationId = metaValues[0]; + String keyMappingId = metaValues[1]; + //todo call the API key retrieving call, return apiApplicationKey; + } catch (MetadataManagementException e) { + String msg = "Error occurred while getting meta data for meta key: " + applicationName; + log.error(msg, e); + throw new APIManagerException(msg, e); + } + return null; + } } catch (APIServicesException e) { String msg = "Error occurred while processing the response of APIM REST endpoints."; log.error(msg, e); @@ -649,9 +800,14 @@ public class APIManagementProviderServiceImpl implements APIManagementProviderSe io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo accessTokenInfo; try { if (username == null || password == null) { - apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); + apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials( + "ClientForConsumerRestCalls", + "client_credentials password refresh_token urn:ietf:params:oauth:grant-type:jwt-bearer"); } else { - apiApplicationKey = apiApplicationServices.generateAndRetrieveApplicationKeys(username, password); + apiApplicationKey = apiApplicationServices.generateAndRetrieveApplicationKeys( + "ClientForConsumerRestCalls", + username, password, + "client_credentials password refresh_token urn:ietf:params:oauth:grant-type:jwt-bearer"); } accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java index d6a3bb2fc57..978a46c13af 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionDataHolder.java @@ -41,7 +41,6 @@ public class APIApplicationManagerExtensionDataHolder { private ConsumerRESTAPIServices consumerRESTAPIServices; private APIApplicationServices apiApplicationServices; private MetadataManagementService metadataManagementService; - private APIApplicationManagerExtensionDataHolder() { } @@ -68,17 +67,18 @@ public class APIApplicationManagerExtensionDataHolder { public void setRealmService(RealmService realmService) { this.realmService = realmService; - this.setTenantManager(realmService); + setTenantManager(realmService != null ? + realmService.getTenantManager() : null); } - private void setTenantManager(RealmService realmService) { - if (realmService == null) { - throw new IllegalStateException("Realm service is not initialized properly"); - } - this.tenantManager = realmService.getTenantManager(); + private void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; } public TenantManager getTenantManager() { + if (tenantManager == null) { + throw new IllegalStateException("Tenant manager is not initialized properly"); + } return tenantManager; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java index b3dc6dbd9df..ffb576295d6 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension/src/main/java/io/entgra/device/mgt/core/apimgt/application/extension/internal/APIApplicationManagerExtensionServiceComponent.java @@ -34,6 +34,40 @@ import org.wso2.carbon.user.core.service.RealmService; @Component( name = "io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionServiceComponent", immediate = true) +/** + * @scr.component name="io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionServiceComponent" + * @scr.reference name="tenant.registryloader" + * interface="org.wso2.carbon.registry.core.service.TenantRegistryLoader" + * cardinality="1..1" + * policy="dynamic" + * bind="setTenantRegistryLoader" + * unbind="unsetTenantRegistryLoader" + * @scr.reference name="tenant.indexloader" + * interface="org.wso2.carbon.registry.indexing.service.TenantIndexingLoader" + * cardinality="1..1" + * policy="dynamic" + * bind="setIndexLoader" + * unbind="unsetIndexLoader" + * @scr.reference name="realm.service" + * immediate="true" + * interface="org.wso2.carbon.user.core.service.RealmService" + * cardinality="1..1" + * policy="dynamic" + * bind="setRealmService" + * unbind="unsetRealmService" + * @scr.reference name="apimgt.extension.ConsumerRESTAPIServices" + * interface="io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices" + * cardinality="0..1" + * policy="dynamic" + * bind="setConsumerRESTAPIServices" + * unbind="unsetConsumerRESTAPIServices" + * @scr.reference name="apimgt.extension.APIApplicationService" + * interface="io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices" + * cardinality="0..1" + * policy="dynamic" + * bind="setAPIApplicationServices" + * unbind="unsetAPIApplicationServices" + */ public class APIApplicationManagerExtensionServiceComponent { private static final Log log = LogFactory.getLog(APIApplicationManagerExtensionServiceComponent.class); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 7d4ef0501dc..45c9ab231fe 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java index 1cdceff56a4..f5cc8b3ec12 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java @@ -24,9 +24,10 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIService public interface APIApplicationServices { - APIApplicationKey createAndRetrieveApplicationCredentials() throws APIServicesException; + APIApplicationKey createAndRetrieveApplicationCredentials(String clientName, String grantType) + throws APIServicesException; - APIApplicationKey generateAndRetrieveApplicationKeys(String username, String password) + APIApplicationKey generateAndRetrieveApplicationKeys(String clientName, String username, String password, String grantType) throws APIServicesException; AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIServicesException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 9dbd5f52cce..a03f81d0860 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -44,7 +44,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { getAPIManagerConfigurationService().getAPIManagerConfiguration(); @Override - public APIApplicationKey createAndRetrieveApplicationCredentials() + public APIApplicationKey createAndRetrieveApplicationCredentials(String clientName, String grantType) throws APIServicesException { String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT); @@ -53,8 +53,8 @@ public class APIApplicationServicesImpl implements APIApplicationServices { JSONObject jsonObject = new JSONObject(); jsonObject.put("callbackUrl", Constants.EMPTY_STRING); - jsonObject.put("clientName", Constants.CLIENT_NAME); - jsonObject.put("grantType", Constants.GRANT_TYPE); + jsonObject.put("clientName", clientName); + jsonObject.put("grantType", grantType); jsonObject.put("owner", serverUser); jsonObject.put("saasApp", true); @@ -75,15 +75,15 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } @Override - public APIApplicationKey generateAndRetrieveApplicationKeys(String username, String password) + public APIApplicationKey generateAndRetrieveApplicationKeys(String clientName, String username, String password, String grantType) throws APIServicesException { String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT); JSONObject jsonObject = new JSONObject(); jsonObject.put("callbackUrl", Constants.EMPTY_STRING); - jsonObject.put("clientName", username); - jsonObject.put("grantType", Constants.GRANT_TYPE); + jsonObject.put("clientName", clientName); + jsonObject.put("grantType", grantType); jsonObject.put("owner", username); jsonObject.put("saasApp", true); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServices.java index 5ed98034e2b..7fddca04f26 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServices.java @@ -23,6 +23,8 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.TokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription; import java.util.List; import java.util.Map; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServicesImpl.java index 293894ee711..a85c611f997 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/ConsumerRESTAPIServicesImpl.java @@ -24,6 +24,10 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.ApiApplicationInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.TokenInfo; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.APIKey; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Application; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer.Subscription; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/APIMConsumer/Subscription.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/APIMConsumer/Subscription.java index 2ff525f5dc8..11fc881c1b9 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/APIMConsumer/Subscription.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/APIMConsumer/Subscription.java @@ -18,8 +18,6 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean.APIMConsumer; -import org.json.JSONObject; - public class Subscription { private String subscriptionId; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java index 6c3cf21c895..6ca26f74f03 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java @@ -27,10 +27,8 @@ public final class Constants { public static final String AMPERSAND = "&"; public static final String SLASH = "/"; public static final String EQUAL = "="; - public static final String CLIENT_NAME = "rest_api_publisher_code"; public static final String SERVER_USER = "WorkflowConfigurations.ServerUser"; public static final String SERVER_PASSWORD = "WorkflowConfigurations.ServerPassword"; - public static final String GRANT_TYPE = "client_credentials password refresh_token"; public static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token"; public static final String OAUTH_EXPIRES_IN = "expires_in"; public static final String OAUTH_TOKEN_SCOPE = "scope"; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml index 2392078c2ec..82957d2b0d0 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml index 53374f48c64..201515986fa 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/src/main/java/io/entgra/device/mgt/core/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/src/main/java/io/entgra/device/mgt/core/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java index 69f51fff56d..63e42132f01 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/src/main/java/io/entgra/device/mgt/core/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension/src/main/java/io/entgra/device/mgt/core/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java @@ -344,7 +344,7 @@ public class KeyMgtServiceImpl implements KeyMgtService { Response response = client.newCall(request).execute(); return gson.fromJson(response.body().string(), OAuthApplication.class); } catch (IOException e) { - msg = "Error occurred while processing the response"; + msg = "Error occurred while processing the response" + e; throw new KeyMgtException(msg); } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml index c0c72a2f658..7e3ef60c38c 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -41,7 +41,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java index fe98a8cef87..e188ae799b4 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -90,7 +90,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { APIApplicationKey apiApplicationKey; AccessTokenInfo accessTokenInfo; try { - apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); + apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials( + "ClientForPublisherRestCalls", + "client_credentials password refresh_token" + ); accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); } catch (APIServicesException e) { @@ -403,7 +406,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { APIApplicationKey apiApplicationKey; AccessTokenInfo accessTokenInfo; try { - apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); + apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials( + "ClientForPublisherRestCalls", + "client_credentials password refresh_token" + ); accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); } catch (APIServicesException e) { diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java index baff1848ed9..bc7b8af32cc 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher/src/main/java/io/entgra/device/mgt/core/apimgt/webapp/publisher/internal/APIPublisherDataHolder.java @@ -75,17 +75,18 @@ public class APIPublisherDataHolder { public void setRealmService(RealmService realmService) { this.realmService = realmService; - this.setTenantManager(realmService); + setTenantManager(realmService != null ? + realmService.getTenantManager() : null); } - private void setTenantManager(RealmService realmService) { - if (realmService == null) { - throw new IllegalStateException("Realm service is not initialized properly"); - } - this.tenantManager = realmService.getTenantManager(); + private void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; } public TenantManager getTenantManager() { + if (tenantManager == null) { + throw new IllegalStateException("Tenant manager is not initialized properly"); + } return tenantManager; } diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index bee1ec27449..20945103345 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml index c9eafdb8003..6a8a2386230 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core application-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java index f7655b566b5..f0e2d040ffa 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.common/src/main/java/io/entgra/device/mgt/core/application/mgt/common/services/ApplicationManager.java @@ -29,6 +29,11 @@ import io.entgra.device.mgt.core.application.mgt.common.response.Category; import io.entgra.device.mgt.core.application.mgt.common.response.Tag; import io.entgra.device.mgt.core.application.mgt.common.wrapper.*; import io.entgra.device.mgt.core.device.mgt.common.Base64File; +<<<<<<< HEAD +======= +import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +>>>>>>> 3616245ae6 (Improve app visibility restricting functionality) import org.apache.cxf.jaxrs.ext.multipart.Attachment; import java.util.List; diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml index 9c3ab8ff851..fde1c890874 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core application-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -153,6 +153,10 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + src/test/resources/testng.xml @@ -160,6 +164,9 @@ ${basedir}/target/coverage-reports/jacoco-unit.exec file:src/test/resources/log4j.properties + + org.ops4j.pax.logging + @@ -404,6 +411,10 @@ org.wso2.carbon.ntask.core provided + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.notification.logger + diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java index 9a50d0d00a6..6b4d590fa8f 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/ApplicationManagerImpl.java @@ -19,6 +19,16 @@ package io.entgra.device.mgt.core.application.mgt.core.impl; import io.entgra.device.mgt.core.application.mgt.common.*; +import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; +import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata; +import org.json.JSONObject; +import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact; +import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstaller; +import io.entgra.device.mgt.core.application.mgt.common.DeviceTypes; +import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger; +import io.entgra.device.mgt.core.application.mgt.common.Pagination; import io.entgra.device.mgt.core.application.mgt.common.config.RatingConfiguration; import io.entgra.device.mgt.core.application.mgt.common.dto.*; import io.entgra.device.mgt.core.application.mgt.common.exception.*; @@ -57,6 +67,7 @@ import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; +import javax.ws.rs.core.Response; import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; @@ -1239,13 +1250,13 @@ public class ApplicationManagerImpl implements ApplicationManager { this.changeLifecycleState(applicationReleaseDTO, lifecycleChanger); } } + if (Constants.ENTERPRISE_APP_TYPE.equals(applicationDTO.getType()) || Constants.PUBLIC_APP_TYPE.equals(applicationDTO.getType())) { + persistAppIconInfo(applicationReleaseDTO); + } applicationReleaseEntities.add(applicationReleaseDTO); } applicationDTO.setId(appId); applicationDTO.setApplicationReleaseDTOs(applicationReleaseEntities); - if (applicationDTO.getType().equals("ENTERPRISE") || applicationDTO.getType().equals("PUBLIC") ) { - persistAppIconInfo(applicationReleaseDTO); - } return APIUtil.appDtoToAppResponse(applicationDTO); } } catch (LifeCycleManagementDAOException e) { @@ -1669,6 +1680,31 @@ public class ApplicationManagerImpl implements ApplicationManager { } } + /** + * Check whether valid metaData value or not + * + * @return true or false + * @throws MetadataManagementException If it is unable to load metaData + */ + private boolean isUserAbleToViewAllRoles() throws MetadataManagementException { + List allMetadata; + allMetadata = APIUtil.getMetadataManagementService().retrieveAllMetadata(); + if (allMetadata != null && !allMetadata.isEmpty()) { + for (Metadata metadata : allMetadata) { + if (Constants.SHOW_ALL_ROLES.equals(metadata.getMetaKey())) { + String metaValue = metadata.getMetaValue(); + if (metaValue != null) { + JSONObject jsonObject; + jsonObject = new JSONObject(metaValue); + boolean isUserAbleToViewAllRoles = jsonObject.getBoolean(Constants.IS_USER_ABLE_TO_VIEW_ALL_ROLES); + return isUserAbleToViewAllRoles; + } + } + } + } + return false; + } + /** * Get assigned role list of the given user. * @@ -3442,7 +3478,8 @@ public class ApplicationManagerImpl implements ApplicationManager { } @Override - public void validateAppCreatingRequest(T param) throws ApplicationManagementException, RequestValidatingException { + public void validateAppCreatingRequest(T param) + throws ApplicationManagementException, RequestValidatingException { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true); String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); int deviceTypeId = -1; @@ -3614,12 +3651,14 @@ public class ApplicationManagerImpl implements ApplicationManager { log.error(msg); throw new ApplicationManagementException(msg); } - if (!hasUserRole(unrestrictedRoles, userName)) { - String msg = "You are trying to restrict the visibility of the application for a role set, but " - + "in order to perform the action at least one role should be assigned to user: " - + userName; - log.error(msg); - throw new BadRequestException(msg); + if (!isUserAbleToViewAllRoles()) { + if (!hasUserRole(unrestrictedRoles, userName)) { + String msg = "You are trying to restrict the visibility of the application for a role set, but " + + "in order to perform the action at least one role should be assigned to user: " + + userName; + log.error(msg); + throw new BadRequestException(msg); + } } } @@ -3672,6 +3711,10 @@ public class ApplicationManagerImpl implements ApplicationManager { String msg = "Error occurred when validating the unrestricted roles given for the web clip"; log.error(msg, e); throw new ApplicationManagementException(msg, e); + } catch (MetadataManagementException e) { + String msg = "Error occurred while retrieving metadata list"; + log.error(msg, e); + throw new ApplicationManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java index cae569bbd3b..e4bfe93d46f 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/impl/SubscriptionManagerImpl.java @@ -19,6 +19,10 @@ package io.entgra.device.mgt.core.application.mgt.core.impl; import com.google.gson.Gson; +import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException; +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 io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey; import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException; import io.entgra.device.mgt.core.application.mgt.common.*; @@ -87,8 +91,8 @@ import java.util.stream.Collectors; * This is the default implementation for the Subscription Manager. */ public class SubscriptionManagerImpl implements SubscriptionManager { - - private static final Log log = LogFactory.getLog(SubscriptionManagerImpl.class); + AppInstallLogContext.Builder appInstallLogContextBuilder = new AppInstallLogContext.Builder(); + private static final EntgraLogger log = new EntgraAppInstallLoggerImpl(SubscriptionManagerImpl.class); private SubscriptionDAO subscriptionDAO; private ApplicationDAO applicationDAO; private LifecycleStateManager lifecycleStateManager; @@ -620,7 +624,9 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Properties properties, boolean isOperationReExecutingDisabled) throws ApplicationManagementException { - + String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); //Get app subscribing info of each device SubscribingDeviceIdHolder subscribingDeviceIdHolder = getSubscribingDeviceIdHolder(devices, applicationDTO.getApplicationReleaseDTOs().get(0).getId()); @@ -670,10 +676,36 @@ public class SubscriptionManagerImpl implements SubscriptionManager { Activity activity = addAppOperationOnDevices(applicationDTO, new ArrayList<>(entry.getValue()), entry.getKey(), action, properties); activityList.add(activity); + for (DeviceIdentifier identifier : deviceIdentifiers) { + log.info(String.format("Web app %s triggered", action), appInstallLogContextBuilder + .setAppId(String.valueOf(applicationDTO.getId())) + .setAppName(applicationDTO.getName()) + .setAppType(applicationDTO.getType()) + .setSubType(subType) + .setTenantId(tenantId) + .setTenantDomain(tenantDomain) + .setDevice(String.valueOf(identifier)) + .setUserName(username) + .setAction(action) + .build()); + } } } else { Activity activity = addAppOperationOnDevices(applicationDTO, deviceIdentifiers, deviceType, action, properties); activityList.add(activity); + for (DeviceIdentifier identifier : deviceIdentifiers) { + log.info(String.format("App %s triggered", action), appInstallLogContextBuilder + .setAppId(String.valueOf(applicationDTO.getId())) + .setAppName(applicationDTO.getName()) + .setAppType(applicationDTO.getType()) + .setSubType(subType) + .setTenantId(tenantId) + .setTenantDomain(tenantDomain) + .setDevice(String.valueOf(identifier)) + .setUserName(username) + .setAction(action) + .build()); + } } ApplicationInstallResponse applicationInstallResponse = new ApplicationInstallResponse(); diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java index 4b78b9e1c2a..8c3ccbc8bfe 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/APIUtil.java @@ -40,6 +40,7 @@ import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder; import io.entgra.device.mgt.core.application.mgt.core.serviceprovider.ISServiceProviderApplicationService; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -64,6 +65,7 @@ public class APIUtil { private static volatile SubscriptionManager subscriptionManager; private static volatile ReviewManager reviewManager; private static volatile AppmDataHandler appmDataHandler; + private static volatile MetadataManagementService metadataManagementService; public static SPApplicationManager getSPApplicationManager() { if (SPApplicationManager == null) { @@ -514,7 +516,22 @@ public class APIUtil { public static String createAppIconPath(ApplicationReleaseDTO applicationReleaseDTO, int tenantId) throws ApplicationManagementException { String basePath = getArtifactDownloadBaseURL() + tenantId + Constants.FORWARD_SLASH + applicationReleaseDTO .getAppHashValue() + Constants.FORWARD_SLASH; - String iconPath = basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName(); - return iconPath; + return basePath + Constants.ICON_ARTIFACT + Constants.FORWARD_SLASH + applicationReleaseDTO.getIconName(); + } + + public static MetadataManagementService getMetadataManagementService() { + if (metadataManagementService == null) { + synchronized (APIUtil.class) { + if (metadataManagementService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + metadataManagementService = (MetadataManagementService) ctx.getOSGiService( + MetadataManagementService.class, null); + if (metadataManagementService == null) { + throw new IllegalStateException("Metadata Management service not initialized."); + } + } + } + } + return metadataManagementService; } } diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java index 5864242acf3..c3e7c491606 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/main/java/io/entgra/device/mgt/core/application/mgt/core/util/Constants.java @@ -70,7 +70,8 @@ public class Constants { public static final String ANY = "ANY"; public static final String DEFAULT_PCK_NAME = "default.app.com"; public static final String ALL = "ALL"; - + public static final String SHOW_ALL_ROLES = "SHOW_ALL_ROLES"; + public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles"; public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id="; public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id"; @@ -93,6 +94,9 @@ public class Constants { public static final String MSI = "MSI"; public static final String APPX = "APPX"; + public static final String ENTERPRISE_APP_TYPE = "ENTERPRISE"; + public static final String PUBLIC_APP_TYPE = "ENTERPRISE"; + private static final Map AGENT_DATA = new HashMap<>(); static { AGENT_DATA.put("android", "android-agent.apk"); diff --git a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml index fc32a2698d0..96fd6acfff1 100644 --- a/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml +++ b/components/application-mgt/io.entgra.device.mgt.core.application.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml @@ -27,7 +27,7 @@ everyone false 500 - jdbc:h2:target/databasetest/CARBON_TEST + jdbc:h2:./target/databasetest/CARBON_TEST org.h2.Driver 50 60000 diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 512aef9700c..2e2e67a22fc 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml index 82a035ace67..b67ccf20ef5 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml index 0691f0648c3..3a7526f4085 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml index d23f1863cd6..d24319a34f7 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core certificate-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -111,6 +111,10 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + src/test/resources/testng.xml @@ -118,6 +122,9 @@ ${basedir}/target/coverage-reports/jacoco-unit.exec file:src/test/resources/log4j.properties + + org.ops4j.pax.logging + @@ -175,7 +182,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/bean/Certificate.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/bean/Certificate.java index e3e55c330f2..acf63daa07a 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/bean/Certificate.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/bean/Certificate.java @@ -25,6 +25,15 @@ public class Certificate { X509Certificate certificate; int tenantId; String tenantDomain; + String deviceIdentifier; + + public String getDeviceIdentifier() { + return deviceIdentifier; + } + + public void setDeviceIdentifier(String deviceIdentifier) { + this.deviceIdentifier = deviceIdentifier; + } public int getTenantId() { return tenantId; diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/CertificateDAO.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/CertificateDAO.java index de3be1856a9..779251761e0 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/CertificateDAO.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/CertificateDAO.java @@ -41,6 +41,17 @@ public interface CertificateDAO { void addCertificate(List certificate) throws CertificateManagementDAOException; + /** + * This can be used to store a certificate in the database, where it will be stored against the serial number + * of the certificate. + * + * @param certificate Holds the certificate and relevant details. + * @throws CertificateManagementDAOException + * + */ + void addCertificate(Certificate certificate) + throws CertificateManagementDAOException; + /** * Usage is to obtain a certificate stored in the database by providing the common name. * @@ -51,6 +62,16 @@ public interface CertificateDAO { */ CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementDAOException; + /** + * Obtain a certificated stored in the database by providing the common name and the tenant ID + * + * @param serialNumber Serial number (Common name) of the certificate + * @param tenantId ID of the certificate owning tenant + * @return representation of the certificate. + * @throws CertificateManagementDAOException if fails to read the certificate from the database + */ + CertificateResponse retrieveCertificate(String serialNumber, int tenantId) throws CertificateManagementDAOException; + /** * Get all the certificates in a paginated manner. * diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/AbstractCertificateDAOImpl.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/AbstractCertificateDAOImpl.java index 45a7e7c56f2..0a8e9e3066d 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/AbstractCertificateDAOImpl.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/dao/impl/AbstractCertificateDAOImpl.java @@ -81,6 +81,40 @@ public abstract class AbstractCertificateDAOImpl implements CertificateDAO{ } } + @Override + public void addCertificate(Certificate certificate) + throws CertificateManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + try { + conn = this.getConnection(); + stmt = conn.prepareStatement( + "INSERT INTO DM_DEVICE_CERTIFICATE (SERIAL_NUMBER, CERTIFICATE, TENANT_ID," + + " USERNAME, DEVICE_IDENTIFIER) VALUES (?,?,?,?,?)"); + PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext. + getThreadLocalCarbonContext(); + String username = threadLocalCarbonContext.getUsername(); + // the serial number of the certificate used for its creation is set as its alias. + String serialNumber = certificate.getSerial(); + if (serialNumber == null || serialNumber.isEmpty()) { + serialNumber = String.valueOf(certificate.getCertificate().getSerialNumber()); + } + byte[] bytes = Serializer.serialize(certificate.getCertificate()); + + stmt.setString(1, serialNumber); + stmt.setBytes(2, bytes); + stmt.setInt(3, certificate.getTenantId()); + stmt.setString(4, username); + stmt.setString(5, certificate.getDeviceIdentifier()); + stmt.executeUpdate(); + } catch (SQLException | IOException e) { + throw new CertificateManagementDAOException("Error occurred while saving the " + + "certificate. ", e); + } finally { + CertificateManagementDAOUtil.cleanupResources(stmt, null); + } + } + @Override public CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementDAOException { @@ -119,6 +153,42 @@ public abstract class AbstractCertificateDAOImpl implements CertificateDAO{ return certificateResponse; } + @Override + public CertificateResponse retrieveCertificate(String serialNumber, int tenantId) throws CertificateManagementDAOException { + Connection conn; + PreparedStatement stmt = null; + ResultSet resultSet = null; + CertificateResponse certificateResponse = null; + try { + conn = this.getConnection(); + String query = + "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM" + + " DM_DEVICE_CERTIFICATE WHERE SERIAL_NUMBER = ? AND TENANT_ID = ? "; + stmt = conn.prepareStatement(query); + stmt.setString(1, serialNumber); + stmt.setInt(2, tenantId); + resultSet = stmt.executeQuery(); + + if (resultSet.next()) { + certificateResponse = new CertificateResponse(); + byte[] certificateBytes = resultSet.getBytes("CERTIFICATE"); + certificateResponse.setCertificate(certificateBytes); + certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER")); + certificateResponse.setTenantId(resultSet.getInt("TENANT_ID")); + certificateResponse.setUsername(resultSet.getString("USERNAME")); + CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse); + } + } catch (SQLException e) { + String errorMsg = + "Unable to get the read the certificate with serial" + serialNumber; + log.error(errorMsg, e); + throw new CertificateManagementDAOException(errorMsg, e); + } finally { + CertificateManagementDAOUtil.cleanupResources(stmt, resultSet); + } + return certificateResponse; + } + @Override public List searchCertificate(String serialNumber) throws CertificateManagementDAOException { diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java index bc98fae4a5c..b8109e74fcf 100755 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/CertificateGenerator.java @@ -55,10 +55,28 @@ import org.bouncycastle.operator.OperatorCreationException; import org.bouncycastle.operator.jcajce.JcaContentSignerBuilder; import org.bouncycastle.pkcs.PKCS10CertificationRequest; import org.bouncycastle.util.Store; -import org.jscep.message.*; +import org.jscep.message.CertRep; +import org.jscep.message.MessageDecodingException; +import org.jscep.message.MessageEncodingException; +import org.jscep.message.PkcsPkiEnvelopeDecoder; +import org.jscep.message.PkcsPkiEnvelopeEncoder; +import org.jscep.message.PkiMessage; +import org.jscep.message.PkiMessageDecoder; +import org.jscep.message.PkiMessageEncoder; import org.jscep.transaction.FailInfo; import org.jscep.transaction.Nonce; import org.jscep.transaction.TransactionId; +import org.wso2.carbon.certificate.mgt.core.dao.CertificateDAO; +import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOException; +import org.wso2.carbon.certificate.mgt.core.dao.CertificateManagementDAOFactory; +import org.wso2.carbon.certificate.mgt.core.dto.CAStatus; +import org.wso2.carbon.certificate.mgt.core.dto.CertificateResponse; +import org.wso2.carbon.certificate.mgt.core.dto.SCEPResponse; +import org.wso2.carbon.certificate.mgt.core.exception.KeystoreException; +import org.wso2.carbon.certificate.mgt.core.exception.TransactionManagementException; +import org.wso2.carbon.certificate.mgt.core.util.CertificateManagementConstants; +import org.wso2.carbon.certificate.mgt.core.util.CommonUtil; +import org.wso2.carbon.certificate.mgt.core.util.Serializer; import org.wso2.carbon.context.PrivilegedCarbonContext; import javax.naming.InvalidNameException; @@ -70,12 +88,34 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigInteger; -import java.security.*; +import java.security.InvalidKeyException; +import java.security.KeyFactory; +import java.security.KeyPair; +import java.security.KeyPairGenerator; +import java.security.NoSuchAlgorithmException; +import java.security.NoSuchProviderException; +import java.security.PrivateKey; +import java.security.PublicKey; +import java.security.SecureRandom; +import java.security.Security; +import java.security.SignatureException; import java.security.cert.Certificate; import java.security.cert.*; import java.security.spec.InvalidKeySpecException; import java.security.spec.X509EncodedKeySpec; import java.util.*; +import java.security.cert.CertificateEncodingException; +import java.security.cert.CertificateException; +import java.security.cert.CertificateExpiredException; +import java.security.cert.CertificateFactory; +import java.security.cert.CertificateNotYetValidException; +import java.security.cert.X509Certificate; +import java.security.spec.InvalidKeySpecException; +import java.security.spec.X509EncodedKeySpec; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Date; +import java.util.List; import java.util.concurrent.TimeUnit; public class CertificateGenerator { @@ -336,15 +376,31 @@ public class CertificateGenerator { CertificateResponse lookUpCertificate = null; KeyStoreReader keyStoreReader = new KeyStoreReader(); if (distinguishedName != null && !distinguishedName.isEmpty()) { - if (distinguishedName.contains("/CN=")) { - String[] dnSplits = distinguishedName.split("/"); - for (String dnPart : dnSplits) { - if (dnPart.contains("CN=")) { - String commonNameExtracted = dnPart.replace("CN=", ""); - lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted); - break; + if (distinguishedName.contains("CN=")) { + String[] dnSplits = null; + if (distinguishedName.contains("/")) { + dnSplits = distinguishedName.split("/"); + } else if (distinguishedName.contains(",")) { + //some older versions of nginx will forward the client certificate subject dn separated with commas + dnSplits = distinguishedName.split(","); + } + String commonNameExtracted = null; + int tenantId = 0; + if (dnSplits != null && dnSplits.length >= 1) { + for (String dnPart : dnSplits) { + if (dnPart.contains("CN=")) { + commonNameExtracted = dnPart.replace("CN=", ""); + } else if (dnPart.contains("OU=")) { + //the OU of the certificate will be like OU=tenant_ ex: OU=tenant_-1234 + //splitting by underscore to extract the tenant domain + String[] orgUnitSplits = dnPart.split("_"); + tenantId = Integer.parseInt(orgUnitSplits[1]); + } } } + + lookUpCertificate = keyStoreReader.getCertificateBySerial(commonNameExtracted, tenantId); + } else { LdapName ldapName; try { @@ -671,6 +727,29 @@ public class CertificateGenerator { throw new KeystoreException(errorMsg, e); } } + public void saveCertificate(org.wso2.carbon.certificate.mgt.core.bean.Certificate + certificate) throws KeystoreException { + + if (certificate == null) { + return; + } + + try { + CertificateDAO certificateDAO = CertificateManagementDAOFactory.getCertificateDAO(); + CertificateManagementDAOFactory.beginTransaction(); + certificateDAO.addCertificate(certificate); + CertificateManagementDAOFactory.commitTransaction(); + } catch (CertificateManagementDAOException e) { + String errorMsg = "Error occurred when saving the generated certificate in database"; + log.error(errorMsg); + CertificateManagementDAOFactory.rollbackTransaction(); + throw new KeystoreException(errorMsg, e); + } catch (TransactionManagementException e) { + String errorMsg = "Error occurred when saving the generated certificate in database"; + log.error(errorMsg); + throw new KeystoreException(errorMsg, e); + } + } public void saveCertInKeyStore(List certificate) throws KeystoreException { @@ -785,8 +864,9 @@ public class CertificateGenerator { X500Name issuerName = new X500Name(subjectDn); String commonName = certificationRequest.getSubject().getRDNs(BCStyle.CN)[0].getFirst() .getValue().toString(); - X500Name subjectName = new X500Name("O=" + commonName + "O=AndroidDevice,CN=" + - serialNumber); + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + X500Name subjectName = new X500Name("O=" + commonName + ",CN=" + + serialNumber + ", OU=tenant_"+tenantId); Date startDate = new Date(System.currentTimeMillis()); Date endDate = new Date(System.currentTimeMillis() + TimeUnit.DAYS.toMillis(365 * 100)); @@ -809,8 +889,8 @@ public class CertificateGenerator { List certificates = new ArrayList<>(); certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); certificate.setCertificate(issuedCert); - certificates.add(certificate); - saveCertInKeyStore(certificates); + certificate.setDeviceIdentifier(commonName); + saveCertificate(certificate); } catch (OperatorCreationException e) { String errorMsg = "Error creating the content signer"; diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/KeyStoreReader.java b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/KeyStoreReader.java index 56ec2bb6f5c..94cab378bff 100755 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/KeyStoreReader.java +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/main/java/io/entgra/device/mgt/core/certificate/mgt/core/impl/KeyStoreReader.java @@ -271,6 +271,43 @@ public class KeyStoreReader { return raPrivateKey; } + public CertificateResponse getCertificateBySerial(String serialNumber, int tenantId) throws KeystoreException { + CertificateResponse certificateResponse = null; + try { + CertificateCacheManager cacheManager = CertificateCacheManagerImpl.getInstance(); + certificateResponse = cacheManager.getCertificateBySerial(serialNumber); + if (certificateResponse == null) { + try { + CertificateManagementDAOFactory.openConnection(); + certificateResponse = certDao.retrieveCertificate(serialNumber, tenantId); + } catch (SQLException e) { + String errorMsg = "Error when making a connection to the database."; + throw new KeystoreException(errorMsg, e); + } finally { + CertificateManagementDAOFactory.closeConnection(); + } + if (certificateResponse != null && certificateResponse.getCertificate() != null) { + Certificate certificate = (Certificate) Serializer.deserialize(certificateResponse.getCertificate()); + if (certificate instanceof X509Certificate) { + X509Certificate x509cert = (X509Certificate) certificate; + String commonName = CertificateGenerator.getCommonName(x509cert); + certificateResponse.setCommonName(commonName); + cacheManager.addCertificateBySerial(serialNumber, certificateResponse); + } + } + } + } catch (CertificateManagementDAOException e) { + String errorMsg = "Error when retrieving certificate from the the database for the serial number: " + + serialNumber; + throw new KeystoreException(errorMsg, e); + + } catch (ClassNotFoundException | IOException e) { + String errorMsg = "Error when de-serializing saved certificate."; + throw new KeystoreException(errorMsg, e); + } + return certificateResponse; + } + public CertificateResponse getCertificateBySerial(String serialNumber) throws KeystoreException { CertificateResponse certificateResponse = null; try { diff --git a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/test/resources/data-source-config.xml b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/test/resources/data-source-config.xml index 27b6dfeaeb8..533fd829598 100644 --- a/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/test/resources/data-source-config.xml +++ b/components/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.core/src/test/resources/data-source-config.xml @@ -18,7 +18,7 @@ --> - jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + jdbc:h2:mem:cdm-test-db;DB_CLOSE_ON_EXIT=FALSE org.h2.Driver wso2carbon wso2carbon diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 98c20d369b1..7833296e8a4 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml index 38ba36543d4..d8a79858c65 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -106,13 +106,19 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + - file:src/test/resources/carbon-home/repository/conf/log4j.properties - + file:src/test/resources/log4j.properties src/test/resources/testng.xml + + org.ops4j.pax.logging + @@ -207,5 +213,15 @@ org.wso2.orbit.javax.xml.bind jaxb-api + + com.sun.xml.bind + jaxb-core + test + + + com.sun.xml.bind + jaxb-impl + test + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml index 8b1dc93e222..610f4f6cda7 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -104,6 +104,21 @@ io.entgra.device.mgt.core.device.mgt.core test + + org.mockito + mockito-core + test + + + com.sun.xml.bind + jaxb-core + test + + + com.sun.xml.bind + jaxb-impl + test + @@ -157,6 +172,25 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + org.ops4j.pax.logging + + + org.jacoco jacoco-maven-plugin diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml index f984260692b..da2c4590695 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger/pom.xml @@ -21,7 +21,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml index a50c455f80e..f238d4d5d4a 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml index c357cd7566a..1608581ec79 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml index 17a7c4b6ff8..c2899b36e36 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index ed434c7873a..aeaed8655c9 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -122,6 +122,16 @@ powermock-module-testng test + + org.wso2.carbon + org.wso2.carbon.securevault + test + + + org.mockito + mockito-core + test + @@ -189,6 +199,25 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + + + file:src/test/resources/log4j.properties + + + src/test/resources/testng.xml + + + org.ops4j.pax.logging + + + diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/src/test/resources/conf/carbon.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/src/test/resources/conf/carbon.xml deleted file mode 100644 index a5518cb720e..00000000000 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/src/test/resources/conf/carbon.xml +++ /dev/null @@ -1,658 +0,0 @@ - - - - - - - - - ${product.name} - - - ${product.key} - - - ${product.version} - - - - - - - - - local:/${carbon.context}/services/ - - - - - - - ${default.server.role} - - - - - - - org.wso2.carbon - - - / - - - - - - - - - 15 - - - - - - - - - 0 - - - - - 9999 - - 11111 - - - - - - 10389 - - 8000 - - - - - - 10500 - - - - - - - org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory - - - - - - - - - java - - - - - - - - - - false - - - false - - - 600 - - - - false - - - - - - - - 30 - - - - - - - - - 15 - - - - - - ${carbon.home}/repository/deployment/server/ - - - 15 - - - ${carbon.home}/repository/conf/axis2/axis2.xml - - - 30000 - - - ${carbon.home}/repository/deployment/client/ - - ${carbon.home}/repository/conf/axis2/axis2_client.xml - - true - - - - - - - - - - admin - Default Administrator Role - - - user - Default User Role - - - - - - - - - - - - ${carbon.home}/repository/resources/security/wso2carbon.jks - - JKS - - wso2carbon - - wso2carbon - - wso2carbon - - - - - - ${carbon.home}/repository/resources/security/client-truststore.jks - - JKS - - wso2carbon - - - - - - - - - - - - - - - - - - - UserManager - - - false - - - - - - - ${carbon.home}/tmp/work - - - - - - true - - - 10 - - - 30 - - - - - - 100 - - - - keystore - certificate - * - - org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor - - - - - jarZip - - org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor - - - - dbs - - org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor - - - - tools - - org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor - - - - toolsAny - - org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor - - - - - - - info - org.wso2.carbon.core.transports.util.InfoProcessor - - - wsdl - org.wso2.carbon.core.transports.util.Wsdl11Processor - - - wsdl2 - org.wso2.carbon.core.transports.util.Wsdl20Processor - - - xsd - org.wso2.carbon.core.transports.util.XsdProcessor - - - - - - false - false - true - svn - http://svnrepo.example.com/repos/ - username - password - true - - - - - - - - - - - - - - - ${require.carbon.servlet} - - - - - true - - - - - - - default repository - ${p2.repo.url} - - - - - - - - true - - - - - - true - - diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/src/test/resources/repository/conf/carbon.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt/src/test/resources/repository/conf/carbon.xml new file mode 100644 index 00000000000..e69de29bb2d diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 6291d849a54..d1c6c2206cb 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml index cab0ec48969..e18d86ef100 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index c6914f57339..12238221675 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml index 09ac87fdb8a..0c2e5663fe0 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -364,7 +364,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/GroupManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/GroupManagementService.java index cfe12bc3f88..33d46f139b5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/GroupManagementService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/GroupManagementService.java @@ -26,6 +26,24 @@ import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.swagger.annotations.*; import org.apache.axis2.transport.http.HTTPConstants; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceGroupList; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceList; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceToGroupsAssignment; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleList; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +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 javax.validation.Valid; import javax.ws.rs.*; @@ -159,6 +177,13 @@ import java.util.List; key = "perm:groups:devices-types", roles = {"Internal/devicemgt-user"}, permissions = {"/device-mgt/groups/devices/types"} + ), + @Scope( + name = "View whether the groups has relevant device types", + description = "View whether the groups has relevant device types", + key = "perm:groups:add", + roles = {"Internal/devicemgt-user"}, + permissions = {"/device-mgt/groups/device-types"} ) } ) @@ -1206,4 +1231,77 @@ public interface GroupManagementService { required = true) List identifiers); + + @POST + @Path("/roles/share") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_POST, + value = "Consolidated API for Creating a Device Group, Adding Devices, and Sharing", + notes = "This API can be used to create a new device group, add devices to the group, and share the group with user roles.", + tags = "Device Group Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:groups:add") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "Created. \n Device group has successfully been created.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the created group."), + @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 has been modified the last time.\n" + + "Used by caches, or in conditional requests.") + } + ), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location " + + "header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Current logged in user is not authorized to perform the operation.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Group not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while creating the group or adding devices or sharing the group.", + response = ErrorResponse.class) + }) + Response createGroupWithRoles( + @ApiParam( + name = "group", + value = "Define the group object with data.", + required = true) + @Valid DeviceGroupRoleWrapper group + ); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/RoleManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/RoleManagementService.java index f7eb730a8b6..5031f1598d1 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/RoleManagementService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/RoleManagementService.java @@ -187,6 +187,104 @@ public interface RoleManagementService { defaultValue = "5") @QueryParam("limit") int limit); + @GET + @Path("/visible/{metaKey}") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = "GET", + value = "Getting the List of Visible Roles", + notes = "WSO2 IoTS supports role-based access control (RBAC) and role management. Using this API you can the list of roles that are in WSO2 IoTS.\n" + + "Note: Internal roles, roles created for service-providers, and application related roles will not be given in the output.", + tags = "Role Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:roles:view") + }) + } + ) + @ApiResponses(value = { + @ApiResponse( + code = 200, + message = "OK. \n Successfully fetched the list of roles in WSO2 IoTS.", + response = RoleList.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 has been modified the last time.\n" + + "Used by caches, or in conditional requests."), + }), + @ApiResponse( + code = 304, + message = "Not Modified. \n Empty body because the client already has the latest version of the " + + "requested resource."), + @ApiResponse( + code = 404, + message = "Not Found. \n The specified resource does not exist.\n", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported", + response = ErrorResponse.class), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n Server error occurred while fetching the list of roles" + + " assigned to the specified user.", + response = ErrorResponse.class) + }) + Response getVisibleRole( + @ApiParam( + name = "filter", + value = "Provide a character or a few characters in the role name.", + required = false) + @QueryParam("filter") String filter, + @ApiParam( + name = "user-store", + value = "The name of the UserStore you wish to get the list of roles.", + required = false) + @QueryParam("user-store") String userStoreName, + @ApiParam( + name = "If-Modified-Since", + value = "Checks if the requested variant was modified, since the specified date-time." + + "Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" + + "Example: Mon, 05 Jan 2014 15:10:00 +0200", + required = false) + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @ApiParam( + name = "offset", + value = "The starting pagination index for the complete list of qualified items.", + required = false, + defaultValue = "0") + @QueryParam("offset") int offset, + @ApiParam( + name = "limit", + value = "Provide how many role details you require from the starting pagination index/offset.", + required = false, + defaultValue = "5") + @QueryParam("limit") int limit, + @ApiParam( + name = "username", + value = "The username of the user.", + required = true, + defaultValue = "admin") + @QueryParam("username") String username, + @ApiParam( + name = "domain", + value = "The domain name of the user store.", + required = false) + @QueryParam("domain") String domain, + @ApiParam( + name = "metaKey", + value = "Key of the metadata", + required = true) + @PathParam("metaKey") String metaKey); + @GET @Path("/filter/{prefix}") @ApiOperation( diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/GroupManagementAdminService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/GroupManagementAdminService.java index 393389340f8..eb5f791ab6d 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/GroupManagementAdminService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/api/admin/GroupManagementAdminService.java @@ -27,8 +27,16 @@ import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.swagger.annotations.*; import org.apache.axis2.transport.http.HTTPConstants; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; import javax.validation.Valid; -import javax.ws.rs.*; + +import javax.ws.rs.Consumes; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +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; @@ -358,4 +366,79 @@ public interface GroupManagementAdminService { required = true) @Valid DeviceGroup group); + + + @POST + @Path("/roles/share") + @ApiOperation( + produces = MediaType.APPLICATION_JSON, + httpMethod = HTTPConstants.HEADER_POST, + value = "Consolidated API for Creating a Device Group, Adding Devices, and Sharing", + notes = "This API can be used to create a new device group, add devices to the group, and share the group with user roles.", + tags = "Device Group Management", + extensions = { + @Extension(properties = { + @ExtensionProperty(name = Constants.SCOPE, value = "perm:groups:add") + }) + } + ) + @ApiResponses( + value = { + @ApiResponse( + code = 201, + message = "Created. \n Device group has successfully been created.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The URL of the created group."), + @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 has been modified the last time.\n" + + "Used by caches, or in conditional requests.") + } + ), + @ApiResponse( + code = 303, + message = "See Other. \n Source can be retrieved from the URL specified at the Location " + + "header.", + responseHeaders = { + @ResponseHeader( + name = "Content-Location", + description = "The Source URL of the document.")}), + @ApiResponse( + code = 400, + message = "Bad Request. \n Invalid request or validation error.", + response = ErrorResponse.class), + @ApiResponse( + code = 401, + message = "Unauthorized. \n Current logged in user is not authorized to perform the operation.", + response = ErrorResponse.class), + @ApiResponse( + code = 404, + message = "Group not found.", + response = ErrorResponse.class), + @ApiResponse( + code = 406, + message = "Not Acceptable.\n The requested media type is not supported."), + @ApiResponse( + code = 500, + message = "Internal Server Error. \n " + + "Server error occurred while creating the group or adding devices or sharing the group.", + response = ErrorResponse.class) + }) + Response createGroupWithRoles(@ApiParam( + name = "group", + value = "Define the group object with data.", + required = true) + @Valid DeviceGroupRoleWrapper group + + ); + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java index 09be7963fdd..67042ede8b1 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -23,6 +23,11 @@ import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProvi import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProviderServiceImpl; import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey; import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException; +import io.entgra.device.mgt.core.apimgt.application.extension.internal.APIApplicationManagerExtensionDataHolder; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.keymgt.extension.DCRResponse; import io.entgra.device.mgt.core.apimgt.keymgt.extension.TokenRequest; import io.entgra.device.mgt.core.apimgt.keymgt.extension.TokenResponse; @@ -804,11 +809,12 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { //todo - lasantha - can't get password from here ApiApplicationKey apiApplicationKey; try { - DCRResponse adminDCRResponse = keyMgtService.dynamicClientRegistration(applicationName, - PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() - .getRealmConfiguration().getAdminUserName(), - "client_credentials", null, new String[] {"device_management"}, false, validityTime, PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm() - .getRealmConfiguration().getAdminPassword()); + + APIApplicationServices apiApplicationServices = DeviceMgtAPIUtils.getApiApplicationServices(); + APIApplicationKey adminDCRResponse = apiApplicationServices.createAndRetrieveApplicationCredentials( + "ClientForJWTTokenGeneration", + "client_credentials password refresh_token urn:ietf:params:oauth:grant-type:jwt-bearer" + ); PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); JWTClientManagerService jwtClientManagerService = (JWTClientManagerService) ctx. @@ -816,11 +822,14 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { JWTClient jwtClient = jwtClientManagerService.getJWTClient(); AccessTokenInfo accessTokenInfo = jwtClient.getAccessToken(adminDCRResponse.getClientId(), adminDCRResponse.getClientSecret(), - username, "appm:subscribe"); + username, "appm:subscribe apim:admin apim:api_key apim:app_import_export apim:app_manage" + + " apim:store_settings apim:sub_alert_manage apim:sub_manage apim:subscribe openid perm:device:enroll " + + "perm:devices:details perm:devices:features perm:devices:search perm:devices:view perm:groups:groups " + + "perm:users:send-invitation"); APIManagementProviderService apiManagementProviderService = DeviceMgtAPIUtils.getAPIManagementService(); apiApplicationKey = apiManagementProviderService.generateAndRetrieveApplicationKeys(applicationName, - new String[] {"device_management"}, null, false, String.valueOf(validityTime), + new String[] {"device_management"}, "PRODUCTION", false, String.valueOf(validityTime), accessTokenInfo.getAccessToken()); } catch (JWTClientException e) { @@ -828,8 +837,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); - } catch (UserStoreException e) { - String msg = "Error while getting user credentials."; + } catch (APIServicesException e) { + String msg = "Error while generating api Application"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java index f0122835e1a..98ca6249d02 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/GroupManagementServiceImpl.java @@ -18,6 +18,28 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceTypesOfGroups; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +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.Device; +import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; +import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo; +import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException; +import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService; +import io.entgra.device.mgt.core.device.mgt.core.service.GroupManagementProviderService; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceGroupList; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceList; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceToGroupsAssignment; @@ -37,10 +59,21 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.user.api.UserRealm; +import org.wso2.carbon.user.api.UserStoreException; import javax.ws.rs.*; +import javax.naming.InitialContext; +import javax.naming.NamingException; +import javax.transaction.UserTransaction; +import javax.ws.rs.DefaultValue; +import javax.ws.rs.GET; +import javax.ws.rs.POST; +import javax.ws.rs.Path; +import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; public class GroupManagementServiceImpl implements GroupManagementService { @@ -94,8 +127,18 @@ public class GroupManagementServiceImpl implements GroupManagementService { request.setGroupName(name); request.setOwner(owner); request.setDepth(depth); - PaginationResult deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() - .getGroupsWithHierarchy(currentUser, request, requireGroupProps); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + UserRealm realmService = DeviceMgtAPIUtils.getRealmService().getTenantUserRealm(tenantId); + String[] roles = realmService.getUserStoreManager().getRoleListOfUser(currentUser); + boolean hasAdminRole = Arrays.asList(roles).contains(DEFAULT_ADMIN_ROLE); + PaginationResult deviceGroupsResult; + if (hasAdminRole) { + deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() + .getGroupsWithHierarchy(null, request, requireGroupProps); + } else{ + deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() + .getGroupsWithHierarchy(currentUser, request, requireGroupProps); + } DeviceGroupList deviceGroupList = new DeviceGroupList(); deviceGroupList.setList(deviceGroupsResult.getData()); deviceGroupList.setCount(deviceGroupsResult.getRecordsTotal()); @@ -104,6 +147,10 @@ public class GroupManagementServiceImpl implements GroupManagementService { String error = "Error occurred while retrieving groups with hierarchy."; log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while getting user realm."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } @@ -416,4 +463,38 @@ public class GroupManagementServiceImpl implements GroupManagementService { } } + @POST + @Path("/roles/share") + @Override + public Response createGroupWithRoles(DeviceGroupRoleWrapper groups) { + if (groups == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + groups.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); + groups.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); + try { + DeviceMgtAPIUtils.getGroupManagementProviderService().createGroupWithRoles(groups, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); + DeviceGroup group = DeviceMgtAPIUtils.getGroupManagementProviderService().getGroup(groups.getName(), + PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername().isEmpty()); + if (group != null) { + DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), groups.getUserRoles()); + return Response.status(Response.Status.CREATED).entity(group.getGroupId()).build(); + } else { + String msg = "Error occurred while retrieving newly created group."; + log.error(msg); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } + } catch (GroupManagementException e) { + String msg = "Error occurred while adding " + groups.getName() + " group"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (GroupAlreadyExistException e) { + String msg = "Group already exists with name : " + groups.getName() + " Try with another group name."; + log.error(msg, e); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); + } catch (RoleDoesNotExistException e) { + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); + } + } + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java index c8df51825e4..5c045166500 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/RoleManagementServiceImpl.java @@ -17,6 +17,14 @@ */ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.impl; +import com.google.common.base.Strings; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata; +import org.apache.axis2.databinding.types.xsd._boolean; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.ErrorResponse; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleInfo; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.RoleList; @@ -28,6 +36,7 @@ import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.DeviceMgtAPIUtils; import io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.SetReferenceTransformer; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.springframework.util.StringUtils; import org.wso2.carbon.CarbonConstants; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.CarbonContext; @@ -50,6 +59,12 @@ import java.net.URI; import java.net.URISyntaxException; import java.net.URLEncoder; import java.util.*; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; +import java.util.List; +import java.util.Optional; +import java.util.Set; import static io.entgra.device.mgt.core.device.mgt.api.jaxrs.util.Constants.PRIMARY_USER_STORE; @@ -97,6 +112,96 @@ public class RoleManagementServiceImpl implements RoleManagementService { } } + @GET + @Path("/visible/{metaKey}") + @Override + public Response getVisibleRole( + @QueryParam("filter") String filter, + @QueryParam("user-store") String userStore, + @HeaderParam("If-Modified-Since") String ifModifiedSince, + @QueryParam("offset") int offset, + @QueryParam("limit") int limit, + @QueryParam("username") String username, + @QueryParam("domain") String domain, + @PathParam("metaKey") String metaKey) { + RequestValidationUtil.validatePaginationParameters(offset, limit); + if (limit == 0){ + limit = Constants.DEFAULT_PAGE_LIMIT; + } + if (!Strings.isNullOrEmpty(domain)) { + username = domain + '/' + username; + } + Metadata metadata; + List visibleRoles; + RoleList visibleRoleList = new RoleList(); + try { + metadata = DeviceMgtAPIUtils.getMetadataManagementService().retrieveMetadata(metaKey); + String metaValue = metadata.getMetaValue(); + JSONParser parser = new JSONParser(); + JSONObject jsonObject = (JSONObject) parser.parse(metaValue); + boolean decision = (boolean) jsonObject.get(Constants.IS_USER_ABLE_TO_VIEW_ALL_ROLES); + if (decision) { + if (Strings.isNullOrEmpty(userStore)){ + userStore = PRIMARY_USER_STORE; + } + try { + visibleRoles = getRolesFromUserStore(filter, userStore); + visibleRoleList.setList(visibleRoles); + + visibleRoles = FilteringUtil.getFilteredList(getRolesFromUserStore(filter, userStore), offset, limit); + visibleRoleList.setList(visibleRoles); + + return Response.status(Response.Status.OK).entity(visibleRoleList).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while retrieving roles from the underlying user stores"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } else { + try { + UserStoreManager userStoreManager = DeviceMgtAPIUtils.getUserStoreManager(); + if (!userStoreManager.isExistingUser(username)) { + if (log.isDebugEnabled()) { + log.debug("User by username: " + username + " does not exist for role retrieval."); + } + String msg = "User by username: " + username + " does not exist for role retrieval."; + return Response.status(Response.Status.NOT_FOUND).entity(msg).build(); + } + visibleRoleList.setList(getFilteredVisibleRoles(userStoreManager, username)); + + return Response.status(Response.Status.OK).entity(visibleRoleList).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while trying to retrieve roles of the user '" + username + "'"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } + } + } catch (MetadataManagementException e) { + String msg = "Error occurred while getting the metadata entry for metaKey:" + metaKey; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (ParseException e) { + String msg = "Error occurred while parsing JSON metadata: " + e.getMessage(); + log.error(msg, e); + return Response.status(Response.Status.BAD_REQUEST).entity(msg).build(); + } + } + + private List getFilteredVisibleRoles(UserStoreManager userStoreManager, String username) + throws UserStoreException { + String[] roleListOfUser; + roleListOfUser = userStoreManager.getRoleListOfUser(username); + List filteredRoles = new ArrayList<>(); + for (String role : roleListOfUser) { + if (!(role.startsWith("Internal/") || role.startsWith("Authentication/"))) { + filteredRoles.add(role); + } + } + return filteredRoles; + } + @GET @Path("/filter/{prefix}") @Override @@ -542,6 +647,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { @Consumes(MediaType.WILDCARD) @Override public Response deleteRole(@PathParam("roleName") String roleName, @QueryParam("user-store") String userStoreName) { + String roleToDelete = roleName; if (userStoreName != null && !userStoreName.isEmpty()) { roleName = userStoreName + "/" + roleName; } @@ -549,6 +655,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { try { final UserRealm userRealm = DeviceMgtAPIUtils.getUserRealm(); final UserStoreManager userStoreManager = userRealm.getUserStoreManager(); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); if (!userStoreManager.isExistingRole(roleName)) { String msg = "No role exists with the name : " + roleName ; return Response.status(404).entity(msg).build(); @@ -558,16 +665,18 @@ public class RoleManagementServiceImpl implements RoleManagementService { if (log.isDebugEnabled()) { log.debug("Deleting the role in user store"); } - userStoreManager.deleteRole(roleName); - // Delete all authorizations for the current role before deleting - authorizationManager.clearRoleAuthorization(roleName); - + DeviceMgtAPIUtils.getGroupManagementProviderService().deleteRoleAndRoleGroupMapping(roleName, roleToDelete, tenantId, userStoreManager, authorizationManager); return Response.status(Response.Status.OK).build(); } catch (UserStoreException e) { String msg = "Error occurred while deleting the role '" + roleName + "'"; log.error(msg, e); return Response.serverError().entity( new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while deleting group-role mapping records"; + log.error(msg, e); + return Response.serverError().entity( + new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build(); } } @@ -597,7 +706,7 @@ public class RoleManagementServiceImpl implements RoleManagementService { userStoreManager.updateUserListOfRole(roleName, usersToDelete, usersToAdd); return Response.status(Response.Status.OK).entity("Role '" + roleName + "' has " + - "successfully been updated with the user list") + "successfully been updated with the user list") .build(); } catch (UserStoreException e) { String msg = "Error occurred while updating the users of the role '" + roleName + "'"; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java index 5209ace4722..d0f5239fa31 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/UserManagementServiceImpl.java @@ -424,6 +424,9 @@ public class UserManagementServiceImpl implements UserManagementService { userList = new ArrayList<>(users.size()); BasicUserInfo user; for (String username : users) { + if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username)) { + continue; + } user = getBasicUserInfo(username); userList.add(user); } @@ -484,6 +487,10 @@ public class UserManagementServiceImpl implements UserManagementService { if (StringUtils.isNotEmpty(username)) { commonUsers = getUserList(null, username); } + if (commonUsers != null) { + commonUsers.remove(Constants.APIM_RESERVED_USER); + commonUsers.remove(Constants.RESERVED_USER); + } if (!skipSearch(commonUsers) && StringUtils.isNotEmpty(firstName)) { tempList = getUserList(Constants.USER_CLAIM_FIRST_NAME, firstName); @@ -658,6 +665,9 @@ public class UserManagementServiceImpl implements UserManagementService { userList = new ArrayList<>(); UserInfo user; for (String username : users) { + if (Constants.APIM_RESERVED_USER.equals(username) || Constants.RESERVED_USER.equals(username)) { + continue; + } user = new UserInfo(); user.setUsername(username); user.setEmailAddress(getClaimValue(username, Constants.USER_CLAIM_EMAIL_ADDRESS)); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java index 5f6d8a7bae9..d7bf236acf8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/service/impl/admin/GroupManagementAdminServiceImpl.java @@ -29,13 +29,34 @@ import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistEx import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.beans.DeviceGroupList; +import io.entgra.device.mgt.core.device.mgt.api.jaxrs.service.api.admin.GroupManagementAdminService; +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.DeviceMgtAPIUtils; +import org.wso2.carbon.context.CarbonContext; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.apache.commons.lang.StringUtils; +import org.wso2.carbon.user.api.UserRealm; +import org.wso2.carbon.user.api.UserStoreException; import javax.ws.rs.DefaultValue; import javax.ws.rs.GET; +import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; import javax.ws.rs.core.Response; import java.util.ArrayList; +import java.util.Arrays; public class GroupManagementAdminServiceImpl implements GroupManagementAdminService { @@ -90,13 +111,25 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ @DefaultValue("5") @QueryParam("limit") int limit) { try { RequestValidationUtil.validatePaginationParameters(offset, limit); + String currentUser = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); GroupPaginationRequest request = new GroupPaginationRequest(offset, limit); request.setGroupName(name); request.setOwner(owner); request.setStatus(status); request.setDepth(depth); - PaginationResult deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() - .getGroupsWithHierarchy(null, request, requireGroupProps); + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + UserRealm realmService = DeviceMgtAPIUtils.getRealmService().getTenantUserRealm(tenantId); + String[] roles = realmService.getUserStoreManager().getRoleListOfUser(currentUser); + boolean isAdmin = DEFAULT_ADMIN_ROLE.equals(currentUser); + boolean hasAdminRole = Arrays.asList(roles).contains(DEFAULT_ADMIN_ROLE); + PaginationResult deviceGroupsResult; + if (StringUtils.isBlank(currentUser) || isAdmin || hasAdminRole) { + deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() + .getGroupsWithHierarchy(null, request, requireGroupProps); + } else { + deviceGroupsResult = DeviceMgtAPIUtils.getGroupManagementProviderService() + .getGroupsWithHierarchy(currentUser, request, requireGroupProps); + } DeviceGroupList deviceGroupList = new DeviceGroupList(); deviceGroupList.setList(deviceGroupsResult.getData()); deviceGroupList.setCount(deviceGroupsResult.getRecordsTotal()); @@ -105,6 +138,10 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ String error = "Error occurred while retrieving groups with hierarchy."; log.error(error, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(error).build(); + } catch (UserStoreException e) { + String msg = "Error occurred while getting user realm."; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } } @@ -144,4 +181,30 @@ public class GroupManagementAdminServiceImpl implements GroupManagementAdminServ return Response.status(Response.Status.CONFLICT).entity(msg).build(); } } + @POST + @Path("/roles/share") + @Override + public Response createGroupWithRoles(DeviceGroupRoleWrapper group) { + if (group == null) { + return Response.status(Response.Status.BAD_REQUEST).build(); + } + group.setOwner(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); + group.setStatus(DeviceGroupConstants.GroupStatus.ACTIVE); + try { + DeviceMgtAPIUtils.getGroupManagementProviderService().createGroupWithRoles(group, DEFAULT_ADMIN_ROLE, DEFAULT_ADMIN_PERMISSIONS); + DeviceMgtAPIUtils.getGroupManagementProviderService().manageGroupSharing(group.getGroupId(), group.getUserRoles()); + return Response.status(Response.Status.CREATED).build(); + } catch (GroupManagementException e) { + String msg = "Error occurred while adding " + group.getName() + " group"; + log.error(msg, e); + return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); + } catch (GroupAlreadyExistException e) { + String msg = "Group already exists with name : " + group.getName() + " Try with another group name."; + log.error(msg, e); + return Response.status(Response.Status.CONFLICT).entity(msg).build(); + } catch (RoleDoesNotExistException e) { + return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); + } + } + } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java index 300e47b1479..0a9b6efa268 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/Constants.java @@ -30,13 +30,16 @@ public class Constants { public static final String USER_CLAIM_MODIFIED = "http://wso2.org/claims/modified"; public static final String USER_CLAIM_DEVICES = "http://wso2.org/claims/devices"; public static final String PRIMARY_USER_STORE = "PRIMARY"; - public static final String DEFAULT_STREAM_VERSION = "1.0.0"; + public static final String APIM_RESERVED_USER = "apim_reserved_user"; + public static final String RESERVED_USER = "reserved_user"; + public static final String DEFAULT_STREAM_VERSION = "1.0.0"; public static final String SCOPE = "scope"; public static final String JDBC_USERSTOREMANAGER = "org.wso2.carbon.user.core.jdbc.JDBCUserStoreManager"; public static final String DEFAULT_SIMPLE_DATE_FORMAT = "EEE, d MMM yyyy HH:mm:ss Z"; public static final int DEFAULT_PAGE_LIMIT = 50; public static final String FORWARD_SLASH = "/"; public static final String ANDROID = "android"; + public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles"; public static final String ANDROID_POLICY_VALIDATOR = "io.entgra.proprietary.uem.platform.android." + "core.polcy.AndroidPolicyPayloadValidator"; public static final String IOS = "ios"; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java index a297bffd48a..f1a5db11562 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.api/src/main/java/io/entgra/device/mgt/core/device/mgt/api/jaxrs/util/DeviceMgtAPIUtils.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.device.mgt.api.jaxrs.util; import io.entgra.device.mgt.core.apimgt.application.extension.APIManagementProviderService; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; import io.entgra.device.mgt.core.apimgt.extension.rest.api.ConsumerRESTAPIServices; import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager; import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager; @@ -157,6 +158,7 @@ public class DeviceMgtAPIUtils { private static volatile SubscriptionManager subscriptionManager; private static volatile ApplicationManager applicationManager; private static volatile ConsumerRESTAPIServices consumerRESTAPIServices; + private static volatile APIApplicationServices apiApplicationServices; private static volatile APIManagementProviderService apiManagementProviderService; static { @@ -410,6 +412,25 @@ public class DeviceMgtAPIUtils { return consumerRESTAPIServices; } + /** + * Initializing and accessing method for APIM API application REST API. + * + * @return APIApplicationServices instance + * @throws IllegalStateException if APIApplicationServices cannot be initialized + */ + public static synchronized APIApplicationServices getApiApplicationServices() { + if (apiApplicationServices == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + apiApplicationServices = (APIApplicationServices) ctx.getOSGiService(APIApplicationServices.class, null); + if (apiApplicationServices == null) { + String msg = "API application service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + return apiApplicationServices; + } + /** * Initializing and accessing method for API management Provider Service. * diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml index d8323a431c3..bec50d0782c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/DeviceManagementConstants.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/DeviceManagementConstants.java index fb4c749b825..6fd2fedde94 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/DeviceManagementConstants.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/DeviceManagementConstants.java @@ -134,6 +134,8 @@ public final class DeviceManagementConstants { public static final String LAST_NAME = "last-name"; public static final String TENANT_ADMIN_USERNAME = "tenant-admin-username"; public static final String TENANT_ADMIN_PASSWORD = "tenant-admin-password"; + + public static final int OTP_DEFAULT_EXPIRY_SECONDS = 3600; } public static final class EventServices { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/general/QREnrollmentDetails.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/general/QREnrollmentDetails.java index df0719d152f..08a334bf2fa 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/general/QREnrollmentDetails.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/general/QREnrollmentDetails.java @@ -18,10 +18,22 @@ package io.entgra.device.mgt.core.device.mgt.common.general; +import java.util.Map; + public class QREnrollmentDetails { String ownershipType; String username; String enrollmentMode; + Map customValues; + + public Map getCustomValues() { + return customValues; + } + + public void setCustomValues(Map customValues) { + this.customValues = customValues; + } + int tokenExpiry; public String getOwnershipType() { return ownershipType; } @@ -34,4 +46,12 @@ public class QREnrollmentDetails { public String getEnrollmentMode() { return enrollmentMode; } public void setEnrollmentMode(String enrollmentMode) { this.enrollmentMode = enrollmentMode; } + + public int getTokenExpiry() { + return tokenExpiry; + } + + public void setTokenExpiry(int tokenExpiry) { + this.tokenExpiry = tokenExpiry; + } } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/group/mgt/DeviceGroupRoleWrapper.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/group/mgt/DeviceGroupRoleWrapper.java new file mode 100644 index 00000000000..768fe55524c --- /dev/null +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/group/mgt/DeviceGroupRoleWrapper.java @@ -0,0 +1,151 @@ +/* + * 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.group.mgt; + +import io.swagger.annotations.ApiModel; +import io.swagger.annotations.ApiModelProperty; +import io.swagger.annotations.ApiParam; + +import java.io.Serializable; +import java.util.List; +import java.util.Map; + +/** + * Holds Device Group details and expose to external access + */ +@ApiModel(value = "DeviceGroupRoleWrapper", description = "This class carries all information related to a managed device group.") +public class DeviceGroupRoleWrapper implements Serializable { + + private static final long serialVersionUID = 1998121711L; + + @ApiModelProperty(name = "id", value = "ID of the device group in the device group information database.") + private int id; + + @ApiModelProperty(name = "description", value = "The device group description that can be set on the device group by the user.", required = true) + private String description; + + @ApiModelProperty(name = "name", value = "The device group name that can be set on the device group by the user.", required = true) + private String name; + + private String owner; + + @ApiModelProperty(name = "status", value = "The status of group that needs updating/retrieval.") + private String status; + + @ApiModelProperty(name = "parentGroupId", value = "Group ID of parent group") + private int parentGroupId; + + @ApiModelProperty(name = "parentPath", value = "Path of parent group") + private String parentPath; + + @ApiModelProperty(name = "childrenGroups", value = "Children groups") + private List childrenGroups; + + @ApiModelProperty(name = "userRoles", value = "User roles") + private List userRoles; + + public DeviceGroupRoleWrapper() { + } + + public DeviceGroupRoleWrapper(String name) { + this.name = name; + } + + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + + private Map groupProperties; + + public int getGroupId() { + return id; + } + + public void setGroupId(int id) { + this.id = id; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public Map getGroupProperties() { + return groupProperties; + } + + public void setGroupProperties(Map groupProperties) { + this.groupProperties = groupProperties; + } + + public int getParentGroupId() { + return parentGroupId; + } + + public void setParentGroupId(int parentGroupId) { + this.parentGroupId = parentGroupId; + } + + public String getParentPath() { + return parentPath; + } + + public void setParentPath(String parentPath) { + this.parentPath = parentPath; + } + + public List getChildrenGroups() { + return childrenGroups; + } + + public void setChildrenGroups(List childrenGroups) { + this.childrenGroups = childrenGroups; + } + + public List getUserRoles() { + return userRoles; + } + + public void setUserRoles(List userRoles) { + this.userRoles = userRoles; + } +} \ No newline at end of file diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/otp/mgt/OTPEmailTypes.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/otp/mgt/OTPEmailTypes.java index afb1d6b0fa9..53113c5b758 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/otp/mgt/OTPEmailTypes.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/otp/mgt/OTPEmailTypes.java @@ -19,5 +19,5 @@ package io.entgra.device.mgt.core.device.mgt.common.otp.mgt; public enum OTPEmailTypes { - USER_VERIFY, DEVICE_ENROLLMENT + USER_VERIFY, DEVICE_ENROLLMENT, USER_INVITE, REMOTE_SESSION } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/spi/OTPManagementService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/spi/OTPManagementService.java index c89d311cda4..e4cfa042b6e 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/spi/OTPManagementService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.common/src/main/java/io/entgra/device/mgt/core/device/mgt/common/spi/OTPManagementService.java @@ -35,7 +35,8 @@ public interface OTPManagementService { * @throws OTPManagementException if error occurred whle verifying validity of the OPT * @throws BadRequestException if found an null value for OTP */ - OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException; + OneTimePinDTO isValidOTP(String oneTimeToken, boolean requireRenewal) throws + OTPManagementException, BadRequestException; /** * Invalidate the OTP and send welcome mail @@ -59,8 +60,7 @@ public interface OTPManagementService { boolean hasEmailRegistered(String email, String emailDomain) throws OTPManagementException, DeviceManagementException; - OneTimePinDTO generateOneTimePin(String email, String emailType, String userName, Object metaDataObj, - int tenantId, boolean persistPin) throws OTPManagementException; + OneTimePinDTO generateOneTimePin(OneTimePinDTO oneTimePinData, boolean persistPin) throws OTPManagementException; OneTimePinDTO getRenewedOtpByEmailAndMailType(String email, String emailType) throws OTPManagementException; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml index a4673c3e6e0..c00dc59b3b6 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -76,12 +76,20 @@ org.apache.maven.plugins maven-surefire-plugin - - file:src/test/resources/log4j.properties - + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + src/test/resources/testng.xml + + ${basedir}/target/coverage-reports/jacoco-unit.exec + file:src/test/resources/log4j.properties + + + org.ops4j.pax.logging + @@ -255,7 +263,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/DeviceManagementConfigService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/DeviceManagementConfigService.java index eac30a6de6d..729e477c007 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/DeviceManagementConfigService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/DeviceManagementConfigService.java @@ -139,7 +139,12 @@ public interface DeviceManagementConfigService { value = "The properties list using for query a device", required = true) @QueryParam("properties") - String properties); + String properties, + @ApiParam( + name = "withAccessToken", + value = "Whether to use access token or otp token for device configuration") + @QueryParam("withAccessToken") + boolean withAccessToken); @PUT @Path("/device/transfer") diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/impl/DeviceManagementConfigServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/impl/DeviceManagementConfigServiceImpl.java index f387dfea322..de80a541d2f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/impl/DeviceManagementConfigServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/service/impl/DeviceManagementConfigServiceImpl.java @@ -21,6 +21,10 @@ import com.fasterxml.jackson.core.JsonParseException; import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.JsonMappingException; import com.fasterxml.jackson.databind.ObjectMapper; +import io.entgra.device.mgt.core.device.mgt.common.exceptions.OTPManagementException; +import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.OTPEmailTypes; +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.common.AppRegistrationCredentials; import io.entgra.device.mgt.core.device.mgt.common.ApplicationRegistrationException; import io.entgra.device.mgt.core.device.mgt.common.DeviceTransferRequest; @@ -48,6 +52,30 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.base.MultitenantConstants; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.AppRegistrationCredentials; +import org.wso2.carbon.device.mgt.common.ApplicationRegistrationException; +import org.wso2.carbon.device.mgt.common.DeviceTransferRequest; +import org.wso2.carbon.device.mgt.common.configuration.mgt.AmbiguousConfigurationException; +import org.wso2.carbon.device.mgt.common.configuration.mgt.DeviceConfiguration; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceNotFoundException; +import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException; +import org.wso2.carbon.device.mgt.common.general.TenantDetail; +import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes; +import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; +import org.wso2.carbon.device.mgt.common.permission.mgt.PermissionManagementException; +import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; +import org.wso2.carbon.device.mgt.core.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.config.keymanager.KeyManagerConfigurations; +import org.wso2.carbon.device.mgt.core.config.ui.UIConfiguration; +import org.wso2.carbon.device.mgt.core.config.ui.UIConfigurationManager; +import org.wso2.carbon.device.mgt.core.permission.mgt.PermissionUtils; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; +import org.wso2.carbon.identity.jwt.client.extension.dto.AccessTokenInfo; +import org.wso2.carbon.identity.jwt.client.extension.exception.JWTClientException; import org.wso2.carbon.user.api.Tenant; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.core.service.RealmService; @@ -70,7 +98,8 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig @Path("/configurations") @Produces(MediaType.APPLICATION_JSON) public Response getConfiguration(@HeaderParam("token") String token, - @QueryParam("properties") String properties) { + @QueryParam("properties") String properties, + @QueryParam("withAccessToken") boolean withAccessToken) { DeviceManagementProviderService dms = DeviceMgtAPIUtils.getDeviceManagementService(); try { if (token == null || token.isEmpty()) { @@ -95,7 +124,8 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig deviceProps.put("token", token); DeviceConfiguration devicesConfiguration = dms.getDeviceConfiguration(deviceProps); - setAccessTokenToDeviceConfigurations(devicesConfiguration); + if (withAccessToken) setAccessTokenToDeviceConfigurations(devicesConfiguration); + else setOTPTokenToDeviceConfigurations(devicesConfiguration); return Response.status(Response.Status.OK).entity(devicesConfiguration).build(); } catch (DeviceManagementException e) { String msg = "Error occurred while retrieving configurations"; @@ -207,6 +237,33 @@ public class DeviceManagementConfigServiceImpl implements DeviceManagementConfig } } + private void setOTPTokenToDeviceConfigurations(DeviceConfiguration deviceConfiguration) + throws DeviceManagementException { + OneTimePinDTO oneTimePinData = new OneTimePinDTO(); + oneTimePinData.setEmail(OTPEmailTypes.DEVICE_ENROLLMENT.toString()); + oneTimePinData.setEmailType(OTPEmailTypes.DEVICE_ENROLLMENT.toString()); + oneTimePinData.setUsername(deviceConfiguration.getDeviceOwner()); + PrivilegedCarbonContext.startTenantFlow(); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain( + deviceConfiguration.getTenantDomain(), true); + oneTimePinData.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + PrivilegedCarbonContext.endTenantFlow(); + OTPManagementService otpManagementService = DeviceMgtAPIUtils.getOtpManagementService(); + try { + OneTimePinDTO oneTimePinDTO = otpManagementService.generateOneTimePin(oneTimePinData, true); + if (oneTimePinDTO == null) { + String msg = "Null value returned when generating OTP token for " + oneTimePinData.getOtpToken(); + log.error(msg); + throw new DeviceManagementException(msg); + } + deviceConfiguration.setAccessToken(oneTimePinDTO.getOtpToken()); + } catch (OTPManagementException ex) { + String msg = "Error occurred while generating one time pin: " + ex.getMessage(); + log.error(msg, ex); + throw new DeviceManagementException(msg, ex); + } + } + @Override @Path("/tenants") @GET diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/util/DeviceMgtAPIUtils.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/util/DeviceMgtAPIUtils.java index 1dd6052def6..fbe57c89283 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.config.api/src/main/java/io/entgra/device/mgt/core/device/mgt/config/api/util/DeviceMgtAPIUtils.java @@ -22,6 +22,8 @@ import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProvide import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.user.core.service.RealmService; /** @@ -34,6 +36,8 @@ public class DeviceMgtAPIUtils { private static DeviceManagementProviderService deviceManagementProviderService = null; private static RealmService realmService = null; + private static OTPManagementService otpManagementService = null; + public static DeviceManagementProviderService getDeviceManagementService() { if (deviceManagementProviderService == null) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); @@ -48,6 +52,19 @@ public class DeviceMgtAPIUtils { return deviceManagementProviderService; } + public static OTPManagementService getOtpManagementService() { + if (otpManagementService == null) { + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + otpManagementService = (OTPManagementService) ctx.getOSGiService(OTPManagementService.class, null); + if (otpManagementService == null) { + String msg = "OTP Management Service has not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + } + return otpManagementService; + } + public static RealmService getRealmService() { if (realmService == null) { PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml index 521ff65c5cb..26f6603912f 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -473,7 +473,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 org.wso2.carbon.multitenancy diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java index 16ac6f62be5..ac91b7036f4 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/GroupDAO.java @@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; import java.util.List; import java.util.Map; @@ -40,6 +41,18 @@ public interface GroupDAO { */ int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException; + /** + * Add properties for device group. + * Note that groupId parameter is considered seperately due to the groupId parameter passed with + * device group Payload is ignored in the add/update logic instead the internal groupId reference is used. + * + * @param groups to be added. + * @param tenantId of the group. + * @return sql execution result. + * @throws GroupManagementDAOException + */ + int addGroupWithRoles(DeviceGroupRoleWrapper groups, int tenantId) throws GroupManagementDAOException; + /** * Add properties for device group. * Note that groupId parameter is considered seperately due to the groupId parameter passed with @@ -52,6 +65,18 @@ public interface GroupDAO { */ boolean addGroupProperties(DeviceGroup deviceGroup, int groupId, int tenantId) throws GroupManagementDAOException; + /** + * Update properties for device group. + * Note that groupId parameter is considered seperately due to the groupId parameter passed with + * device group Payload is ignored in the add/update logic instead the internal groupId reference is used. + * + * @param groups to be updated. + * @param tenantId of the group. + * @return sql execution result. + * @throws GroupManagementDAOException + */ + boolean addGroupPropertiesWithRoles(DeviceGroupRoleWrapper groups, int groupId, int tenantId) throws GroupManagementDAOException; + /** * Update properties for device group. * Note that groupId parameter is considered seperately due to the groupId parameter passed with @@ -130,6 +155,15 @@ public interface GroupDAO { */ void deleteGroupsMapping(List groupIds, int tenantId) throws GroupManagementDAOException; + /** + * Delete mappings of Device Groups. + * + * @param role of Device Groups. + * @param tenantId of the role. + * @throws GroupManagementDAOException on error during deletion of mappings of groups + */ + void deleteGroupsMapping(String role, int tenantId) throws GroupManagementDAOException; + /** * Delete existing Device Groups. * @@ -186,6 +220,19 @@ public interface GroupDAO { */ List getGroups(GroupPaginationRequest paginationRequest, int tenantId) throws GroupManagementDAOException; + /** + * Get paginated list of Device Groups in tenant with specified device group ids. + * + * @param paginationRequest to filter results. + * @param deviceGroupIds of groups required. + * @param tenantId of user's tenant. + * @param isWithParentPath of user's ParentPath. + * @return List of all Device Groups in tenant. + * @throws GroupManagementDAOException + */ + List getGroups(GroupPaginationRequest paginationRequest, List deviceGroupIds, + int tenantId, boolean isWithParentPath) throws GroupManagementDAOException; + /** * Get paginated list of Device Groups in tenant with specified device group ids. * @@ -412,4 +459,4 @@ public interface GroupDAO { List groupNames) throws GroupManagementDAOException; -} +} \ No newline at end of file diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java index 803526e593f..e1fc26eb8ee 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/AbstractGroupDAOImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.dao.impl; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; @@ -49,7 +50,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { throws GroupManagementDAOException { try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP " + "WHERE TENANT_ID = ?"; if (StringUtils.isNotBlank(request.getGroupName())) { sql += " AND GROUP_NAME LIKE ?"; @@ -103,7 +104,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { @Override public List getGroups(GroupPaginationRequest request, List deviceGroupIds, - int tenantId) throws GroupManagementDAOException { + int tenantId) throws GroupManagementDAOException { int deviceGroupIdsCount = deviceGroupIds.size(); if (deviceGroupIdsCount == 0) { return new ArrayList<>(); @@ -111,7 +112,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP WHERE TENANT_ID = ?"; + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP WHERE TENANT_ID = ?"; if (StringUtils.isNotBlank(request.getGroupName())) { sql += " AND GROUP_NAME LIKE ?"; } @@ -164,6 +165,73 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { throw new GroupManagementDAOException(msg, e); } } + @Override + public List getGroups(GroupPaginationRequest request, List deviceGroupIds, + int tenantId, boolean isWithParentPath) throws GroupManagementDAOException { + int deviceGroupIdsCount = deviceGroupIds.size(); + if (deviceGroupIdsCount == 0) { + return new ArrayList<>(); + } + + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP WHERE TENANT_ID = ?"; + if (StringUtils.isNotBlank(request.getGroupName())) { + sql += " AND GROUP_NAME LIKE ?"; + } + if (StringUtils.isNotBlank(request.getOwner())) { + sql += " AND OWNER LIKE ?"; + } + if (StringUtils.isNotBlank(request.getParentPath())) { + if(isWithParentPath){ + sql += " AND PARENT_PATH LIKE ?"; + } + } + sql += " AND ID IN ("; + for (int i = 0; i < deviceGroupIdsCount; i++) { + sql += (deviceGroupIdsCount - 1 != i) ? "?," : "?"; + } + sql += ")"; + if (request.getRowCount() != 0) { + sql += " LIMIT ? OFFSET ?"; + } + + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + int paramIndex = 1; + stmt.setInt(paramIndex++, tenantId); + if (StringUtils.isNotBlank(request.getGroupName())) { + stmt.setString(paramIndex++, request.getGroupName() + "%"); + } + if (StringUtils.isNotBlank(request.getOwner())) { + stmt.setString(paramIndex++, request.getOwner() + "%"); + } + if (StringUtils.isNotBlank(request.getParentPath())) { + if(isWithParentPath){ + stmt.setString(paramIndex++, request.getParentPath()); + } + } + for (Integer deviceGroupId : deviceGroupIds) { + stmt.setInt(paramIndex++, deviceGroupId); + } + if (request.getRowCount() != 0) { + stmt.setInt(paramIndex++, request.getRowCount()); + stmt.setInt(paramIndex, request.getStartIndex()); + } + List deviceGroupList = new ArrayList<>(); + try (ResultSet resultSet = stmt.executeQuery()) { + while (resultSet.next()) { + deviceGroupList.add(GroupManagementDAOUtil.loadGroup(resultSet)); + } + } + return deviceGroupList; + } + } catch (SQLException e) { + String msg = "Error occurred while retrieving groups of groups IDs " + deviceGroupIds.toString() + + " in tenant: " + tenantId; + log.error(msg); + throw new GroupManagementDAOException(msg, e); + } + } @Override public int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException { @@ -175,11 +243,11 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { Connection conn = GroupManagementDAOFactory.getConnection(); String sql; if (deviceGroup.getStatus() == null || deviceGroup.getStatus().isEmpty()) { - sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH) " - + "VALUES (?, ?, ?, ?, ?)"; - } else { - sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, STATUS) " + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, PARENT_GROUP_ID) " + "VALUES (?, ?, ?, ?, ?, ?)"; + } else { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, PARENT_GROUP_ID, STATUS) " + + "VALUES (?, ?, ?, ?, ?, ?, ?)"; hasStatus = true; } stmt = conn.prepareStatement(sql, new String[]{"ID"}); @@ -188,8 +256,9 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { stmt.setString(3, deviceGroup.getOwner()); stmt.setInt(4, tenantId); stmt.setString(5, deviceGroup.getParentPath()); + stmt.setInt(6, deviceGroup.getParentGroupId()); if (hasStatus) { - stmt.setString(6, deviceGroup.getStatus()); + stmt.setString(7, deviceGroup.getStatus()); } stmt.executeUpdate(); @@ -206,6 +275,47 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } } + @Override + public int addGroupWithRoles(DeviceGroupRoleWrapper groups, int tenantId) throws GroupManagementDAOException { + int groupId = -1; + boolean hasStatus = false; + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + String sql; + if (groups.getStatus() == null || groups.getStatus().isEmpty()) { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, PARENT_GROUP_ID) " + + "VALUES (?, ?, ?, ?, ?, ?)"; + } else { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, PARENT_GROUP_ID, STATUS) " + + "VALUES (?, ?, ?, ?, ?, ?, ?)"; + hasStatus = true; + } + try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) { + stmt.setString(1, groups.getDescription()); + stmt.setString(2, groups.getName()); + stmt.setString(3, groups.getOwner()); + stmt.setInt(4, tenantId); + stmt.setString(5, groups.getParentPath()); + stmt.setInt(6, groups.getParentGroupId()); + if (hasStatus) { + stmt.setString(7, groups.getStatus()); + } + stmt.executeUpdate(); + try (ResultSet rs = stmt.getGeneratedKeys();) { + if (rs.next()) { + groupId = rs.getInt(1); + } + return groupId; + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding deviceGroup '" + + groups.getName() + "'"; + log.error(msg); + throw new GroupManagementDAOException(msg, e); + } + } + public boolean addGroupProperties(DeviceGroup deviceGroup, int groupId, int tenantId) throws GroupManagementDAOException { boolean status; @@ -234,6 +344,33 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { return status; } + public boolean addGroupPropertiesWithRoles(DeviceGroupRoleWrapper groups, int groupId, int tenantId) + throws GroupManagementDAOException { + boolean status; + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + try (PreparedStatement stmt = conn.prepareStatement( + "INSERT INTO GROUP_PROPERTIES(GROUP_ID, PROPERTY_NAME, " + + "PROPERTY_VALUE, TENANT_ID) VALUES (?, ?, ?, ?)")) { + for (Map.Entry entry : groups.getGroupProperties().entrySet()) { + stmt.setInt(1, groupId); + stmt.setString(2, entry.getKey()); + stmt.setString(3, entry.getValue()); + stmt.setInt(4, tenantId); + stmt.addBatch(); + } + stmt.executeBatch(); + status = true; + } + } catch (SQLException e) { + String msg = "Error occurred while adding properties for group '" + + groups.getName() + "' values : " + groups.getGroupProperties(); + log.error(msg); + throw new GroupManagementDAOException(msg, e); + } + return status; + } + public boolean updateGroupProperties(DeviceGroup deviceGroup, int groupId, int tenantId) throws GroupManagementDAOException { boolean status; @@ -303,7 +440,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { try { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = "UPDATE DM_GROUP SET DESCRIPTION = ?, GROUP_NAME = ?, OWNER = ?, STATUS = ?, " - + "PARENT_PATH = ? WHERE ID = ? AND TENANT_ID = ?"; + + "PARENT_PATH = ?, PARENT_GROUP_ID = ? WHERE ID = ? AND TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)){ for (DeviceGroup deviceGroup : deviceGroups) { stmt.setString(1, deviceGroup.getDescription()); @@ -311,8 +448,9 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { stmt.setString(3, deviceGroup.getOwner()); stmt.setString(4, deviceGroup.getStatus()); stmt.setString(5, deviceGroup.getParentPath()); - stmt.setInt(6, deviceGroup.getGroupId()); - stmt.setInt(7, tenantId); + stmt.setInt(6, deviceGroup.getParentGroupId()); + stmt.setInt(7, deviceGroup.getGroupId()); + stmt.setInt(8, tenantId); stmt.addBatch(); } stmt.executeBatch(); @@ -403,6 +541,23 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } } + @Override + public void deleteGroupsMapping(String role, int tenantId) throws GroupManagementDAOException { + + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + String sql = "DELETE FROM DM_ROLE_GROUP_MAP WHERE ROLE = ? AND TENANT_ID = ?"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, role); + stmt.setInt(2, tenantId); + stmt.executeUpdate(); + } + } catch (SQLException e) { + String msg = "Error occurred while removing record from group-role mapping."; + log.error(msg); + throw new GroupManagementDAOException(msg, e); + } + } @Override public void deleteGroups(List groupIds, int tenantId) throws GroupManagementDAOException { try { @@ -491,7 +646,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { ResultSet resultSet = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP WHERE ID = ? " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP WHERE ID = ? " + "AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setInt(1, groupId); @@ -514,7 +669,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { public List getChildrenGroups(String parentPath, int tenantId) throws GroupManagementDAOException { try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP " + "WHERE PARENT_PATH LIKE ? AND TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, parentPath + "%"); @@ -539,7 +694,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { public List getRootGroups(int tenantId) throws GroupManagementDAOException { try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP " + "WHERE PARENT_PATH LIKE ? AND TENANT_ID = ?"; try (PreparedStatement stmt = conn.prepareStatement(sql)) { stmt.setString(1, "/"); @@ -567,7 +722,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { List deviceGroupBuilders = new ArrayList<>(); try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT G.ID, G.GROUP_NAME, G.DESCRIPTION, G.OWNER, G.STATUS, G.PARENT_PATH FROM DM_GROUP G " + + String sql = "SELECT G.ID, G.GROUP_NAME, G.DESCRIPTION, G.OWNER, G.STATUS, G.PARENT_PATH, G.PARENT_GROUP_ID FROM DM_GROUP G " + "INNER JOIN DM_DEVICE_GROUP_MAP GM ON G.ID = GM.GROUP_ID " + "WHERE GM.DEVICE_ID = ? AND GM.TENANT_ID = ?"; stmt = conn.prepareStatement(sql); @@ -705,7 +860,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { try { Connection conn = GroupManagementDAOFactory.getConnection(); String sql = - "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP " + "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP " + "WHERE LOWER(GROUP_NAME) = LOWER(?) AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, groupName); @@ -876,7 +1031,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { List deviceGroupList = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP g, " + + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID P FROM DM_GROUP g, " + "(SELECT GROUP_ID FROM DM_ROLE_GROUP_MAP WHERE ROLE IN ("; int index = 0; @@ -990,7 +1145,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { List deviceGroupList = null; try { Connection conn = GroupManagementDAOFactory.getConnection(); - String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH FROM DM_GROUP " + String sql = "SELECT ID, DESCRIPTION, GROUP_NAME, OWNER, STATUS, PARENT_PATH, PARENT_GROUP_ID FROM DM_GROUP " + "WHERE OWNER = ? AND TENANT_ID = ?"; stmt = conn.prepareStatement(sql); stmt.setString(1, username); @@ -1128,7 +1283,7 @@ public abstract class AbstractGroupDAOImpl implements GroupDAO { } - @Override + @Override public List getAllDevicesOfGroup(String groupName, int tenantId) throws GroupManagementDAOException { Connection conn; List devices; diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java index f2aeaed327a..6a786a0bfd8 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/impl/group/PostgreSQLGroupDAOImpl.java @@ -18,6 +18,9 @@ package io.entgra.device.mgt.core.device.mgt.core.dao.impl.group; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; import io.entgra.device.mgt.core.device.mgt.common.Device; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException; @@ -39,6 +42,7 @@ import java.util.List; */ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { + private static final Log log = LogFactory.getLog(PostgreSQLGroupDAOImpl.class); @Override public int addGroup(DeviceGroup deviceGroup, int tenantId) throws GroupManagementDAOException { PreparedStatement stmt = null; @@ -49,7 +53,7 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { Connection conn = GroupManagementDAOFactory.getConnection(); String sql; if(StringUtils.isEmpty(deviceGroup.getStatus())) { - sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH) " + + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, PARENT_GROUP_ID) " + "VALUES (?, ?, ?, ?) RETURNING ID"; } else { sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, STATUS) " + @@ -79,6 +83,46 @@ public class PostgreSQLGroupDAOImpl extends AbstractGroupDAOImpl { } } + @Override + public int addGroupWithRoles(DeviceGroupRoleWrapper groups, int tenantId) throws GroupManagementDAOException { + int groupId = -1; + boolean hasStatus = false; + try { + Connection conn = GroupManagementDAOFactory.getConnection(); + String sql; + if (StringUtils.isEmpty(groups.getStatus())) { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH) " + + "VALUES (?, ?, ?, ?) RETURNING ID"; + } else { + sql = "INSERT INTO DM_GROUP(DESCRIPTION, GROUP_NAME, OWNER, TENANT_ID, PARENT_PATH, STATUS) " + + "VALUES (?, ?, ?, ?, ?) RETURNING ID"; + hasStatus = true; + } + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, groups.getDescription()); + stmt.setString(2, groups.getName()); + stmt.setString(3, groups.getOwner()); + stmt.setInt(4, tenantId); + stmt.setString(5, groups.getParentPath()); + if (hasStatus) { + stmt.setString(6, groups.getStatus()); + } + stmt.execute(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + groupId = rs.getInt(1); + } + return groupId; + } + } + } catch (SQLException e) { + String msg = "Error occurred while adding deviceGroup '" + + groups.getName() + "'"; + log.error(msg); + throw new GroupManagementDAOException(msg, e); + } + } + @Override public List getDevices(int groupId, int startIndex, int rowCount, int tenantId) throws GroupManagementDAOException { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/util/GroupManagementDAOUtil.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/util/GroupManagementDAOUtil.java index acf8d4c6146..42307e6b74c 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/util/GroupManagementDAOUtil.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/dao/util/GroupManagementDAOUtil.java @@ -87,6 +87,7 @@ public final class GroupManagementDAOUtil { group.setOwner(resultSet.getString("OWNER")); group.setStatus(resultSet.getString("STATUS")); group.setParentPath(resultSet.getString("PARENT_PATH")); + group.setParentGroupId(resultSet.getInt("PARENT_GROUP_ID")); return group; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java index a901ffeddf1..3fa8fdc4530 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/internal/DeviceManagementDataHolder.java @@ -118,18 +118,18 @@ public class DeviceManagementDataHolder { public void setRealmService(RealmService realmService) { this.realmService = realmService; - this.setTenantManager(realmService); + setTenantManager(realmService != null ? + realmService.getTenantManager() : null); } public TenantManager getTenantManager() { - return tenantManager; - } - - private void setTenantManager(RealmService realmService) { - if (realmService == null) { - throw new IllegalStateException("Realm service is not initialized properly"); + if (tenantManager == null) { + throw new IllegalStateException("Tenant manager is not initialized properly"); } - this.tenantManager = realmService.getTenantManager(); + return tenantManager; } + + private void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; } public DeviceManagementProviderService getDeviceManagementProvider() { diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java index 5e5ca5c13d0..e7524759395 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/operation/mgt/OperationManagerImpl.java @@ -19,6 +19,23 @@ package io.entgra.device.mgt.core.device.mgt.core.operation.mgt; import io.entgra.device.mgt.core.device.mgt.common.*; +import com.google.gson.Gson; +import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.device.mgt.core.notification.logger.DeviceConnectivityLogContext; +import io.entgra.device.mgt.core.notification.logger.impl.EntgraDeviceConnectivityLoggerImpl; +import io.entgra.device.mgt.core.notification.logger.impl.EntgraPolicyLoggerImpl; +import org.apache.commons.lang.StringUtils; +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.DeviceIdentifier; +import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext; +import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo; +import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation; +import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig; +import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.authorization.DeviceAccessAuthorizationException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.InvalidDeviceException; @@ -68,7 +85,8 @@ import java.util.concurrent.ThreadPoolExecutor; */ public class OperationManagerImpl implements OperationManager { - private static final Log log = LogFactory.getLog(OperationManagerImpl.class); + DeviceConnectivityLogContext.Builder deviceConnectivityLogContextBuilder = new DeviceConnectivityLogContext.Builder(); + private static final EntgraLogger log = new EntgraDeviceConnectivityLoggerImpl(OperationManagerImpl.class); private static final int CACHE_VALIDITY_PERIOD = 5 * 60 * 1000; private static final String NOTIFIER_TYPE_LOCAL = "LOCAL"; private static final String SYSTEM = "system"; @@ -151,6 +169,8 @@ public class OperationManagerImpl implements OperationManager { } } + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); DeviceIDHolder deviceValidationResult = DeviceManagerUtil.validateDeviceIdentifiers(deviceIds); List validDeviceIds = deviceValidationResult.getValidDeviceIDList(); if (!validDeviceIds.isEmpty()) { @@ -227,6 +247,10 @@ public class OperationManagerImpl implements OperationManager { activity.setActivityStatus( this.getActivityStatus(deviceValidationResult, deviceAuthorizationResult)); } + for (DeviceIdentifier deviceId : authorizedDeviceIds) { + device = getDevice(deviceId); + log.info("Operation added", deviceConnectivityLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(deviceType).setActionTag("ADD_OPERATION").setTenantDomain(tenantDomain).setTenantId(tenantId).setUserName(initiatedBy).setOperationCode(operationCode).build()); + } return activity; } catch (OperationManagementDAOException e) { OperationManagementDAOFactory.rollbackTransaction(); @@ -448,6 +472,7 @@ public class OperationManagerImpl implements OperationManager { int failAttempts = 0; while (true) { try { + OperationManagementDAOFactory.beginTransaction(); operationMappingDAO.updateOperationMapping(operation.getId(), device.getEnrolmentInfo().getId(), io.entgra.device.mgt.core.device.mgt.core.dto.operation.mgt.Operation.PushNotificationStatus.SCHEDULED); OperationManagementDAOFactory.commitTransaction(); @@ -470,6 +495,11 @@ public class OperationManagerImpl implements OperationManager { } catch (InterruptedException ignore) { break; } + } catch (TransactionManagementException ex) { + log.error("Error occurred while initiating the transaction", ex); + break; + } finally { + OperationManagementDAOFactory.closeConnection(); } } } catch (Exception e) { @@ -673,7 +703,9 @@ public class OperationManagerImpl implements OperationManager { if (log.isDebugEnabled()) { log.debug("Device identifier id:[" + deviceId.getId() + "] type:[" + deviceId.getType() + "]"); } - + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); EnrolmentInfo enrolmentInfo = this.getActiveEnrolmentInfo(deviceId); if (enrolmentInfo == null) { throw new OperationManagementException("Device not found for the given device Identifier:" + @@ -686,16 +718,25 @@ public class OperationManagerImpl implements OperationManager { case INACTIVE: case UNREACHABLE: this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE); - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); DeviceCacheManagerImpl.getInstance().removeDeviceFromCache(deviceId, tenantId); break; } - + log.info("Device Connected", deviceConnectivityLogContextBuilder + .setDeviceId(deviceId.getId()) + .setDeviceType(deviceId.getType()) + .setActionTag("PENDING_OPERATION") + .setTenantDomain(tenantDomain) + .setTenantId(String.valueOf(tenantId)) + .setUserName(userName) + .build()); return getOperations(deviceId, Operation.Status.PENDING, enrolmentId); } @Override public List getPendingOperations(Device device) throws OperationManagementException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); EnrolmentInfo enrolmentInfo = device.getEnrolmentInfo(); if (enrolmentInfo == null) { throw new OperationManagementException("Device not found for the given device Identifier:" + @@ -713,10 +754,10 @@ public class OperationManagerImpl implements OperationManager { this.setEnrolmentStatus(enrolmentId, EnrolmentInfo.Status.ACTIVE); enrolmentInfo.setStatus(EnrolmentInfo.Status.ACTIVE); device.setEnrolmentInfo(enrolmentInfo); - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); DeviceCacheManagerImpl.getInstance().addDeviceToCache(deviceIdentifier, device, tenantId); break; } + log.info("Device Connected", deviceConnectivityLogContextBuilder.setDeviceId(device.getDeviceIdentifier()).setDeviceType(device.getType()).setActionTag("PENDING_OPERATION").setTenantDomain(tenantDomain).setTenantId(String.valueOf(tenantId)).setUserName(userName).build()); return getOperations(deviceIdentifier, Operation.Status.PENDING, enrolmentId); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java index eaac0bf8271..02373de9365 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/dao/impl/GenericOTPManagementDAOImpl.java @@ -18,6 +18,7 @@ package io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.impl; +import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DBConnectionException; import io.entgra.device.mgt.core.device.mgt.common.otp.mgt.dto.OneTimePinDTO; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.AbstractDAOImpl; @@ -25,7 +26,12 @@ import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.dao.OTPManagementDAO; import io.entgra.device.mgt.core.device.mgt.core.otp.mgt.exception.OTPManagementDAOException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; - +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.exceptions.DBConnectionException; +import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; +import org.wso2.carbon.device.mgt.core.otp.mgt.dao.AbstractDAOImpl; +import org.wso2.carbon.device.mgt.core.otp.mgt.dao.OTPManagementDAO; +import org.wso2.carbon.device.mgt.core.otp.mgt.exception.OTPManagementDAOException; import java.sql.*; import java.util.Calendar; import java.util.List; @@ -51,7 +57,8 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM + "META_INFO, " + "CREATED_AT," + "TENANT_ID," - + "USERNAME) VALUES (?, ?, ?, ?, ?, ?, ?)"; + + "USERNAME, " + + "EXPIRY_TIME) VALUES (?, ?, ?, ?, ?, ?, ?, ?)"; try { Connection conn = this.getDBConnection(); Calendar calendar = Calendar.getInstance(); @@ -65,6 +72,8 @@ public class GenericOTPManagementDAOImpl extends AbstractDAOImpl implements OTPM stmt.setTimestamp(5, timestamp); stmt.setInt(6, oneTimePinDTO.getTenantId()); stmt.setString(7, oneTimePinDTO.getUsername()); + stmt.setInt(8, oneTimePinDTO.getExpiryTime() == 0 + ? DeviceManagementConstants.OTPProperties.OTP_DEFAULT_EXPIRY_SECONDS : oneTimePinDTO.getExpiryTime()); stmt.addBatch(); } stmt.executeBatch(); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java index 087cf3851f9..074eb8eed78 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/otp/mgt/service/OTPManagementServiceImpl.java @@ -117,7 +117,8 @@ public class OTPManagementServiceImpl implements OTPManagementService { } @Override - public OneTimePinDTO isValidOTP(String oneTimeToken) throws OTPManagementException, BadRequestException { + public OneTimePinDTO isValidOTP(String oneTimeToken, boolean requireRenewal) throws OTPManagementException, + BadRequestException { if (StringUtils.isBlank(oneTimeToken)){ String msg = "Received blank OTP to verify. OTP: " + oneTimeToken; log.error(msg); @@ -141,17 +142,19 @@ public class OTPManagementServiceImpl implements OTPManagementService { oneTimePinDTO.getCreatedAt().getTime() + oneTimePinDTO.getExpiryTime() * 1000L); if (currentTimestamp.after(expiredTimestamp)) { - String renewedOTP = UUID.randomUUID().toString(); - renewOTP(oneTimePinDTO, renewedOTP); - Gson gson = new Gson(); - Tenant tenant = gson.fromJson(oneTimePinDTO.getMetaInfo(), Tenant.class); + if (requireRenewal) { + String renewedOTP = UUID.randomUUID().toString(); + renewOTP(oneTimePinDTO, renewedOTP); + Gson gson = new Gson(); + Tenant tenant = gson.fromJson(oneTimePinDTO.getMetaInfo(), Tenant.class); - Properties props = new Properties(); - props.setProperty("first-name", tenant.getAdminFirstName()); - props.setProperty("otp-token", renewedOTP); - props.setProperty("email", oneTimePinDTO.getEmail()); - props.setProperty("type", oneTimePinDTO.getEmailType()); - sendMail(props, oneTimePinDTO.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); + Properties props = new Properties(); + props.setProperty("first-name", tenant.getAdminFirstName()); + props.setProperty("otp-token", renewedOTP); + props.setProperty("email", oneTimePinDTO.getEmail()); + props.setProperty("type", oneTimePinDTO.getEmailType()); + sendMail(props, oneTimePinDTO.getEmail(), DeviceManagementConstants.EmailAttributes.USER_VERIFY_TEMPLATE); + } return null; } return oneTimePinDTO; @@ -224,9 +227,6 @@ public class OTPManagementServiceImpl implements OTPManagementService { } } } - int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); - OneTimePinDTO oneTimePinDTO; - List oneTimePinDTOList = new ArrayList<>(); Properties props = new Properties(); props.setProperty("enrollment-steps", enrollmentSteps.toString()); try { @@ -234,16 +234,11 @@ public class OTPManagementServiceImpl implements OTPManagementService { for (String username : deviceEnrollmentInvitation.getUsernames()) { String emailAddress = DeviceManagerUtil.getUserClaimValue( username, DeviceManagementConstants.User.CLAIM_EMAIL_ADDRESS); - oneTimePinDTO = generateOneTimePin(emailAddress, OTPEmailTypes.DEVICE_ENROLLMENT.toString(), username, - null, tenantId, false); - oneTimePinDTOList.add(oneTimePinDTO); props.setProperty("first-name", DeviceManagerUtil. getUserClaimValue(username, DeviceManagementConstants.User.CLAIM_FIRST_NAME)); props.setProperty("username", username); - props.setProperty("otp-token", oneTimePinDTO.getOtpToken()); sendMail(props, emailAddress, DeviceManagementConstants.EmailAttributes.USER_ENROLLMENT_TEMPLATE); } - this.otpManagementDAO.addOTPData(oneTimePinDTOList); ConnectionManagerUtil.commitDBTransaction(); } catch (UserStoreException e) { String msg = "Error occurred while getting claim values to invite user"; @@ -257,11 +252,6 @@ public class OTPManagementServiceImpl implements OTPManagementService { String msg = "SQL Error occurred when adding OPT data to send device enrollment Invitation."; log.error(msg, e); throw new OTPManagementException(msg, e); - } catch (OTPManagementDAOException e) { - ConnectionManagerUtil.rollbackDBTransaction(); - String msg = "Error occurred while saving the OTP data."; - log.error(msg, e); - throw new OTPManagementException(msg, e); } finally { ConnectionManagerUtil.closeDBConnection(); } @@ -269,27 +259,17 @@ public class OTPManagementServiceImpl implements OTPManagementService { /** * Create One Time Token - * @param email email - * @param emailType email type - * @param userName username - * @param metaDataObj meta data object - * @param tenantId tenant Id + * @param oneTimePinDTO Data related to the one time pin * @return {@link OneTimePinDTO} */ @Override - public OneTimePinDTO generateOneTimePin(String email, String emailType, String userName, Object metaDataObj, - int tenantId, boolean persistPin) throws OTPManagementException { + public OneTimePinDTO generateOneTimePin(OneTimePinDTO oneTimePinDTO, boolean persistPin) throws OTPManagementException { String otpValue = UUID.randomUUID().toString(); Gson gson = new Gson(); - String metaInfo = gson.toJson(metaDataObj); + String metaInfo = gson.toJson(oneTimePinDTO.getMetaInfo()); - OneTimePinDTO oneTimePinDTO = new OneTimePinDTO(); - oneTimePinDTO.setEmail(email); - oneTimePinDTO.setTenantId(tenantId); - oneTimePinDTO.setUsername(userName); - oneTimePinDTO.setEmailType(emailType); oneTimePinDTO.setMetaInfo(metaInfo); oneTimePinDTO.setOtpToken(otpValue); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index 02d6b010eb8..eb1a60c48c5 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -21,6 +21,30 @@ 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.*; +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 io.entgra.device.mgt.core.device.mgt.common.ActivityPaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.Billing; +import io.entgra.device.mgt.core.device.mgt.common.Device; +import io.entgra.device.mgt.core.device.mgt.common.DeviceEnrollmentInfoNotification; +import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; +import io.entgra.device.mgt.core.device.mgt.common.DeviceManager; +import io.entgra.device.mgt.core.device.mgt.common.DeviceNotification; +import io.entgra.device.mgt.core.device.mgt.common.DevicePropertyNotification; +import io.entgra.device.mgt.core.device.mgt.common.DeviceTransferRequest; +import io.entgra.device.mgt.core.device.mgt.common.DynamicTaskContext; +import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo; +import io.entgra.device.mgt.core.device.mgt.common.FeatureManager; +import io.entgra.device.mgt.core.device.mgt.common.InitialOperationConfig; +import io.entgra.device.mgt.core.device.mgt.common.MonitoringOperation; +import io.entgra.device.mgt.core.device.mgt.common.OperationMonitoringTaskConfig; +import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; +import io.entgra.device.mgt.core.device.mgt.common.StartupOperationConfig; +import io.entgra.device.mgt.core.device.mgt.common.BillingResponse; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.Application; import io.entgra.device.mgt.core.device.mgt.common.app.mgt.ApplicationManagementException; import io.entgra.device.mgt.core.device.mgt.common.configuration.mgt.*; @@ -111,13 +135,27 @@ import java.sql.SQLException; import java.sql.Timestamp; import java.time.LocalDateTime; import java.util.*; +import java.time.LocalTime; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.Collection; +import java.util.Collections; +import java.util.Date; +import java.util.Enumeration; +import java.util.HashMap; +import java.util.HashSet; +import java.util.List; +import java.util.Map; +import java.util.Properties; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; public class DeviceManagementProviderServiceImpl implements DeviceManagementProviderService, PluginInitializationListener { - private static final Log log = LogFactory.getLog(DeviceManagementProviderServiceImpl.class); + DeviceEnrolmentLogContext.Builder deviceEnrolmentLogContextBuilder = new DeviceEnrolmentLogContext.Builder(); + + private static final EntgraLogger log = new EntgraDeviceEnrolmentLoggerImpl(DeviceManagementProviderServiceImpl.class); private static final String OPERATION_RESPONSE_EVENT_STREAM_DEFINITION = "org.wso2.iot.OperationResponseStream"; private final DeviceManagementPluginRepository pluginRepository; @@ -205,6 +243,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } return false; } + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); EnrollmentConfiguration enrollmentConfiguration = DeviceManagerUtil.getEnrollmentConfigurationEntry(); String deviceSerialNumber = null; if (enrollmentConfiguration != null) { @@ -291,6 +331,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv device.getType() + " upon the user '" + device.getEnrolmentInfo().getOwner() + "'"); } + log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder + .setDeviceId(String.valueOf(existingDevice.getId())) + .setDeviceType(String.valueOf(existingDevice.getType())) + .setOwner(newEnrolmentInfo.getOwner()) + .setOwnership(String.valueOf(newEnrolmentInfo.getOwnership())) + .setTenantID(String.valueOf(tenantId)) + .setTenantDomain(tenantDomain) + .setUserName(userName) + .build()); status = true; } else { log.warn("Unable to update device enrollment for device : " + device.getDeviceIdentifier() + @@ -327,6 +376,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } device.setEnrolmentInfo(enrollment); DeviceManagementDAOFactory.commitTransaction(); + log.info("Device enrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(String.valueOf(device.getType())).setOwner(enrollment.getOwner()).setOwnership(String.valueOf(enrollment.getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build()); } else { DeviceManagementDAOFactory.rollbackTransaction(); throw new DeviceManagementException("No device type registered with name - " + device.getType() @@ -404,6 +454,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv if (log.isDebugEnabled()) { log.debug("Modifying enrollment for device: " + device.getId() + " of type '" + device.getType() + "'"); } + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); DeviceManager deviceManager = this.getDeviceManager(device.getType()); DeviceIdentifier deviceIdentifier = new DeviceIdentifier(device.getDeviceIdentifier(), device.getType()); if (deviceManager == null) { @@ -432,6 +484,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv enrollmentDAO.updateEnrollment(device.getEnrolmentInfo(), tenantId); 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()); this.removeDeviceFromCache(deviceIdentifier); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); @@ -515,7 +568,8 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } int tenantId = this.getTenantId(); - + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); Device device = this.getDevice(deviceId, false); if (device == null) { if (log.isDebugEnabled()) { @@ -549,7 +603,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv } } //procees to dis-enroll a device from traccar ends - + log.info("Device disenrolled successfully", deviceEnrolmentLogContextBuilder.setDeviceId(String.valueOf(device.getId())).setDeviceType(String.valueOf(device.getType())).setOwner(device.getEnrolmentInfo().getOwner()).setOwnership(String.valueOf(device.getEnrolmentInfo().getOwnership())).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).setUserName(userName).build()); } catch (DeviceManagementDAOException e) { DeviceManagementDAOFactory.rollbackTransaction(); String msg = "Error occurred while dis-enrolling '" + deviceId.getType() + @@ -1006,7 +1060,15 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv dateDiff = endDate.getTime() - device.getEnrolmentInfo().getDateOfEnrolment(); } } - long dateInDays = TimeUnit.DAYS.convert(dateDiff, TimeUnit.MILLISECONDS); + + // Convert dateDiff to days as a decimal value + double dateDiffInDays = (double) dateDiff / (24 * 60 * 60 * 1000); + + if (dateDiffInDays % 1 >= 0.9) { + dateDiffInDays = Math.ceil(dateDiffInDays); + } + + long dateInDays = (long) dateDiffInDays; double cost = (tenantCost.getCost() / 365) * dateInDays; totalCost += cost; device.setCost(Math.round(cost * 100.0) / 100.0); @@ -1073,9 +1135,13 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv long difference_In_Days = (difference_In_Time / (1000 * 60 * 60 * 24)) % 365; + if (difference_In_Time % (1000 * 60 * 60 * 24) >= 0.9 * (1000 * 60 * 60 * 24)) { + difference_In_Days++; + } + for (int i = 1; i <= difference_In_Years; i++) { List allDevicesPerYear = new ArrayList<>(); - LocalDateTime oneYearAfterStart = startDate.toLocalDateTime().plusYears(1); + LocalDateTime oneYearAfterStart = startDate.toLocalDateTime().plusYears(1).with(LocalTime.of(23, 59, 59));; Timestamp newStartDate; Timestamp newEndDate; @@ -1084,14 +1150,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv remainingDaysConsidered = true; oneYearAfterStart = startDate.toLocalDateTime(); newEndDate = endDate; - } else if (Timestamp.valueOf(oneYearAfterStart).getTime() >= endDate.getTime()) { - newEndDate = Timestamp.valueOf(oneYearAfterStart); } else { - oneYearAfterStart = startDate.toLocalDateTime().plusYears(1); + oneYearAfterStart = startDate.toLocalDateTime().plusYears(1).with(LocalTime.of(23, 59, 59));; newEndDate = Timestamp.valueOf(oneYearAfterStart); } } else { - oneYearAfterStart = startDate.toLocalDateTime().plusYears(1); + oneYearAfterStart = startDate.toLocalDateTime().plusYears(1).with(LocalTime.of(23, 59, 59));; newEndDate = Timestamp.valueOf(oneYearAfterStart); } @@ -1114,7 +1178,7 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv allDevices.addAll(billingResponse.getDevice()); totalCost = totalCost + billingResponse.getTotalCostPerYear(); deviceCount = deviceCount + billingResponse.getDeviceCount(); - LocalDateTime nextStartDate = oneYearAfterStart.plusDays(1); + LocalDateTime nextStartDate = oneYearAfterStart.plusDays(1).with(LocalTime.of(00, 00, 00)); startDate = Timestamp.valueOf(nextStartDate); } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java index 1bae5b30ce5..ef2338688f7 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderService.java @@ -24,6 +24,15 @@ import io.entgra.device.mgt.core.device.mgt.common.GroupPaginationRequest; import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException; import io.entgra.device.mgt.core.device.mgt.common.group.mgt.*; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroup; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceTypesOfGroups; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; +import org.wso2.carbon.user.api.AuthorizationManager; +import org.wso2.carbon.user.api.UserStoreManager; import java.util.List; @@ -43,6 +52,16 @@ public interface GroupManagementProviderService { void createGroup(DeviceGroup deviceGroup, String defaultRole, String[] defaultPermissions) throws GroupManagementException, GroupAlreadyExistException; + /** + * Add new device group and create default role with default permissions. + * + * @param groups to add + * @param defaultRole of the deviceGroup + * @param defaultPermissions of the default role + * @throws GroupManagementException + */ + void createGroupWithRoles(DeviceGroupRoleWrapper groups, String defaultRole, String[] defaultPermissions) throws GroupAlreadyExistException,GroupManagementException, RoleDoesNotExistException; + /** * Update existing device group. * @@ -63,6 +82,18 @@ public interface GroupManagementProviderService { */ boolean deleteGroup(int groupId, boolean isDeleteChildren) throws GroupManagementException; + /** + * Delete existing device group. + * + * @param role to be deleted with the userStore name. + * @param roleToDelete to delete the role. + * @param tenantId to belongs to roles. + * @param userStoreManager with details. + * @param authorizationManager with details. + * @throws GroupManagementException + */ + void deleteRoleAndRoleGroupMapping(String role, String roleToDelete, int tenantId, UserStoreManager userStoreManager, AuthorizationManager authorizationManager) throws GroupManagementException; + /** * Get the device group provided the device group id. * diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java index c605a8ebe7b..a35d4d74bb0 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/main/java/io/entgra/device/mgt/core/device/mgt/core/service/GroupManagementProviderServiceImpl.java @@ -19,6 +19,23 @@ 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.group.mgt.DeviceGroup; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupConstants; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceGroupRoleWrapper; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.DeviceTypesOfGroups; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupAlreadyExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupManagementException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.GroupNotExistException; +import io.entgra.device.mgt.core.device.mgt.common.group.mgt.RoleDoesNotExistException; +import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceDAO; +import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOException; +import io.entgra.device.mgt.core.device.mgt.core.dao.DeviceManagementDAOFactory; +import io.entgra.device.mgt.core.device.mgt.core.dao.GroupDAO; +import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOException; +import io.entgra.device.mgt.core.device.mgt.core.dao.GroupManagementDAOFactory; +import io.entgra.device.mgt.core.device.mgt.common.Device; +import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier; +import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceNotFoundException; import io.entgra.device.mgt.core.device.mgt.common.exceptions.TransactionManagementException; @@ -35,12 +52,20 @@ import org.apache.commons.logging.LogFactory; 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.GroupPaginationRequest; +import io.entgra.device.mgt.core.device.mgt.common.PaginationResult; +import org.wso2.carbon.user.api.AuthorizationManager; import org.wso2.carbon.user.api.UserRealm; import org.wso2.carbon.user.api.UserStoreException; import org.wso2.carbon.user.api.UserStoreManager; import java.sql.SQLException; import java.util.*; +import java.util.ArrayList; +import java.util.HashMap; +import java.util.Iterator; +import java.util.List; +import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.stream.Collectors; @@ -125,6 +150,59 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } + public void createGroupWithRoles(DeviceGroupRoleWrapper groups, String defaultRole, String[] defaultPermissions) throws GroupAlreadyExistException, GroupManagementException { + if (groups == null) { + String msg = "Received incomplete data for createGroup"; + log.error(msg); + throw new GroupManagementException(msg); + } + if (log.isDebugEnabled()) { + log.debug("Creating group '" + groups.getName() + "'"); + } + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + try { + GroupManagementDAOFactory.beginTransaction(); + DeviceGroup existingGroup = this.groupDAO.getGroup(groups.getName(), tenantId); + if (existingGroup == null) { + if (groups.getParentGroupId() == 0) { + groups.setParentPath(DeviceGroupConstants.HierarchicalGroup.SEPERATOR); + } else { + DeviceGroup immediateParentGroup = groupDAO.getGroup(groups.getParentGroupId(), tenantId); + if (immediateParentGroup == null) { + GroupManagementDAOFactory.rollbackTransaction(); + String msg = "Parent group with group ID '" + groups.getParentGroupId() + "' does not exist. Hence creating of group '" + groups.getName() + "' was not success"; + log.error(msg); + throw new GroupManagementException(msg); + } + String parentPath = DeviceManagerUtil.createParentPath(immediateParentGroup); + groups.setParentPath(parentPath); + } + int updatedGroupID = this.groupDAO.addGroupWithRoles(groups, tenantId); + if (groups.getGroupProperties() != null && groups.getGroupProperties().size() > 0) { + this.groupDAO.addGroupPropertiesWithRoles(groups, updatedGroupID, tenantId); + } + GroupManagementDAOFactory.commitTransaction(); + } else { + throw new GroupAlreadyExistException("Group already exists with name : " + groups.getName() + " Try with another group name."); + } + } catch (GroupManagementDAOException e) { + GroupManagementDAOFactory.rollbackTransaction(); + String msg = e.getMessage(); + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } finally { + GroupManagementDAOFactory.closeConnection(); + } + + if (log.isDebugEnabled()) { + log.debug("DeviceGroup added: " + groups.getName()); + } + } + /** * {@inheritDoc} */ @@ -236,6 +314,13 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid newParentPath = DeviceGroupConstants.HierarchicalGroup.SEPERATOR; } childrenGroup.setParentPath(newParentPath); + if (!DeviceGroupConstants.HierarchicalGroup.SEPERATOR.equals(newParentPath)) { + String[] groupIds = newParentPath.split(DeviceGroupConstants.HierarchicalGroup.SEPERATOR); + int latestGroupId = Integer.parseInt(groupIds[groupIds.length - 1]); + childrenGroup.setParentGroupId(latestGroupId); + } else { + childrenGroup.setParentGroupId(0); + } } } } @@ -276,6 +361,40 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } } + /** + * {@inheritDoc} + */ + @Override + public void deleteRoleAndRoleGroupMapping(String roleName, String roleToDelete, int tenantId, UserStoreManager userStoreManager, AuthorizationManager authorizationManager) throws GroupManagementException { + if (log.isDebugEnabled()) { + log.debug("Delete roles"); + } + try { + GroupManagementDAOFactory.beginTransaction(); + groupDAO.deleteGroupsMapping(roleToDelete, tenantId); + userStoreManager.deleteRole(roleName); + // Delete all authorizations for the current role before deleting + authorizationManager.clearRoleAuthorization(roleName); + GroupManagementDAOFactory.commitTransaction(); + } catch (UserStoreException e) { + GroupManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while deleting the role '" + roleName + "'"; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (TransactionManagementException e) { + String msg = "Error occurred while initiating transaction."; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } catch (GroupManagementDAOException e) { + GroupManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while deleting the role"; + log.error(msg, e); + throw new GroupManagementException(msg, e); + } finally { + GroupManagementDAOFactory.closeConnection(); + } + } + /** * {@inheritDoc} */ @@ -442,7 +561,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid @Override public PaginationResult getGroupsWithHierarchy(String username, GroupPaginationRequest request, - boolean requireGroupProps) throws GroupManagementException { + boolean requireGroupProps) throws GroupManagementException { if (request == null) { String msg = "Received incomplete data for retrieve groups with hierarchy"; log.error(msg); @@ -451,6 +570,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid if (log.isDebugEnabled()) { log.debug("Get groups with hierarchy " + request.toString()); } + boolean isWithParentPath = false; DeviceManagerUtil.validateGroupListPageSize(request); List rootGroups; try { @@ -462,7 +582,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid } else { List allDeviceGroupIdsOfUser = getGroupIds(username); GroupManagementDAOFactory.openConnection(); - rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId); + rootGroups = this.groupDAO.getGroups(request, allDeviceGroupIdsOfUser, tenantId, isWithParentPath); } String parentPath; List childrenGroups; @@ -1283,7 +1403,7 @@ public class GroupManagementProviderServiceImpl implements GroupManagementProvid * @throws GroupManagementDAOException on error during population of group properties. */ private void createGroupWithChildren(DeviceGroup parentGroup, List childrenGroups, - boolean requireGroupProps, int tenantId, int depth, int counter) throws GroupManagementDAOException { + boolean requireGroupProps, int tenantId, int depth, int counter) throws GroupManagementDAOException { if (childrenGroups.isEmpty() || depth == counter) { return; } diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql index d22d8f312fc..4f83fa5b5ed 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.core/src/test/resources/sql/h2.sql @@ -16,6 +16,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( OWNER VARCHAR(45) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/pom.xml index a9814241de5..c12f494f374 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -78,7 +78,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.url.printer/pom.xml b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.url.printer/pom.xml index 57ff12e288f..d0ecba20649 100644 --- a/components/device-mgt/io.entgra.device.mgt.core.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/io.entgra.device.mgt.core.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/exception/StorageManagementException.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/exception/StorageManagementException.java new file mode 100644 index 00000000000..38985716deb --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/common/exception/StorageManagementException.java @@ -0,0 +1,32 @@ +/* Copyright (c) 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 org.wso2.carbon.device.mgt.core.common.exception; + +/** + * Represents the exception thrown during storing and retrieving the artifacts. + */ +public class StorageManagementException extends Exception { + public StorageManagementException(String message, Throwable ex) { + super(message, ex); + } + + public StorageManagementException(String message) { + super(message); + } +} + diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index cb1c9dba670..7e01efb3242 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.device.mgt.core.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.device.mgt.core.server.bootup.heartbeat.beacon/pom.xml index 99713117887..e6848b89c81 100644 --- a/components/heartbeat-management/io.entgra.device.mgt.core.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.device.mgt.core.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core heartbeat-management - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index 819685280bf..7bf1a8fbdb9 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/io.entgra.device.mgt.core.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/io.entgra.device.mgt.core.device.mgt.oauth.extensions/pom.xml index fa60f27f1e4..8bf81024df5 100644 --- a/components/identity-extensions/io.entgra.device.mgt.core.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/io.entgra.device.mgt.core.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core identity-extensions - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/pom.xml b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/pom.xml index 8b646fa964e..e5157d6a82f 100644 --- a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core identity-extensions - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -155,7 +155,12 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 + test + + + org.mockito + mockito-core test @@ -253,12 +258,19 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + file:src/test/resources/log4j.properties src/test/resources/testng.xml + + org.ops4j.pax.logging + diff --git a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/main/java/io/entgra/device/mgt/core/identity/jwt/client/extension/internal/JWTClientExtensionDataHolder.java b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/main/java/io/entgra/device/mgt/core/identity/jwt/client/extension/internal/JWTClientExtensionDataHolder.java index 7d253b2333e..cd3999c9bf7 100644 --- a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/main/java/io/entgra/device/mgt/core/identity/jwt/client/extension/internal/JWTClientExtensionDataHolder.java +++ b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/main/java/io/entgra/device/mgt/core/identity/jwt/client/extension/internal/JWTClientExtensionDataHolder.java @@ -74,17 +74,18 @@ public class JWTClientExtensionDataHolder { public void setRealmService(RealmService realmService) { this.realmService = realmService; - this.setTenantManager(realmService); + setTenantManager(realmService != null ? + realmService.getTenantManager() : null); } - private void setTenantManager(RealmService realmService) { - if (realmService == null) { - throw new IllegalStateException("Realm service is not initialized properly"); - } - this.tenantManager = realmService.getTenantManager(); + private void setTenantManager(TenantManager tenantManager) { + this.tenantManager = tenantManager; } public TenantManager getTenantManager() { + if (tenantManager == null) { + throw new IllegalStateException("Tenant manager is not initialized properly"); + } return tenantManager; } } diff --git a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/java/io/entgra/device/mgt/core/identity/jwt/client/extension/service/JWTClientTest.java b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/java/io/entgra/device/mgt/core/identity/jwt/client/extension/service/JWTClientTest.java index d497d5e1080..beb7db9962e 100644 --- a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/java/io/entgra/device/mgt/core/identity/jwt/client/extension/service/JWTClientTest.java +++ b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/java/io/entgra/device/mgt/core/identity/jwt/client/extension/service/JWTClientTest.java @@ -43,9 +43,10 @@ import java.security.NoSuchAlgorithmException; import java.util.HashMap; import java.util.Map; import java.util.Properties; +import org.powermock.modules.testng.PowerMockTestCase; @PrepareForTest(JWTClientUtil.class) -public class JWTClientTest { +public class JWTClientTest extends PowerMockTestCase{ private static final Log log = LogFactory.getLog(JWTClientTest.class); @ObjectFactory diff --git a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/resources/user-test/user-mgt-registry-test.xml b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/resources/user-test/user-mgt-registry-test.xml index fc32a2698d0..96fd6acfff1 100644 --- a/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/resources/user-test/user-mgt-registry-test.xml +++ b/components/identity-extensions/io.entgra.device.mgt.core.identity.jwt.client.extension/src/test/resources/user-test/user-mgt-registry-test.xml @@ -27,7 +27,7 @@ everyone false 500 - jdbc:h2:target/databasetest/CARBON_TEST + jdbc:h2:./target/databasetest/CARBON_TEST org.h2.Driver 50 60000 diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index 216bfb4d71e..bc0478f310f 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/pom.xml b/components/logger/io.entgra.device.mgt.core.notification.logger/pom.xml index 324934a4dd4..70ca947ed2c 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/pom.xml +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core logger - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT io.entgra.device.mgt.core.notification.logger diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/AppInstallLogContext.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/AppInstallLogContext.java new file mode 100644 index 00000000000..33cffac3666 --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/AppInstallLogContext.java @@ -0,0 +1,181 @@ +/* + * 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.notification.logger; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; + +public class AppInstallLogContext extends LogContext { + private final String appId; + private final String appName; + private final String appType; + private final String subType; + private final String tenantId; + private final String tenantDomain; + private final String device; + private final String userName; + private final String action; + + private AppInstallLogContext(Builder builder) { + this.appId = builder.appId; + this.appName = builder.appName; + this.appType = builder.appType; + this.subType = builder.subType; + this.tenantId = builder.tenantId; + this.tenantDomain = builder.tenantDomain; + this.device = builder.device; + this.userName = builder.userName; + this.action = builder.action; + } + + public String getAppId() { + return appId; + } + + public String getAppName() { + return appName; + } + + public String getAppType() { + return appType; + } + + public String getSubType() { + return subType; + } + + public String getTenantId() { + return tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public String getDevice() { + return device; + } + + public String getUserName() { + return userName; + } + + public String getAction() { + return action; + } + + public static class Builder { + private String appId; + private String appName; + private String appType; + private String subType; + private String tenantId; + private String tenantDomain; + private String device; + private String userName; + private String action; + + public Builder() { + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getAppId() { + return appId; + } + + public Builder setAppId(String appId) { + this.appId = appId; + return this; + } + + public String getAppName() { + return appName; + } + + public Builder setAppName(String appName) { + this.appName = appName; + return this; + } + + public String getAppType() { + return appType; + } + + public Builder setAppType(String appType) { + this.appType = appType; + return this; + } + + public String getSubType() { + return subType; + } + + public Builder setSubType(String subType) { + this.subType = subType; + return this; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public Builder setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + return this; + } + + public String getTenantId() { + return tenantId; + } + + public Builder setTenantId(String tenantId) { + this.tenantId = tenantId; + return this; + } + + public String getDevice() { + return device; + } + + public Builder setDevice(String device) { + this.device = device; + return this; + } + + public String getAction() { + return action; + } + + public Builder setAction(String action) { + this.action = action; + return this; + } + + public AppInstallLogContext build() { + return new AppInstallLogContext(this); + } + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceConnectivityLogContext.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceConnectivityLogContext.java new file mode 100644 index 00000000000..d110e84a43b --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceConnectivityLogContext.java @@ -0,0 +1,150 @@ +/* + * 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.notification.logger; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; + +public class DeviceConnectivityLogContext extends LogContext { + + private final String deviceId; + private final String deviceType; + private final String actionTag; + private final String operationCode; + private final String tenantId; + private final String tenantDomain; + private final String userName; + + private DeviceConnectivityLogContext(Builder builder) { + this.deviceId = builder.deviceId; + this.deviceType = builder.deviceType; + this.actionTag = builder.actionTag; + this.operationCode = builder.operationCode; + this.tenantId = builder.tenantId; + this.tenantDomain = builder.tenantDomain; + this.userName = builder.userName; + } + + public String getDeviceId() { + return deviceId; + } + + public String getDeviceType() { + return deviceType; + } + + public String getActionTag() { + return actionTag; + } + + public String getOperationCode() { + return operationCode; + } + + public String getTenantId() { + return tenantId; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public String getUserName() { + return userName; + } + + public static class Builder { + private String deviceId; + private String deviceType; + private String operationCode; + private String actionTag; + private String tenantId; + private String tenantDomain; + private String userName; + + public Builder() { + } + + public String getDeviceId() { + return deviceId; + } + + public Builder setDeviceId(String deviceId) { + this.deviceId = deviceId; + return this; + } + + public String getDeviceType() { + return deviceType; + } + + public Builder setDeviceType(String deviceType) { + this.deviceType = deviceType; + return this; + } + + public String getOperationCode() { + return operationCode; + } + + public Builder setOperationCode(String operationCode) { + this.operationCode = operationCode; + return this; + } + + public String getTenantId() { + return tenantId; + } + + public Builder setTenantId(String tenantId) { + this.tenantId = tenantId; + return this; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public Builder setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + return this; + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getActionTag() { + return actionTag; + } + + public Builder setActionTag(String actionTag) { + this.actionTag = actionTag; + return this; + } + + public DeviceConnectivityLogContext build() { + return new DeviceConnectivityLogContext(this); + } + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceEnrolmentLogContext.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceEnrolmentLogContext.java new file mode 100644 index 00000000000..b355b296716 --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/DeviceEnrolmentLogContext.java @@ -0,0 +1,149 @@ +/* + * 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.notification.logger; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; + +public class DeviceEnrolmentLogContext extends LogContext { + private final String deviceId; + private final String deviceType; + private final String owner; + private final String ownership; + private final String tenantID; + private final String tenantDomain; + private final String userName; + + private DeviceEnrolmentLogContext(Builder builder) { + this.deviceId = builder.deviceId; + this.deviceType = builder.deviceType; + this.owner = builder.owner; + this.ownership = builder.ownership; + this.tenantID = builder.tenantID; + this.tenantDomain = builder.tenantDomain; + this.userName = builder.userName; + } + + public String getTenantID() { + return tenantID; + } + + public String getDeviceId() { + return deviceId; + } + + public String getOwner() { + return owner; + } + + public String getDeviceType() { + return deviceType; + } + + public String getOwnership() { + return ownership; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public String getUserName() { + return userName; + } + public static class Builder { + private String deviceId; + private String deviceType; + private String owner; + private String ownership; + private String tenantID; + private String tenantDomain; + private String userName; + + public Builder() { + } + + public String getDeviceType() { + return deviceType; + } + + public Builder setDeviceType(String deviceType) { + this.deviceType = deviceType; + return this; + } + + public String getTenantID() { + return tenantID; + } + + public Builder setTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public Builder setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + return this; + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getDeviceId() { + return deviceId; + } + + public Builder setDeviceId(String deviceId) { + this.deviceId = deviceId; + return this; + } + + public String getOwner() { + return owner; + } + + public Builder setOwner(String owner) { + this.owner = owner; + return this; + } + + public String getOwnership() { + return ownership; + } + + public Builder setOwnership(String ownership) { + this.ownership = ownership; + return this; + } + + public DeviceEnrolmentLogContext build() { + return new DeviceEnrolmentLogContext(this); + } + + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/PolicyLogContext.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/PolicyLogContext.java new file mode 100644 index 00000000000..9dbd10a0592 --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/PolicyLogContext.java @@ -0,0 +1,133 @@ +/* + * 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.notification.logger; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; + +public class PolicyLogContext extends LogContext { + private final String policyName; + private final String payload; + private final String actionTag; + private final String userName; + private final String tenantID; + private final String tenantDomain; + + private PolicyLogContext(Builder builder) { + this.policyName = builder.policyName; + this.payload = builder.payload; + this.actionTag = builder.actionTag; + this.userName = builder.userName; + this.tenantID = builder.tenantID; + this.tenantDomain = builder.tenantDomain; + } + + public String getPolicyName() { + return policyName; + } + + public String getPayload() { + return payload; + } + + public String getActionTag() { + return actionTag; + } + + public String getUserName() { + return userName; + } + + public String getTenantID() { + return tenantID; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public static class Builder { + private String policyName; + private String payload; + private String actionTag; + private String userName; + private String tenantID; + private String tenantDomain; + + public Builder() { + } + + public String getPolicyName() { + return policyName; + } + + public Builder setPolicyName(String policyName) { + this.policyName = policyName; + return this; + } + + public String getPayload() { + return payload; + } + + public Builder setPayload(String payload) { + this.payload = payload; + return this; + } + + public String getActionTag() { + return actionTag; + } + + public Builder setActionTag(String actionTag) { + this.actionTag = actionTag; + return this; + } + + public String getUserName() { + return userName; + } + + public Builder setUserName(String userName) { + this.userName = userName; + return this; + } + + public String getTenantID() { + return tenantID; + } + + public Builder setTenantID(String tenantID) { + this.tenantID = tenantID; + return this; + } + + public String getTenantDomain() { + return tenantDomain; + } + + public Builder setTenantDomain(String tenantDomain) { + this.tenantDomain = tenantDomain; + return this; + } + + public PolicyLogContext build() { + return new PolicyLogContext(this); + } + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraAppInstallLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraAppInstallLoggerImpl.java new file mode 100644 index 00000000000..81f071c2afe --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraAppInstallLoggerImpl.java @@ -0,0 +1,318 @@ +/* + * 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.notification.logger.impl; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; +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.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + +public class EntgraAppInstallLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraAppInstallLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + public void info(String message) { + log.info(message); + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public void info(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.info(message); + } + + @Override + public void info(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.info(object); + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.info(object, t); + } + + public void debug(String message) { + log.debug(message); + } + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void debug(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.debug(message); + } + + @Override + public void debug(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.debug(object); + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.debug(object, t); + } + + public void error(String message) { + log.error(message); + } + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void error(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.error(message, t); + } + + @Override + public void error(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.error(object); + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.error(object, t); + } + + public void warn(String message) { + log.warn(message); + } + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void warn(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.warn(message, t); + } + + @Override + public void warn(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.warn(object); + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.warn(object, t); + } + + public void trace(String message) { + log.trace(message); + } + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void trace(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.trace(message); + } + + @Override + public void trace(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.trace(object); + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.trace(object, t); + } + + public void fatal(String message) { + log.fatal(message); + } + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void fatal(String message, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.fatal(message); + } + + @Override + public void fatal(Object object, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.fatal(object); + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + AppInstallLogContext appInstallLogContext = (AppInstallLogContext) logContext; + MDCContextUtil.populateAppInstallMDCContext(appInstallLogContext); + log.fatal(object, t); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceConnectivityLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceConnectivityLoggerImpl.java new file mode 100644 index 00000000000..aaa62bf4887 --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceConnectivityLoggerImpl.java @@ -0,0 +1,318 @@ +/* + * 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.notification.logger.impl; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.device.mgt.core.notification.logger.DeviceConnectivityLogContext; +import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + +public class EntgraDeviceConnectivityLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraDeviceConnectivityLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + public void info(String message) { + log.info(message); + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public void info(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.info(message); + } + + @Override + public void info(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.info(object); + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.info(object, t); + } + + public void debug(String message) { + log.debug(message); + } + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void debug(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.debug(message); + } + + @Override + public void debug(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.debug(object); + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.debug(object, t); + } + + public void error(String message) { + log.error(message); + } + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void error(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.error(message, t); + } + + @Override + public void error(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.error(object); + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.error(object, t); + } + + public void warn(String message) { + log.warn(message); + } + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void warn(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.warn(message, t); + } + + @Override + public void warn(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.warn(object); + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.warn(object, t); + } + + public void trace(String message) { + log.trace(message); + } + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void trace(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.trace(message); + } + + @Override + public void trace(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.trace(object); + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.trace(object, t); + } + + public void fatal(String message) { + log.fatal(message); + } + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void fatal(String message, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.fatal(message); + } + + @Override + public void fatal(Object object, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.fatal(object); + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + DeviceConnectivityLogContext deviceConnectivityLogContext = (DeviceConnectivityLogContext) logContext; + MDCContextUtil.populateDeviceConnectivityMDCContext(deviceConnectivityLogContext); + log.fatal(object, t); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceEnrolmentLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceEnrolmentLoggerImpl.java new file mode 100644 index 00000000000..db0b7dd2653 --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceEnrolmentLoggerImpl.java @@ -0,0 +1,318 @@ +/* + * 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.notification.logger.impl; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; +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.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + +public class EntgraDeviceEnrolmentLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraDeviceEnrolmentLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + public void info(String message) { + log.info(message); + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public void info(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.info(message); + } + + @Override + public void info(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.info(object); + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.info(object, t); + } + + public void debug(String message) { + log.debug(message); + } + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void debug(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.debug(message); + } + + @Override + public void debug(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.debug(object); + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.debug(object, t); + } + + public void error(String message) { + log.error(message); + } + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void error(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.error(message, t); + } + + @Override + public void error(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.error(object); + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.error(object, t); + } + + public void warn(String message) { + log.warn(message); + } + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void warn(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.warn(message, t); + } + + @Override + public void warn(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.warn(object); + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.warn(object, t); + } + + public void trace(String message) { + log.trace(message); + } + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void trace(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.trace(message); + } + + @Override + public void trace(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.trace(object); + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.trace(object, t); + } + + public void fatal(String message) { + log.fatal(message); + } + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void fatal(String message, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.fatal(message); + } + + @Override + public void fatal(Object object, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.fatal(object); + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + DeviceEnrolmentLogContext deviceEnrolmentLogContext = (DeviceEnrolmentLogContext) logContext; + MDCContextUtil.populateDeviceEnrolmentMDCContext(deviceEnrolmentLogContext); + log.fatal(object, t); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceLoggerImpl.java index ae10ae87c2f..a51987463f1 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceLoggerImpl.java +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraDeviceLoggerImpl.java @@ -17,7 +17,6 @@ */ package io.entgra.device.mgt.core.notification.logger.impl; - import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.device.mgt.core.notification.logger.DeviceLogContext; @@ -26,7 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.MDC; - public class EntgraDeviceLoggerImpl implements EntgraLogger { private static Log log = null; @@ -74,7 +72,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger { log.info(object, t); } - public void debug(String message) { log.debug(message); } @@ -114,7 +111,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger { log.debug(object, t); } - public void error(String message) { log.error(message); } @@ -161,7 +157,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger { log.error(object, t); } - public void warn(String message) { log.warn(message); } @@ -208,7 +203,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger { log.warn(object, t); } - public void trace(String message) { log.trace(message); } @@ -248,7 +242,6 @@ public class EntgraDeviceLoggerImpl implements EntgraLogger { log.trace(object, t); } - public void fatal(String message) { log.fatal(message); } diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraPolicyLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraPolicyLoggerImpl.java new file mode 100644 index 00000000000..218252f260a --- /dev/null +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraPolicyLoggerImpl.java @@ -0,0 +1,318 @@ +/* + * 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.notification.logger.impl; + +import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; +import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.device.mgt.core.notification.logger.PolicyLogContext; +import io.entgra.device.mgt.core.notification.logger.util.MDCContextUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.log4j.MDC; + +public class EntgraPolicyLoggerImpl implements EntgraLogger { + + private static Log log = null; + + public EntgraPolicyLoggerImpl(Class clazz) { + log = LogFactory.getLog(clazz); + } + + public void info(String message) { + log.info(message); + } + + public void info(String message, Throwable t) { + log.info(message, t); + } + + @Override + public void info(Object o) { + log.info(o); + } + + @Override + public void info(Object o, Throwable throwable) { + log.info(o, throwable); + } + + @Override + public void info(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.info(message); + } + + @Override + public void info(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.info(object); + } + + @Override + public void info(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.info(object, t); + } + + public void debug(String message) { + log.debug(message); + } + + public void debug(String message, Throwable t) { + log.debug(message, t); + } + + @Override + public void debug(Object o) { + log.debug(o); + } + + @Override + public void debug(Object o, Throwable throwable) { + log.debug(o, throwable); + } + + @Override + public void debug(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.debug(message); + } + + @Override + public void debug(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.debug(object); + } + + @Override + public void debug(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.debug(object, t); + } + + public void error(String message) { + log.error(message); + } + + public void error(String message, Throwable t) { + log.error(message, t); + } + + @Override + public void error(Object o) { + log.error(o); + } + + @Override + public void error(Object o, Throwable throwable) { + log.error(o, throwable); + } + + @Override + public void error(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.error(message); + } + + @Override + public void error(String message, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.error(message, t); + } + + @Override + public void error(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.error(object); + } + + @Override + public void error(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.error(object, t); + } + + public void warn(String message) { + log.warn(message); + } + + public void warn(String message, Throwable t) { + log.warn(message, t); + } + + @Override + public void warn(Object o) { + log.warn(o); + } + + @Override + public void warn(Object o, Throwable throwable) { + log.warn(o, throwable); + } + + @Override + public void warn(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.warn(message); + } + + @Override + public void warn(String message, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.warn(message, t); + } + + @Override + public void warn(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.warn(object); + } + + @Override + public void warn(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.warn(object, t); + } + + public void trace(String message) { + log.trace(message); + } + + public void trace(String message, Throwable t) { + log.trace(message, t); + } + + @Override + public void trace(Object o) { + log.trace(o); + } + + @Override + public void trace(Object o, Throwable throwable) { + log.trace(o, throwable); + } + + @Override + public void trace(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.trace(message); + } + + @Override + public void trace(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.trace(object); + } + + @Override + public void trace(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.trace(object, t); + } + + public void fatal(String message) { + log.fatal(message); + } + + public void fatal(String message, Throwable t) { + log.fatal(message, t); + } + + @Override + public void fatal(Object o) { + log.fatal(0); + } + + @Override + public void fatal(Object o, Throwable throwable) { + log.fatal(0, throwable); + } + + @Override + public void fatal(String message, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.fatal(message); + } + + @Override + public void fatal(Object object, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.fatal(object); + } + + @Override + public void fatal(Object object, Throwable t, LogContext logContext) { + PolicyLogContext policyLogContext = (PolicyLogContext) logContext; + MDCContextUtil.populatePolicyMDCContext(policyLogContext); + log.fatal(object, t); + } + + @Override + public boolean isDebugEnabled() { + return log.isDebugEnabled(); + } + + @Override + public boolean isErrorEnabled() { + return log.isErrorEnabled(); + } + + @Override + public boolean isFatalEnabled() { + return log.isFatalEnabled(); + } + + @Override + public boolean isInfoEnabled() { + return log.isInfoEnabled(); + } + + @Override + public boolean isTraceEnabled() { + return log.isTraceEnabled(); + } + + @Override + public boolean isWarnEnabled() { + return log.isWarnEnabled(); + } + + @Override + public void clearLogContext() { + MDC.clear(); + } +} diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraUserLoggerImpl.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraUserLoggerImpl.java index 6a082b013d4..fa482605f6e 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraUserLoggerImpl.java +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/impl/EntgraUserLoggerImpl.java @@ -17,7 +17,6 @@ */ package io.entgra.device.mgt.core.notification.logger.impl; - import io.entgra.device.mgt.core.device.mgt.extensions.logger.LogContext; import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; import io.entgra.device.mgt.core.notification.logger.UserLogContext; @@ -26,7 +25,6 @@ import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.MDC; - public class EntgraUserLoggerImpl implements EntgraLogger { private static Log log = null; diff --git a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java index 09f903188a0..dc046e8eeb8 100644 --- a/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java +++ b/components/logger/io.entgra.device.mgt.core.notification.logger/src/main/java/io/entgra/device/mgt/core/notification/logger/util/MDCContextUtil.java @@ -17,8 +17,7 @@ */ package io.entgra.device.mgt.core.notification.logger.util; -import io.entgra.device.mgt.core.notification.logger.DeviceLogContext; -import io.entgra.device.mgt.core.notification.logger.UserLogContext; +import io.entgra.device.mgt.core.notification.logger.*; import org.apache.log4j.MDC; public final class MDCContextUtil { @@ -62,6 +61,105 @@ public final class MDCContextUtil { } } + + public static void populatePolicyMDCContext(final PolicyLogContext mdcContext) { + if (mdcContext.getPolicyName() != null) { + MDC.put("PolicyName", mdcContext.getPolicyName()); + } + if (mdcContext.getPayload() != null) { + MDC.put("Payload", mdcContext.getPayload()); + } + if (mdcContext.getActionTag() != null) { + MDC.put("ActionTag", mdcContext.getActionTag()); + } + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + if (mdcContext.getTenantDomain() != null) { + MDC.put("TenantDomain", mdcContext.getTenantDomain()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + } + + public static void populateAppInstallMDCContext(final AppInstallLogContext mdcContext) { + if (mdcContext.getAppId() != null) { + MDC.put("AppId", mdcContext.getAppId()); + } + if (mdcContext.getAppName() != null) { + MDC.put("AppName", mdcContext.getAppName()); + } + if (mdcContext.getAppType() != null) { + MDC.put("AppType", mdcContext.getAppType()); + } + if (mdcContext.getSubType() != null) { + MDC.put("SubType", mdcContext.getSubType()); + } + if (mdcContext.getDevice() != null) { + MDC.put("Device", mdcContext.getDevice()); + } + if (mdcContext.getTenantDomain() != null) { + MDC.put("TenantDomain", mdcContext.getTenantDomain()); + } + if (mdcContext.getTenantId() != null) { + MDC.put("TenantId", mdcContext.getTenantId()); + } + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + if (mdcContext.getAction() != null) { + MDC.put("Action", mdcContext.getAction()); + } + } + + public static void populateDeviceConnectivityMDCContext(final DeviceConnectivityLogContext mdcContext) { + if (mdcContext.getDeviceId() != null) { + MDC.put("DeviceId", mdcContext.getDeviceId()); + } + if (mdcContext.getDeviceType() != null) { + MDC.put("DeviceType", mdcContext.getDeviceType()); + } + if (mdcContext.getOperationCode() != null) { + MDC.put("OperationCode", mdcContext.getOperationCode()); + } + if (mdcContext.getTenantDomain() != null) { + MDC.put("TenantDomain", mdcContext.getTenantDomain()); + } + if (mdcContext.getTenantId() != null) { + MDC.put("TenantId", mdcContext.getTenantId()); + } + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + if (mdcContext.getActionTag() != null) { + MDC.put("ActionTag", mdcContext.getActionTag()); + } + } + + public static void populateDeviceEnrolmentMDCContext(final DeviceEnrolmentLogContext mdcContext) { + if (mdcContext.getDeviceId() != null) { + MDC.put("DeviceId", mdcContext.getDeviceId()); + } + if (mdcContext.getDeviceType() != null) { + MDC.put("DeviceType", mdcContext.getDeviceType()); + } + if (mdcContext.getOwner() != null) { + MDC.put("Owner", mdcContext.getOwner()); + } + if (mdcContext.getOwnership() != null) { + MDC.put("Ownership", mdcContext.getOwnership()); + } + if (mdcContext.getTenantID() != null) { + MDC.put("TenantId", mdcContext.getTenantID()); + } + if (mdcContext.getTenantDomain() != null) { + MDC.put("TenantDomain", mdcContext.getTenantDomain()); + } + if (mdcContext.getUserName() != null) { + MDC.put("UserName", mdcContext.getUserName()); + } + } } diff --git a/components/logger/pom.xml b/components/logger/pom.xml index cb85a7f88cc..c4dfdd014bb 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/pom.xml b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/pom.xml index c71669f41e3..c8af2e90038 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/pom.xml +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core operation-template-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -119,6 +119,10 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + file:src/test/resources/carbon-home/repository/conf/log4j.properties @@ -126,6 +130,9 @@ src/test/resources/testng.xml + + org.ops4j.pax.logging + diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/mock/BaseOperationTemplatePluginTest.java b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/mock/BaseOperationTemplatePluginTest.java index c5633116028..58c7e8b65f3 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/mock/BaseOperationTemplatePluginTest.java +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/java/io/entgra/device/mgt/core/operation/template/mock/BaseOperationTemplatePluginTest.java @@ -144,6 +144,7 @@ public abstract class BaseOperationTemplatePluginTest { conn = ConnectionManagerUtils.getDBConnection(); stmt = conn.createStatement(); stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/dm-db-h2.sql'"); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/insert-subtypes.sql'"); } finally { TestUtils.cleanupResources(conn, stmt, null); } diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql index 60521565889..df3277920dd 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, - PARENT_PATH VARCHAR(255) DEFAULT '/', + PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); @@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, - DEVICE_TYPE_ID INT(11) DEFAULT NULL, + DEVICE_TYPE_ID INT DEFAULT NULL, DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, TENANT_ID INTEGER DEFAULT 0, @@ -84,8 +84,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, @@ -108,7 +108,19 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID) ); - +CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + STATUS VARCHAR(50) DEFAULT NULL, + UPDATE_TIME TIMESTAMP DEFAULT NULL, + CHANGED_BY VARCHAR(255) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_status_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_device_status_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES + DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE +); CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING ( ID INTEGER AUTO_INCREMENT NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -176,17 +188,17 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ); CREATE TABLE IF NOT EXISTS DM_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) DEFAULT NULL , DESCRIPTION VARCHAR(1000) NULL, PAYLOAD_VERSION VARCHAR (45) NULL, - TENANT_ID INT(11) NOT NULL , - PROFILE_ID INT(11) NOT NULL , + TENANT_ID INT NOT NULL , + PROFILE_ID INT NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL, COMPLIANCE VARCHAR(100) NULL, PRIORITY INT NOT NULL, - ACTIVE INT(2) NOT NULL, - UPDATED INT(1) NULL, + ACTIVE INT NOT NULL, + UPDATED INT NULL, POLICY_TYPE VARCHAR(45) NULL, PRIMARY KEY (ID) , CONSTRAINT FK_DM_PROFILE_DM_POLICY @@ -197,11 +209,11 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , - DEVICE_ID INT(11) NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT , + DEVICE_ID INT NOT NULL , + ENROLMENT_ID INT NOT NULL, DEVICE BLOB NOT NULL, - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_POLICY_DEVICE_POLICY FOREIGN KEY (POLICY_ID ) @@ -216,9 +228,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( - ID INT(11) NOT NULL , + ID INT NOT NULL , DEVICE_TYPE VARCHAR(300) NOT NULL , - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY FOREIGN KEY (POLICY_ID ) @@ -228,11 +240,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( - ID INT(11) NOT NULL AUTO_INCREMENT, - PROFILE_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT, + PROFILE_ID INT NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, DEVICE_TYPE VARCHAR(300) NOT NULL, - TENANT_ID INT(11) NOT NULL , + TENANT_ID INT NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES @@ -243,11 +255,11 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ); CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT(11) NOT NULL AUTO_INCREMENT, + ID INT NOT NULL AUTO_INCREMENT, ACTION_TYPE VARCHAR(45) NOT NULL, - CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, - POLICY_ID INT(11) NOT NULL, - FEATURE_ID INT(11) DEFAULT NULL, + CORRECTIVE_POLICY_ID INT DEFAULT NULL, + POLICY_ID INT NOT NULL, + FEATURE_ID INT DEFAULT NULL, IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID), CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION @@ -258,9 +270,9 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( ); CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , ROLE_NAME VARCHAR(45) NOT NULL , - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_ROLE_POLICY_POLICY FOREIGN KEY (POLICY_ID ) @@ -284,11 +296,11 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( ID INT NOT NULL AUTO_INCREMENT , DEVICE_ID INT NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL , POLICY_CONTENT BLOB NULL , TENANT_ID INT NOT NULL, - APPLIED TINYINT(1) NULL , + APPLIED TINYINT NULL , CREATED_TIME TIMESTAMP NULL , UPDATED_TIME TIMESTAMP NULL , APPLIED_TIME TIMESTAMP NULL , @@ -341,7 +353,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL, TENANT_ID INT NOT NULL, STATUS INT NULL, @@ -356,7 +368,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, DEVICE_TYPE VARCHAR(300) NOT NULL , - TENANT_ID INT(11) NOT NULL, + TENANT_ID INT NOT NULL, PRIMARY KEY (ID) ); @@ -385,7 +397,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, - MEMORY_USAGE INTEGER(10) NULL, + MEMORY_USAGE INTEGER NULL, IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -405,6 +417,16 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- +CREATE TABLE IF NOT EXISTS DM_APP_ICONS ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ICON_PATH VARCHAR(150) DEFAULT NULL, + PACKAGE_NAME VARCHAR(150) NOT NULL, + VERSION VARCHAR(50) DEFAULT '1.1.0', + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + -- NOTIFICATION TABLE -- CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, @@ -425,7 +447,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( DEVICE_ID INT NULL, ENROLMENT_ID INT NOT NULL, KEY_FIELD VARCHAR(45) NULL, - VALUE_FIELD VARCHAR(1000) NULL, + VALUE_FIELD VARCHAR(1500) NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) @@ -454,7 +476,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, GEO_HASH VARCHAR(45) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, ALTITUDE DOUBLE NULL, SPEED FLOAT NULL, BEARING FLOAT NULL, @@ -491,8 +513,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, - PLUGGED_IN INT(1) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + PLUGGED_IN INT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) @@ -519,7 +541,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS LONGITUDE DOUBLE NULL, SPEED FLOAT NULL, HEADING FLOAT NULL, - TIMESTAMP BIGINT(15) NOT NULL, + TIMESTAMP BIGINT NOT NULL, GEO_HASH VARCHAR(45) NULL, DEVICE_OWNER VARCHAR(45) NULL, DEVICE_ALTITUDE DOUBLE NULL, @@ -588,8 +610,7 @@ CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( CREATED_AT TIMESTAMP NOT NULL, EXPIRY_TIME INT NOT NULL DEFAULT 3600, IS_EXPIRED BOOLEAN DEFAULT false, - PRIMARY KEY (ID), - CONSTRAINT email_type_uk UNIQUE (EMAIL, EMAIL_TYPE) + PRIMARY KEY (ID) ); -- END OF DM_OTP_DATA TABLE -- @@ -725,52 +746,94 @@ CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING ( -- END OF DM_GEOFENCE_GROUP_MAPPING TABLE-- +-- DM_EXT_GROUP_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + TRACCAR_GROUP_ID INT DEFAULT 0, + GROUP_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + STATUS INT DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_EXT_GROUP_MAPPING TABLE-- + +-- END OF DM_EXT_DEVICE_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + TRACCAR_DEVICE_ID INT DEFAULT 0, + DEVICE_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + STATUS INT DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_EXT_DEVICE_MAPPING TABLE-- + +-- END OF DM_EXT_PERMISSION_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( + TRACCAR_DEVICE_ID INT DEFAULT 0, + TRACCAR_USER_ID INT DEFAULT 0 +); +-- END OF DM_EXT_PERMISSION_MAPPING TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +); + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +); +-- END OF DYNAMIC TASK TABLE-- + -- DM_DEVICE_SUB_TYPE TABLE-- CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( TENANT_ID INT DEFAULT 0, - SUB_TYPE_ID INT NOT NULL, + SUB_TYPE_ID VARCHAR(45) NOT NULL, DEVICE_TYPE VARCHAR(25) NOT NULL, SUB_TYPE_NAME VARCHAR(45) NOT NULL, TYPE_DEFINITION TEXT NOT NULL, PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) ); - -- END OF DM_DEVICE_SUB_TYPE TABLE-- +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100) NULL, + STATUS VARCHAR(100) NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- + -- SUB_OPERATION_TEMPLATE TABLE-- -CREATE TABLE SUB_OPERATION_TEMPLATE ( - SUB_OPERATION_TEMPLATE_ID int NOT NULL AUTO_INCREMENT, +CREATE TABLE IF NOT EXISTS SUB_OPERATION_TEMPLATE ( + SUB_OPERATION_TEMPLATE_ID INT NOT NULL AUTO_INCREMENT, OPERATION_DEFINITION TEXT NOT NULL, - OPERATION_CODE varchar(100) NOT NULL, - SUB_TYPE_ID int NOT NULL, + OPERATION_CODE VARCHAR(100) NOT NULL, + SUB_TYPE_ID INT NOT NULL, DEVICE_TYPE VARCHAR(25) NOT NULL, - CREATE_TIMESTAMP timestamp NULL DEFAULT NULL, - UPDATE_TIMESTAMP timestamp NULL DEFAULT NULL, + CREATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, + UPDATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, PRIMARY KEY (SUB_OPERATION_TEMPLATE_ID), - UNIQUE KEY SUB_OPERATION_TEMPLATE (SUB_TYPE_ID,OPERATION_CODE, DEVICE_TYPE), + CONSTRAINT uk_sub_operation_template UNIQUE (SUB_TYPE_ID, OPERATION_CODE, DEVICE_TYPE), +-- UNIQUE KEY SUB_OPERATION_TEMPLATE (SUB_TYPE_ID, OPERATION_CODE, DEVICE_TYPE), CONSTRAINT fk_SUB_OPERATION_TEMPLATE_DM_DEVICE_SUB_TYPE FOREIGN KEY (SUB_TYPE_ID, DEVICE_TYPE) REFERENCES DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, DEVICE_TYPE) ); -/* - * 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. - */ - -- END OF SUB_OPERATION_TEMPLATE TABLE-- - -INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES -(3,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 3, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'), -(4,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 4, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'); diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/insert-subtypes.sql b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/insert-subtypes.sql new file mode 100644 index 00000000000..ffa001a0862 --- /dev/null +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/dbscripts/insert-subtypes.sql @@ -0,0 +1,3 @@ +INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES +(3,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 3, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'), +(4,-1234,'METER','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 4, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'); \ No newline at end of file diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/cdm-config.xml index b6c2900db7b..3ce48daefe4 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/cdm-config.xml +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/cdm-config.xml @@ -31,18 +31,10 @@ 60000 true - - io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider - - - io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider - - - io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider - - - io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider - + io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider + io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider + io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider + io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider @@ -50,16 +42,16 @@ https://localhost:9443 - admin - admin + ${admin.username} + ${admin.username} https://localhost:9443 - admin - admin + ${admin.username} + ${admin.username} - org.wso2.carbon.policy.mgt + io.entgra.device.mgt.core.policy.mgt true 60000 5 @@ -90,7 +82,7 @@ device caching for upto configured expiry-time in seconds. In clustered setup all worker nodes can enable the device-cache to improve performance. --> - false + true 600 10000 + + true + 600 + 10000 + true - false + true 86400 @@ -120,6 +114,11 @@ false + false + + DM_DB + ARCHIVAL_DB + io.entgra.device.mgt.core.device.mgt.core.task.impl.ArchivalTask 0 0 0 1/1 * ? * @@ -159,7 +158,7 @@ true - wss://localhost:9443 + ws://localhost:9763 2 100 20 @@ -167,5 +166,50 @@ 640 BYOD,COPE + + false + false + io.entgra.device.mgt.core.device.mgt.common.enrollment.notification.EnrollmentNotifier + http://localhost:8280 + + + false + + + test_role + + /permission/admin/Login + + + + + + + + <a href='https://entgra.io' target='_blank'> + Entgra + </a> + IoT Server 5.2.0 | © 2023 + , All Rights Reserved. + + Entgra + + repository/resources/whitelabel + favicon.png + logo.png + icon.png + default + + + + + + + + + + false + Replace with mail + diff --git a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml index ad8165fc674..2e591b07c92 100644 --- a/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml +++ b/components/operation-template-mgt/io.entgra.device.mgt.core.operation.template/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml @@ -18,7 +18,7 @@ --> - jdbc:h2:mem:smart-meter-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + jdbc:h2:mem:smart-meter-test-db;DB_CLOSE_ON_EXIT=FALSE org.h2.Driver wso2carbon wso2carbon diff --git a/components/operation-template-mgt/pom.xml b/components/operation-template-mgt/pom.xml index d83ea2e190b..94c29533feb 100644 --- a/components/operation-template-mgt/pom.xml +++ b/components/operation-template-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.decision.point/pom.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.decision.point/pom.xml index 0eff71e8f98..0439397aff7 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.decision.point/pom.xml +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.decision.point/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core policy-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.information.point/pom.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.information.point/pom.xml index 10fa65047d5..eac063769da 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.information.point/pom.xml +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.information.point/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core policy-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/pom.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/pom.xml index 52d3c6c045a..fbfb70849b9 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/pom.xml +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core policy-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml index 6887a4f3e52..f93f4629248 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core policy-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -116,12 +116,19 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + file:src/test/resources/log4j.properties src/test/resources/testng.xml + + org.ops4j.pax.logging + @@ -254,7 +261,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test @@ -276,6 +283,10 @@ org.wso2.orbit.javax.xml.bind jaxb-api + + io.entgra.device.mgt.core + io.entgra.device.mgt.core.notification.logger + diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java index b07f311ce10..c5d661c5678 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/impl/PolicyAdministratorPointImpl.java @@ -19,6 +19,9 @@ package io.entgra.device.mgt.core.policy.mgt.core.impl; import io.entgra.device.mgt.core.device.mgt.common.PolicyPaginationRequest; +import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.device.mgt.core.notification.logger.PolicyLogContext; +import io.entgra.device.mgt.core.notification.logger.impl.EntgraPolicyLoggerImpl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.context.PrivilegedCarbonContext; @@ -54,7 +57,8 @@ import java.util.Set; public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { - private static final Log log = LogFactory.getLog(PolicyAdministratorPointImpl.class); + PolicyLogContext.Builder policyLogContextBuilder = new PolicyLogContext.Builder(); + private static final EntgraLogger log = new EntgraPolicyLoggerImpl(PolicyAdministratorPointImpl.class); private PolicyManager policyManager; private ProfileManager profileManager; @@ -135,6 +139,8 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { try { int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(); + String userName = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); TaskService taskService = PolicyManagementDataHolder.getInstance().getTaskService(); if (log.isDebugEnabled()) { @@ -168,11 +174,13 @@ public class PolicyAdministratorPointImpl implements PolicyAdministratorPoint { properties, triggerInfo); taskManager.registerTask(taskInfo); taskManager.scheduleTask(taskInfo.getName()); + log.info("Apply changes to device", policyLogContextBuilder.setActionTag("PUBLISH_CHANGES").setUserName(userName).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).build()); } else { if (!taskManager.isTaskScheduled(taskName)) { TaskInfo taskInfo = new TaskInfo(taskName, PolicyManagementConstants.DELEGATION_TASK_CLAZZ, properties, triggerInfo); taskManager.scheduleTask(taskInfo.getName()); + log.info("Apply changes to device", policyLogContextBuilder.setActionTag("PUBLISH_CHANGES").setUserName(userName).setTenantID(String.valueOf(tenantId)).setTenantDomain(tenantDomain).build()); } else { throw new PolicyManagementException("There is a task already running for policy changes. Please try " + "to apply " + diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java index 5cc0dc35b8f..d0534e28aca 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/main/java/io/entgra/device/mgt/core/policy/mgt/core/mgt/impl/PolicyManagerImpl.java @@ -18,6 +18,10 @@ package io.entgra.device.mgt.core.policy.mgt.core.mgt.impl; +import com.google.gson.Gson; +import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger; +import io.entgra.device.mgt.core.notification.logger.PolicyLogContext; +import io.entgra.device.mgt.core.notification.logger.impl.EntgraPolicyLoggerImpl; 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.PolicyPaginationRequest; @@ -48,6 +52,7 @@ import io.entgra.device.mgt.core.policy.mgt.core.util.PolicyManagerUtil; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.PrivilegedCarbonContext; import java.sql.SQLException; import java.sql.Timestamp; @@ -55,12 +60,13 @@ import java.util.*; public class PolicyManagerImpl implements PolicyManager { + PolicyLogContext.Builder policyLogContextBuilder = new PolicyLogContext.Builder(); private final PolicyDAO policyDAO; private final ProfileDAO profileDAO; private final FeatureDAO featureDAO; private final ProfileManager profileManager; private final PolicyConfiguration policyConfiguration; - private static final Log log = LogFactory.getLog(PolicyManagerImpl.class); + private static final EntgraLogger log = new EntgraPolicyLoggerImpl(PolicyManagerImpl.class); public PolicyManagerImpl() { this.policyDAO = PolicyManagementDAOFactory.getPolicyDAO(); @@ -72,6 +78,9 @@ public class PolicyManagerImpl implements PolicyManager { @Override public Policy addPolicy(Policy policy) throws PolicyManagementException { + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); try { PolicyManagementDAOFactory.beginTransaction(); if (policy.getProfile() != null && policy.getProfile().getProfileId() == 0) { @@ -153,11 +162,16 @@ public class PolicyManagerImpl implements PolicyManager { } finally { PolicyManagementDAOFactory.closeConnection(); } + String stringPayload = new Gson().toJson(policy); + log.info("Policy created", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("ADD_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); return policy; } @Override public Policy updatePolicy(Policy policy) throws PolicyManagementException { + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); try { // Previous policy needs to be obtained before beginning the transaction Policy previousPolicy = this.getPolicy(policy.getId()); @@ -299,6 +313,8 @@ public class PolicyManagerImpl implements PolicyManager { } finally { PolicyManagementDAOFactory.closeConnection(); } + String stringPayload = new Gson().toJson(policy); + log.info("Policy updated", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("UPDATE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); return policy; } @@ -488,6 +504,10 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean updatePolicyPriorities(List policies) throws PolicyManagementException { + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); + String stringPayload = new Gson().toJson(policies); boolean bool; try { List existingPolicies; @@ -516,18 +536,24 @@ public class PolicyManagerImpl implements PolicyManager { } finally { PolicyManagementDAOFactory.closeConnection(); } + log.info("Policy priorities updated", policyLogContextBuilder.setPayload(stringPayload).setActionTag("UPDATE_POLICY_PRIORITIES").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); return bool; } @Override public boolean deletePolicy(Policy policy) throws PolicyManagementException { try { + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); PolicyManagementDAOFactory.beginTransaction(); policyDAO.deleteAllPolicyRelatedConfigs(policy.getId()); policyDAO.deletePolicy(policy.getId()); featureDAO.deleteFeaturesOfProfile(policy.getProfileId()); profileDAO.deleteProfile(policy.getProfileId()); PolicyManagementDAOFactory.commitTransaction(); + String stringPayload = new Gson().toJson(policy); + log.info("Policy deleted", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("DELETE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); return true; } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); @@ -548,6 +574,9 @@ public class PolicyManagerImpl implements PolicyManager { @Override public boolean deletePolicy(int policyId) throws PolicyManagementException { + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); boolean bool; List policies = this.getPolicies(); Policy pol = null; @@ -578,6 +607,8 @@ public class PolicyManagerImpl implements PolicyManager { featureDAO.deleteFeaturesOfProfile(policy.getProfileId()); profileDAO.deleteProfile(policy.getProfileId()); PolicyManagementDAOFactory.commitTransaction(); + String stringPayload = new Gson().toJson(policy); + log.info("Policy deleted", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(stringPayload).setActionTag("DELETE_POLICY").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); return bool; } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); @@ -636,6 +667,9 @@ public class PolicyManagerImpl implements PolicyManager { List deviceList = new ArrayList<>(); DeviceManagementProviderService deviceManagementService = PolicyManagementDataHolder .getInstance().getDeviceManagementService(); + String tenantId = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId()); + String tenantDomain = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain()); + String userName = String.valueOf(PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername()); for (DeviceIdentifier deviceIdentifier : deviceIdentifierList) { try { Device device = deviceManagementService.getDevice(deviceIdentifier, false); @@ -664,6 +698,9 @@ public class PolicyManagerImpl implements PolicyManager { } policy.setDevices(deviceList); } + String policyPayload = new Gson().toJson(policy); + String deviceListPayload = new Gson().toJson(deviceList); + log.info("Policy added to devices", policyLogContextBuilder.setPolicyName(policy.getPolicyName()).setPayload(" Policy: " + policyPayload + " DeviceList: " + deviceListPayload).setActionTag("ADD_POLICY_TO_DEVICE").setUserName(userName).setTenantID(tenantId).setTenantDomain(tenantDomain).build()); } catch (PolicyManagerDAOException e) { PolicyManagementDAOFactory.rollbackTransaction(); throw new PolicyManagementException("Error occurred while adding the policy (" diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql index defd753f334..e3ed0cd6ec2 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/sql/CreateH2TestDB.sql @@ -1,3 +1,51 @@ + DROP VIEW IF EXISTS FEATURE_NON_COMPLIANCE_INFO; + ALTER TABLE IF EXISTS DM_DEVICE DROP CONSTRAINT IF EXISTS fk_DM_DEVICE_DM_DEVICE_TYPE2; +-- ALTER TABLE IF EXISTS DM_DEVICE_TYPE_PLATFORM DROP CONSTRAINT IF EXISTS DM_DEVICE_TYPE_DM_DEVICE_TYPE_PLATFORM_MAPPING; + ALTER TABLE IF EXISTS DM_ROLE_GROUP_MAP DROP CONSTRAINT IF EXISTS FK_DM_ROLE_GROUP_MAP_DM_GROUP2; + ALTER TABLE IF EXISTS DM_DEVICE_GROUP_MAP DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_GROUP_MAP_DM_GROUP2; + ALTER TABLE IF EXISTS DM_DEVICE_GROUP_POLICY DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_GROUP_POLICY; +-- ALTER TABLE IF EXISTS DM_GEOFENCE_GROUP_MAPPING DROP CONSTRAINT IF EXISTS FK_DM_GEOFENCE_GROUP_MAPPING_GROUP; +-- ALTER TABLE IF EXISTS DM_DEVICE_EVENT_GROUP_MAPPING DROP CONSTRAINT IF EXISTS FK_DM_EVENT_GROUP_MAPPING_GROUP; + + ALTER TABLE IF EXISTS DM_DEVICE_GROUP_MAP DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_GROUP_MAP_DM_DEVICE2; + ALTER TABLE IF EXISTS DM_ENROLMENT DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_ENROLMENT; + ALTER TABLE IF EXISTS DM_DEVICE_STATUS DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_STATUS_DEVICE; + ALTER TABLE IF EXISTS DM_DEVICE_POLICY DROP CONSTRAINT IF EXISTS FK_DEVICE_DEVICE_POLICY; + ALTER TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED DROP CONSTRAINT IF EXISTS FK_DM_POLICY_DEVCIE_APPLIED; + ALTER TABLE IF EXISTS DM_APPLICATION DROP CONSTRAINT IF EXISTS FK_DM_DEVICE; + ALTER TABLE IF EXISTS DM_NOTIFICATION DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_NOTIFICATION; + ALTER TABLE IF EXISTS DM_DEVICE_INFO DROP CONSTRAINT IF EXISTS DM_DEVICE_INFO_DEVICE; + ALTER TABLE IF EXISTS DM_DEVICE_LOCATION DROP CONSTRAINT IF EXISTS DM_DEVICE_LOCATION_DEVICE; + ALTER TABLE IF EXISTS DM_DEVICE_DETAIL DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_DETAILS_DEVICE; + + ALTER TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_OPERATION_MAPPING_OPERATION; + ALTER TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_OPERATION_RESPONSE_OPERATION; + + ALTER TABLE IF EXISTS DM_DEVICE_STATUS DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_STATUS_ENROLMENT; + ALTER TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_OPERATION_MAPPING_DEVICE; + ALTER TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_OPERATION_RESPONSE_ENROLLMENT; + ALTER TABLE IF EXISTS DM_APPLICATION DROP CONSTRAINT IF EXISTS FK_DM_ENROLEMENT; + ALTER TABLE IF EXISTS DM_DEVICE_INFO DROP CONSTRAINT IF EXISTS DM_DEVICE_INFO_DEVICE_ENROLLMENT; + ALTER TABLE IF EXISTS DM_DEVICE_LOCATION DROP CONSTRAINT IF EXISTS DM_DEVICE_LOCATION_DM_ENROLLMENT; + ALTER TABLE IF EXISTS DM_DEVICE_DETAIL DROP CONSTRAINT IF EXISTS FK_DM_ENROLMENT_DEVICE_DETAILS; + ALTER TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE DROP CONSTRAINT IF EXISTS FK_DM_EN_OP_MAP_RESPONSE; + ALTER TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE DROP CONSTRAINT IF EXISTS FK_DM_EN_OP_MAP_RESPONSE_LARGE; + ALTER TABLE IF EXISTS DM_DEVICE_OPERATION_RESPONSE_LARGE DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_OPERATION_RESPONSE_LARGE_MAPPING; +-- + ALTER TABLE IF EXISTS DM_POLICY DROP CONSTRAINT IF EXISTS FK_DM_PROFILE_DM_POLICY; + ALTER TABLE IF EXISTS DM_PROFILE_FEATURES DROP CONSTRAINT IF EXISTS FK_DM_PROFILE_DM_POLICY_FEATURES; +-- + ALTER TABLE IF EXISTS DM_DEVICE_POLICY DROP CONSTRAINT IF EXISTS FK_POLICY_DEVICE_POLICY; + ALTER TABLE IF EXISTS DM_DEVICE_TYPE_POLICY DROP CONSTRAINT IF EXISTS FK_DEVICE_TYPE_POLICY; + ALTER TABLE IF EXISTS DM_POLICY_CORRECTIVE_ACTION DROP CONSTRAINT IF EXISTS FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION; + ALTER TABLE IF EXISTS DM_ROLE_POLICY DROP CONSTRAINT IF EXISTS FK_ROLE_POLICY_POLICY; + ALTER TABLE IF EXISTS DM_USER_POLICY DROP CONSTRAINT IF EXISTS DM_POLICY_USER_POLICY; + ALTER TABLE IF EXISTS DM_POLICY_CRITERIA DROP CONSTRAINT IF EXISTS FK_POLICY_POLICY_CRITERIA; + ALTER TABLE IF EXISTS DM_DEVICE_GROUP_POLICY DROP CONSTRAINT IF EXISTS FK_DM_DEVICE_GROUP_DM_POLICY; + ALTER TABLE IF EXISTS DM_POLICY_CRITERIA DROP CONSTRAINT IF EXISTS FK_CRITERIA_POLICY_CRITERIA; + ALTER TABLE IF EXISTS DM_POLICY_CRITERIA_PROPERTIES DROP CONSTRAINT IF EXISTS FK_POLICY_CRITERIA_PROPERTIES; + ALTER TABLE IF EXISTS DM_POLICY_COMPLIANCE_FEATURES DROP CONSTRAINT IF EXISTS FK_COMPLIANCE_FEATURES_STATUS; + DROP TABLE IF EXISTS DM_DEVICE_TYPE; CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( ID INT AUTO_INCREMENT NOT NULL, @@ -13,24 +61,23 @@ DROP TABLE IF EXISTS DM_GROUP; CREATE TABLE IF NOT EXISTS DM_GROUP ( ID INTEGER AUTO_INCREMENT NOT NULL, GROUP_NAME VARCHAR(100) DEFAULT NULL, - DESCRIPTION TEXT DEFAULT NULL, STATUS VARCHAR(50) DEFAULT NULL, - DATE_OF_CREATE BIGINT DEFAULT NULL, - DATE_OF_LAST_UPDATE BIGINT DEFAULT NULL, - OWNER VARCHAR(45) DEFAULT NULL, + DESCRIPTION TEXT DEFAULT NULL, + OWNER VARCHAR(255) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); - -DROP TABLE IF EXISTS DM_DEVICE_CERTIFICATE; -CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( - ID INTEGER auto_increment NOT NULL, - SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, - CERTIFICATE BLOB DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - USERNAME VARCHAR(500) DEFAULT NULL, - PRIMARY KEY (ID) +DROP TABLE IF EXISTS DM_ROLE_GROUP_MAP; +CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP ( + ID INTEGER AUTO_INCREMENT NOT NULL, + GROUP_ID INTEGER DEFAULT NULL, + ROLE VARCHAR(45) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_DM_ROLE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID) + REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE ); DROP TABLE IF EXISTS DM_DEVICE; @@ -38,13 +85,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, - DEVICE_TYPE_ID INT(11) DEFAULT NULL, + DEVICE_TYPE_ID INT DEFAULT NULL, DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID), - CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID ) - REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID) + REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uk_DM_DEVICE UNIQUE (NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) ); DROP TABLE IF EXISTS DM_DEVICE_PROPERTIES; @@ -53,8 +101,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, PROPERTY_NAME VARCHAR(100) DEFAULT 0, PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, - TENANT_ID VARCHAR(100) DEFAULT NULL, - PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME) + TENANT_ID VARCHAR(100), + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID) ); DROP TABLE IF EXISTS GROUP_PROPERTIES; @@ -74,9 +122,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID), CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID) - REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + REFERENCES DM_DEVICE (ID) ON DELETE CASCADE ON UPDATE CASCADE, CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID) - REFERENCES DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE ); DROP TABLE IF EXISTS DM_OPERATION; @@ -96,7 +144,7 @@ DROP TABLE IF EXISTS DM_ENROLMENT; CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, - OWNER VARCHAR(50) NOT NULL, + OWNER VARCHAR(255) NOT NULL, OWNERSHIP VARCHAR(45) DEFAULT NULL, STATUS VARCHAR(50) NULL, IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE, @@ -105,7 +153,8 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( TENANT_ID INT NOT NULL, PRIMARY KEY (ID), CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES - DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID) ); DROP TABLE IF EXISTS DM_DEVICE_STATUS; CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( @@ -119,7 +168,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( CONSTRAINT fk_dm_device_status_device FOREIGN KEY (DEVICE_ID) REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT fk_dm_device_status_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES - DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE ); DROP TABLE IF EXISTS DM_ENROLMENT_OP_MAPPING; CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING ( @@ -167,10 +216,14 @@ CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE ( ID INTEGER NOT NULL, OPERATION_RESPONSE LONGBLOB DEFAULT NULL, OPERATION_ID INTEGER NOT NULL, + EN_OP_MAP_ID INTEGER NOT NULL, RECEIVED_TIMESTAMP TIMESTAMP NULL, DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, CONSTRAINT fk_dm_device_operation_response_large_mapping FOREIGN KEY (ID) REFERENCES DM_DEVICE_OPERATION_RESPONSE (ID) + ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID) + REFERENCES DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); @@ -181,30 +234,25 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ID INT NOT NULL AUTO_INCREMENT , PROFILE_NAME VARCHAR(45) NOT NULL , TENANT_ID INT NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , CREATED_TIME DATETIME NOT NULL , UPDATED_TIME DATETIME NOT NULL , - PRIMARY KEY (ID) , - CONSTRAINT DM_PROFILE_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE ) - REFERENCES DM_DEVICE_TYPE (NAME ) - ON DELETE NO ACTION - ON UPDATE NO ACTION + PRIMARY KEY (ID) ); DROP TABLE IF EXISTS DM_POLICY; CREATE TABLE IF NOT EXISTS DM_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) DEFAULT NULL , - PAYLOAD_VERSION VARCHAR (45) DEFAULT NULL, DESCRIPTION VARCHAR(1000) NULL, - TENANT_ID INT(11) NOT NULL , - PROFILE_ID INT(11) NOT NULL , + PAYLOAD_VERSION VARCHAR (45) NULL, + TENANT_ID INT NOT NULL , + PROFILE_ID INT NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL, COMPLIANCE VARCHAR(100) NULL, PRIORITY INT NOT NULL, - ACTIVE INT(2) NOT NULL, - UPDATED INT(1) NULL, + ACTIVE INT NOT NULL, + UPDATED INT NULL, POLICY_TYPE VARCHAR(45) NULL, PRIMARY KEY (ID) , CONSTRAINT FK_DM_PROFILE_DM_POLICY @@ -213,31 +261,13 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ON DELETE NO ACTION ON UPDATE NO ACTION ); - -DROP TABLE IF EXISTS DM_POLICY_CORRECTIVE_ACTION; -CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT(11) NOT NULL AUTO_INCREMENT, - ACTION_TYPE VARCHAR(45) NOT NULL, - CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, - POLICY_ID INT(11) NOT NULL, - FEATURE_ID INT(11) DEFAULT NULL, - IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, - PRIMARY KEY (ID), - CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION - FOREIGN KEY (POLICY_ID) - REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION -); - - DROP TABLE IF EXISTS DM_DEVICE_POLICY; CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , - DEVICE_ID INT(11) NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT , + DEVICE_ID INT NOT NULL , + ENROLMENT_ID INT NOT NULL, DEVICE BLOB NOT NULL, - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_POLICY_DEVICE_POLICY FOREIGN KEY (POLICY_ID ) @@ -253,29 +283,24 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( DROP TABLE IF EXISTS DM_DEVICE_TYPE_POLICY; CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( - ID INT(11) NOT NULL , - DEVICE_TYPE VARCHAR(20) NOT NULL , - POLICY_ID INT(11) NOT NULL , + ID INT NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY FOREIGN KEY (POLICY_ID ) REFERENCES DM_POLICY (ID ) ON DELETE NO ACTION - ON UPDATE NO ACTION, - CONSTRAINT FK_DEVICE_TYPE_POLICY_DEVICE_TYPE - FOREIGN KEY (DEVICE_TYPE ) - REFERENCES DM_DEVICE_TYPE (NAME) - ON DELETE NO ACTION ON UPDATE NO ACTION ); DROP TABLE IF EXISTS DM_PROFILE_FEATURES; CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( - ID INT(11) NOT NULL AUTO_INCREMENT, - PROFILE_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT, + PROFILE_ID INT NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, - TENANT_ID INT(11) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL, + TENANT_ID INT NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES @@ -285,11 +310,26 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ON UPDATE NO ACTION ); +CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( + ID INT NOT NULL AUTO_INCREMENT, + ACTION_TYPE VARCHAR(45) NOT NULL, + CORRECTIVE_POLICY_ID INT DEFAULT NULL, + POLICY_ID INT NOT NULL, + FEATURE_ID INT DEFAULT NULL, + IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + DROP TABLE IF EXISTS DM_ROLE_POLICY; CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , ROLE_NAME VARCHAR(45) NOT NULL , - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_ROLE_POLICY_POLICY FOREIGN KEY (POLICY_ID ) @@ -315,11 +355,11 @@ DROP TABLE IF EXISTS DM_DEVICE_POLICY_APPLIED; CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( ID INT NOT NULL AUTO_INCREMENT , DEVICE_ID INT NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL , POLICY_CONTENT BLOB NULL , TENANT_ID INT NOT NULL, - APPLIED TINYINT(1) NULL , + APPLIED TINYINT NULL , CREATED_TIME TIMESTAMP NULL , UPDATED_TIME TIMESTAMP NULL , APPLIED_TIME TIMESTAMP NULL , @@ -363,7 +403,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( POLICY_CRITERION_ID INT NOT NULL, PROP_KEY VARCHAR(45) NULL, PROP_VALUE VARCHAR(100) NULL, - CONTENT BLOB NULL COMMENT 'This is used to ', + CONTENT BLOB NULL, PRIMARY KEY (ID), CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES FOREIGN KEY (POLICY_CRITERION_ID) @@ -376,7 +416,7 @@ DROP TABLE IF EXISTS DM_POLICY_COMPLIANCE_STATUS; CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL, TENANT_ID INT NOT NULL, STATUS INT NULL, @@ -391,8 +431,8 @@ DROP TABLE IF EXISTS DM_POLICY_CHANGE_MGT; CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, - DEVICE_TYPE VARCHAR(20) NOT NULL, - TENANT_ID INT(11) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , + TENANT_ID INT NOT NULL, PRIMARY KEY (ID) ); @@ -423,7 +463,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, - MEMORY_USAGE INTEGER(10) NULL, + MEMORY_USAGE INTEGER NULL, IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -434,7 +474,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( REFERENCES DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT FK_DM_APP_MAP_DM_ENROL + CONSTRAINT fk_dm_enrolement FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT (ID) ON DELETE NO ACTION @@ -448,15 +488,14 @@ DROP TABLE IF EXISTS DM_NOTIFICATION; CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, DEVICE_ID INTEGER NOT NULL, - OPERATION_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NULL, TENANT_ID INTEGER NOT NULL, STATUS VARCHAR(10) NULL, - DESCRIPTION VARCHAR(100) NULL, + DESCRIPTION VARCHAR(1000) NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, PRIMARY KEY (NOTIFICATION_ID), CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES - DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, - CONSTRAINT fk_dm_operation_notification FOREIGN KEY (OPERATION_ID) REFERENCES - DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION ); -- NOTIFICATION TABLE END -- @@ -494,7 +533,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, GEO_HASH VARCHAR(45) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, + ALTITUDE DOUBLE NULL, + SPEED FLOAT NULL, + BEARING FLOAT NULL, + DISTANCE DOUBLE NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_LOCATION_DEVICE FOREIGN KEY (DEVICE_ID) @@ -507,6 +550,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( ON DELETE NO ACTION ON UPDATE NO ACTION ); +DROP INDEX IF EXISTS DM_DEVICE_LOCATION_GEO_hashx; +CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC); DROP TABLE IF EXISTS DM_DEVICE_DETAIL; CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( @@ -527,8 +572,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, - PLUGGED_IN INT(1) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + PLUGGED_IN INT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) @@ -553,15 +598,14 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( CONSTRAINT FK_DM_DEVICE_GROUP_POLICY FOREIGN KEY (DEVICE_GROUP_ID) REFERENCES DM_GROUP (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION, + ON DELETE CASCADE + ON UPDATE CASCADE , CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY FOREIGN KEY (POLICY_ID) REFERENCES DM_POLICY (ID) - ON DELETE NO ACTION - ON UPDATE NO ACTION + ON DELETE CASCADE + ON UPDATE CASCADE ); - -- END OF POLICY AND DEVICE GROUP MAPPING -- -- DASHBOARD RELATED VIEWS -- @@ -621,22 +665,4 @@ DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID ORDER BY TENANT_ID, DEVICE_ID; -/* - * 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. - */ - -- END OF DASHBOARD RELATED VIEWS -- diff --git a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml index fc32a2698d0..96fd6acfff1 100644 --- a/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml +++ b/components/policy-mgt/io.entgra.device.mgt.core.policy.mgt.core/src/test/resources/user-test/user-mgt-registry-test.xml @@ -27,7 +27,7 @@ everyone false 500 - jdbc:h2:target/databasetest/CARBON_TEST + jdbc:h2:./target/databasetest/CARBON_TEST org.h2.Driver 50 60000 diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 2daade26a6f..0d6b866dea1 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/pom.xml b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/pom.xml index 45b7fd07c9e..8c1e357da7c 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/pom.xml +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/pom.xml @@ -20,7 +20,7 @@ io.entgra.device.mgt.core subtype-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -114,6 +114,10 @@ org.apache.maven.plugins maven-surefire-plugin + + --add-opens=java.xml/jdk.xml.internal=ALL-UNNAMED + --add-opens=java.base/jdk.internal.loader=ALL-UNNAMED + file:src/test/resources/carbon-home/repository/conf/log4j.properties @@ -121,6 +125,9 @@ src/test/resources/testng.xml + + org.ops4j.pax.logging + @@ -342,7 +349,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql index 40ad63072f6..df3277920dd 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -23,7 +23,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( STATUS VARCHAR(50) DEFAULT NULL, DESCRIPTION TEXT DEFAULT NULL, OWNER VARCHAR(255) DEFAULT NULL, - PARENT_PATH VARCHAR(255) DEFAULT '/', + PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); @@ -42,7 +42,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE ( ID INTEGER auto_increment NOT NULL, DESCRIPTION TEXT DEFAULT NULL, NAME VARCHAR(100) DEFAULT NULL, - DEVICE_TYPE_ID INT(11) DEFAULT NULL, + DEVICE_TYPE_ID INT DEFAULT NULL, DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, TENANT_ID INTEGER DEFAULT 0, @@ -84,8 +84,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( CREATE TABLE IF NOT EXISTS DM_OPERATION ( ID INTEGER AUTO_INCREMENT NOT NULL, TYPE VARCHAR(50) NOT NULL, - CREATED_TIMESTAMP TIMESTAMP NOT NULL, - RECEIVED_TIMESTAMP TIMESTAMP NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + RECEIVED_TIMESTAMP BIGINT NULL, OPERATION_CODE VARCHAR(1000) NOT NULL, INITIATED_BY VARCHAR(100) NULL, OPERATION_DETAILS BLOB DEFAULT NULL, @@ -108,7 +108,19 @@ CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID) ); - +CREATE TABLE IF NOT EXISTS DM_DEVICE_STATUS ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + DEVICE_ID INTEGER NOT NULL, + STATUS VARCHAR(50) DEFAULT NULL, + UPDATE_TIME TIMESTAMP DEFAULT NULL, + CHANGED_BY VARCHAR(255) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_status_device FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_device_status_enrolment FOREIGN KEY (ENROLMENT_ID) REFERENCES + DM_ENROLMENT (ID) ON DELETE CASCADE ON UPDATE CASCADE +); CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING ( ID INTEGER AUTO_INCREMENT NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -176,17 +188,17 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE ( ); CREATE TABLE IF NOT EXISTS DM_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , NAME VARCHAR(45) DEFAULT NULL , DESCRIPTION VARCHAR(1000) NULL, PAYLOAD_VERSION VARCHAR (45) NULL, - TENANT_ID INT(11) NOT NULL , - PROFILE_ID INT(11) NOT NULL , + TENANT_ID INT NOT NULL , + PROFILE_ID INT NOT NULL , OWNERSHIP_TYPE VARCHAR(45) NULL, COMPLIANCE VARCHAR(100) NULL, PRIORITY INT NOT NULL, - ACTIVE INT(2) NOT NULL, - UPDATED INT(1) NULL, + ACTIVE INT NOT NULL, + UPDATED INT NULL, POLICY_TYPE VARCHAR(45) NULL, PRIMARY KEY (ID) , CONSTRAINT FK_DM_PROFILE_DM_POLICY @@ -197,11 +209,11 @@ CREATE TABLE IF NOT EXISTS DM_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , - DEVICE_ID INT(11) NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT , + DEVICE_ID INT NOT NULL , + ENROLMENT_ID INT NOT NULL, DEVICE BLOB NOT NULL, - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_POLICY_DEVICE_POLICY FOREIGN KEY (POLICY_ID ) @@ -216,9 +228,9 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( - ID INT(11) NOT NULL , + ID INT NOT NULL , DEVICE_TYPE VARCHAR(300) NOT NULL , - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_DEVICE_TYPE_POLICY FOREIGN KEY (POLICY_ID ) @@ -228,11 +240,11 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( ); CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( - ID INT(11) NOT NULL AUTO_INCREMENT, - PROFILE_ID INT(11) NOT NULL, + ID INT NOT NULL AUTO_INCREMENT, + PROFILE_ID INT NOT NULL, FEATURE_CODE VARCHAR(100) NOT NULL, DEVICE_TYPE VARCHAR(300) NOT NULL, - TENANT_ID INT(11) NOT NULL , + TENANT_ID INT NOT NULL , CONTENT BLOB NULL DEFAULT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES @@ -243,11 +255,11 @@ CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( ); CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( - ID INT(11) NOT NULL AUTO_INCREMENT, + ID INT NOT NULL AUTO_INCREMENT, ACTION_TYPE VARCHAR(45) NOT NULL, - CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, - POLICY_ID INT(11) NOT NULL, - FEATURE_ID INT(11) DEFAULT NULL, + CORRECTIVE_POLICY_ID INT DEFAULT NULL, + POLICY_ID INT NOT NULL, + FEATURE_ID INT DEFAULT NULL, IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, PRIMARY KEY (ID), CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION @@ -258,9 +270,9 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( ); CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( - ID INT(11) NOT NULL AUTO_INCREMENT , + ID INT NOT NULL AUTO_INCREMENT , ROLE_NAME VARCHAR(45) NOT NULL , - POLICY_ID INT(11) NOT NULL , + POLICY_ID INT NOT NULL , PRIMARY KEY (ID) , CONSTRAINT FK_ROLE_POLICY_POLICY FOREIGN KEY (POLICY_ID ) @@ -284,11 +296,11 @@ CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( ID INT NOT NULL AUTO_INCREMENT , DEVICE_ID INT NOT NULL , - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL , POLICY_CONTENT BLOB NULL , TENANT_ID INT NOT NULL, - APPLIED TINYINT(1) NULL , + APPLIED TINYINT NULL , CREATED_TIME TIMESTAMP NULL , UPDATED_TIME TIMESTAMP NULL , APPLIED_TIME TIMESTAMP NULL , @@ -341,7 +353,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( ID INT NOT NULL AUTO_INCREMENT, DEVICE_ID INT NOT NULL, - ENROLMENT_ID INT(11) NOT NULL, + ENROLMENT_ID INT NOT NULL, POLICY_ID INT NOT NULL, TENANT_ID INT NOT NULL, STATUS INT NULL, @@ -356,7 +368,7 @@ CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( ID INT NOT NULL AUTO_INCREMENT, POLICY_ID INT NOT NULL, DEVICE_TYPE VARCHAR(300) NOT NULL , - TENANT_ID INT(11) NOT NULL, + TENANT_ID INT NOT NULL, PRIMARY KEY (ID) ); @@ -385,7 +397,7 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( LOCATION_URL VARCHAR(100) DEFAULT NULL, IMAGE_URL VARCHAR(100) DEFAULT NULL, APP_PROPERTIES BLOB NULL, - MEMORY_USAGE INTEGER(10) NULL, + MEMORY_USAGE INTEGER NULL, IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, DEVICE_ID INTEGER NOT NULL, ENROLMENT_ID INTEGER NOT NULL, @@ -405,6 +417,16 @@ CREATE TABLE IF NOT EXISTS DM_APPLICATION ( -- POLICY RELATED TABLES FINISHED -- +CREATE TABLE IF NOT EXISTS DM_APP_ICONS ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ICON_PATH VARCHAR(150) DEFAULT NULL, + PACKAGE_NAME VARCHAR(150) NOT NULL, + VERSION VARCHAR(50) DEFAULT '1.1.0', + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (ID) +); + -- NOTIFICATION TABLE -- CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, @@ -425,7 +447,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( DEVICE_ID INT NULL, ENROLMENT_ID INT NOT NULL, KEY_FIELD VARCHAR(45) NULL, - VALUE_FIELD VARCHAR(1000) NULL, + VALUE_FIELD VARCHAR(1500) NULL, PRIMARY KEY (ID), CONSTRAINT DM_DEVICE_INFO_DEVICE FOREIGN KEY (DEVICE_ID) @@ -454,7 +476,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( STATE VARCHAR(45) NULL, COUNTRY VARCHAR(45) NULL, GEO_HASH VARCHAR(45) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, ALTITUDE DOUBLE NULL, SPEED FLOAT NULL, BEARING FLOAT NULL, @@ -491,8 +513,8 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( CPU_USAGE DECIMAL(5) NULL, TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, - PLUGGED_IN INT(1) NULL, - UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + PLUGGED_IN INT NULL, + UPDATE_TIMESTAMP BIGINT NOT NULL, PRIMARY KEY (ID), CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE FOREIGN KEY (DEVICE_ID) @@ -519,7 +541,7 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS LONGITUDE DOUBLE NULL, SPEED FLOAT NULL, HEADING FLOAT NULL, - TIMESTAMP BIGINT(15) NOT NULL, + TIMESTAMP BIGINT NOT NULL, GEO_HASH VARCHAR(45) NULL, DEVICE_OWNER VARCHAR(45) NULL, DEVICE_ALTITUDE DOUBLE NULL, @@ -744,24 +766,6 @@ CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING ( STATUS INT DEFAULT 0, PRIMARY KEY (ID) ); -/* - * 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. - */ - -- END OF DM_EXT_DEVICE_MAPPING TABLE-- -- END OF DM_EXT_PERMISSION_MAPPING TABLE-- @@ -773,23 +777,23 @@ CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( -- DYNAMIC TASK TABLES-- CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( - DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, - NAME VARCHAR(300) DEFAULT NULL , - CRON VARCHAR(8000) DEFAULT NULL, - IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, - TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, - TENANT_ID INTEGER DEFAULT 0, - PRIMARY KEY (DYNAMIC_TASK_ID) + DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) ); CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( - DYNAMIC_TASK_ID INTEGER NOT NULL, - PROPERTY_NAME VARCHAR(100) DEFAULT 0, - PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, - TENANT_ID VARCHAR(100), - PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), - CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES - DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE ); -- END OF DYNAMIC TASK TABLE-- @@ -802,5 +806,34 @@ CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( TYPE_DEFINITION TEXT NOT NULL, PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) ); +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + +-- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- +CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_NAME VARCHAR(100) NOT NULL, + IOTS_DEVICE_IDENTIFIER VARCHAR(300) DEFAULT NULL UNIQUE, + TRACCAR_DEVICE_UNIQUE_ID INT NOT NULL, + TRACCAR_USENAME VARCHAR(100) NULL, + STATUS VARCHAR(100) NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_TRACCAR_UNSYNCED_DEVICES TABLE -- + +-- SUB_OPERATION_TEMPLATE TABLE-- +CREATE TABLE IF NOT EXISTS SUB_OPERATION_TEMPLATE ( + SUB_OPERATION_TEMPLATE_ID INT NOT NULL AUTO_INCREMENT, + OPERATION_DEFINITION TEXT NOT NULL, + OPERATION_CODE VARCHAR(100) NOT NULL, + SUB_TYPE_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + CREATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, + UPDATE_TIMESTAMP TIMESTAMP NULL DEFAULT NULL, + PRIMARY KEY (SUB_OPERATION_TEMPLATE_ID), + CONSTRAINT uk_sub_operation_template UNIQUE (SUB_TYPE_ID, OPERATION_CODE, DEVICE_TYPE), +-- UNIQUE KEY SUB_OPERATION_TEMPLATE (SUB_TYPE_ID, OPERATION_CODE, DEVICE_TYPE), + CONSTRAINT fk_SUB_OPERATION_TEMPLATE_DM_DEVICE_SUB_TYPE FOREIGN KEY (SUB_TYPE_ID, DEVICE_TYPE) REFERENCES DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, DEVICE_TYPE) +); --- END OF DM_DEVICE_SUB_TYPE TABLE-- \ No newline at end of file +-- END OF SUB_OPERATION_TEMPLATE TABLE-- diff --git a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml index ad8165fc674..2e591b07c92 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml +++ b/components/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml @@ -18,7 +18,7 @@ --> - jdbc:h2:mem:smart-meter-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + jdbc:h2:mem:smart-meter-test-db;DB_CLOSE_ON_EXIT=FALSE org.h2.Driver wso2carbon wso2carbon diff --git a/components/subtype-mgt/pom.xml b/components/subtype-mgt/pom.xml index 0f4e0f5f5a2..91d04c4c335 100644 --- a/components/subtype-mgt/pom.xml +++ b/components/subtype-mgt/pom.xml @@ -20,7 +20,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml index 0913807c9c8..26e51edae75 100755 --- a/components/task-mgt/pom.xml +++ b/components/task-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.common/pom.xml index daf623b3354..06997c8f170 100755 --- a/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.common/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.common/pom.xml @@ -20,7 +20,7 @@ task-manager io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.core/pom.xml index 802b4fc403a..20edac784a0 100755 --- a/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.core/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.device.mgt.core.task.mgt.core/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core task-manager - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/pom.xml b/components/task-mgt/task-manager/pom.xml index 9ea2215ea77..f0eb9087822 100755 --- a/components/task-mgt/task-manager/pom.xml +++ b/components/task-mgt/task-manager/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core task-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/io.entgra.device.mgt.core.task.mgt.watcher/pom.xml b/components/task-mgt/task-watcher/io.entgra.device.mgt.core.task.mgt.watcher/pom.xml index e6c32be2040..7c15343e735 100755 --- a/components/task-mgt/task-watcher/io.entgra.device.mgt.core.task.mgt.watcher/pom.xml +++ b/components/task-mgt/task-watcher/io.entgra.device.mgt.core.task.mgt.watcher/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core task-watcher - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/pom.xml b/components/task-mgt/task-watcher/pom.xml index 456c5732048..d14ddd7d188 100755 --- a/components/task-mgt/task-watcher/pom.xml +++ b/components/task-mgt/task-watcher/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core task-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/pom.xml b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/pom.xml index 1d07439a11c..b4ba0d60bfe 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/pom.xml +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.common/pom.xml @@ -20,7 +20,7 @@ tenant-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/pom.xml b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/pom.xml index 5ed39189904..8163f936a30 100644 --- a/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/pom.xml +++ b/components/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.core/pom.xml @@ -20,7 +20,7 @@ tenant-mgt io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/pom.xml b/components/tenant-mgt/pom.xml index ce01e21a9cc..bdc00ce03d7 100644 --- a/components/tenant-mgt/pom.xml +++ b/components/tenant-mgt/pom.xml @@ -20,7 +20,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/email-sender/io.entgra.device.mgt.core.transport.mgt.email.sender.core/pom.xml b/components/transport-mgt/email-sender/io.entgra.device.mgt.core.transport.mgt.email.sender.core/pom.xml index 2b70f9001df..6550c0c17bf 100644 --- a/components/transport-mgt/email-sender/io.entgra.device.mgt.core.transport.mgt.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/io.entgra.device.mgt.core.transport.mgt.email.sender.core/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core email-sender - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index 77c2cf12cb6..06b561b2374 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core transport-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index a2140712f7c..7c275e0a25c 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api/pom.xml index 2e0dd266f57..9abdfa37357 100644 --- a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core sms-handler - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.common/pom.xml index fceb5e77d1d..60dcfdbe953 100644 --- a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core sms-handler - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.core/pom.xml index e91b0ed983e..a23d2d922d9 100644 --- a/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core sms-handler - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index 6eda7374a97..18baf3dd9db 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core transport-mgt - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/pom.xml index a58b6b40ae7..685e75809d8 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT 4.0.0 diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/DefaultTokenHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/DefaultTokenHandler.java index 1d757b421e7..a40dcafefdf 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/DefaultTokenHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/DefaultTokenHandler.java @@ -19,7 +19,6 @@ package io.entgra.device.mgt.core.ui.request.interceptor; import com.google.gson.Gson; -import com.google.gson.JsonElement; import com.google.gson.JsonObject; import com.google.gson.JsonParser; import io.entgra.device.mgt.core.ui.request.interceptor.beans.AuthData; @@ -27,13 +26,22 @@ import io.entgra.device.mgt.core.ui.request.interceptor.beans.ProxyResponse; import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerConstants; import io.entgra.device.mgt.core.ui.request.interceptor.util.HandlerUtil; import org.apache.commons.lang.StringUtils; +import io.entgra.ui.request.interceptor.util.HandlerConstants; +import io.entgra.ui.request.interceptor.util.HandlerUtil; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpHeaders; import org.apache.http.HttpStatus; -import org.apache.http.client.methods.HttpGet; import org.apache.http.client.utils.URIBuilder; import org.apache.http.entity.ContentType; +import io.entgra.ui.request.interceptor.beans.ProxyResponse; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.exceptions.OTPManagementException; +import org.wso2.carbon.device.mgt.common.otp.mgt.OTPEmailTypes; +import org.wso2.carbon.device.mgt.common.otp.mgt.dto.OneTimePinDTO; +import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; +import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.core.service.RealmService; import javax.servlet.annotation.MultipartConfig; import javax.servlet.annotation.WebServlet; @@ -55,71 +63,28 @@ public class DefaultTokenHandler extends HttpServlet { HttpSession httpSession = req.getSession(false); if (httpSession != null) { - AuthData authData = (AuthData) httpSession.getAttribute(HandlerConstants.SESSION_AUTH_DATA_KEY); - if (authData == null) { - HandlerUtil.sendUnAuthorizeResponse(resp); - return; + String userWithDomain = (String) httpSession.getAttribute(HandlerConstants.USERNAME_WITH_DOMAIN); + String[] userNameParts = userWithDomain.split("@"); + + OneTimePinDTO oneTimePinData = new OneTimePinDTO(); + oneTimePinData.setEmail(OTPEmailTypes.REMOTE_SESSION.toString()); + oneTimePinData.setEmailType(OTPEmailTypes.REMOTE_SESSION.toString()); + oneTimePinData.setUsername(userNameParts[0]); + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + RealmService realmService = (RealmService) ctx.getOSGiService(RealmService.class, null); + try { + oneTimePinData.setTenantId(realmService.getTenantManager().getTenantId(userNameParts[1])); + } catch (UserStoreException e) { + throw new RuntimeException(e); } - - AuthData defaultAuthData = (AuthData) httpSession - .getAttribute(HandlerConstants.SESSION_DEFAULT_AUTH_DATA_KEY); - if (defaultAuthData != null) { - HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(defaultAuthData.getAccessToken())); - return; - } - - String clientId = authData.getClientId(); - String clientSecret = authData.getClientSecret(); - - String queryString = req.getQueryString(); - String scopeString = ""; - if (StringUtils.isNotEmpty(queryString)) { - scopeString = req.getParameter("scopes"); - if (scopeString != null) { - scopeString = "?scopes=" + scopeString; - } - } - - String iotsCoreUrl = req.getScheme() + HandlerConstants.SCHEME_SEPARATOR - + System.getProperty(HandlerConstants.IOT_GW_HOST_ENV_VAR) - + HandlerConstants.COLON + HandlerUtil.getGatewayPort(req.getScheme()); - String tokenUrl = iotsCoreUrl + "/api/device-mgt/v1.0/devices/" + clientId - + "/" + clientSecret + "/default-token" + scopeString; - - HttpGet defaultTokenRequest = new HttpGet(tokenUrl); - defaultTokenRequest - .setHeader(HttpHeaders.AUTHORIZATION, HandlerConstants.BEARER + authData.getAccessToken()); - defaultTokenRequest - .setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_FORM_URLENCODED.toString()); - ProxyResponse tokenResultResponse = HandlerUtil.execute(defaultTokenRequest); - - if (tokenResultResponse.getExecutorResponse().contains(HandlerConstants.EXECUTOR_EXCEPTION_PREFIX)) { - log.error("Error occurred while invoking the API to get default token data."); - HandlerUtil.handleError(resp, tokenResultResponse); - return; - } - String tokenResult = tokenResultResponse.getData(); - if (tokenResult == null) { - log.error("Invalid default token response is received."); - HandlerUtil.handleError(resp, tokenResultResponse); - return; - } - - JsonParser jsonParser = new JsonParser(); - JsonElement jTokenResult = jsonParser.parse(tokenResult); - if (jTokenResult.isJsonObject()) { - JsonObject jTokenResultAsJsonObject = jTokenResult.getAsJsonObject(); - AuthData newDefaultAuthData = new AuthData(); - newDefaultAuthData.setClientId(clientId); - newDefaultAuthData.setClientSecret(clientSecret); - - String defaultToken = jTokenResultAsJsonObject.get("accessToken").getAsString(); - newDefaultAuthData.setAccessToken(defaultToken); - newDefaultAuthData.setRefreshToken(jTokenResultAsJsonObject.get("refreshToken").getAsString()); - newDefaultAuthData.setScope(jTokenResultAsJsonObject.get("scopes").getAsString()); - httpSession.setAttribute(HandlerConstants.SESSION_DEFAULT_AUTH_DATA_KEY, newDefaultAuthData); - - HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(defaultToken)); + oneTimePinData.setExpiryTime(DeviceManagementConstants.OTPProperties.OTP_DEFAULT_EXPIRY_SECONDS); + OTPManagementService otpManagementService = HandlerUtil.getOTPManagementService(); + try { + oneTimePinData = otpManagementService.generateOneTimePin(oneTimePinData, true); + HandlerUtil.handleSuccess(resp, constructSuccessProxyResponse(oneTimePinData.getOtpToken())); + } catch (OTPManagementException e) { + log.error("Failed while generating remote session OTP for user " + userWithDomain, e); + HandlerUtil.handleError(resp, HttpStatus.SC_INTERNAL_SERVER_ERROR); } } else { HandlerUtil.sendUnAuthorizeResponse(resp); diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/UserHandler.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/UserHandler.java index d5e8d2bf4d7..c0f6c7f6ee9 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/UserHandler.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/UserHandler.java @@ -120,6 +120,7 @@ public class UserHandler extends HttpServlet { proxyResponse.setData( jTokenResultAsJsonObject.get("username").getAsString().replaceAll("@carbon.super", "")); HandlerUtil.handleSuccess(resp, proxyResponse); + httpSession.setAttribute(HandlerConstants.USERNAME_WITH_DOMAIN, jTokenResultAsJsonObject.get("username").getAsString()); log.info("Customer login", userLogContextBuilder.setUserName(proxyResponse.getData()).setUserRegistered(true).build()); } } catch (IOException e) { diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java index 239cf1c944c..9aa9cb9fe68 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerConstants.java @@ -106,4 +106,5 @@ public class HandlerConstants { public static final String IOT_REPORTING_WEBAPP_HOST_ENV_VAR = "iot.reporting.webapp.host"; public static final String USER_SCOPES = "userScopes"; public static final String HUBSPOT_CHAT_URL = "api.hubapi.com"; + public static final String USERNAME_WITH_DOMAIN = "usernameWithDomain"; } diff --git a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerUtil.java b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerUtil.java index 5a05a194251..f15215067eb 100644 --- a/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerUtil.java +++ b/components/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor/src/main/java/io/entgra/device/mgt/core/ui/request/interceptor/util/HandlerUtil.java @@ -51,6 +51,9 @@ import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; import org.w3c.dom.Document; +import io.entgra.ui.request.interceptor.beans.ProxyResponse; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.spi.OTPManagementService; import org.xml.sax.SAXException; import javax.servlet.http.HttpServletRequest; @@ -70,6 +73,8 @@ public class HandlerUtil { private static boolean isLoginCacheInitialized = false; private static AuthData authData; + private static OTPManagementService otpManagementService; + /*** * * @param httpRequest - httpMethod e.g:- HttpPost, HttpGet @@ -742,4 +747,12 @@ public class HandlerUtil { public static boolean isPropertyDefined(String property) { return StringUtils.isEmpty(System.getProperty(property)); } + + public static OTPManagementService getOTPManagementService() { + if (otpManagementService == null) { + otpManagementService = (OTPManagementService) PrivilegedCarbonContext + .getThreadLocalCarbonContext().getOSGiService(OTPManagementService.class, null); + } + return otpManagementService; + } } diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 47912a84653..0faab0c2fa8 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/pom.xml index 6476fc0aa62..44862e66e75 100644 --- a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core webapp-authenticator-framework - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml @@ -273,7 +273,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 test diff --git a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java index 6545b7bbabd..11395eef604 100644 --- a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java +++ b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/BasicAuthAuthenticator.java @@ -35,6 +35,7 @@ import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.nio.charset.Charset; import java.util.Base64; import java.util.Properties; +import java.util.StringTokenizer; public class BasicAuthAuthenticator implements WebappAuthenticator { @@ -50,15 +51,23 @@ public class BasicAuthAuthenticator implements WebappAuthenticator { @Override public boolean canHandle(Request request) { /* - This is done to avoid every endpoint being able to use basic auth. Add the following to - the required web.xml of the web app. + This is done to avoid every web app being able to use basic auth. Add the following to + the required web.xml of the web app. This is a global config for a web app to allow all + contexts of the web app to use basic auth basicAuth true + + Adding the basicAuthAllowList parameter allows to selectively allow some context paths in a + web app to use basic auth while all the other context remain unavailable with basic auth. + If this parameter is present, any context that requires basic auth must be specially + added as comma separated list to the param-value of basicAuthAllowList. */ - if (!isAuthenticationSupported(request)) { - return false; + if (!isAllowListedForBasicAuth(request)) { + if (!isAuthenticationSupported(request)) { + return false; + } } if (request.getCoyoteRequest() == null || request.getCoyoteRequest().getMimeHeaders() == null) { return false; @@ -75,6 +84,20 @@ public class BasicAuthAuthenticator implements WebappAuthenticator { return false; } + private boolean isAllowListedForBasicAuth(Request request) { + String param = request.getContext().findParameter("basicAuthAllowList"); + if (param != null && !param.isEmpty()) { + //Add the nonSecured end-points to cache + String[] basicAuthAllowList = param.split(","); + for (String contexPath : basicAuthAllowList) { + if (request.getRequestURI().toString().endsWith(contexPath.trim())) { + return true; + } + } + } + return false; + } + @Override public AuthenticationInfo authenticate(Request request, Response response) { AuthenticationInfo authenticationInfo = new AuthenticationInfo(); diff --git a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java index 5238828dd06..cb9bf502158 100644 --- a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java +++ b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/CertificateAuthenticator.java @@ -74,9 +74,17 @@ public class CertificateAuthenticator implements WebappAuthenticator { // When there is a load balancer terminating mutual SSL, it should pass this header along and // as the value of this header, the client certificate subject dn should be passed. if (request.getHeader(PROXY_MUTUAL_AUTH_HEADER) != null) { + if (log.isDebugEnabled()) { + log.debug("PROXY_MUTUAL_AUTH_HEADER " + request.getHeader(PROXY_MUTUAL_AUTH_HEADER)); + } CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance(). getCertificateManagementService().verifySubjectDN(request.getHeader(PROXY_MUTUAL_AUTH_HEADER)); authenticationInfo = checkCertificateResponse(certificateResponse); + if (log.isDebugEnabled()) { + log.debug("Certificate Serial : " + certificateResponse.getSerialNumber() + + ", CN : " + certificateResponse.getCommonName() + + " , username" + authenticationInfo.getUsername()); + } } else if (request.getHeader(MUTUAL_AUTH_HEADER) != null) { Object object = request.getAttribute(CLIENT_CERTIFICATE_ATTRIBUTE); @@ -89,7 +97,6 @@ public class CertificateAuthenticator implements WebappAuthenticator { CertificateResponse certificateResponse = AuthenticatorFrameworkDataHolder.getInstance(). getCertificateManagementService().verifyPEMSignature(clientCertificate[0]); authenticationInfo = checkCertificateResponse(certificateResponse); - } else { authenticationInfo.setStatus(Status.FAILURE); authenticationInfo.setMessage("No client certificate is present"); diff --git a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/OneTimeTokenAuthenticator.java b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/OneTimeTokenAuthenticator.java index 82e592524b0..29392b63f52 100644 --- a/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/OneTimeTokenAuthenticator.java +++ b/components/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework/src/main/java/io/entgra/device/mgt/core/webapp/authenticator/framework/authenticator/OneTimeTokenAuthenticator.java @@ -49,8 +49,18 @@ public class OneTimeTokenAuthenticator implements WebappAuthenticator { try { OTPManagementService otpManagementService = AuthenticatorFrameworkDataHolder.getInstance() .getOtpManagementService(); - OneTimePinDTO validOTP = otpManagementService.isValidOTP(request.getHeader(Constants.HTTPHeaders - .ONE_TIME_TOKEN_HEADER)); + OneTimePinDTO validOTP; + if (request.getRequestURI().toString().endsWith("cloud/download-url") + || request.getRequestURI().toString().endsWith("cloud/tenant")) { + validOTP = otpManagementService.isValidOTP(request.getHeader(Constants.HTTPHeaders + .ONE_TIME_TOKEN_HEADER), true); + } else { + log.info("Validating OTP for enrollments PIN: " + request.getHeader(Constants + .HTTPHeaders.ONE_TIME_TOKEN_HEADER)); + validOTP = otpManagementService.isValidOTP(request.getHeader(Constants.HTTPHeaders + .ONE_TIME_TOKEN_HEADER), false); + } + if (validOTP != null) { authenticationInfo.setStatus(Status.CONTINUE); authenticationInfo.setTenantId(validOTP.getTenantId()); diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index f5f2d2c1f3d..252b96df531 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.feature/pom.xml index e7d57bd4b7e..c087fc0b4a5 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core grafana-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.server.feature/pom.xml index 01debfaf078..570f87276fd 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.device.mgt.core.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core grafana-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index 2087a828701..7dd4d6fb949 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core analytics-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index 168b828243f..2ebf097dd77 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml index 73abea954fb..c0456a9c1ca 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml @@ -20,7 +20,7 @@ io.entgra.device.mgt.core apimgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.feature/pom.xml index f13b9e39271..b157b5afa63 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core apimgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml index b0f3a595a59..98ac163d227 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api.feature/pom.xml @@ -17,14 +17,12 @@ ~ under the License. --> - + io.entgra.device.mgt.core apimgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.feature/pom.xml index 636cc8c34eb..696558150fc 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core apimgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml index 1a2cb3b77e2..6ed24661094 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core apimgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 9c37daadaef..7e04260393b 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/pom.xml index eaa8ffa5c76..28411676893 100644 --- a/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.device.mgt.core.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core application-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index 4877de4bbe3..499e95ba461 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api.feature/pom.xml index 5617820cf52..da7eeda702b 100644 --- a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core certificate-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.feature/pom.xml index c21ff6fb193..b434483af3b 100644 --- a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core certificate-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.server.feature/pom.xml index 3867d0806ea..ad2d1c068c8 100644 --- a/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/io.entgra.device.mgt.core.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core certificate-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index 3acaabfd9d7..366cffe69eb 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.feature/pom.xml index ee3a2da42ac..7a33d7ebefb 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.defaultrole.manager.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.feature/pom.xml index 5d58fe1956f..bd44c707b07 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger.feature/pom.xml index 6ba482a99f5..0798f33b74e 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.logger.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 89babbcd7a7..dfbd7c1aa59 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index 9dacdae6bac..3e3e688d592 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index e37e6fbd262..844427fea52 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index f74312e6a39..8648168dca3 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature/pom.xml index 810e45e3b72..1c2f9f450a6 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.core.device.mgt.extensions.stateengine.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-extensions-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index e02dcb80128..84e33b2daf5 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.api.feature/pom.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.api.feature/pom.xml index 845e0f69d7f..8f8ec91fbac 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/pom.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/pom.xml index 2a2c6468b1a..406388f4229 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml index 3ce48daefe4..c40cefc413a 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/cdm-config.xml @@ -189,7 +189,7 @@ <a href='https://entgra.io' target='_blank'> Entgra </a> - IoT Server 5.2.0 | © 2023 + UEM Server 5.3.0 | © 2023 , All Rights Reserved. Entgra diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml index 46114821a2e..b16935562de 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf/mdm-ui-config.xml @@ -224,9 +224,22 @@ perm:admin:tenant:view perm:admin:metadata:view perm:admin:usage:view - perm:android:clear-applicatio + perm:android:clear-application perm:android:suspend-package perm:android:alternate-install + perm:ios:lock + perm:ios:location + perm:ios:ring + perm:ios:clear-passcode + perm:ios:enterprise-wipe + perm:ios:notification + perm:ios:wipe-data + perm:ios:boolean-setting + perm:ios:wallpaper + perm:ios:app-attributes + perm:ios:app-configurations + perm:mac-os:restart + perm:mac-os:shut-down device-mgt diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 index 262761caecc..2152b1814f0 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/cdm-config.xml.j2 @@ -325,12 +325,16 @@ - <a href='https://entgra.io' target='_blank'> - Entgra - </a> - IoT Server 5.2.0 | © 2023 - , All Rights Reserved. - + <a href='https://entgra.io' target='_blank'> + Entgra + </a> + {% if product_conf is defined %} + {{product_conf.server_name}} {{product_conf.server_version}} | © {{product_conf.current_year}} + {% else %} + Entgra UEM Server + {% endif %} + , All Rights Reserved. + Entgra repository/resources/whitelabel diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index df3277920dd..15ffa69605f 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -25,6 +25,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( OWNER VARCHAR(255) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index c162d41e060..5b6b3b93f14 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -41,6 +41,7 @@ IF NOT EXISTS(SELECT * OWNER VARCHAR(255) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ); diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 6dcc7bec443..86da197b12f 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -29,6 +29,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( OWNER VARCHAR(255) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ) ENGINE = InnoDB; diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index a6f87c9cb63..6cc55f7e741 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -52,6 +52,7 @@ CREATE TABLE DM_GROUP ( OWNER VARCHAR2(255) DEFAULT NULL, PARENT_PATH VARCHAR2(255) DEFAULT NULL, TENANT_ID NUMBER(10) DEFAULT 0, + PARENT_GROUP_ID NUMBER(10) DEFAULT 0, CONSTRAINT PK_DM_GROUP PRIMARY KEY (ID) ) / diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index 8c601111b74..b1fc128cf91 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -23,6 +23,7 @@ CREATE TABLE IF NOT EXISTS DM_GROUP ( OWNER VARCHAR(45) DEFAULT NULL, PARENT_PATH VARCHAR(255) DEFAULT NULL, TENANT_ID INTEGER DEFAULT 0, + PARENT_GROUP_ID INTEGER DEFAULT 0, PRIMARY KEY (ID) ) ; diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions.feature/pom.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions.feature/pom.xml index 904012948e0..062cc6df3e0 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.extensions.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.feature/pom.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.feature/pom.xml index 6455ab6f058..9ef814e62f5 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.feature/pom.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.server.feature/pom.xml b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.server.feature/pom.xml index cb5841a715e..80ed932a53c 100644 --- a/features/device-mgt/io.entgra.device.mgt.core.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/io.entgra.device.mgt.core.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core device-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index 230fa3700f9..96c5194c45b 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.device.mgt.core.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.device.mgt.core.server.heart.beat.feature/pom.xml index e1b4db491a2..096683db820 100644 --- a/features/heartbeat-management/io.entgra.device.mgt.core.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.device.mgt.core.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core heart-beat-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index f551b3e5181..a2d4bed8ba4 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/jwt-client/io.entgra.device.mgt.core.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/io.entgra.device.mgt.core.identity.jwt.client.extension.feature/pom.xml index 57b14380276..13e974fbdb2 100644 --- a/features/jwt-client/io.entgra.device.mgt.core.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/io.entgra.device.mgt.core.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core jwt-client-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index 3220ebb7da6..c3e2fafa706 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/logger/io.entgra.device.mgt.core.notification.logger.feature/pom.xml b/features/logger/io.entgra.device.mgt.core.notification.logger.feature/pom.xml index 1bfe57fa697..fd4fb89fd9a 100644 --- a/features/logger/io.entgra.device.mgt.core.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.device.mgt.core.notification.logger.feature/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core logger-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/logger/pom.xml b/features/logger/pom.xml index f4b3d3e41aa..34a5aa4ccfb 100644 --- a/features/logger/pom.xml +++ b/features/logger/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/operation-template-mgt-plugin-feature/io.entgra.device.mgt.core.operation.template.feature/pom.xml b/features/operation-template-mgt-plugin-feature/io.entgra.device.mgt.core.operation.template.feature/pom.xml index f9f8ce9f41d..3eb94e0b04c 100644 --- a/features/operation-template-mgt-plugin-feature/io.entgra.device.mgt.core.operation.template.feature/pom.xml +++ b/features/operation-template-mgt-plugin-feature/io.entgra.device.mgt.core.operation.template.feature/pom.xml @@ -17,13 +17,12 @@ ~ under the License. --> - + io.entgra.device.mgt.core operation-template-mgt-plugin-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/operation-template-mgt-plugin-feature/pom.xml b/features/operation-template-mgt-plugin-feature/pom.xml index a16c2191341..8351d509465 100644 --- a/features/operation-template-mgt-plugin-feature/pom.xml +++ b/features/operation-template-mgt-plugin-feature/pom.xml @@ -17,13 +17,12 @@ ~ under the License. --> - + io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/policy-mgt/io.entgra.device.mgt.core.policy.mgt.server.feature/pom.xml b/features/policy-mgt/io.entgra.device.mgt.core.policy.mgt.server.feature/pom.xml index 7f96d0da930..02b8f172a58 100644 --- a/features/policy-mgt/io.entgra.device.mgt.core.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/io.entgra.device.mgt.core.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core policy-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index 97a7746320d..5eaac22ad1f 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt.feature/pom.xml b/features/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt.feature/pom.xml index cf0e00a0b59..30094f7686f 100644 --- a/features/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt.feature/pom.xml +++ b/features/subtype-mgt/io.entgra.device.mgt.core.subtype.mgt.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../../pom.xml diff --git a/features/subtype-mgt/pom.xml b/features/subtype-mgt/pom.xml index f37cf1d8f35..3cccf87ad1b 100644 --- a/features/subtype-mgt/pom.xml +++ b/features/subtype-mgt/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/task-mgt/io.entgra.device.mgt.core.task.mgt.feature/pom.xml b/features/task-mgt/io.entgra.device.mgt.core.task.mgt.feature/pom.xml index 7984cd55212..3243b268274 100755 --- a/features/task-mgt/io.entgra.device.mgt.core.task.mgt.feature/pom.xml +++ b/features/task-mgt/io.entgra.device.mgt.core.task.mgt.feature/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../../pom.xml diff --git a/features/task-mgt/pom.xml b/features/task-mgt/pom.xml index a70cbbc67a7..d7e84d2782d 100755 --- a/features/task-mgt/pom.xml +++ b/features/task-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.server.feature/pom.xml b/features/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.server.feature/pom.xml index 001cc0dd34a..002b18f48f8 100644 --- a/features/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.server.feature/pom.xml +++ b/features/tenant-mgt/io.entgra.device.mgt.core.tenant.mgt.server.feature/pom.xml @@ -20,7 +20,7 @@ tenant-mgt-feature io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/tenant-mgt/pom.xml b/features/tenant-mgt/pom.xml index a19947d3328..8f87de9b1f4 100644 --- a/features/tenant-mgt/pom.xml +++ b/features/tenant-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/pom.xml index 73986be63f4..ee105d34b80 100644 --- a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core email-sender-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm index 7765bcdda2e..ef5307de332 100644 --- a/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm +++ b/features/transport-mgt/email-sender/io.entgra.device.mgt.core.email.sender.feature/src/main/resources/email/templates/user-enrollment.vm @@ -37,7 +37,7 @@

You have been invited to enrol your device in Entgra IoT Server. - Click here to begin device enrolment.

+ Click here to begin device enrolment.

Enrollment Steps are as below, diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index a75c167bfa6..53fcfbaee91 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core transport-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index ee58261e6c4..23513d7ed89 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api.feature/pom.xml index 5dcab5c6545..b6dd0dcc5c3 100644 --- a/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core sms-handler-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.server.feature/pom.xml index d9b3cb564c8..c7f0a53f588 100644 --- a/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.device.mgt.core.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core sms-handler-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index d60cefe7be4..8350d1b2d2b 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core transport-mgt-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor.feature/pom.xml index 90ba4c04ccc..53903a27e5d 100644 --- a/features/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.device.mgt.core.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index 45b132211db..a3ead6185d3 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ io.entgra.device.mgt.core.parent io.entgra.device.mgt.core - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/pom.xml index ce0141f9159..f8aa63d70f1 100644 --- a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core webapp-authenticator-framework-feature - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../pom.xml diff --git a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml index bf5d2e00e24..c3bb4569b87 100644 --- a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml +++ b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf/webapp-authenticator-config.xml @@ -24,8 +24,8 @@ false https://${iot.keymanager.host}:${iot.keymanager.https.port} - ${admin.username} - ${admin.password} + {{super_admin.username}} + {{super_admin.password}} 100 100 diff --git a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2 b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2 index 7c3ce354864..6c51e0f2b64 100644 --- a/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2 +++ b/features/webapp-authenticator-framework/io.entgra.device.mgt.core.webapp.authenticator.framework.server.feature/src/main/resources/conf_templates/templates/repository/conf/etc/webapp-authenticator-config.xml.j2 @@ -14,8 +14,8 @@ false https://${iot.keymanager.host}:${iot.keymanager.https.port} - ${admin.username} - ${admin.password} + {{super_admin.username}} + {{super_admin.password}} 100 100 diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index 5aaec7c6b5b..adbbd923162 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index 28dfc7301ba..1a0eab8a0f6 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ io.entgra.device.mgt.core io.entgra.device.mgt.core.parent pom - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT WSO2 Carbon - Device Management - Parent https://entgra.io WSO2 Connected Device Manager Components @@ -833,6 +833,16 @@ jaxb-api ${version.org.wso2.orbit.javax.xml.bind} + + com.sun.xml.bind + jaxb-core + 2.3.0.1 + + + com.sun.xml.bind + jaxb-impl + 2.3.1 + org.apache.axis2.transport @@ -1654,7 +1664,7 @@ org.powermock - powermock-api-mockito + powermock-api-mockito2 ${power.mock.version} test @@ -1741,6 +1751,11 @@ mockito-inline ${mokito.version} + + org.mockito + mockito-core + ${mokito.version} + org.ops4j.pax.logging pax-logging-api @@ -1888,7 +1903,7 @@ org.apache.maven.plugins maven-surefire-plugin - 2.22.0 + 2.22.2 ${basedir}/target/coverage-reports/jacoco-ut.exec @@ -1982,7 +1997,7 @@ 1.2.11-wso2v25 - 5.0.26-SNAPSHOT + 5.0.27-SNAPSHOT 4.9.2 @@ -2113,7 +2128,7 @@ 0.7.8 0.7.5.201505241946 1.0b3 - 1.7.4 + 2.0.2 1.4.0.wso2v1 1.7.25 @@ -2136,7 +2151,7 @@ [1.6.0, 2.0.0) [1.2.0,1.3.0) - 4.2.0 + 2.23.4 2.8.1.wso2v2 4.3.1.wso2v1 2.1.210.wso2v1