diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml index c976a122660..1f61d4764fe 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml index 12c5939e74f..ab6af57c814 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml index e00fe81ccd6..62ae2b4b8c1 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index e94704b2d94..da7f65cd21c 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index c4b202c764d..e18b9424af1 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 50651fabe17..e05177b5ac0 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index 093dcfa209b..966a9e36492 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java index 014a59b9c5c..a68e8b20789 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/src/main/java/org/wso2/carbon/apimgt/application/extension/api/util/APIUtil.java @@ -49,6 +49,7 @@ public class APIUtil { private static final String DEFAULT_ANALYTICS_ARTIFACT_TAG = "analytics_artifacts_management"; private static final String DEFAULT_TRANSPORT_MGT_TAG = "transport_management"; private static final String DEFAULT_ENTERPRISE_TAG= "androidforwork"; + private static final String DEFAULT_ANALYTICS_MGT_TAG= "analytics_management"; public static final String PERMISSION_PROPERTY_NAME = "name"; @@ -119,6 +120,7 @@ public class APIUtil { allowedApisTags.add(DEFAULT_APP_MGT_SUB_MGT_TAG); allowedApisTags.add(DEFAULT_ANALYTICS_ARTIFACT_TAG); allowedApisTags.add(DEFAULT_TRANSPORT_MGT_TAG); + allowedApisTags.add(DEFAULT_ANALYTICS_MGT_TAG); // In an environment only super tenant should be capable of calling this API tag if (PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId() == MultitenantConstants.SUPER_TENANT_ID) { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index cb70bb49272..174bc258a27 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml index 93950734eb1..eb165c0a8db 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/DCRRequest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/DCRRequest.java index 36f6c4d9f73..5054e2220d0 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/DCRRequest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/DCRRequest.java @@ -28,9 +28,9 @@ import javax.xml.bind.annotation.XmlRootElement; @JsonIgnoreProperties(ignoreUnknown = true) public class DCRRequest { @XmlElement(required = true) - private String clientName; + private String applicationName; @XmlElement(required = true) - private String owner; + private String username; @XmlElement(required = true) private String grantTypes; @XmlElement @@ -40,20 +40,20 @@ public class DCRRequest { @XmlElement private boolean isSaasApp; - public String getClientName() { - return clientName; + public String getApplicationName() { + return applicationName; } - public void setClientName(String clientName) { - this.clientName = clientName; + public void setApplicationName(String applicationName) { + this.applicationName = applicationName; } - public String getOwner() { - return owner; + public String getUsername() { + return username; } - public void setOwner(String owner) { - this.owner = owner; + public void setUsername(String username) { + this.username = username; } public String getGrantTypes() { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerService.java index 14ca64a2e60..32f4e5112a1 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerService.java @@ -20,6 +20,7 @@ package org.wso2.carbon.apimgt.keymgt.extension.api; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; @@ -38,9 +39,12 @@ public interface KeyManagerService { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/token") - Response generateAccessToken(@FormParam("client_id") String clientId, + Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader, + @FormParam("client_id") String clientId, @FormParam("client_secret") String clientSecret, @FormParam("refresh_token") String refreshToken, @FormParam("scope") String scope, - @FormParam("grant_type") String grantType); + @FormParam("grant_type") String grantType, + @FormParam("assertion") String assertion, + @FormParam("admin_access_token") String admin_access_token); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerServiceImpl.java index 53b2c4ffca5..161413b4ffb 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/api/KeyManagerServiceImpl.java @@ -27,14 +27,17 @@ import org.wso2.carbon.apimgt.keymgt.extension.exception.BadRequestException; import org.wso2.carbon.apimgt.keymgt.extension.exception.KeyMgtException; import org.wso2.carbon.apimgt.keymgt.extension.service.KeyMgtService; import org.wso2.carbon.apimgt.keymgt.extension.service.KeyMgtServiceImpl; +import org.wso2.carbon.device.mgt.common.exceptions.UnAuthorizedException; import javax.ws.rs.Consumes; import javax.ws.rs.FormParam; +import javax.ws.rs.HeaderParam; import javax.ws.rs.POST; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import javax.ws.rs.core.Response; +import java.util.Base64; public class KeyManagerServiceImpl implements KeyManagerService { @@ -46,7 +49,7 @@ public class KeyManagerServiceImpl implements KeyManagerService { public Response dynamicClientRegistration(DCRRequest dcrRequest) { try { KeyMgtService keyMgtService = new KeyMgtServiceImpl(); - DCRResponse resp = keyMgtService.dynamicClientRegistration(dcrRequest.getClientName(), dcrRequest.getOwner(), + DCRResponse resp = keyMgtService.dynamicClientRegistration(dcrRequest.getApplicationName(), dcrRequest.getUsername(), dcrRequest.getGrantTypes(), dcrRequest.getCallBackUrl(), dcrRequest.getTags(), dcrRequest.getIsSaasApp()); return Response.status(Response.Status.CREATED).entity(resp).build(); } catch (KeyMgtException e) { @@ -58,20 +61,32 @@ public class KeyManagerServiceImpl implements KeyManagerService { @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path("/token") - public Response generateAccessToken(@FormParam("client_id") String clientId, + public Response generateAccessToken(@HeaderParam("Authorization") String basicAuthHeader, + @FormParam("client_id") String clientId, @FormParam("client_secret") String clientSecret, @FormParam("refresh_token") String refreshToken, @FormParam("scope") String scope, - @FormParam("grant_type") String grantType) { + @FormParam("grant_type") String grantType, + @FormParam("assertion") String assertion, + @FormParam("admin_access_token") String admin_access_token) { try { + if (basicAuthHeader == null) { + String msg = "Invalid credentials. Make sure your API call is invoked with a Basic Authorization header."; + throw new UnAuthorizedException(msg); + } + String encodedClientCredentials = new String(Base64.getDecoder().decode(basicAuthHeader.split(" ")[1])); KeyMgtService keyMgtService = new KeyMgtServiceImpl(); TokenResponse resp = keyMgtService.generateAccessToken( - new TokenRequest(clientId, clientSecret, refreshToken, scope, grantType)); + new TokenRequest(encodedClientCredentials.split(":")[0], + encodedClientCredentials.split(":")[1], refreshToken, scope, + grantType, assertion,admin_access_token)); return Response.status(Response.Status.CREATED).entity(resp).build(); } catch (KeyMgtException e) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(e.getMessage()).build(); } catch (BadRequestException e) { return Response.status(Response.Status.BAD_REQUEST).entity(e.getMessage()).build(); + } catch (UnAuthorizedException e) { + return Response.status(Response.Status.UNAUTHORIZED).entity(e.getMessage()).build(); } } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml index db8c5f919d9..2b4513d71d3 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/DCRResponse.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/DCRResponse.java index 22dc2336a6a..9d854b9ebe3 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/DCRResponse.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/DCRResponse.java @@ -19,27 +19,27 @@ package org.wso2.carbon.apimgt.keymgt.extension; public class DCRResponse { - String clientId; - String clientSecret; + String client_id; + String client_secret; - public DCRResponse(String clientId, String clientSecret) { - this.clientId = clientId; - this.clientSecret = clientSecret; + public DCRResponse(String client_id, String client_secret) { + this.client_id = client_id; + this.client_secret = client_secret; } public String getClientId() { - return clientId; + return client_id; } - public void setClientId(String clientId) { - this.clientId = clientId; + public void setClientId(String client_id) { + this.client_id = client_id; } public String getClientSecret() { - return clientSecret; + return client_secret; } - public void setClientSecret(String clientSecret) { - this.clientSecret = clientSecret; + public void setClientSecret(String client_secret) { + this.client_secret = client_secret; } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenRequest.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenRequest.java index 8ab5c3da354..ae5b668cba4 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenRequest.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenRequest.java @@ -24,13 +24,18 @@ public class TokenRequest { private String refreshToken; private String scope; private String grantType; + private String assertion; + private String admin_access_token; - public TokenRequest(String clientId, String clientSecret, String refreshToken, String scope, String grantType) { + public TokenRequest(String clientId, String clientSecret, String refreshToken, String scope, String grantType, + String assertion, String admin_access_token) { this.clientId = clientId; this.clientSecret = clientSecret; this.refreshToken = refreshToken; this.scope = scope; this.grantType = grantType; + this.assertion = assertion; + this.admin_access_token = admin_access_token; } public String getClientId() { @@ -72,4 +77,20 @@ public class TokenRequest { public void setRefreshToken(String refreshToken) { this.refreshToken = refreshToken; } + + public String getAssertion() { + return assertion; + } + + public void setAssertion(String assertion) { + this.assertion = assertion; + } + + public String getAdminAccessToken() { + return admin_access_token; + } + + public void setAdminAccessToken(String admin_access_token) { + this.admin_access_token = admin_access_token; + } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenResponse.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenResponse.java index 8373d7f8f1b..02988138786 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenResponse.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/TokenResponse.java @@ -22,14 +22,14 @@ public class TokenResponse { private String access_token; private String refresh_token; private String scope; - private String tokenType; + private String token_type; private int expires_in; - public TokenResponse(String access_token, String refresh_token, String scope, String tokenType, int expires_in) { + public TokenResponse(String access_token, String refresh_token, String scope, String token_type, int expires_in) { this.access_token = access_token; this.refresh_token = refresh_token; this.scope = scope; - this.tokenType = tokenType; + this.token_type = token_type; this.expires_in = expires_in; } @@ -57,12 +57,12 @@ public class TokenResponse { this.scope = scope; } - public String getTokenType() { - return tokenType; + public String getToken_Type() { + return token_type; } - public void setTokenType(String tokenType) { - this.tokenType = tokenType; + public void setTokenType(String token_type) { + this.token_type = token_type; } public int getExpiresIn() { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java index 23daf8dfdda..a593e04bc63 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/src/main/java/org/wso2/carbon/apimgt/keymgt/extension/service/KeyMgtServiceImpl.java @@ -20,6 +20,7 @@ package org.wso2.carbon.apimgt.keymgt.extension.service; import com.google.gson.Gson; import okhttp3.Credentials; +import okhttp3.FormBody; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -41,7 +42,6 @@ import org.wso2.carbon.apimgt.keymgt.extension.KeyMgtConstants; import org.wso2.carbon.apimgt.keymgt.extension.OAuthApplication; import org.wso2.carbon.apimgt.keymgt.extension.TokenRequest; import org.wso2.carbon.apimgt.keymgt.extension.TokenResponse; -import org.wso2.carbon.apimgt.keymgt.extension.exception.BadRequestException; import org.wso2.carbon.apimgt.keymgt.extension.exception.KeyMgtException; import org.wso2.carbon.context.PrivilegedCarbonContext; import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; @@ -53,9 +53,7 @@ import org.wso2.carbon.user.api.UserStoreManager; import org.wso2.carbon.user.core.service.RealmService; import org.wso2.carbon.utils.multitenancy.MultitenantUtils; -import javax.net.ssl.HostnameVerifier; import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSession; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; @@ -82,6 +80,17 @@ public class KeyMgtServiceImpl implements KeyMgtService { public DCRResponse dynamicClientRegistration(String clientName, String owner, String grantTypes, String callBackUrl, String[] tags, boolean isSaasApp) throws KeyMgtException { + if (owner == null) { + PrivilegedCarbonContext threadLocalCarbonContext = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + try { + owner = APIUtil.getTenantAdminUserName(threadLocalCarbonContext.getTenantDomain()); + } catch (APIManagementException e) { + String msg = "Error occurred while retrieving admin user for the tenant " + threadLocalCarbonContext.getTenantDomain(); + log.error(msg, e); + throw new KeyMgtException(msg); + } + } + String tenantDomain = MultitenantUtils.getTenantDomain(owner); int tenantId; @@ -97,10 +106,8 @@ public class KeyMgtServiceImpl implements KeyMgtService { kmConfig = getKeyManagerConfig(); if (KeyMgtConstants.SUPER_TENANT.equals(tenantDomain)) { - OAuthApplication superTenantOauthApp = createOauthApplication( - KeyMgtConstants.RESERVED_OAUTH_APP_NAME_PREFIX + KeyMgtConstants.SUPER_TENANT, - kmConfig.getAdminUsername(), tags); - return new DCRResponse(superTenantOauthApp.getClientId(), superTenantOauthApp.getClientSecret()); + OAuthApplication dcrApplication = createOauthApplication(clientName, kmConfig.getAdminUsername(), tags); + return new DCRResponse(dcrApplication.getClientId(), dcrApplication.getClientSecret()); } else { // super-tenant admin dcr and token generation OAuthApplication superTenantOauthApp = createOauthApplication( @@ -141,7 +148,7 @@ public class KeyMgtServiceImpl implements KeyMgtService { } } - public TokenResponse generateAccessToken(TokenRequest tokenRequest) throws KeyMgtException, BadRequestException { + public TokenResponse generateAccessToken(TokenRequest tokenRequest) throws KeyMgtException { try { Application application = APIUtil.getApplicationByClientId(tokenRequest.getClientId()); String tenantDomain = MultitenantUtils.getTenantDomain(application.getOwner()); @@ -167,20 +174,43 @@ public class KeyMgtServiceImpl implements KeyMgtService { } JSONObject jsonObject = new JSONObject(); - if ("client_credentials".equals(tokenRequest.getGrantType())) { - jsonObject.put("grant_type", "password"); - jsonObject.put("username", username); - jsonObject.put("password", password); - } else if ("refresh_token".equals(tokenRequest.getGrantType())) { - jsonObject.put("grant_type", "refresh_token"); - jsonObject.put("refresh_token", tokenRequest.getRefreshToken()); - } else { - msg = "Invalid grant type: " + tokenRequest.getGrantType(); - throw new BadRequestException(msg); + RequestBody appTokenPayload; + switch (tokenRequest.getGrantType()) { + case "client_credentials": + case "password": + appTokenPayload = new FormBody.Builder() + .add("grant_type", "password") + .add("username", username) + .add("password", password) + .add("scope", tokenRequest.getScope()).build(); + break; + + case "refresh_token": + appTokenPayload = new FormBody.Builder() + .add("grant_type", "refresh_token") + .add("refresh_token", tokenRequest.getRefreshToken()) + .add("scope", tokenRequest.getScope()).build(); + break; + case "urn:ietf:params:oauth:grant-type:jwt-bearer": + appTokenPayload = new FormBody.Builder() + .add("grant_type", "urn:ietf:params:oauth:grant-type:jwt-bearer") + .add("assertion", tokenRequest.getAssertion()) + .add("scope", tokenRequest.getScope()).build(); + break; + case "access_token": + appTokenPayload = new FormBody.Builder() + .add("grant_type", "access_token") + .add("admin_access_token", tokenRequest.getAdminAccessToken()) + .add("scope", tokenRequest.getScope()).build(); + break; + default: + appTokenPayload = new FormBody.Builder() + .add("grant_type", tokenRequest.getGrantType()) + .add("scope", tokenRequest.getScope()).build(); + break; } jsonObject.put("scope", tokenRequest.getScope()); - RequestBody appTokenPayload = RequestBody.Companion.create(jsonObject.toString(), JSON); kmConfig = getKeyManagerConfig(); String appTokenEndpoint = kmConfig.getServerUrl() + KeyMgtConstants.OAUTH2_TOKEN_ENDPOINT; Request request = new Request.Builder() @@ -449,12 +479,7 @@ public class KeyMgtServiceImpl implements KeyMgtService { }; return new OkHttpClient.Builder() .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) - .hostnameVerifier(new HostnameVerifier() { - @Override - public boolean verify(String s, SSLSession sslSession) { - return true; - } - }).build(); + .hostnameVerifier((hostname, sslSession) -> true).build(); } private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 6b37a451cef..9ce1f97c272 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 14c8bf7b9f6..42be48bb6b8 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml index 63fb1a3161e..360ac894af1 100644 --- a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml @@ -20,7 +20,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.api/pom.xml index e7d23df6ff1..faa87b8b49d 100644 --- a/components/application-mgt/io.entgra.application.mgt.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.application.mgt.common/pom.xml index 1c46b1a5ade..d5d862c5ebd 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.application.mgt.core/pom.xml index 3e2b826b3be..a913a4ec905 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml index be2284b2b3d..4e0e62eb9f7 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml index 51782d3a4ee..22a3ac685ed 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index 7c4a10f8b3a..ff9f2fb36a2 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 540e793bc62..82b0af45885 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 9944bfcb1dd..204e1c85ad6 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 049a2cf8fda..d622975bd74 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.devicemgt certificate-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 7ec0505c8da..eb9649ea777 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 58c56c8a3ee..b55942b3f47 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index f74bc3226bf..25e65956b78 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index ad4bfeb4c51..ec3a220aa32 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index 6ca9edf24ad..c370f4f5d0d 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index c52e88660a6..e38abbc4795 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 3013e227bf6..a6c89035e64 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 099d7c44c2a..8a1b06f8f66 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml index 680a3d3f58b..8aba7713b74 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index d6c8bfc127e..21dfffffc4b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java index ccbf8aafed6..b8c626cb415 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/service/impl/DeviceManagementServiceImpl.java @@ -102,6 +102,7 @@ import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.search.mgt.SearchMgtException; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl; import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants; import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; @@ -492,7 +493,8 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { if (HttpReportingUtil.isTrackerEnabled()) { String currentUser = CarbonContext.getThreadLocalCarbonContext().getUsername(); - JSONObject obj = new JSONObject(DeviceAPIClientServiceImpl.returnUser(currentUser)); + DeviceAPIClientService deviceAPIClientService = DeviceMgtAPIUtils.getDeviceAPIClientService(); + JSONObject obj = new JSONObject(deviceAPIClientService.returnUser(currentUser)); if (obj.has("error")) { return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(obj.getString("error")).build(); @@ -530,21 +532,23 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { } int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + TrackerDeviceInfo trackerDevice; for (Device device : devices.getList()) { - TrackerDeviceInfo trackerDevice = DeviceAPIClientServiceImpl - .getTrackerDevice(device.getId(), tenantId); - int traccarDeviceId = trackerDevice.getTraccarDeviceId(); - boolean getPermission = DeviceAPIClientServiceImpl.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); - traccarValidIdList.add(traccarDeviceId); - if (!getPermission) { - DeviceAPIClientServiceImpl.addTrackerUserDevicePermission(userId, traccarDeviceId); + trackerDevice = deviceAPIClientService.getTrackerDevice(device.getId(), tenantId); + if(trackerDevice != null) { + int traccarDeviceId = trackerDevice.getTraccarDeviceId(); + boolean getPermission = deviceAPIClientService.getUserIdofPermissionByDeviceIdNUserId(traccarDeviceId, userId); + traccarValidIdList.add(traccarDeviceId); + if (!getPermission) { + deviceAPIClientService.addTrackerUserDevicePermission(userId, traccarDeviceId); + } } } //Remove necessary List getAllUserDevices = - DeviceAPIClientServiceImpl.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList); + deviceAPIClientService.getUserIdofPermissionByUserIdNIdList(userId, traccarValidIdList); for (TrackerPermissionInfo getAllUserDevice : getAllUserDevices) { - DeviceAPIClientServiceImpl.removeTrackerUserDevicePermission( + deviceAPIClientService.removeTrackerUserDevicePermission( getAllUserDevice.getTraccarUserId(), getAllUserDevice.getTraccarDeviceId(), TraccarHandlerConstants.Types.REMOVE_TYPE_SINGLE); @@ -570,6 +574,7 @@ public class DeviceManagementServiceImpl implements DeviceManagementService { log.error(msg, e); return Response.status(Response.Status.INTERNAL_SERVER_ERROR).entity(msg).build(); } + /*Get Device Id List*/ return Response.status(Response.Status.OK).entity(obj.getString("token")).build(); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java index 8861833f5aa..92bc2790d49 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/src/main/java/org/wso2/carbon/device/mgt/jaxrs/util/DeviceMgtAPIUtils.java @@ -87,6 +87,7 @@ import org.wso2.carbon.device.mgt.core.privacy.PrivacyComplianceProvider; import org.wso2.carbon.device.mgt.core.search.mgt.SearchManagerService; import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; import org.wso2.carbon.device.mgt.core.service.GroupManagementProviderService; +import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; import org.wso2.carbon.device.mgt.jaxrs.beans.DeviceTypeVersionWrapper; import org.wso2.carbon.device.mgt.jaxrs.beans.ErrorResponse; import org.wso2.carbon.device.mgt.jaxrs.beans.OperationStatusBean; @@ -592,6 +593,19 @@ public class DeviceMgtAPIUtils { return analyticsDataAPI; } + public static DeviceAPIClientService getDeviceAPIClientService() { + DeviceAPIClientService deviceAPIClientService; + PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext(); + deviceAPIClientService = (DeviceAPIClientService) ctx.getOSGiService( + DeviceAPIClientService.class, null); + if (deviceAPIClientService == null) { + String msg = "Device API Client service not initialized."; + log.error(msg); + throw new IllegalStateException(msg); + } + return deviceAPIClientService; + } + public static int getTenantId(String tenantDomain) throws DeviceManagementException { RealmService realmService = (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext().getOSGiService(RealmService.class, null); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index 3cd3649b882..dbc0a8672b3 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceMgtDeniedException.java b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceMgtDeniedException.java new file mode 100644 index 00000000000..4aede0f36aa --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/src/main/java/org/wso2/carbon/device/mgt/common/exceptions/DeviceMgtDeniedException.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2022, Entgra (pvt) Ltd. (http://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.common.exceptions; + +public class DeviceMgtDeniedException extends DeviceManagementException { + + + private static final long serialVersionUID = 2259395710324103446L; + + public DeviceMgtDeniedException() {super();} + + public DeviceMgtDeniedException(String msg) { + super(msg); + } + + public DeviceMgtDeniedException(Throwable cause) { + super(cause); + } + + public DeviceMgtDeniedException(String msg, Exception nestedEx) { + super(msg, nestedEx); + } + + public DeviceMgtDeniedException(String message, Throwable cause) { + super(message, cause); + } +} + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 0befe78e37e..d0cc7fa7a48 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java index 43d21b4d0e9..034ecbff779 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/dao/impl/tracker/TrackerDAOImpl.java @@ -18,6 +18,7 @@ package org.wso2.carbon.device.mgt.core.dao.impl.tracker; +import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; @@ -26,6 +27,7 @@ import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.TrackerDAO; +import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.dao.util.TrackerManagementDAOUtil; import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants; @@ -104,27 +106,34 @@ public class TrackerDAOImpl implements TrackerDAO { @Override public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { - PreparedStatement stmt = null; - ResultSet rs = null; + TrackerDeviceInfo trackerDeviceInfo = null; try { Connection conn = TrackerManagementDAOFactory.getConnection(); - String sql = "SELECT ID, TRACCAR_DEVICE_ID, DEVICE_ID, TENANT_ID, STATUS FROM DM_EXT_DEVICE_MAPPING WHERE " + - "DEVICE_ID = ? AND TENANT_ID = ? ORDER BY ID DESC LIMIT 1"; - stmt = conn.prepareStatement(sql); - stmt.setInt(1, deviceId); - stmt.setInt(2, tenantId); - rs = stmt.executeQuery(); - if (rs.next()) { - return TrackerManagementDAOUtil.loadTrackerDevice(rs); + String sql = "SELECT " + + "DM_EXT_DEVICE_MAPPING.ID, " + + "DM_EXT_DEVICE_MAPPING.TRACCAR_DEVICE_ID, " + + "DM_EXT_DEVICE_MAPPING.DEVICE_ID, " + + "DM_EXT_DEVICE_MAPPING.TENANT_ID, " + + "DM_EXT_DEVICE_MAPPING.STATUS " + + "FROM DM_EXT_DEVICE_MAPPING " + + "JOIN DM_DEVICE ON DM_EXT_DEVICE_MAPPING.DEVICE_ID=DM_DEVICE.ID " + + "WHERE DM_EXT_DEVICE_MAPPING.DEVICE_ID = ? AND DM_EXT_DEVICE_MAPPING.TENANT_ID = ? " + + "ORDER BY DM_EXT_DEVICE_MAPPING.ID DESC LIMIT 1"; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, deviceId); + stmt.setInt(2, tenantId); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + trackerDeviceInfo = TrackerManagementDAOUtil.loadTrackerDevice(rs); + } + } } - return null; } catch (SQLException e) { String msg = "Error occurred while retrieving data from the trackerDevice table "; log.error(msg, e); throw new TrackerManagementDAOException(msg, e); - } finally { - TrackerManagementDAOUtil.cleanupResources(stmt, rs); } + return trackerDeviceInfo; } @Override diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/DeviceDetailsDAO.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/DeviceDetailsDAO.java index d3a30b0a507..10c7a9f34f8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/DeviceDetailsDAO.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/DeviceDetailsDAO.java @@ -99,6 +99,17 @@ public interface DeviceDetailsDAO { */ DeviceLocation getDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException; + + /** + * This method will return the device location exist or not + * @param deviceId - id of the device. + * @param enrollmentId - enrolment id of the device. + * @return - if device location exist + * @throws DeviceDetailsMgtDAOException if SQL error occurred while processing the query. + */ + boolean hasLocations(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException; + + /** * This method will delete the device location from the database. * @param deviceId diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java index ff17b026f4f..535a1cbb081 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/dao/impl/DeviceDetailsDAOImpl.java @@ -25,6 +25,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.device.mgt.common.Device; import org.wso2.carbon.device.mgt.common.device.details.DeviceInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; +import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOException; import org.wso2.carbon.device.mgt.core.dao.DeviceManagementDAOFactory; import org.wso2.carbon.device.mgt.core.dao.util.DeviceManagementDAOUtil; import org.wso2.carbon.device.mgt.core.device.details.mgt.dao.DeviceDetailsDAO; @@ -378,6 +379,27 @@ public class DeviceDetailsDAOImpl implements DeviceDetailsDAO { } } + @Override + public boolean hasLocations(int deviceId, int enrollmentId) throws + DeviceDetailsMgtDAOException { + try { + Connection conn = this.getConnection(); + String sql = "SELECT DEVICE_ID FROM DM_DEVICE_LOCATION WHERE DEVICE_ID = ? AND ENROLMENT_ID = ? " + + "LIMIT 1"; + ResultSet rs; + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, deviceId); + stmt.setInt(2, enrollmentId); + rs = stmt.executeQuery(); + return rs.next(); + } + } catch (SQLException e) { + String msg = "Error occurred while fetching the location of the registered devices."; + log.error(msg, e); + throw new DeviceDetailsMgtDAOException(msg, e); + } + } + @Override public void deleteDeviceLocation(int deviceId, int enrollmentId) throws DeviceDetailsMgtDAOException { diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java index e9e5b0aaf5c..585074894df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/device/details/mgt/impl/DeviceInformationManagerImpl.java @@ -403,10 +403,14 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { } } else { if(!HttpReportingUtil.isLocationPublishing()) { - log.info("Location publishing is disabled"); + if (log.isDebugEnabled()) { + log.debug("Location publishing is disabled"); + } } if (!HttpReportingUtil.isTrackerEnabled()) { - log.info("Traccar is disabled"); + if (log.isDebugEnabled()) { + log.info("Traccar is disabled"); + } } } //Tracker update GPS Location @@ -435,17 +439,46 @@ public class DeviceInformationManagerImpl implements DeviceInformationManager { DeviceLocation mostRecentDeviceLocation = deviceLocations.get(deviceLocations.size() - 1); mostRecentDeviceLocation.setDeviceId(device.getId()); DeviceManagementDAOFactory.beginTransaction(); - DeviceLocation previousLocation = deviceDetailsDAO.getDeviceLocation(device.getId(), + boolean previousLocation = deviceDetailsDAO.hasLocations(device.getId(), device.getEnrolmentInfo().getId()); - if (previousLocation == null) { - deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId()); - } else { + if (previousLocation) { deviceDetailsDAO.updateDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId()); + } else { + deviceDetailsDAO.addDeviceLocation(mostRecentDeviceLocation, device.getEnrolmentInfo().getId()); } deviceDetailsDAO.addDeviceLocationsInfo(device, deviceLocations, CarbonContext.getThreadLocalCarbonContext().getTenantId()); + for (DeviceLocation deviceLocation: deviceLocations) { + //Tracker update GPS Location + if (HttpReportingUtil.isLocationPublishing() && HttpReportingUtil.isTrackerEnabled()) { + try { + DeviceManagementDataHolder.getInstance().getDeviceAPIClientService() + .updateLocation(device, deviceLocation, CarbonContext.getThreadLocalCarbonContext().getTenantId()); + } catch (ExecutionException e) { + log.error("ExecutionException : " + e); + //throw new RuntimeException(e); + // NOTE: Exception was not thrown due to being conflicted with non-traccar features + } catch (InterruptedException e) { + log.error("InterruptedException : " + e); + //throw new RuntimeException(e); + // NOTE: Exception was not thrown due to being conflicted with non-traccar features + } + } else { + if(!HttpReportingUtil.isLocationPublishing()) { + if (log.isDebugEnabled()) { + log.debug("Location publishing is disabled"); + } + } + if (!HttpReportingUtil.isTrackerEnabled()) { + if (log.isDebugEnabled()) { + log.info("Traccar is disabled"); + } + } + } + } + DeviceManagementDAOFactory.commitTransaction(); } catch (TransactionManagementException e) { throw new DeviceDetailsMgtException("Transactional error occurred while adding the device location " + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java index c777ea87995..2f0439f8ca7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/service/DeviceManagementProviderServiceImpl.java @@ -3981,9 +3981,12 @@ public class DeviceManagementProviderServiceImpl implements DeviceManagementProv deviceLocation.setBearing(Float.parseFloat(bearing)); deviceInformationManager.addDeviceLocation(device, deviceLocation); } catch (DeviceDetailsMgtException e) { - //We are not failing the execution since this is not critical for the functionality. But logging as - // a warning for reference. - //Exception was not thrown due to being conflicted with non-traccar features + /*** + * NOTE: + * We are not failing the execution since this is not critical for the functionality. But logging as + * a warning for reference. + * Exception was not thrown due to being conflicted with non-traccar features + */ log.warn("Error occurred while trying to add '" + device.getType() + "' device '" + device.getDeviceIdentifier() + "' (id:'" + device.getId() + "') location (lat:" + latitude + ", lon:" + longitude + ", altitude: " + altitude + diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java index 605d4f7a46b..73aca76059b 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/DeviceAPIClientService.java @@ -20,10 +20,14 @@ package org.wso2.carbon.device.mgt.core.traccar.api.service; import org.wso2.carbon.device.mgt.common.Device; +import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; +import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; import org.wso2.carbon.device.mgt.common.device.details.DeviceLocation; import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; + +import java.util.List; import java.util.concurrent.ExecutionException; public interface DeviceAPIClientService { @@ -81,4 +85,22 @@ public interface DeviceAPIClientService { */ void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException; + + String returnUser(String username); + + TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws + TrackerManagementDAOException; + + boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws + TrackerManagementDAOException; + + void addTrackerUserDevicePermission(int userId, int deviceId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; + + List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws + TrackerManagementDAOException; + + void removeTrackerUserDevicePermission(int userId, int deviceId, int removeType) throws + TrackerManagementDAOException, ExecutionException, InterruptedException; + } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java new file mode 100644 index 00000000000..193bdb211c1 --- /dev/null +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/TraccarClientFactory.java @@ -0,0 +1,802 @@ +/* + * Copyright (c) 2022, Entgra (pvt) Ltd. (http://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.traccar.api.service; + +import okhttp3.ConnectionPool; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.RequestBody; +import okhttp3.Response; +import org.apache.commons.codec.binary.Base64; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.json.JSONArray; +import org.json.JSONObject; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.TrackerDeviceInfo; +import org.wso2.carbon.device.mgt.common.TrackerGroupInfo; +import org.wso2.carbon.device.mgt.common.TrackerPermissionInfo; +import org.wso2.carbon.device.mgt.common.exceptions.TransactionManagementException; +import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; +import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; +import org.wso2.carbon.device.mgt.core.dao.TrackerDAO; +import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOFactory; +import org.wso2.carbon.device.mgt.core.traccar.api.service.TraccarClient; +import org.wso2.carbon.device.mgt.core.traccar.api.service.impl.DeviceAPIClientServiceImpl; +import org.wso2.carbon.device.mgt.core.traccar.common.TraccarHandlerConstants; +import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; +import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarGroups; +import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; +import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarUser; +import org.wso2.carbon.device.mgt.core.traccar.common.config.TraccarGateway; +import org.wso2.carbon.device.mgt.core.traccar.common.util.TraccarUtil; +import org.wso2.carbon.device.mgt.core.traccar.core.config.TraccarConfigurationManager; +import org.wso2.carbon.device.mgt.core.util.HttpReportingUtil; + +import java.io.IOException; +import java.sql.SQLException; +import java.time.LocalDateTime; +import java.time.ZoneId; +import java.util.Date; +import java.util.List; +import java.util.Objects; +import java.util.Random; +import java.util.concurrent.Callable; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.stream.Collectors; +import java.util.stream.IntStream; + +public class TraccarClientFactory { + + private static TraccarClientFactory INSTANCE; + private static final Log log = LogFactory.getLog(TraccarClientFactory.class); + private static final int THREAD_POOL_SIZE = 50; + private final OkHttpClient client; + private final ExecutorService executor = Executors.newFixedThreadPool(THREAD_POOL_SIZE); + final TraccarGateway traccarGateway = getTraccarGateway(); + final String endpoint = traccarGateway.getPropertyByName(TraccarHandlerConstants.TraccarConfig.ENDPOINT).getValue(); + final String authorization = traccarGateway.getPropertyByName(TraccarHandlerConstants.TraccarConfig.AUTHORIZATION).getValue(); + final String authorizationKey = traccarGateway.getPropertyByName(TraccarHandlerConstants.TraccarConfig.AUTHORIZATION_KEY).getValue(); + final String defaultPort = traccarGateway.getPropertyByName(TraccarHandlerConstants.TraccarConfig.DEFAULT_PORT).getValue(); + final String locationUpdatePort = traccarGateway.getPropertyByName(TraccarHandlerConstants.TraccarConfig.LOCATION_UPDATE_PORT).getValue(); + + final String username = PrivilegedCarbonContext.getThreadLocalCarbonContext().getUsername(); + private final TrackerDAO trackerDAO; + + /** + * This is the private constructor method as this class is a singleton + */ + private TraccarClientFactory() { + client = new OkHttpClient.Builder() + .connectTimeout(30, TimeUnit.SECONDS) + .writeTimeout(30, TimeUnit.SECONDS) + .readTimeout(45, TimeUnit.SECONDS) + .connectionPool(new ConnectionPool(100, 50, TimeUnit.SECONDS)) + .build(); + this.trackerDAO = TrackerManagementDAOFactory.getTrackerDAO(); + } + + /** + * This method is used to initiate a singleton instance of this class. + * + * @return TraccarClientFactory instance + */ + public static TraccarClientFactory getInstance() { + if(INSTANCE == null) { + INSTANCE = new TraccarClientFactory(); + } + return INSTANCE; + } + + private class OkHttpClientThreadPool implements Callable { + final String publisherUrlWithContext; + final JSONObject payload; + private final String method; + private String authorizeKey; + private String serverUri; + + private OkHttpClientThreadPool(String publisherUrlWithContext, JSONObject payload, String method, + String authorizeKey, String serverUri) { + this.publisherUrlWithContext = publisherUrlWithContext; + this.payload = payload; + this.method = method; + this.authorizeKey = authorizeKey; + this.serverUri = serverUri; + } + + @Override + public String call() throws IOException { + RequestBody requestBody; + Request.Builder builder = new Request.Builder(); + Request request; + Response response; + + if (Objects.equals(method, TraccarHandlerConstants.Methods.POST)) { + requestBody = RequestBody.create(payload.toString(), MediaType.parse("application/json; charset=utf-8")); + builder = builder.post(requestBody); + } else if (Objects.equals(method, TraccarHandlerConstants.Methods.PUT)) { + requestBody = RequestBody.create(payload.toString(), MediaType.parse("application/json; charset=utf-8")); + builder = builder.put(requestBody); + } else if (Objects.equals(method, TraccarHandlerConstants.Methods.DELETE)) { + if (publisherUrlWithContext.contains("permission")) { + requestBody = RequestBody.create(payload.toString(), MediaType.parse("application/json; charset=utf-8")); + builder = builder.delete(requestBody); + } else { + builder = builder.delete(); + } + } + + request = builder.url(serverUri + publisherUrlWithContext).addHeader(authorization, authorizeKey).build(); + response = client.newCall(request).execute(); + return response.body().string(); + } + } + + public String fetchAllUsers() throws ExecutionException, InterruptedException { + String url = defaultPort + "/api/users"; + + Future result = executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + return result.get(); + } + + public String fetchUserInfo(String userName) throws ExecutionException, InterruptedException { + String allUsers = fetchAllUsers(); //get all users + JSONArray fetchAllUsers = new JSONArray(allUsers); //loop users + for (int i = 0; i < fetchAllUsers.length(); i++) { + // if login is null then check the name or if login is not null then check the login + if (fetchAllUsers.getJSONObject(i).isNull("login")) { + if (Objects.equals(fetchAllUsers.getJSONObject(i).getString("name"), userName)) { + return fetchAllUsers.getJSONObject(i).toString(); + } + } else { + if (Objects.equals(fetchAllUsers.getJSONObject(i).getString("login"), userName) || + Objects.equals(fetchAllUsers.getJSONObject(i).getString("name"), userName)) { + return fetchAllUsers.getJSONObject(i).toString(); + } + } + } + return TraccarHandlerConstants.Types.USER_NOT_FOUND; + } + + public String returnUser(String userName) throws TrackerManagementDAOException { + try { + String result = fetchUserInfo(userName); + Date today = new Date(); + LocalDateTime tomorrow = LocalDateTime.from(today.toInstant().atZone(ZoneId.of("UTC"))).plusDays(1); + String token = DeviceAPIClientServiceImpl.generateRandomString(TraccarHandlerConstants.Types.TRACCAR_TOKEN); + + TraccarUser traccarUser = new TraccarUser(); + traccarUser.setToken(token); + + if (Objects.equals(result, TraccarHandlerConstants.Types.USER_NOT_FOUND)) { + //create user + log.info("Creating a user on Traccar client"); + traccarUser.setName(userName); + traccarUser.setLogin(userName); + traccarUser.setEmail(userName); + traccarUser.setPassword(DeviceAPIClientServiceImpl.generateRandomString(TraccarHandlerConstants.Types.DEFAULT_RANDOM)); + traccarUser.setDeviceLimit(-1); + traccarUser.setExpirationTime(tomorrow.toString()); + DeviceAPIClientServiceImpl.createUser(traccarUser); + } else { + //update user + log.info("Updating the user on Traccar client"); + JSONObject obj = new JSONObject(result); + + traccarUser.setId(obj.getInt("id")); + traccarUser.setName(obj.getString("name")); + if (!obj.isNull("login")) { + traccarUser.setLogin(obj.getString("login")); + } + traccarUser.setEmail(obj.getString("email")); + traccarUser.setDeviceLimit(obj.getInt("deviceLimit")); + traccarUser.setUserLimit(obj.getInt("userLimit")); + traccarUser.setAdministrator(obj.getBoolean("administrator")); + traccarUser.setDisabled(obj.getBoolean("disabled")); + traccarUser.setReadonly(obj.getBoolean("readonly")); + if (!obj.getBoolean("administrator")) { + traccarUser.setExpirationTime(tomorrow.toString()); + } else if (!obj.isNull("expirationTime")) { + traccarUser.setExpirationTime(obj.getString("expirationTime")); + } + DeviceAPIClientServiceImpl.updateUser(traccarUser, obj.getInt("id")); + } + result = fetchUserInfo(userName); + return result; + } catch (InterruptedException | ExecutionException e) { + JSONObject obj = new JSONObject(); + String msg = "Error occurred while executing enrollment status of the device."; + obj.put("error", msg); + obj.put("e", e); + log.error(msg, e); + return obj.toString(); + } + } + + public String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException { + String url = defaultPort + "/api/users"; + JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser); + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + return res.get(); + } + + public String updateUser(TraccarUser traccarUser, int userId) throws ExecutionException, InterruptedException { + String url = defaultPort + "/api/users/" + userId; + JSONObject payload = TraccarUtil.TraccarUserPayload(traccarUser); + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + return res.get(); + } + + public void setPermission(int userId, int deviceId) + throws ExecutionException, InterruptedException, TrackerManagementDAOException { + JSONObject payload = new JSONObject(); + payload.put("userId", userId); + payload.put("deviceId", deviceId); + + String url = defaultPort + "/api/permissions"; + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + String result = res.get(); + + if (("").equals(result)) { + try { + TrackerManagementDAOFactory.beginTransaction(); + trackerDAO.addTrackerUserDevicePermission(userId, deviceId); + TrackerManagementDAOFactory.commitTransaction(); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } else { + String msg = "Couldn't add the permission record: " + result; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } + + public void removePermission(int userId, int deviceId, int removeType) + throws TrackerManagementDAOException, ExecutionException, InterruptedException { + JSONObject payload = new JSONObject(); + payload.put("userId", userId); + payload.put("deviceId", deviceId); + + String url = defaultPort + "/api/permissions"; + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.DELETE, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + + if (res.get() != null) { + try { + TrackerManagementDAOFactory.beginTransaction(); + trackerDAO.removeTrackerUserDevicePermission(deviceId, userId, removeType); + TrackerManagementDAOFactory.commitTransaction(); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } else { + String msg = "Error occured while removing permission."; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } + + public List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) + throws TrackerManagementDAOException { + try { + TrackerManagementDAOFactory.openConnection(); + return trackerDAO.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList); + } catch (TrackerManagementDAOException e) { + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } + + public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { + try { + TrackerManagementDAOFactory.openConnection(); + TrackerDeviceInfo trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId); + if(trackerDeviceInfo == null) { + String msg = "No tracker device is found upon the device ID of: " + deviceId; + if (log.isDebugEnabled()) { + log.debug(msg); + } + return null; + } else { + return trackerDeviceInfo; + } + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + String msg = "Could not add new device location"; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } + + public boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) + throws TrackerManagementDAOException { + Boolean result = false; + try { + TrackerManagementDAOFactory.openConnection(); + result = trackerDAO.getUserIdofPermissionByDeviceIdNUserId(deviceId, userId); + } catch (TrackerManagementDAOException e) { + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + return result; + } + + /** + * Add Traccar Device operation. + * + * @param traccarDevice with DeviceName UniqueId, Status, Disabled LastUpdate, PositionId, GroupId + * Model, Contact, Category, fenceIds + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation + */ + public void addDevice(TraccarDevice traccarDevice, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerDeviceInfo trackerDeviceInfo = null; + try { + TrackerManagementDAOFactory.openConnection(); + trackerDeviceInfo = trackerDAO.getTrackerDevice(traccarDevice.getId(), tenantId); + } catch (TrackerManagementDAOException e) { + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + + if (trackerDeviceInfo == null) { + //add the device + String url = defaultPort + "/api/devices"; + JSONObject payload = TraccarUtil.TraccarDevicePayload(traccarDevice); + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + String result = res.get(); + log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar."); + if (res.isDone() && result.charAt(0) == '{') { + JSONObject obj = new JSONObject(result); + if (obj.has("id")) { + int traccarDeviceId = obj.getInt("id"); + int deviceId = traccarDevice.getId(); + log.info("TraccarDeviceId - " + traccarDeviceId); + try { + TrackerManagementDAOFactory.beginTransaction(); + trackerDAO.addTrackerDevice(traccarDeviceId, deviceId, tenantId); + trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId); + if (trackerDeviceInfo != null && trackerDeviceInfo.getStatus() == 0) { + trackerDAO.updateTrackerDeviceIdANDStatus(trackerDeviceInfo.getTraccarDeviceId(), deviceId, tenantId, 1); + } + TrackerManagementDAOFactory.commitTransaction(); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while mapping with deviceId ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + + JSONObject returnUserInfo = new JSONObject(returnUser(username)); + setPermission(returnUserInfo.getInt("id"), traccarDeviceId); + } + } + } else { + String msg = "The device already exist"; + log.error(msg); + throw new TrackerAlreadyExistException(msg); + } + } + + /** + * Add Device GPS Location operation. + * + * @param deviceInfo with DeviceIdentifier, Timestamp, Lat, Lon, Bearing, Speed, ignition + */ + public void updateLocation(TraccarDevice device, TraccarPosition deviceInfo, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerDeviceInfo trackerDeviceInfo = null; + try { + TrackerManagementDAOFactory.openConnection(); + trackerDeviceInfo = trackerDAO.getTrackerDevice(device.getId(), tenantId); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + String msg = "Could not add new device location"; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + + + //check if the device is already exist before updating the location + if (trackerDeviceInfo == null) { + //add device if not exist + addDevice(device, tenantId); + } else { + //Update Location + if (log.isDebugEnabled()) { + log.info("Updating Location of the device: " + device.getId()); + } + String url = locationUpdatePort + "/?id=" + deviceInfo.getDeviceIdentifier() + + "×tamp=" + deviceInfo.getTimestamp() + "&lat=" + deviceInfo.getLat() + + "&lon=" + deviceInfo.getLon() + "&bearing=" + deviceInfo.getBearing() + + "&speed=" + deviceInfo.getSpeed() + "&ignition=true"; + + executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[0] + ":" + + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[1] + ":")); + } + } + + /** + * Dis-enroll a Device operation. + * + * @param deviceId identified via deviceIdentifier + * @throws TrackerManagementDAOException Failed while dis-enroll a Traccar Device operation + */ + public void disEnrollDevice(int deviceId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { + TrackerDeviceInfo trackerDeviceInfo = null; + List trackerPermissionInfo = null; + try { + TrackerManagementDAOFactory.beginTransaction(); + try { + TrackerManagementDAOFactory.openConnection(); + trackerDeviceInfo = trackerDAO.getTrackerDevice(deviceId, tenantId); + if (trackerDeviceInfo != null) { + trackerDAO.removeTrackerDevice(deviceId, tenantId); + TrackerManagementDAOFactory.commitTransaction(); + trackerPermissionInfo = trackerDAO.getUserIdofPermissionByDeviceId(trackerDeviceInfo.getTraccarDeviceId()); + } else { + String msg = "Tracker device for device id " + deviceId + " not found"; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection ."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + String msg = "Could not add new device location"; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection"; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } + log.info("Disenrolling Device with device id " + deviceId + " from traccar client"); + //Delete from traccar + if (trackerDeviceInfo != null) { + + if (trackerPermissionInfo.size() > 0) { + String url = defaultPort + "/api/devices/" + trackerPermissionInfo.get(0).getTraccarDeviceId(); + + executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.DELETE, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + } else { + String msg = "Tracker permission mapping info not found"; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + //remove permissions + try { + removePermission( + trackerPermissionInfo.get(0).getTraccarUserId(), + trackerPermissionInfo.get(0).getTraccarDeviceId(), + TraccarHandlerConstants.Types.REMOVE_TYPE_MULTIPLE); + } catch (ExecutionException e) { + String msg = "Error occured while removing tacker permissions "; + log.error(msg); + throw new ExecutionException(msg, e); + } + } else { + String msg = "Tracker device not found"; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } + + /** + * Add Traccar Device operation. + * + * @param groupInfo with groupName + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation + */ + public void addGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerGroupInfo trackerGroupInfo = null; + try { + TrackerManagementDAOFactory.openConnection(); + trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId); + if (trackerGroupInfo != null) { + String msg = "The group already exit"; + log.error(msg); + throw new TrackerAlreadyExistException(msg); + } + } catch (TrackerManagementDAOException e) { + String msg = "Error occurred while mapping with groupId."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection."; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + + JSONObject payload = new JSONObject(); + payload.put("name", groupInfo.getName()); + payload.put("attributes", new JSONObject()); + + String url = defaultPort + "/api/groups"; + + Future res = executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.POST, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + String result = res.get(); + log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar."); + if (res.isDone() && result.charAt(0) == '{') { + JSONObject obj = new JSONObject(result); + if (obj.has("id")) { + int traccarGroupId = obj.getInt("id"); + try { + TrackerManagementDAOFactory.beginTransaction(); + trackerDAO.addTrackerGroup(traccarGroupId, groupId, tenantId); + trackerGroupInfo = trackerDAO.getTrackerGroup(groupId, tenantId); + if (trackerGroupInfo.getStatus() == 0) { + trackerDAO.updateTrackerGroupIdANDStatus(trackerGroupInfo.getTraccarGroupId(), groupId, tenantId, 1); + TrackerManagementDAOFactory.commitTransaction(); + } + } catch (TransactionManagementException e) { + String msg = "Error occurred establishing the DB connection. "; + log.error(msg, e); + TrackerManagementDAOFactory.rollbackTransaction(); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while mapping with deviceId. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } else { + // TODO: Assumed the error message change if wrong + log.error("Response does not contains the key id: " + result); + } + } else { + // TODO: Assumed the error message change if wrong + log.error("Response does not contains a JSON object " + result); + } + } + + /** + * update Traccar Group operation. + * + * @param groupInfo with groupName + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation + */ + public void updateGroup(TraccarGroups groupInfo, int groupId, int tenantId) throws + TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { + TrackerGroupInfo res = null; + try { + TrackerManagementDAOFactory.openConnection(); + res = trackerDAO.getTrackerGroup(groupId, tenantId); + } catch (SQLException e) { + String msg = "Error occurred establishing the DB connection. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + String msg = "Could not find traccar group details. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + + if ((res == null) || (res.getTraccarGroupId() == 0)) { + //add a new traccar group + addGroup(groupInfo, groupId, tenantId); + } else if (res != null && (res.getTraccarGroupId() != 0 && res.getStatus() == 0)) { + //update the traccargroupId and status + try { + TrackerManagementDAOFactory.beginTransaction(); + trackerDAO.updateTrackerGroupIdANDStatus(res.getTraccarGroupId(), groupId, tenantId, 1); + TrackerManagementDAOFactory.commitTransaction(); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Could not update the traccar group. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } else { + JSONObject obj = new JSONObject(res); + JSONObject payload = new JSONObject(); + payload.put("id", obj.getInt("traccarGroupId")); + payload.put("name", groupInfo.getName()); + payload.put("attributes", new JSONObject()); + + String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId"); + + executor.submit(new OkHttpClientThreadPool(url, payload, TraccarHandlerConstants.Methods.PUT, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + } + } + + /** + * Add Traccar Device operation. + * + * @param groupId + * @throws TrackerManagementDAOException Failed while add Traccar Device the operation + */ + public void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { + TrackerGroupInfo res = null; + JSONObject obj = null; + try { + TrackerManagementDAOFactory.beginTransaction(); + res = trackerDAO.getTrackerGroup(groupId, tenantId); + if (res != null) { + obj = new JSONObject(res); + if (obj != null) { + trackerDAO.removeTrackerGroup(obj.getInt("id")); + String url = defaultPort + "/api/groups/" + obj.getInt("traccarGroupId"); + executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.DELETE, + authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), + serverUrl(HttpReportingUtil.trackerServer()))); + TrackerManagementDAOFactory.commitTransaction(); + } else { + String msg = "Tracker group JSON object is null"; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } else { + String msg = "Tracker group not found"; + log.error(msg); + throw new TrackerManagementDAOException(msg); + } + } catch (TransactionManagementException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred establishing the DB connection. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } catch (TrackerManagementDAOException e) { + TrackerManagementDAOFactory.rollbackTransaction(); + String msg = "Error occurred while mapping with groupId. "; + log.error(msg, e); + throw new TrackerManagementDAOException(msg, e); + } finally { + TrackerManagementDAOFactory.closeConnection(); + } + } + + public String generateRandomString(int len) { + String chars = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz"; + Random rnd = new Random(); + return IntStream.range(0, len).mapToObj(i -> String.valueOf(chars.charAt(rnd.nextInt(chars.length())))).collect(Collectors.joining()); + } + + private TraccarGateway getTraccarGateway() { + return TraccarConfigurationManager.getInstance().getTraccarConfig().getTraccarGateway( + TraccarHandlerConstants.TraccarConfig.GATEWAY_NAME); + } + + public String authorizedKey(String trackerUser, String trackerPassword) { + String newAuthorizationKey = authorizationKey; + if (trackerUser != null && trackerPassword != null) { + newAuthorizationKey = trackerUser + ':' + trackerPassword; + + byte[] result = newAuthorizationKey.getBytes(); + byte[] res = Base64.encodeBase64(result); + newAuthorizationKey = "Basic " + new String(res); + } + return newAuthorizationKey; + } + + public String serverUrl(String serverUrl) { + if (serverUrl != null) { + return serverUrl; + } else { + return endpoint; + } + } +} diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java index 526de67f616..0e9264a325c 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/addons/TraccarClientImpl.java @@ -403,6 +403,7 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); + log.info("Device " + traccarDevice.getDeviceIdentifier() + " has been added to Traccar."); if (result.charAt(0) == '{') { JSONObject obj = new JSONObject(result); if (obj.has("id")) { @@ -465,6 +466,7 @@ public class TraccarClientImpl implements TraccarClient { TrackerManagementDAOFactory.closeConnection(); } + //check if the device is already exist before updating the location if (trackerDeviceInfo == null) { //add device if not exist @@ -481,7 +483,8 @@ public class TraccarClientImpl implements TraccarClient { executor.submit(new OkHttpClientThreadPool(url, null, TraccarHandlerConstants.Methods.GET, authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), - "http://localhost:")); + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[0] + ":" + + Objects.requireNonNull(HttpReportingUtil.trackerServer()).split(":")[1] + ":")); } } @@ -579,8 +582,8 @@ public class TraccarClientImpl implements TraccarClient { authorizedKey(HttpReportingUtil.trackerUser(), HttpReportingUtil.trackerPassword()), serverUrl(HttpReportingUtil.trackerServer()))); String result = res.get(); - - if (result.charAt(0) == '{') { + log.info("Group " + trackerGroupInfo.getGroupId() + " has been added to Traccar."); + if (res.isDone() && result.charAt(0) == '{') { JSONObject obj = new JSONObject(result); if (obj.has("id")) { int traccarGroupId = obj.getInt("id"); diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java index f1f71cb99a8..9095f3dd5b8 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/main/java/org/wso2/carbon/device/mgt/core/traccar/api/service/impl/DeviceAPIClientServiceImpl.java @@ -30,7 +30,7 @@ import org.wso2.carbon.device.mgt.common.group.mgt.DeviceGroup; import org.wso2.carbon.device.mgt.common.exceptions.TrackerAlreadyExistException; import org.wso2.carbon.device.mgt.core.dao.TrackerManagementDAOException; import org.wso2.carbon.device.mgt.core.traccar.api.service.DeviceAPIClientService; -import org.wso2.carbon.device.mgt.core.traccar.api.service.addons.TraccarClientImpl; +import org.wso2.carbon.device.mgt.core.traccar.api.service.TraccarClientFactory; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarDevice; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarGroups; import org.wso2.carbon.device.mgt.core.traccar.common.beans.TraccarPosition; @@ -43,9 +43,10 @@ import java.util.concurrent.ExecutionException; public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { private static final Log log = LogFactory.getLog(DeviceAPIClientServiceImpl.class); + TraccarClientFactory client = TraccarClientFactory.getInstance(); + @Override public void addDevice(Device device, int tenantId) throws ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); String lastUpdatedTime = String.valueOf((new Date().getTime())); TraccarDevice traccarDevice = new TraccarDevice(device.getId(), device.getName(), device.getDeviceIdentifier(), "online", "false", lastUpdatedTime, "", "", "", "", @@ -61,8 +62,8 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { } } + @Override public void updateLocation(Device device, DeviceLocation deviceLocation, int tenantId) throws ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); TraccarPosition traccarPosition = new TraccarPosition(device.getDeviceIdentifier(), deviceLocation.getUpdatedTime().getTime(), deviceLocation.getLatitude(), deviceLocation.getLongitude(), @@ -83,8 +84,8 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { } } + @Override public void disEnrollDevice(int deviceId, int tenantId) throws ExecutionException, InterruptedException{ - TraccarClientImpl client = new TraccarClientImpl(); try { client.disEnrollDevice(deviceId, tenantId); } catch (TrackerManagementDAOException e) { @@ -93,86 +94,92 @@ public class DeviceAPIClientServiceImpl implements DeviceAPIClientService { } } + @Override public void addGroup(DeviceGroup group, int groupId, int tenantId) throws TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); TraccarGroups traccarGroups = new TraccarGroups(group.getName()); client.addGroup(traccarGroups, groupId, tenantId); } + @Override public void updateGroup(DeviceGroup group, int groupId, int tenantId) throws TrackerManagementDAOException, TrackerAlreadyExistException, ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); TraccarGroups traccarGroups = new TraccarGroups(group.getName()); client.updateGroup(traccarGroups, groupId, tenantId); } + @Override public void deleteGroup(int groupId, int tenantId) throws TrackerManagementDAOException, ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); client.deleteGroup(groupId, tenantId); } - public static String fetchUserInfo(String userName) throws ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); - return client.fetchUserInfo(userName); + @Override + public String returnUser(String username) { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + try { + return client.returnUser(username); + } catch (TrackerManagementDAOException e) { + JSONObject obj = new JSONObject(); + String msg = "Error occurred while creating a user: "+ e; + obj.put("error", msg); + return obj.toString(); + } } - public static TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws + @Override + public TrackerDeviceInfo getTrackerDevice(int deviceId, int tenantId) throws TrackerManagementDAOException { - TraccarClientImpl client = new TraccarClientImpl(); + TraccarClientFactory client = TraccarClientFactory.getInstance(); return client.getTrackerDevice(deviceId, tenantId); } - public static boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws + @Override + public boolean getUserIdofPermissionByDeviceIdNUserId(int deviceId, int userId) throws TrackerManagementDAOException { - TraccarClientImpl client = new TraccarClientImpl(); + TraccarClientFactory client = TraccarClientFactory.getInstance(); return client.getUserIdofPermissionByDeviceIdNUserId(deviceId, userId); } - public static String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); - return client.createUser(traccarUser); + @Override + public void addTrackerUserDevicePermission(int userId, int deviceId) throws + TrackerManagementDAOException, ExecutionException, InterruptedException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + client.setPermission(userId, deviceId); } - public static String updateUser(TraccarUser traccarUser, int userId) throws - ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); - return client.updateUser(traccarUser, userId); + @Override + public List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws + TrackerManagementDAOException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + return client.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList); } - public static String returnUser(String userName) { - TraccarClientImpl client = new TraccarClientImpl(); - try { - return client.returnUser(userName); - } catch (TrackerManagementDAOException e) { - JSONObject obj = new JSONObject(); - String msg = "Error occurred while creating a user: "+ e; - obj.put("error", msg); - return obj.toString(); - } + @Override + public void removeTrackerUserDevicePermission(int userId, int deviceId, int removeType) throws + TrackerManagementDAOException, ExecutionException, InterruptedException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + client.removePermission(userId, deviceId, removeType); } - public static void addTrackerUserDevicePermission(int userId, int deviceId) throws - TrackerManagementDAOException, ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); - client.setPermission(userId, deviceId); + public static String fetchUserInfo(String userName) throws ExecutionException, InterruptedException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + return client.fetchUserInfo(userName); } - public static void removeTrackerUserDevicePermission(int userId, int deviceId, int removeType) throws - TrackerManagementDAOException, ExecutionException, InterruptedException { - TraccarClientImpl client = new TraccarClientImpl(); - client.removePermission(userId, deviceId, removeType); + public static String createUser(TraccarUser traccarUser) throws ExecutionException, InterruptedException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + return client.createUser(traccarUser); } - public static List getUserIdofPermissionByUserIdNIdList(int userId, List NotInDeviceIdList) throws - TrackerManagementDAOException { - TraccarClientImpl client = new TraccarClientImpl(); - return client.getUserIdofPermissionByUserIdNIdList(userId, NotInDeviceIdList); + public static String updateUser(TraccarUser traccarUser, int userId) throws + ExecutionException, InterruptedException { + TraccarClientFactory client = TraccarClientFactory.getInstance(); + return client.updateUser(traccarUser, userId); } public static String generateRandomString(int len) { - TraccarClientImpl client = new TraccarClientImpl(); + TraccarClientFactory client = TraccarClientFactory.getInstance(); return client.generateRandomString(len); } diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml index 3521695b04e..7a6de290f2e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/src/test/resources/config/operation/traccar-config.xml @@ -27,8 +27,8 @@ sample http://localhost: - - 5055 + 4385 + 8085 Authorization Basic YWRtaW46YWRtaW4= diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index af341bd2237..1c99a2dacec 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index 4ea09202904..b2d3719a1ca 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 30dd8350137..77a3975b576 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index f0b9f8d53d7..17d77238ccc 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heartbeat-management - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index a9fbf08f920..5c61a5466cd 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index 3d50ba427f2..12061ef50d4 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index 42c88bfd991..39939ffa785 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index 7f913e4ed35..3db90077389 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index 42beb5aed58..a576f4078f6 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index 0adb75e3c6b..e3dc162f348 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index cedcaebce4b..0fb40c689d2 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 11f60551479..9ee2075f015 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 0b63e8cab5a..19c6e1f1a97 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 0d095491d00..9f44f63c7ec 100644 --- a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index 814b4a3ca7f..d904b8b9ad7 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index 75dc068d4b3..3413d5d3bdd 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml index ae1448a9b35..c4908bb79f6 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml index 5e03f73ea6e..19c849c922e 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml index db84dbea647..37bf5cf102b 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index 63bea3e65ba..c0fd64b9bb5 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index a16779fa36b..f48d158f339 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT 4.0.0 diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 71a27034a68..99b29301d9a 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index d8678499bbb..1c80234717d 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index 2059dd6747a..e06000c2240 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml index 6b1080b2323..dce339e52a8 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml index 3d13fda245c..2171feb79ac 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index 4430db116e3..59418796836 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index 885d39740d8..a0fd2bcf4dc 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index f884d50748e..8c1a4ee5fbf 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml index 5c595e9dbb7..c39c1943f60 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/p2.inf b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/p2.inf index 03e2e6eb95b..fa1ab939b09 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/p2.inf +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/p2.inf @@ -1,3 +1,4 @@ instructions.configure = \ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../deployment/server/webapps/);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.apimgt.keymgt.extension_${feature.version}/webapps/api-key-management.war,target:${installFolder}/../../deployment/server/webapps/api-key-management.war,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.apimgt.keymgt.extension_${feature.version}/synapse-configs/default/api/_API_Key_Management_.xml,target:${installFolder}/../../deployment/server/synapse-configs/default/api/_API_Key_Management_.xml,overwrite:true);\ diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/synapse-configs/default/api/_API_Key_Management_.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/synapse-configs/default/api/_API_Key_Management_.xml new file mode 100644 index 00000000000..0d2b9836793 --- /dev/null +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/src/main/resources/synapse-configs/default/api/_API_Key_Management_.xml @@ -0,0 +1,46 @@ + + + + + + + + + + + + 60000 + fault + + + + + + + + + + + + + + diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index 726ea0ba46c..131f4b9ecf2 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index e7a005a023d..fdc80950665 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml index e022d1b0953..f9ef4921c5f 100644 --- a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml index 68d9c4fe024..88886a20735 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index 6b04ee5c4db..d7aa57a857b 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index 0013d62cde9..dc58d2d3f48 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index 6756a17e6ca..d6b11ce3b28 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index 50a8ea30019..d25f322e9cf 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index 10b9d056845..62ef8f7e3d3 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index 52b5299f23a..bc33325ede4 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 0786fd59f94..ce062e31ce8 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index 1119fc97e41..68e037d481b 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index f914bb3526e..75821c5ef1b 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index ca184ef0024..5a527436aff 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index da1792525df..67d02c0b14c 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index 4a808be5c89..2f4a1051a0f 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 5d64bb645b9..292a4e998cc 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/traccar-config.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/traccar-config.xml index 3521695b04e..7a6de290f2e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/traccar-config.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf/traccar-config.xml @@ -27,8 +27,8 @@ sample http://localhost: - - 5055 + 4385 + 8085 Authorization Basic YWRtaW46YWRtaW4= diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/mdm-ui-config.xml.j2 b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/mdm-ui-config.xml.j2 deleted file mode 100644 index bc4b4672368..00000000000 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/conf_templates/templates/repository/conf/mdm-ui-config.xml.j2 +++ /dev/null @@ -1,284 +0,0 @@ - - - - - {% if mdm_ui_conf.enable_oauth is defined %} - {{mdm_ui_conf.enable_oauth}} - {% else %} - true - {% endif %} - {% if mdm_ui_conf.enable_sso is defined %} - {{mdm_ui_conf.enable_sso}} - {% else %} - true - {% endif %} - - {% if mdm_ui_conf.login_cache_capacity is defined %} - {{mdm_ui_conf.login_cache_capacity}} - {% else %} - 10000 - {% endif %} - - - {% if mdm_ui_conf.hide_bill_generation_in_super_tenant is defined %} - {{mdm_ui_conf.hide_bill_generation_in_super_tenant}} - {% else %} - false - {% endif %} - {% if mdm_ui_conf.hide_bill_generation_in_sub_tenant is defined %} - {{mdm_ui_conf.hide_bill_generation_in_sub_tenant}} - {% else %} - true - {% endif %} - {% if mdm_ui_conf.hide_total_calculation_in_super_tenant is defined %} - {{mdm_ui_conf.hide_total_calculation_in_super_tenant}} - {% else %} - false - {% endif %} - {% if mdm_ui_conf.hide_total_calculation_in_sub_tenant is defined %} - {{mdm_ui_conf.hide_total_calculation_in_sub_tenant}} - {% else %} - true - {% endif %} - {% if mdm_ui_conf.hide_domain_selection_in_super_tenant is defined %} - {{mdm_ui_conf.hide_domain_selection_in_super_tenant}} - {% else %} - false - {% endif %} - {% if mdm_ui_conf.hide_domain_selection_in_sub_tenant is defined %} - {{mdm_ui_conf.hide_domain_selection_in_sub_tenant}} - {% else %} - true - {% endif %} - - - - - {% if mdm_ui_conf.app_registration.tags is defined %} - {%- for tag in mdm_ui_conf.app_registration.tags -%} - {{tag}} - {% endfor %} - {% else %} - application_management - device_management - subscription_management - review_management - {% endif %} - - {% if mdm_ui_conf.app_registration.allow_to_all_domains is defined %} - {{mdm_ui_conf.app_registration.allow_to_all_domains}} - {% else %} - true - {% endif %} - - - perm:app:review:view - perm:app:review:update - perm:app:publisher:service-provider:view - perm:app:publisher:service-provider:create - perm:app:publisher:service-provider:attach - perm:app:publisher:service-provider:detach - perm:app:publisher:service-provider:connect - perm:app:publisher:view - perm:app:publisher:update - perm:app:store:view - perm:app:subscription:install - perm:app:subscription:uninstall - perm:admin:app:review:update - perm:admin:app:review:view - perm:admin:app:publisher:update - perm:admin:app:review:update - perm:admin:app:subscription:view - perm:admin:app:subscription:modify - perm:device-types:types - perm:enterprise:modify - perm:enterprise:view - perm:android-work:customer - perm:android-work:admin - perm:application-command:modify - perm:sign-csr - perm:admin:devices:view - perm:admin:topics:view - perm:roles:add - perm:roles:add-users - perm:roles:update - perm:roles:permissions - perm:roles:details - perm:roles:view - perm:roles:create-combined-role - perm:roles:delete - perm:dashboard:vulnerabilities - perm:dashboard:non-compliant-count - perm:dashboard:non-compliant - perm:dashboard:by-groups - perm:dashboard:device-counts - perm:dashboard:feature-non-compliant - perm:dashboard:count-overview - perm:dashboard:filtered-count - perm:dashboard:details - perm:get-activity - perm:devices:delete - perm:devices:applications - perm:devices:effective-policy - perm:devices:compliance-data - perm:devices:features - perm:devices:operations - perm:devices:search - perm:devices:details - perm:devices:update - perm:devices:view - perm:view-configuration - perm:manage-configuration - perm:policies:remove - perm:policies:priorities - perm:policies:deactivate - perm:policies:get-policy-details - perm:policies:manage - perm:policies:activate - perm:policies:update - perm:policies:changes - perm:policies:get-details - perm:users:add - perm:users:details - perm:users:count - perm:users:delete - perm:users:roles - perm:users:user-details - perm:users:credentials - perm:users:search - perm:users:is-exist - perm:users:update - perm:users:send-invitation - perm:admin-users:view - perm:admin:devices:update-enrollment - perm:groups:devices - perm:groups:update - perm:groups:add - perm:groups:device - perm:groups:devices-count - perm:groups:remove - perm:groups:groups - perm:groups:groups-view - perm:groups:share - perm:groups:count - perm:groups:roles - perm:groups:devices-remove - perm:groups:devices-add - perm:groups:assign - perm:device-types:configs - perm:device-types:features - perm:device-types:types - perm:applications:install - perm:applications:uninstall - perm:admin-groups:count - perm:admin-groups:view - perm:admin-groups:add - perm:notifications:mark-checked - perm:notifications:view - perm:admin:certificates:delete - perm:admin:certificates:details - perm:admin:certificates:view - perm:admin:certificates:add - perm:admin:certificates:verify - perm:admin - perm:devicetype:deployment - perm:device-types:events - perm:device-types:events:view - perm:admin:device-type - perm:admin:device-type:view - perm:admin:device-type:configs - perm:device:enroll - perm:geo-service:analytics-view - perm:geo-service:alerts-manage - appm:read - perm:devices:permanent-delete - perm:android:manage-configuration - perm:android:view-configuration - perm:user:permission-view - perm:ios:view-configuration - perm:ios:manage-configuration - perm:ios:dep-view - perm:ios:dep-add - perm:windows:view-configuration - perm:windows:manage-configuration - perm:android:lock-devices - perm:android:unlock-devices - perm:android:location - perm:android:clear-password - perm:android:control-camera - perm:android:update-default-sim - perm:android:google-account - perm:android:enterprise-wipe - perm:android:wipe - perm:android:ring - perm:android:applications - perm:android:reboot - perm:android:change-LockTask - perm:android:mute - perm:android:configure-display-message - perm:android:send-app-restrictions - perm:android:file-transfer - perm:android:set-webclip - perm:android:set-password-policy - perm:android:change-lock-code - perm:android:upgrade-firmware - perm:android:send-notification - perm:geo-service:geo-fence - perm:metadata:view - perm:metadata:create - perm:metadata:update - 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:shut-down - perm:mac-os:restart - perm:android:info - perm:windows:lock-devices - perm:windows:disenroll - perm:windows:wipe - perm:windows:ring - perm:windows:lock-reset - perm:windows:reboot - perm:windows:location - perm:admin:tenant:view - perm:admin:metadata:view - perm:android:authenticate-account - {% if mdm_ui_conf.scopes is defined %} - {%- for scope in mdm_ui_conf.scopes -%} - {{scope}} - {% endfor %} - {% endif %} - - - {% if mdm_ui_conf.sso_conf is defined %} - {{mdm_ui_conf.sso_conf.issuer}} - {% else %} - device-mgt - {% endif %} - - - diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mssql.sql new file mode 100644 index 00000000000..8af559a4471 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mssql.sql @@ -0,0 +1,161 @@ +USE [DM_DB] +GO + +SET ANSI_NULLS ON +GO + +SET QUOTED_IDENTIFIER ON +GO + +declare @retention datetime2 +declare @i int +declare @count int +declare @BEFOREDATE varchar(10) +declare @TS varchar(22) +declare @ROWS int + +set @BEFOREDATE = '2021-09-01`'; + +set @retention = CAST(@BEFOREDATE as datetime2) + +DECLARE @TEMP_DM_ENROLMENT_OP_MAPPING TABLE ( + ENROLMENT_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + [STATUS] VARCHAR(50) NULL, + CREATED_TIMESTAMP BIGINT NOT NULL, + UPDATED_TIMESTAMP BIGINT NOT NULL, + PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL, + OPERATION_CODE VARCHAR(50) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + [TYPE] VARCHAR(20) NOT NULL, + DEVICE_ID INTEGER NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NULL, + TENANT_ID INTEGER NULL +); + +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Moving retainable operation mappings and operation mapping records created after %s', 10, 1, @TS, @BEFOREDATE) WITH NOWAIT; +INSERT INTO @TEMP_DM_ENROLMENT_OP_MAPPING + ([ENROLMENT_ID], + [OPERATION_ID], + [STATUS], + [CREATED_TIMESTAMP], + [UPDATED_TIMESTAMP], + [PUSH_NOTIFICATION_STATUS], + [OPERATION_CODE], + [INITIATED_BY], + [TYPE], + [DEVICE_ID], + [DEVICE_TYPE], + [DEVICE_IDENTIFICATION], + [TENANT_ID]) +SELECT [ENROLMENT_ID], [OPERATION_ID], [STATUS], [CREATED_TIMESTAMP], [UPDATED_TIMESTAMP], [PUSH_NOTIFICATION_STATUS], + [OPERATION_CODE], [INITIATED_BY], [TYPE], [DEVICE_ID], [DEVICE_TYPE], [DEVICE_IDENTIFICATION], [TENANT_ID] FROM [dbo].[DM_ENROLMENT_OP_MAPPING] +WHERE [STATUS] = 'PENDING' OR [STATUS] = 'IN_PROGRESS' OR [UPDATED_TIMESTAMP] >= (SELECT DATEDIFF_BIG(millisecond, '1970-01-01 00:00:00', @retention)); + +SET @ROWS = @@ROWCOUNT +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Added %d records to variable table @TEMP_DM_ENROLMENT_OP_MAPPING', 10, 1, @TS, @ROWS) WITH NOWAIT; + +RAISERROR (N'Removing FK constraints...', 10, 1) WITH NOWAIT; +ALTER TABLE [dbo].[DM_NOTIFICATION] DROP CONSTRAINT [FL_DM_NOTIFICATION]; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE_LARGE] DROP CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_LARGE_OPERATION]; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE_LARGE] DROP CONSTRAINT [FK_DM_EN_OP_MAP_RESPONSE_LARGE]; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] DROP CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_ENROLMENT]; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] DROP CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_OPERATION]; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] DROP CONSTRAINT [FK_DM_EN_OP_MAP_RESPONSE]; +ALTER TABLE [dbo].[DM_ENROLMENT_OP_MAPPING] DROP CONSTRAINT [FK_DM_DEVICE_OPERATION_MAPPING_DEVICE]; +ALTER TABLE [dbo].[DM_ENROLMENT_OP_MAPPING] DROP CONSTRAINT [FK_DM_DEVICE_OPERATION_MAPPING_OPERATION]; +RAISERROR (N'Removing FK constraints - COMPLETED', 10, 1) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; + +TRUNCATE TABLE [dbo].[DM_NOTIFICATION]; +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s [DM_NOTIFICATION] table truncated', 10, 1, @TS) WITH NOWAIT; + +TRUNCATE TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE_LARGE]; +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s [DM_DEVICE_OPERATION_RESPONSE_LARGE] table truncated', 10, 1, @TS) WITH NOWAIT; + +TRUNCATE TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE]; +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s [DM_DEVICE_OPERATION_RESPONSE] table truncated', 10, 1, @TS) WITH NOWAIT; + +TRUNCATE TABLE [dbo].[DM_ENROLMENT_OP_MAPPING]; +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s [DM_ENROLMENT_OP_MAPPING] table truncated', 10, 1, @TS) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; + +RAISERROR (N'Adding back the FK constraints', 10, 1) WITH NOWAIT; +ALTER TABLE [dbo].[DM_NOTIFICATION] WITH CHECK ADD CONSTRAINT [FL_DM_NOTIFICATION] FOREIGN KEY([DEVICE_ID]) REFERENCES [dbo].[DM_DEVICE] ([ID]); +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE_LARGE] WITH CHECK ADD CONSTRAINT [FK_DM_EN_OP_MAP_RESPONSE_LARGE] FOREIGN KEY([EN_OP_MAP_ID]) REFERENCES [dbo].[DM_ENROLMENT_OP_MAPPING] ([ID]); +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] WITH CHECK ADD CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_ENROLMENT] FOREIGN KEY([ENROLMENT_ID]) REFERENCES [dbo].[DM_ENROLMENT] ([ID]); +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] WITH CHECK ADD CONSTRAINT [FK_DM_EN_OP_MAP_RESPONSE] FOREIGN KEY([EN_OP_MAP_ID]) REFERENCES [dbo].[DM_ENROLMENT_OP_MAPPING] ([ID]); +ALTER TABLE [dbo].[DM_ENROLMENT_OP_MAPPING] WITH CHECK ADD CONSTRAINT [FK_DM_DEVICE_OPERATION_MAPPING_DEVICE] FOREIGN KEY([ENROLMENT_ID]) REFERENCES [dbo].[DM_ENROLMENT] ([ID]); +RAISERROR (N'Adding FK constraints - COMPLETED', 10, 1) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; + +INSERT INTO [dbo].[DM_ENROLMENT_OP_MAPPING] + ([ENROLMENT_ID], + [OPERATION_ID], + [STATUS], + [PUSH_NOTIFICATION_STATUS], + [CREATED_TIMESTAMP], + [UPDATED_TIMESTAMP], + [OPERATION_CODE], + [INITIATED_BY], + [TYPE], + [DEVICE_ID], + [DEVICE_TYPE], + [DEVICE_IDENTIFICATION], + [TENANT_ID]) +SELECT [ENROLMENT_ID], [OPERATION_ID], [STATUS], [PUSH_NOTIFICATION_STATUS], [CREATED_TIMESTAMP], [UPDATED_TIMESTAMP], + [OPERATION_CODE], [INITIATED_BY], [TYPE], [DEVICE_ID], [DEVICE_TYPE], [DEVICE_IDENTIFICATION], [TENANT_ID] FROM @TEMP_DM_ENROLMENT_OP_MAPPING; + +SET @ROWS = @@ROWCOUNT +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Added %d records to [DM_ENROLMENT_OP_MAPPING] back from variable table @TEMP_DM_ENROLMENT_OP_MAPPING', 10, 1, @TS, @ROWS) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; + + +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Adding operation ids which needs to preserve in to [TEMP_DATA]', 10, 1, @TS) WITH NOWAIT; +DECLARE @TEMP_DATA TABLE ( + [OPERATION_ID] [int] NULL +); + +INSERT INTO @TEMP_DATA + ([OPERATION_ID]) + SELECT DISTINCT OPERATION_ID FROM @TEMP_DM_ENROLMENT_OP_MAPPING; + +SET @ROWS = @@ROWCOUNT +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Added %d records of Operations which needs to preserve for [DM_ENROLMENT_OP_MAPPING] in to [TEMP_DATA]', 10, 1, @TS, @ROWS) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; + + +DELETE dop FROM [dbo].[DM_OPERATION] AS dop +LEFT JOIN @TEMP_DATA AS td +ON dop.ID = td.OPERATION_ID +WHERE td.OPERATION_ID IS NULL; + +SET @ROWS = @@ROWCOUNT +SET @TS = CONVERT(varchar, SYSDATETIME(), 121); +RAISERROR (N'%s Removed %d of records from [DM_OPERATION]', 10, 1, @TS, @ROWS) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; +GO + +RAISERROR (N'Adding back the FK constraints for DM_OPERATION', 10, 1) WITH NOWAIT; +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE_LARGE] WITH CHECK ADD CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_LARGE_OPERATION] FOREIGN KEY([OPERATION_ID]) REFERENCES [dbo].[DM_OPERATION] ([ID]); +ALTER TABLE [dbo].[DM_DEVICE_OPERATION_RESPONSE] WITH CHECK ADD CONSTRAINT [FK_DM_DEVICE_OPERATION_RESP_OPERATION] FOREIGN KEY([OPERATION_ID]) REFERENCES [dbo].[DM_OPERATION] ([ID]); +ALTER TABLE [dbo].[DM_ENROLMENT_OP_MAPPING] WITH CHECK ADD CONSTRAINT [FK_DM_DEVICE_OPERATION_MAPPING_OPERATION] FOREIGN KEY([OPERATION_ID]) REFERENCES [dbo].[DM_OPERATION] ([ID]); +RAISERROR (N'Adding FK constraints for DM_OPERATION - COMPLETED', 10, 1) WITH NOWAIT; +RAISERROR (N'-----------------------------', 10, 1) WITH NOWAIT; +GO + +RAISERROR (N'Start reindexing', 10, 1) WITH NOWAIT; +ALTER INDEX ALL ON [dbo].[DM_OPERATION] +REORGANIZE; +PRINT 'Re-indexed [DM_OPERATION]'; +GO \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mysql.sql new file mode 100644 index 00000000000..df58b1cf844 --- /dev/null +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cleanup-scripts/mysql.sql @@ -0,0 +1,286 @@ +/* + This cleanup script can be run in 2 different ways: + + 1) Logging all queries to a file: mysql -u user -p < mysql.sql --verbose > mysql.log 2>&1 + + - Change the mysql.log file path as needed + - Can be run without the --verbose flag which will only log the timestamped select queries or any errors + e.g: SELECT CONCAT(NOW(), ': Starting cleanup script...') AS ''; + + 2) Logging queries to general_log file/table + + - Do note that in order for this to work the user need to have SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) + - Uncomment lines 36-38 and 288 to log to a file and change the general.log file path as needed + - To log queries to a table, comment line 36 and change log_output to 'TABLE' + - The log_output = 'TABLE' will have queries in BLOB type which needs to be converted to readable format + i.e. SELECT CONVERT(argument using utf8) FROM mysql.general_log; + + */ +SET @startTime = NOW(); +SELECT CONCAT(@startTime, ': Starting cleanup script...') AS ''; + +/* + Rename DM_DB to the CDM MySQL datasource that is running on your server + */ +USE DM_DB; + +/* + Change @retention date to the date that you want the records to be retained after a certain date. + Any records that are older than the retention date will be dropped after this script has successfully + executed + RETENTION date format - YYYY-MM-DD HH:MM:SS + */ +SET @retention = '2022-08-16 00:00:00'; +SELECT CONCAT(NOW(), ': Retention date set to - ', @retention, '.') AS ''; + +-- SET GLOBAL general_log_file = '/var/log/mysql/general.log'; +-- SET GLOBAL log_output = 'TABLE'; +-- SET GLOBAL general_log = 'ON'; + +/* + Create table structure for NEW_DM_ENROLMENT_OP_MAPPING +*/ +SELECT CONCAT(NOW(), ': Creating NEW_DM_ENROLMENT_OP_MAPPING table.') AS ''; +CREATE TABLE NEW_DM_ENROLMENT_OP_MAPPING ( + ID INTEGER NOT NULL AUTO_INCREMENT, + ENROLMENT_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + STATUS VARCHAR(50) NULL, + PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL, + CREATED_TIMESTAMP INTEGER NOT NULL, + UPDATED_TIMESTAMP INTEGER NOT NULL, + OPERATION_CODE VARCHAR(50) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + TYPE VARCHAR(20) NOT NULL, + DEVICE_ID INTEGER DEFAULT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); + +/* + Set the AUTO_INCREMENT value of the NEW_DM_ENROLMENT_OP_MAPPING table to match existing DM_ENROLMENT_OP_MAPPING + table's value +*/ +SET @DM_ENROLMENT_OP_MAPPING_INCREMENT_VALUE := (SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='DM_ENROLMENT_OP_MAPPING' LIMIT 1); +SELECT CONCAT(NOW(), ': Set AUTO_INCREMENT value of NEW_DM_ENROLMENT_OP_MAPPING table to - ', @DM_ENROLMENT_OP_MAPPING_INCREMENT_VALUE, '.') AS ''; +SET @sql1 = CONCAT('ALTER TABLE NEW_DM_ENROLMENT_OP_MAPPING AUTO_INCREMENT = ', @DM_ENROLMENT_OP_MAPPING_INCREMENT_VALUE); +PREPARE st FROM @sql1; +EXECUTE st; +DEALLOCATE PREPARE st; + +/* + Drop the foreign keys of the original DM_ENROLMENT_OP_MAPPING table and then rename DM_ENROLMENT_OP_MAPPING to + OLD_DM_ENROLMENT_OP_MAPPING and NEW_DM_ENROLMENT_OP_MAPPING to DM_ENROLMENT_OP_MAPPING + */ +SELECT CONCAT(NOW(), ': Dropping foreign keys of DM_ENROLMENT_OP_MAPPING.') AS ''; +ALTER TABLE DM_ENROLMENT_OP_MAPPING DROP FOREIGN KEY fk_dm_device_operation_mapping_device; +ALTER TABLE DM_ENROLMENT_OP_MAPPING DROP FOREIGN KEY fk_dm_device_operation_mapping_operation; + +SELECT CONCAT(NOW(), ': Renaming DM_ENROLMENT_OP_MAPPING to OLD_DM_ENROLMENT_OP_MAPPING and NEW_DM_ENROLMENT_OP_MAPPING to DM_ENROLMENT_OP_MAPPING.') AS ''; +RENAME TABLE DM_ENROLMENT_OP_MAPPING TO OLD_DM_ENROLMENT_OP_MAPPING, NEW_DM_ENROLMENT_OP_MAPPING TO DM_ENROLMENT_OP_MAPPING; + +/* + Create table structure for NEW_DM_DEVICE_OPERATION_RESPONSE +*/ +SELECT CONCAT(NOW(), ': Creating NEW_DM_DEVICE_OPERATION_RESPONSE table.') AS ''; +CREATE TABLE NEW_DM_DEVICE_OPERATION_RESPONSE ( + ID INTEGER NOT NULL AUTO_INCREMENT, + ENROLMENT_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + EN_OP_MAP_ID INTEGER NOT NULL, + OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL, + IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + PRIMARY KEY (ID) +); + +/* + Set the AUTO_INCREMENT value of the NEW_DM_DEVICE_OPERATION_RESPONSE table to match existing + DM_DEVICE_OPERATION_RESPONSE table's value +*/ +SET @DM_DEVICE_OPERATION_RESPONSE_INCREMENT_VALUE := (SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='DM_DEVICE_OPERATION_RESPONSE' LIMIT 1); +SELECT CONCAT(NOW(), ': Set AUTO_INCREMENT value of NEW_DM_DEVICE_OPERATION_RESPONSE table to - ', @DM_DEVICE_OPERATION_RESPONSE_INCREMENT_VALUE, '.') AS ''; +SET @sql2 = CONCAT('ALTER TABLE NEW_DM_DEVICE_OPERATION_RESPONSE AUTO_INCREMENT = ', @DM_DEVICE_OPERATION_RESPONSE_INCREMENT_VALUE); +PREPARE st FROM @sql2; +EXECUTE st; +DEALLOCATE PREPARE st; + +/* + Drop the foreign keys of the original DM_DEVICE_OPERATION_RESPONSE table and then rename + DM_DEVICE_OPERATION_RESPONSE to OLD_DM_DEVICE_OPERATION_RESPONSE and NEW_DM_DEVICE_OPERATION_RESPONSE to + DM_DEVICE_OPERATION_RESPONSE + */ +SELECT CONCAT(NOW(), ': Dropping foreign keys of DM_DEVICE_OPERATION_RESPONSE.') AS ''; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE DROP FOREIGN KEY fk_dm_device_operation_response_enrollment; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE DROP FOREIGN KEY fk_dm_device_operation_response_operation; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE DROP FOREIGN KEY fk_dm_en_op_map_response; + +SELECT CONCAT(NOW(), ': Renaming DM_DEVICE_OPERATION_RESPONSE to OLD_DM_DEVICE_OPERATION_RESPONSE and NEW_DM_DEVICE_OPERATION_RESPONSE to DM_DEVICE_OPERATION_RESPONSE.') AS ''; +RENAME TABLE DM_DEVICE_OPERATION_RESPONSE TO OLD_DM_DEVICE_OPERATION_RESPONSE, NEW_DM_DEVICE_OPERATION_RESPONSE TO DM_DEVICE_OPERATION_RESPONSE; + +/* + Create table structure for NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE +*/ +SELECT CONCAT(NOW(), ': Creating NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE table.') AS ''; +CREATE TABLE NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE ( + ID INTEGER NOT NULL, + OPERATION_RESPONSE LONGBLOB, + OPERATION_ID INTEGER NOT NULL, + EN_OP_MAP_ID INTEGER NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL +); + +/* + Drop the foreign keys of the original DM_DEVICE_OPERATION_RESPONSE_LARGE table and then rename + DM_DEVICE_OPERATION_RESPONSE_LARGE to OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE and + NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE to DM_DEVICE_OPERATION_RESPONSE_LARGE + */ +SELECT CONCAT(NOW(), ': Dropping foreign keys of DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE DROP FOREIGN KEY fk_dm_device_operation_response_large; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE DROP FOREIGN KEY fk_dm_en_op_map_response_large; + +SELECT CONCAT(NOW(), ': Renaming DM_DEVICE_OPERATION_RESPONSE_LARGE to OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE and NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE to DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +RENAME TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE TO OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE, NEW_DM_DEVICE_OPERATION_RESPONSE_LARGE TO DM_DEVICE_OPERATION_RESPONSE_LARGE; + +/* + Create table structure for NEW_DM_OPERATION +*/ +SELECT CONCAT(NOW(), ': Creating NEW_DM_OPERATION table.') AS ''; +CREATE TABLE NEW_DM_OPERATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + TYPE VARCHAR(20) NOT NULL, + CREATED_TIMESTAMP BIGINT(15) NOT NULL, + RECEIVED_TIMESTAMP BIGINT(15) NULL, + OPERATION_CODE VARCHAR(50) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + OPERATION_DETAILS BLOB DEFAULT NULL, + ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID) +); + +/* + Set the AUTO_INCREMENT value of the NEW_DM_OPERATION table to match existing DM_OPERATION table's value +*/ +SET @DM_OPERATION_INCREMENT_VALUE := (SELECT AUTO_INCREMENT FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME='DM_OPERATION' LIMIT 1); +SELECT CONCAT(NOW(), ': Set AUTO_INCREMENT value of NEW_DM_OPERATION table to - ', @DM_OPERATION_INCREMENT_VALUE, '.') AS ''; +SET @sql3 = CONCAT('ALTER TABLE NEW_DM_OPERATION AUTO_INCREMENT = ', @DM_OPERATION_INCREMENT_VALUE); +PREPARE st FROM @sql3; +EXECUTE st; +DEALLOCATE PREPARE st; + +/* + Rename DM_OPERATION to OLD_DM_OPERATION and NEW_DM_OPERATION to DM_OPERATION + */ +SELECT CONCAT(NOW(), ': Renaming DM_OPERATION to OLD_DM_OPERATION and NEW_DM_OPERATION to DM_OPERATION.') AS ''; +RENAME TABLE DM_OPERATION TO OLD_DM_OPERATION, NEW_DM_OPERATION TO DM_OPERATION; + +/* + Insert data into DM_DEVICE_OPERATION_RESPONSE from OLD_DM_DEVICE_OPERATION_RESPONSE that is greater than or + equal to the retention date declared at the start of the script +*/ +SELECT CONCAT(NOW(), ': Inserting data into DM_DEVICE_OPERATION_RESPONSE FROM OLD_DM_DEVICE_OPERATION_RESPONSE.') AS ''; +INSERT INTO DM_DEVICE_OPERATION_RESPONSE (ID, ENROLMENT_ID, OPERATION_ID, EN_OP_MAP_ID, OPERATION_RESPONSE, IS_LARGE_RESPONSE, RECEIVED_TIMESTAMP) +SELECT ID, ENROLMENT_ID, OPERATION_ID, EN_OP_MAP_ID, OPERATION_RESPONSE, IS_LARGE_RESPONSE, RECEIVED_TIMESTAMP +FROM OLD_DM_DEVICE_OPERATION_RESPONSE +WHERE RECEIVED_TIMESTAMP >= @retention; +SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_DEVICE_OPERATION_RESPONSE.') AS ''; + +/* + Insert data into DM_DEVICE_OPERATION_RESPONSE_LARGE from OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE that is greater + than or equal to the retention date declared at the start of the script +*/ +SELECT CONCAT(NOW(), ': Inserting data into DM_DEVICE_OPERATION_RESPONSE_LARGE FROM OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +INSERT INTO DM_DEVICE_OPERATION_RESPONSE_LARGE (ID, OPERATION_RESPONSE, OPERATION_ID, EN_OP_MAP_ID, RECEIVED_TIMESTAMP, DEVICE_IDENTIFICATION) +SELECT ID, OPERATION_RESPONSE, OPERATION_ID, EN_OP_MAP_ID, RECEIVED_TIMESTAMP, DEVICE_IDENTIFICATION +FROM OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE +WHERE RECEIVED_TIMESTAMP >= @retention; +SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; + +/* + Insert data into DM_ENROLMENT_OP_MAPPING from OLD_DM_ENROLMENT_OP_MAPPING that has any mapping IDs that are from + DM_DEVICE_OPERATION_RESPONSE or with the status of 'PENDING' / 'IN_PROGRESS'. + This is done because if there are any records with the status of 'PENDING' or 'IN_PROGRESS' that are older than + the retention date the below statement will retain them +*/ +SELECT CONCAT(NOW(), ': Inserting data into DM_ENROLMENT_OP_MAPPING FROM OLD_DM_ENROLMENT_OP_MAPPING.') AS ''; +INSERT INTO DM_ENROLMENT_OP_MAPPING (ID, ENROLMENT_ID, OPERATION_ID, STATUS, PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP, +OPERATION_CODE, INITIATED_BY, TYPE, DEVICE_ID, DEVICE_TYPE, DEVICE_IDENTIFICATION, TENANT_ID) +SELECT ID, ENROLMENT_ID, OPERATION_ID, STATUS, PUSH_NOTIFICATION_STATUS, CREATED_TIMESTAMP, UPDATED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, +TYPE, DEVICE_ID, DEVICE_TYPE, DEVICE_IDENTIFICATION, TENANT_ID +FROM OLD_DM_ENROLMENT_OP_MAPPING +WHERE ID IN(SELECT EN_OP_MAP_ID FROM DM_DEVICE_OPERATION_RESPONSE) OR STATUS = 'PENDING' OR STATUS = 'IN_PROGRESS'; +SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_ENROLMENT_OP_MAPPING.') AS ''; + +/* + Insert data into NEW_DM_OPERATION from DM_OPERATION only with the OPERATION_IDs from DM_ENROLMENT_OP_MAPPING +*/ +SELECT CONCAT(NOW(), ': Inserting data into DM_OPERATION FROM OLD_DM_OPERATION.') AS ''; +INSERT INTO DM_OPERATION (ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, ENABLED) +SELECT ID, TYPE, CREATED_TIMESTAMP, RECEIVED_TIMESTAMP, OPERATION_CODE, INITIATED_BY, OPERATION_DETAILS, ENABLED +FROM OLD_DM_OPERATION +WHERE ID IN(SELECT OPERATION_ID FROM DM_ENROLMENT_OP_MAPPING); +SELECT CONCAT(NOW(), ': Inserted ', ROW_COUNT(),' records to DM_OPERATION.') AS ''; + +/* + Add back foreign key constraints to the new tables that were created which contains data from the retention date + onwards +*/ +SELECT CONCAT(NOW(), ': Adding foreign key constraints to DM_ENROLMENT_OP_MAPPING.') AS ''; +ALTER TABLE DM_ENROLMENT_OP_MAPPING ADD CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE DM_ENROLMENT_OP_MAPPING ADD CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; + +SELECT CONCAT(NOW(), ': Adding foreign key constraints to DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE ADD CONSTRAINT fk_dm_device_operation_response_large FOREIGN KEY (ID) REFERENCES DM_DEVICE_OPERATION_RESPONSE(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE ADD 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; + +SELECT CONCAT(NOW(), ': Adding foreign key constraints to DM_DEVICE_OPERATION_RESPONSE.') AS ''; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE ADD CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES DM_ENROLMENT(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE ADD CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES DM_OPERATION(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; +ALTER TABLE DM_DEVICE_OPERATION_RESPONSE ADD CONSTRAINT fk_dm_en_op_map_response FOREIGN KEY (EN_OP_MAP_ID) REFERENCES DM_ENROLMENT_OP_MAPPING(ID) ON DELETE NO ACTION ON UPDATE NO ACTION; + +/* + Drop the original tables that were renamed and truncate DM_NOTIFICATION. DM_NOTIFICATION table is truncated + because the data is not necessary to be retained + */ +SELECT CONCAT(NOW(), ': Dropping table OLD_DM_ENROLMENT_OP_MAPPING.') AS ''; +DROP TABLE OLD_DM_ENROLMENT_OP_MAPPING; + +SELECT CONCAT(NOW(), ': Dropping table OLD_DM_DEVICE_OPERATION_RESPONSE.') AS ''; +DROP TABLE OLD_DM_DEVICE_OPERATION_RESPONSE; + +SELECT CONCAT(NOW(), ': Dropping table OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +DROP TABLE OLD_DM_DEVICE_OPERATION_RESPONSE_LARGE; + +SELECT CONCAT(NOW(), ': Dropping table OLD_DM_OPERATION.') AS ''; +DROP TABLE OLD_DM_OPERATION; + +SELECT CONCAT(NOW(), ': Truncating table DM_NOTIFICATION.') AS ''; +TRUNCATE TABLE DM_NOTIFICATION; + +/* + Create new indexes for the new tables which contains data from the retention date onwards + */ +SELECT CONCAT(NOW(), ': Adding indexes to DM_ENROLMENT_OP_MAPPING.') AS ''; +CREATE INDEX fk_dm_device_operation_mapping_operation ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID); +CREATE INDEX IDX_DM_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, OPERATION_ID); +CREATE INDEX ID_DM_ENROLMENT_OP_MAPPING_UPDATED_TIMESTAMP ON DM_ENROLMENT_OP_MAPPING(UPDATED_TIMESTAMP); +CREATE INDEX IDX_ENROLMENT_OP_MAPPING ON DM_ENROLMENT_OP_MAPPING(UPDATED_TIMESTAMP); +CREATE INDEX IDX_EN_OP_MAPPING_EN_ID ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID); +CREATE INDEX IDX_EN_OP_MAPPING_OP_ID ON DM_ENROLMENT_OP_MAPPING(OPERATION_ID); +CREATE INDEX IDX_EN_OP_MAPPING_EN_ID_STATUS ON DM_ENROLMENT_OP_MAPPING(ENROLMENT_ID, STATUS); + +SELECT CONCAT(NOW(), ': Adding indexes to DM_DEVICE_OPERATION_RESPONSE.') AS ''; +CREATE INDEX IDX_DM_RES_RT ON DM_DEVICE_OPERATION_RESPONSE(RECEIVED_TIMESTAMP); +CREATE INDEX IDX_ENID_OP_ID ON DM_DEVICE_OPERATION_RESPONSE(OPERATION_ID, ENROLMENT_ID); +CREATE INDEX IDX_DM_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE(EN_OP_MAP_ID); + +SELECT CONCAT(NOW(), ': Adding indexes to DM_DEVICE_OPERATION_RESPONSE_LARGE.') AS ''; +CREATE INDEX IDX_DM_RES_LRG_RT ON DM_DEVICE_OPERATION_RESPONSE_LARGE(RECEIVED_TIMESTAMP); +CREATE INDEX IDX_DM_EN_OP_MAP_ID ON DM_DEVICE_OPERATION_RESPONSE_LARGE(EN_OP_MAP_ID); + +-- SET GLOBAL general_log = 'OFF'; +SET @endTime = NOW(); +SELECT CONCAT(@endTime, ': Cleanup script finished executing in ', TIME_FORMAT(TIMEDIFF(@endTime, @startTime), '%H:%i:%s'),'.') AS ''; \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf index 6779ade766f..eead8934994 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/p2.inf @@ -7,6 +7,7 @@ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../featur org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/license-config.xml,target:${installFolder}/../../conf/etc/license-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/conf/remote-appmanager-config.xml,target:${installFolder}/../../conf/etc/remote-appmanager-config.xml,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/dbscripts/cdm,target:${installFolder}/../../../dbscripts/cdm,overwrite:true);\ +org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/dbscripts/cleanup-scripts,target:${installFolder}/../../../dbscripts/cleanup-scripts,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/rxts/license.rxt,target:${installFolder}/../../../repository/resources/rxts/license.rxt,overwrite:true);\ org.eclipse.equinox.p2.touchpoint.natives.mkdir(path:${installFolder}/../../../repository/resources/email-templates);\ org.eclipse.equinox.p2.touchpoint.natives.copy(source:${installFolder}/../features/org.wso2.carbon.device.mgt.basics_${feature.version}/email/templates,target:${installFolder}/../../../repository/resources/email-templates,overwrite:true);\ diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index 9bcb6d6ca7c..f7aba136725 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,7 +4,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index ddc399c1f06..9c1ba91932a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 69f95968253..d43ed0a2de0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index bb8b811db8f..1d5acbb0695 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 76e9a7f2c3d..f95769cf951 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heart-beat-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index b2075cb342d..24a288ee6d2 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index 2b0572be747..41a044162aa 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt jwt-client-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index d9356cb4641..9dfc4d5cd87 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 09c15644015..892d0fd571b 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index a36dd681d56..5e45494f39a 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index a6ad5f5c742..80e716c1f3c 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index 52befa6b1ff..5793d712ec9 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index 75d30dacd30..0d80c1302d3 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml index 8a878c57662..165e5ded694 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml index 9154a51a185..2b73289eadf 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index 4b268b90ecd..c0d6653d889 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml index 44054577802..5c613386070 100644 --- a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index 861715b1958..470bd572899 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index 9e90f810171..34649cbffaa 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../pom.xml diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index eaf6204755e..dd798c1ce2a 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index 7dbe25b3e23..69f91264084 100644 --- a/pom.xml +++ b/pom.xml @@ -17,13 +17,14 @@ ~ under the License. --> - + 4.0.0 org.wso2.carbon.devicemgt carbon-devicemgt pom - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -37,7 +38,7 @@ components/heartbeat-management components/device-mgt components/device-mgt-extensions - components/identity-extensions + components/identity-extensions components/apimgt-extensions components/application-mgt components/policy-mgt @@ -54,7 +55,7 @@ features/heartbeat-management features/ui-request-interceptor features/jwt-client - features/device-mgt-extensions + features/device-mgt-extensions features/transport-mgt features/analytics-mgt features/webapp-authenticator-framework @@ -366,11 +367,11 @@ - - org.wso2.carbon - org.wso2.carbon.application.deployer - ${carbon.kernel.version} - + + org.wso2.carbon + org.wso2.carbon.application.deployer + ${carbon.kernel.version} + org.wso2.carbon org.wso2.carbon.registry.core @@ -540,7 +541,8 @@ javax.servlet - javax.servlet-api + javax.servlet-api + @@ -1236,11 +1238,11 @@ - - org.wso2.carbon.commons - org.wso2.carbon.application.mgt.stub - ${carbon.commons.version} - + + org.wso2.carbon.commons + org.wso2.carbon.application.mgt.stub + ${carbon.commons.version} + org.wso2.carbon.event-processing org.wso2.carbon.event.processor.stub @@ -1329,11 +1331,11 @@ neethi ${neethi.version} - - commons-codec - commons-codec - ${commons.codec.verision} - + + commons-codec + commons-codec + ${commons.codec.verision} + commons-pool.wso2 @@ -1504,31 +1506,31 @@ org.wso2.carbon.event.output.adapter.core ${carbon.analytics.common.version} - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.datasource.commons - ${carbon.analytics.version} - - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.dataservice.commons - ${carbon.analytics.version} - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.publisher.stub - ${carbon.analytics.common.version} - - - org.wso2.carbon.analytics - org.wso2.carbon.analytics.api - ${carbon.analytics.version} - - - org.wso2.carbon.analytics-common - org.wso2.carbon.event.stream.persistence.stub - ${carbon.analytics.common.version} - + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.datasource.commons + ${carbon.analytics.version} + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.dataservice.commons + ${carbon.analytics.version} + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.publisher.stub + ${carbon.analytics.common.version} + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + ${carbon.analytics.version} + + + org.wso2.carbon.analytics-common + org.wso2.carbon.event.stream.persistence.stub + ${carbon.analytics.common.version} + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.extensions.device.type.deployer @@ -1544,37 +1546,37 @@ org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt ${carbon.device.mgt.version} - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions.push.notification.provider.http - ${carbon.device.mgt.version} - + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions.push.notification.provider.http + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp ${carbon.device.mgt.version} - - org.wso2.carbon.devicemgt - org.wso2.carbon.device.mgt.extensions.pull.notification - ${carbon.device.mgt.version} - + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions.pull.notification + ${carbon.device.mgt.version} + org.wso2.orbit.com.fasterxml.jackson.core jackson-annotations ${jackson-annotations.version} - - org.wso2.orbit.com.fasterxml.jackson.core - jackson-databind - ${jackson-databind.version} - + + org.wso2.orbit.com.fasterxml.jackson.core + jackson-databind + ${jackson-databind.version} + - - org.wso2.orbit.joda-time - joda-time - ${joda-time.version} - + + org.wso2.orbit.joda-time + joda-time + ${joda-time.version} + org.wso2.orbit.org.owasp.encoder encoder @@ -1611,46 +1613,46 @@ wss4j ${org.apache.ws.security.wso2.version} - - org.wso2.carbon.store - org.wso2.store.sso.common - ${carbon.store.sso.common.version} - - - io.github.openfeign - feign-core - ${io.github.openfeign.version} - - - io.github.openfeign - feign-jaxrs - ${io.github.openfeign.version} - - - io.github.openfeign - feign-gson - ${io.github.openfeign.version} - - - io.github.openfeign - feign-jackson - ${io.github.openfeign.version} - - - io.github.openfeign - feign-slf4j - ${io.github.openfeign.version} - - - org.apache.oltu.oauth2 - org.apache.oltu.oauth2.client - ${oltu.client.version} - - - com.fasterxml.jackson.datatype - jackson-datatype-joda - ${jackson.datatype.joda.version} - + + org.wso2.carbon.store + org.wso2.store.sso.common + ${carbon.store.sso.common.version} + + + io.github.openfeign + feign-core + ${io.github.openfeign.version} + + + io.github.openfeign + feign-jaxrs + ${io.github.openfeign.version} + + + io.github.openfeign + feign-gson + ${io.github.openfeign.version} + + + io.github.openfeign + feign-jackson + ${io.github.openfeign.version} + + + io.github.openfeign + feign-slf4j + ${io.github.openfeign.version} + + + org.apache.oltu.oauth2 + org.apache.oltu.oauth2.client + ${oltu.client.version} + + + com.fasterxml.jackson.datatype + jackson-datatype-joda + ${jackson.datatype.joda.version} + org.javassist javassist @@ -1759,9 +1761,9 @@ - https://gitlab.com/entgra/carbon-device-mgt.git - scm:git:https://gitlab.com/entgra/carbon-device-mgt.git - scm:git:https://gitlab.com/entgra/carbon-device-mgt.git + https://repository.entgra.net/community/device-mgt-core.git + scm:git:https://repository.entgra.net/community/device-mgt-core.git + scm:git:https://repository.entgra.net/community/device-mgt-core.git HEAD @@ -1905,113 +1907,6 @@ - - - wso2.releases - WSO2 internal Repository - http://maven.wso2.org/nexus/content/repositories/releases/ - - true - daily - ignore - - - - wso2.snapshots - Apache Snapshot Repository - http://maven.wso2.org/nexus/content/repositories/snapshots/ - - true - daily - - - false - - - - wso2-nexus - WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ - - true - daily - ignore - - - - - - - - wso2-nexus - WSO2 internal Repository - http://maven.wso2.org/nexus/content/groups/wso2-public/ - - true - daily - ignore - - - - wso2.releases - WSO2 internal Repository - http://maven.wso2.org/nexus/content/repositories/releases/ - - true - daily - ignore - - - - wso2.snapshots - WSO2 Snapshot Repository - http://maven.wso2.org/nexus/content/repositories/snapshots/ - - true - daily - - - false - - - - entgra-nexus - Entgra internal Repository - http://nexus.entgra.io/repository/maven-public/ - - true - daily - ignore - - - - entgra.releases - Entgra internal Repository - http://nexus.entgra.io/repository/maven-releases/ - - true - daily - ignore - - - - entgra.snapshots - Entgra Snapshot Repository - http://nexus.entgra.io/repository/maven-snapshots/ - - true - daily - - - false - - - - 2.2.1 7.4.0 @@ -2059,11 +1954,11 @@ 5.18.187 - [5.2.0, 7.0.0) + [5.2.0, 7.0.0) 6.4.111 5.5.2 - 1.0.31 - [1.0.31, 2.0.0) + 1.0.31 + [1.0.31, 2.0.0) [5.14.0, 6.0.0) [6.0.0, 7.0.0) @@ -2081,15 +1976,15 @@ 1.2.11.wso2v10 - 5.0.12-SNAPSHOT + 5.0.14-SNAPSHOT 4.7.35 1.4.0.wso2v1 - [1.4.0,2.0.0) + [1.4.0,2.0.0) 2.4.0.wso2v1 2.6.0.wso2v1 - [2.6.0,3.0.0) + [2.6.0,3.0.0) 9.0.174 @@ -2098,8 +1993,8 @@ 5.1.37 [5.1.3,6.0.0) - 1.3.25 - [1.3.0,2.0.0) + 1.3.25 + [1.3.0,2.0.0) 2.1.23 @@ -2145,7 +2040,7 @@ 1.0.3.wso2v1 - [1.0.3, 2.0.0) + [1.0.3, 2.0.0) 1.5.6.wso2v1 4.3.1.wso2v2 @@ -2181,8 +2076,8 @@ 1.0.10 2.9.8.wso2v1 - 2.6.1.wso2v3 - 2.8.2.wso2v1 + 2.6.1.wso2v3 + 2.8.2.wso2v1 1.2.0.wso2v1 5.0.2.Final @@ -2207,18 +2102,18 @@ 2.1.7-wso2v227 1.5.11.wso2v15 - - 1.5.1 - - - 9.3.1 - [9.3.1,10.0.0) - - 1.0.1 - 2.1.5 - 1.9 - (1.9,2.0] - 3.26.0-GA + + 1.5.1 + + + 9.3.1 + [9.3.1,10.0.0) + + 1.0.1 + 2.1.5 + 1.9 + (1.9,2.0] + 3.26.0-GA true @@ -2249,14 +2144,75 @@ [1.2.0,1.3.0) + + + internal.nexus + Entgra Internal Repository + https://nexus-local.entgra.io/repository/maven-public/ + + true + daily + ignore + + + + wso2-nexus + WSO2 Public Repository + https://maven.wso2.org/nexus/content/groups/wso2-public/ + + true + daily + ignore + + + + + + + + internal.nexus + Entgra Internal Repository + https://nexus-local.entgra.io/repository/maven-public/ + + true + daily + ignore + + + + entgra.nexus + Entgra Public Repository + https://nexus.entgra.io/repository/maven-public/ + + true + daily + ignore + + + + wso2-nexus + WSO2 Public Repository + https://maven.wso2.org/nexus/content/groups/wso2-public/ + + true + daily + ignore + + + + maven-snapshots - https://nexus.entgra.io/repository/maven-snapshots/ - - + https://nexus.entgra.io/repository/maven-snapshot/ + + maven-release - https://nexus.entgra.io/repository/maven-releases/ + https://nexus.entgra.io/repository/maven-release/