mirror of
https://repository.entgra.net/community/device-mgt-core.git
synced 2025-10-06 02:01:45 +00:00
Sync apim420 branch with master branch
Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/261
This commit is contained in:
commit
bfae0e0de8
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -45,9 +45,9 @@ import javax.ws.rs.core.*;
|
|||||||
@Scope(
|
@Scope(
|
||||||
name = "Using Grafana APIs required for Grafana iframes",
|
name = "Using Grafana APIs required for Grafana iframes",
|
||||||
description = "Grafana API proxy to validate requests.",
|
description = "Grafana API proxy to validate requests.",
|
||||||
key = "perm:grafana:api:view",
|
key = "grafana:api:view",
|
||||||
roles = {"Internal/grafanamgt-user"},
|
roles = {"Internal/devicemgt-user"},
|
||||||
permissions = {"/analytics-mgt/grafana-mgt/api/view"}
|
permissions = {"/device-mgt/grafana/view"}
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -71,7 +71,7 @@ public interface GrafanaAPIProxyService {
|
|||||||
tags = "Analytics",
|
tags = "Analytics",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
|
@ExtensionProperty(name = SCOPE, value = "grafana:api:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -88,7 +88,7 @@ public interface GrafanaAPIProxyService {
|
|||||||
tags = "Analytics",
|
tags = "Analytics",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
|
@ExtensionProperty(name = SCOPE, value = "grafana:api:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -104,7 +104,7 @@ public interface GrafanaAPIProxyService {
|
|||||||
tags = "Analytics",
|
tags = "Analytics",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
|
@ExtensionProperty(name = SCOPE, value = "grafana:api:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -121,7 +121,7 @@ public interface GrafanaAPIProxyService {
|
|||||||
tags = "Analytics",
|
tags = "Analytics",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
|
@ExtensionProperty(name = SCOPE, value = "grafana:api:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -137,7 +137,7 @@ public interface GrafanaAPIProxyService {
|
|||||||
tags = "Analytics",
|
tags = "Analytics",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:grafana:api:view")
|
@ExtensionProperty(name = SCOPE, value = "grafana:api:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>grafana-mgt</artifactId>
|
<artifactId>grafana-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>analytics-mgt</artifactId>
|
<artifactId>analytics-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -20,7 +20,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -19,19 +19,17 @@
|
|||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
||||||
|
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.*;
|
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public interface PublisherRESTAPIServices {
|
public interface PublisherRESTAPIServices {
|
||||||
|
|
||||||
JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
Scope[] getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
|
boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key)
|
||||||
@ -43,13 +41,13 @@ public interface PublisherRESTAPIServices {
|
|||||||
boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
|
APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
boolean updateApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
||||||
@ -59,27 +57,27 @@ public interface PublisherRESTAPIServices {
|
|||||||
String asyncApiDefinition)
|
String asyncApiDefinition)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
APIIdentifier apiIdentifier)
|
String apiUuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean addApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
String uuid, Mediation mediation)
|
String uuid, Mediation mediation)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean updateApiSpecificMediationPolicyContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
String uuid, Mediation mediation)
|
String uuid, Mediation mediation)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean changeLifeCycleStatus(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
String uuid, String action)
|
String uuid, String action)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
||||||
Boolean deploymentStatus)
|
Boolean deploymentStatus)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
APIRevision apiRevision)
|
APIRevision apiRevision)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
@ -87,15 +85,15 @@ public interface PublisherRESTAPIServices {
|
|||||||
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
|
String apiRevisionId, List<APIRevisionDeployment> apiRevisionDeploymentList)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
abstract boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
JSONObject apiRevisionDeployment, String uuid)
|
APIRevision apiRevisionDeployment, String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
JSONObject apiRevision, String uuid)
|
APIRevision apiRevision, String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
String uuid)
|
String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
@ -108,6 +106,6 @@ public interface PublisherRESTAPIServices {
|
|||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
|
|
||||||
boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
APIInfo api, String docId, String docContent)
|
String apiUuid, String docId, String docContent)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
throws APIServicesException, BadRequestException, UnexpectedResponseException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -21,21 +21,20 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api;
|
|||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils;
|
|
||||||
import okhttp3.*;
|
import okhttp3.*;
|
||||||
|
import okhttp3.Request.Builder;
|
||||||
import org.apache.commons.httpclient.HttpStatus;
|
import org.apache.commons.httpclient.HttpStatus;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.commons.ssl.Base64;
|
import org.apache.commons.ssl.Base64;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.wso2.carbon.apimgt.api.model.*;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -51,7 +50,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
+ Constants.COLON + port;
|
+ Constants.COLON + port;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
public Scope[] getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getAllScopesUrl = endPointPrefix + Constants.GET_ALL_SCOPES;
|
String getAllScopesUrl = endPointPrefix + Constants.GET_ALL_SCOPES;
|
||||||
@ -65,8 +64,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
JSONArray scopeList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||||
return jsonObject;
|
return gson.fromJson(scopeList.toString(), Scope[].class);
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -119,7 +118,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
log.error(msg);
|
log.error(msg);
|
||||||
throw new BadRequestException(msg);
|
throw new BadRequestException(msg);
|
||||||
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
|
} else if (HttpStatus.SC_NOT_FOUND == response.code()) {
|
||||||
String msg = "Shared scope key not found";
|
String msg = "Shared scope key not found : " + key;
|
||||||
log.info(msg);
|
log.info(msg);
|
||||||
return false;
|
return false;
|
||||||
} else {
|
} else {
|
||||||
@ -139,14 +138,21 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
String addNewSharedScopeEndPoint = endPointPrefix + Constants.SCOPE_API_ENDPOINT;
|
||||||
|
|
||||||
ScopeUtils scopeUtil = new ScopeUtils();
|
JSONArray bindings = new JSONArray();
|
||||||
scopeUtil.setKey(scope.getKey());
|
if (scope.getBindings() != null) {
|
||||||
scopeUtil.setName(scope.getName());
|
for (String str : scope.getBindings()) {
|
||||||
scopeUtil.setDescription(scope.getDescription());
|
bindings.put(str);
|
||||||
scopeUtil.setRoles(scope.getRoles());
|
}
|
||||||
String scopeString = scopeUtil.toJSON();
|
}
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
JSONObject payload = new JSONObject();
|
||||||
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
||||||
|
payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : ""));
|
||||||
|
payload.put("description", (scope.getDescription() != null ? scope.getDescription() : ""));
|
||||||
|
payload.put("bindings", (bindings != null ? bindings : ""));
|
||||||
|
payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0));
|
||||||
|
|
||||||
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addNewSharedScopeEndPoint)
|
.url(addNewSharedScopeEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -186,14 +192,21 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
String updateScopeUrl = endPointPrefix + Constants.SCOPE_API_ENDPOINT + scope.getId();
|
||||||
|
|
||||||
ScopeUtils scopeUtil = new ScopeUtils();
|
JSONArray bindings = new JSONArray();
|
||||||
scopeUtil.setKey(scope.getKey());
|
if (scope.getBindings() != null) {
|
||||||
scopeUtil.setName(scope.getName());
|
for (String str : scope.getBindings()) {
|
||||||
scopeUtil.setDescription(scope.getDescription());
|
bindings.put(str);
|
||||||
scopeUtil.setRoles(scope.getRoles());
|
}
|
||||||
String scopeString = scopeUtil.toJSON();
|
}
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, scopeString);
|
JSONObject payload = new JSONObject();
|
||||||
|
payload.put("name", (scope.getName() != null ? scope.getName() : ""));
|
||||||
|
payload.put("displayName", (scope.getDisplayName() != null ? scope.getDisplayName() : ""));
|
||||||
|
payload.put("description", (scope.getDescription() != null ? scope.getDescription() : ""));
|
||||||
|
payload.put("bindings", (bindings != null ? bindings : ""));
|
||||||
|
payload.put("usageCount", (scope.getUsageCount() != 0 ? scope.getUsageCount() : 0));
|
||||||
|
|
||||||
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(updateScopeUrl)
|
.url(updateScopeUrl)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -228,10 +241,10 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIIdentifier apiIdentifier)
|
public APIInfo getApi(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String apiUuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiIdentifier.getUUID();
|
String getAllApi = endPointPrefix + Constants.API_ENDPOINT + apiUuid;
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(getAllApi)
|
.url(getAllApi)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -242,15 +255,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
return gson.fromJson(response.body().string(), APIInfo.class);
|
||||||
return jsonObject;
|
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
||||||
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
//TODO: max attempt count
|
//TODO: max attempt count
|
||||||
return getApi(apiApplicationKey, refreshedAccessToken, apiIdentifier);
|
return getApi(apiApplicationKey, refreshedAccessToken, apiUuid);
|
||||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||||
String msg = "Bad Request, Invalid request";
|
String msg = "Bad Request, Invalid request";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -267,7 +279,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
public APIInfo[] getApis(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
String getAllApis = endPointPrefix + Constants.GET_ALL_APIS;
|
||||||
@ -281,8 +293,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
JSONArray apiList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||||
return jsonObject;
|
return gson.fromJson(apiList.toString(), APIInfo[].class);
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -306,58 +318,111 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
public APIInfo addAPI(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIInfo api)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
String addAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT;
|
||||||
|
|
||||||
String apiString = "{\n" +
|
JSONObject payload = new JSONObject();
|
||||||
" \"name\": \"" + api.getName() + "\",\n" +
|
payload.put("name", api.getName());
|
||||||
" \"description\":\"" + api.getDescription() + "\",\n" +
|
payload.put("description", api.getDescription());
|
||||||
" \"context\":\"" + api.getContext() + "\",\n" +
|
payload.put("context", api.getContext());
|
||||||
" \"version\":\"" + api.getVersion() + "\",\n" +
|
payload.put("version", api.getVersion());
|
||||||
" \"provider\":\"" + api.getProvider() + "\",\n" +
|
payload.put("provider", api.getProvider());
|
||||||
" \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" +
|
payload.put("lifeCycleStatus", api.getLifeCycleStatus());
|
||||||
" \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" +
|
payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null));
|
||||||
" \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" +
|
payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null));
|
||||||
" \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" +
|
payload.put("responseCachingEnabled", api.isResponseCachingEnabled());
|
||||||
" \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" +
|
payload.put("cacheTimeout", api.getCacheTimeout());
|
||||||
" \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" +
|
payload.put("hasThumbnail", api.isHasThumbnail());
|
||||||
" \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" +
|
payload.put("isDefaultVersion", api.isDefaultVersion());
|
||||||
" \"isRevision\": " + api.isRevision() + ",\n" +
|
payload.put("isRevision", api.isRevision());
|
||||||
" \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" +
|
payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null));
|
||||||
" \"revisionId\": " + api.getRevisionId() + ",\n" +
|
payload.put("revisionId", api.getRevisionId());
|
||||||
" \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" +
|
payload.put("enableSchemaValidation", api.isEnableSchemaValidation());
|
||||||
" \"type\": \"" + api.getType() + "\",\n" +
|
payload.put("type", api.getType());
|
||||||
" \"transport\": " + gson.toJson(api.getTransport()) + ",\n" +
|
payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy());
|
||||||
" \"tags\": " + gson.toJson(api.getTags()) + ",\n" +
|
payload.put("authorizationHeader", api.getAuthorizationHeader());
|
||||||
" \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" +
|
payload.put("visibility", api.getVisibility());
|
||||||
" \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" +
|
payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : ""));
|
||||||
" \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" +
|
|
||||||
" \"visibility\": \"" + api.getVisibility() + "\",\n" +
|
|
||||||
" \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" +
|
|
||||||
" \"subscriptionAvailableTenants\": [],\n" +
|
|
||||||
" \"additionalProperties\": [],\n" +
|
|
||||||
" \"monetization\": " + api.getMonetization() + ",\n" +
|
|
||||||
" \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" +
|
|
||||||
" \"websubSubscriptionConfiguration\": {\n" +
|
|
||||||
" \"enable\": false,\n" +
|
|
||||||
" \"secret\": \"\",\n" +
|
|
||||||
" \"signingAlgorithm\": \"SHA1\",\n" +
|
|
||||||
" \"signatureHeader\": \"x-hub-signature\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"workflowStatus\": null,\n" +
|
|
||||||
" \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" +
|
|
||||||
" \"endpointImplementationType\": \"ENDPOINT\",\n" +
|
|
||||||
" \"scopes\": " + api.getScopes().toString() + ",\n" +
|
|
||||||
" \"operations\": " + api.getOperations().toString() + ",\n" +
|
|
||||||
" \"threatProtectionPolicies\": null,\n" +
|
|
||||||
" \"categories\": [],\n" +
|
|
||||||
" \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" +
|
|
||||||
" \"serviceInfo\": " + api.getServiceInfo() + "\n" +
|
|
||||||
"}";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
//Lists
|
||||||
|
if (api.getTransport() != null) {
|
||||||
|
JSONArray transport = new JSONArray();
|
||||||
|
for (String str : api.getTransport()) {
|
||||||
|
transport.put(str);
|
||||||
|
}
|
||||||
|
payload.put("transport", transport);
|
||||||
|
}
|
||||||
|
if (api.getTags() != null) {
|
||||||
|
JSONArray tags = new JSONArray();
|
||||||
|
for (String str : api.getTags()) {
|
||||||
|
tags.put(str);
|
||||||
|
}
|
||||||
|
payload.put("tags", tags);
|
||||||
|
}
|
||||||
|
if (api.getPolicies() != null) {
|
||||||
|
JSONArray policies = new JSONArray();
|
||||||
|
for (String str : api.getPolicies()) {
|
||||||
|
policies.put(str);
|
||||||
|
}
|
||||||
|
payload.put("policies", policies);
|
||||||
|
}
|
||||||
|
if (api.getMediationPolicies() != null) {
|
||||||
|
JSONArray mediationPolicies = new JSONArray();
|
||||||
|
for (MediationPolicy object : api.getMediationPolicies()) {
|
||||||
|
mediationPolicies.put(new JSONObject(gson.toJson(object)));
|
||||||
|
}
|
||||||
|
payload.put("mediationPolicies", mediationPolicies);
|
||||||
|
}
|
||||||
|
if (api.getSubscriptionAvailableTenants() != null) {
|
||||||
|
JSONArray subscriptionAvailableTenants = new JSONArray();
|
||||||
|
for (String str : api.getSubscriptionAvailableTenants()) {
|
||||||
|
subscriptionAvailableTenants.put(str);
|
||||||
|
}
|
||||||
|
payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants);
|
||||||
|
}
|
||||||
|
if (api.getAdditionalProperties() != null) {
|
||||||
|
JSONArray additionalProperties = new JSONArray();
|
||||||
|
for (AdditionalProperties str : api.getAdditionalProperties()) {
|
||||||
|
additionalProperties.put(str);
|
||||||
|
}
|
||||||
|
payload.put("additionalProperties", additionalProperties);
|
||||||
|
}
|
||||||
|
if (api.getScopes() != null) {
|
||||||
|
JSONArray scopes = new JSONArray();
|
||||||
|
for (JSONObject object : api.getScopes()) {
|
||||||
|
scopes.put(object);
|
||||||
|
}
|
||||||
|
payload.put("scopes", scopes);
|
||||||
|
}
|
||||||
|
if (api.getOperations() != null) {
|
||||||
|
JSONArray operations = new JSONArray();
|
||||||
|
for (Operations operation : api.getOperations()) {
|
||||||
|
operations.put(new JSONObject(gson.toJson(operation)));
|
||||||
|
}
|
||||||
|
payload.put("operations", operations);
|
||||||
|
}
|
||||||
|
if (api.getCategories() != null) {
|
||||||
|
JSONArray categories = new JSONArray();
|
||||||
|
for (String str : api.getCategories()) {
|
||||||
|
categories.put(str);
|
||||||
|
}
|
||||||
|
payload.put("categories", categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
//objects
|
||||||
|
payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null));
|
||||||
|
payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null));
|
||||||
|
payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null));
|
||||||
|
payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null));
|
||||||
|
payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null));
|
||||||
|
payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null));
|
||||||
|
payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null));
|
||||||
|
payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null));
|
||||||
|
payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null));
|
||||||
|
|
||||||
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addAPIEndPoint)
|
.url(addAPIEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -368,8 +433,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_CREATED == response.code()) {
|
if (HttpStatus.SC_CREATED == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
return gson.fromJson(response.body().string(), APIInfo.class);
|
||||||
return jsonObject;
|
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -398,53 +462,106 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
String updateAPIEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId();
|
||||||
|
|
||||||
String apiString = "{\n" +
|
JSONObject payload = new JSONObject();
|
||||||
" \"name\": \"" + api.getName() + "\",\n" +
|
payload.put("name", api.getName());
|
||||||
" \"description\":\"" + api.getDescription() + "\",\n" +
|
payload.put("description", api.getDescription());
|
||||||
" \"context\":\"" + api.getContext() + "\",\n" +
|
payload.put("context", api.getContext());
|
||||||
" \"version\":\"" + api.getVersion() + "\",\n" +
|
payload.put("version", api.getVersion());
|
||||||
" \"provider\":\"" + api.getProvider() + "\",\n" +
|
payload.put("provider", api.getProvider());
|
||||||
" \"lifeCycleStatus\":\"" + api.getLifeCycleStatus() + "\",\n" +
|
payload.put("lifeCycleStatus", api.getLifeCycleStatus());
|
||||||
" \"wsdlInfo\": " + api.getWsdlInfo() + ",\n" +
|
payload.put("wsdlInfo", (api.getWsdlInfo() != null ? api.getWsdlInfo() : null));
|
||||||
" \"wsdlUrl\":" + api.getWsdlUrl() + ",\n" +
|
payload.put("wsdlUrl", (api.getWsdlUrl() != null ? api.getWsdlUrl() : null));
|
||||||
" \"responseCachingEnabled\": " + api.isResponseCachingEnabled() + ",\n" +
|
payload.put("responseCachingEnabled", api.isResponseCachingEnabled());
|
||||||
" \"cacheTimeout\": " + api.getCacheTimeout() + ",\n" +
|
payload.put("cacheTimeout", api.getCacheTimeout());
|
||||||
" \"hasThumbnail\": " + api.isHasThumbnail() + ",\n" +
|
payload.put("hasThumbnail", api.isHasThumbnail());
|
||||||
" \"isDefaultVersion\": " + api.isDefaultVersion() + ",\n" +
|
payload.put("isDefaultVersion", api.isDefaultVersion());
|
||||||
" \"isRevision\": " + api.isRevision() + ",\n" +
|
payload.put("isRevision", api.isRevision());
|
||||||
" \"revisionedApiId\": " + api.getRevisionedApiId() + ",\n" +
|
payload.put("revisionedApiId", (api.getRevisionedApiId() != null ? api.getRevisionedApiId() : null));
|
||||||
" \"revisionId\": " + api.getRevisionId() + ",\n" +
|
payload.put("revisionId", api.getRevisionId());
|
||||||
" \"enableSchemaValidation\": " + api.isEnableSchemaValidation() + ",\n" +
|
payload.put("enableSchemaValidation", api.isEnableSchemaValidation());
|
||||||
" \"type\": \"" + api.getType() + "\",\n" +
|
payload.put("type", api.getType());
|
||||||
" \"transport\": " + gson.toJson(api.getTransport()) + ",\n" +
|
payload.put("apiThrottlingPolicy", api.getApiThrottlingPolicy());
|
||||||
" \"tags\": " + gson.toJson(api.getTags()) + ",\n" +
|
payload.put("authorizationHeader", api.getAuthorizationHeader());
|
||||||
" \"policies\": " + gson.toJson(api.getPolicies()) + ",\n" +
|
payload.put("visibility", api.getVisibility());
|
||||||
" \"apiThrottlingPolicy\": " + api.getApiThrottlingPolicy() + ",\n" +
|
payload.put("subscriptionAvailability", (api.getSubscriptionAvailability() != null ? api.getSubscriptionAvailability() : ""));
|
||||||
" \"authorizationHeader\": \"" + api.getAuthorizationHeader() + "\",\n" +
|
|
||||||
" \"visibility\": \"" + api.getVisibility() + "\",\n" +
|
|
||||||
" \"subscriptionAvailability\": \"" + api.getSubscriptionAvailability() + "\",\n" +
|
|
||||||
" \"subscriptionAvailableTenants\": [],\n" +
|
|
||||||
" \"additionalProperties\": [],\n" +
|
|
||||||
" \"monetization\": " + api.getMonetization() + ",\n" +
|
|
||||||
" \"corsConfiguration\": " + gson.toJson(api.getCorsConfiguration()) + ",\n" +
|
|
||||||
" \"websubSubscriptionConfiguration\": {\n" +
|
|
||||||
" \"enable\": false,\n" +
|
|
||||||
" \"secret\": \"\",\n" +
|
|
||||||
" \"signingAlgorithm\": \"SHA1\",\n" +
|
|
||||||
" \"signatureHeader\": \"x-hub-signature\"\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"workflowStatus\": null,\n" +
|
|
||||||
" \"endpointConfig\": " + api.getEndpointConfig().toString() + ",\n" +
|
|
||||||
" \"endpointImplementationType\": \"ENDPOINT\",\n" +
|
|
||||||
" \"scopes\": " + api.getScopes().toString() + ",\n" +
|
|
||||||
" \"operations\": " + api.getOperations().toString() + ",\n" +
|
|
||||||
" \"threatProtectionPolicies\": null,\n" +
|
|
||||||
" \"categories\": [],\n" +
|
|
||||||
" \"keyManagers\": " + gson.toJson(api.getKeyManagers()) + ",\n" +
|
|
||||||
" \"serviceInfo\": " + api.getServiceInfo() + "\n" +
|
|
||||||
"}";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, apiString);
|
//Lists
|
||||||
|
if (api.getTransport() != null) {
|
||||||
|
JSONArray transport = new JSONArray();
|
||||||
|
for (String str : api.getTransport()) {
|
||||||
|
transport.put(str);
|
||||||
|
}
|
||||||
|
payload.put("transport", transport);
|
||||||
|
}
|
||||||
|
if (api.getTags() != null) {
|
||||||
|
JSONArray tags = new JSONArray();
|
||||||
|
for (String str : api.getTags()) {
|
||||||
|
tags.put(str);
|
||||||
|
}
|
||||||
|
payload.put("tags", tags);
|
||||||
|
}
|
||||||
|
if (api.getPolicies() != null) {
|
||||||
|
JSONArray policies = new JSONArray();
|
||||||
|
for (String str : api.getPolicies()) {
|
||||||
|
policies.put(str);
|
||||||
|
}
|
||||||
|
payload.put("policies", policies);
|
||||||
|
}
|
||||||
|
if (api.getMediationPolicies() != null) {
|
||||||
|
JSONArray mediationPolicies = new JSONArray();
|
||||||
|
for (MediationPolicy object : api.getMediationPolicies()) {
|
||||||
|
mediationPolicies.put(new JSONObject(gson.toJson(object)));
|
||||||
|
}
|
||||||
|
payload.put("mediationPolicies", mediationPolicies);
|
||||||
|
}
|
||||||
|
if (api.getSubscriptionAvailableTenants() != null) {
|
||||||
|
JSONArray subscriptionAvailableTenants = new JSONArray();
|
||||||
|
for (String str : api.getSubscriptionAvailableTenants()) {
|
||||||
|
subscriptionAvailableTenants.put(str);
|
||||||
|
}
|
||||||
|
payload.put("subscriptionAvailableTenants", subscriptionAvailableTenants);
|
||||||
|
}
|
||||||
|
if (api.getAdditionalProperties() != null) {
|
||||||
|
JSONArray additionalProperties = new JSONArray();
|
||||||
|
for (AdditionalProperties str : api.getAdditionalProperties()) {
|
||||||
|
additionalProperties.put(str);
|
||||||
|
}
|
||||||
|
payload.put("additionalProperties", additionalProperties);
|
||||||
|
}
|
||||||
|
if (api.getScopes() != null) {
|
||||||
|
JSONArray scopes = new JSONArray();
|
||||||
|
for (JSONObject object : api.getScopes()) {
|
||||||
|
scopes.put(object);
|
||||||
|
}
|
||||||
|
payload.put("scopes", scopes);
|
||||||
|
}
|
||||||
|
if (api.getOperations() != null) {
|
||||||
|
JSONArray operations = new JSONArray();
|
||||||
|
for (Operations operation : api.getOperations()) {
|
||||||
|
operations.put(new JSONObject(gson.toJson(operation)));
|
||||||
|
}
|
||||||
|
payload.put("operations", operations);
|
||||||
|
}
|
||||||
|
if (api.getCategories() != null) {
|
||||||
|
JSONArray categories = new JSONArray();
|
||||||
|
for (String str : api.getCategories()) {
|
||||||
|
categories.put(str);
|
||||||
|
}
|
||||||
|
payload.put("categories", categories);
|
||||||
|
}
|
||||||
|
|
||||||
|
//objects
|
||||||
|
payload.put("monetization", (api.getMonetization() != null ? new JSONObject(gson.toJson(api.getMonetization())) : null));
|
||||||
|
payload.put("corsConfiguration", (api.getCorsConfiguration() != null ? new JSONObject(gson.toJson(api.getCorsConfiguration())) : null));
|
||||||
|
payload.put("websubSubscriptionConfiguration", (api.getWebsubSubscriptionConfiguration() != null ? new JSONObject(gson.toJson(api.getWebsubSubscriptionConfiguration())) : null));
|
||||||
|
payload.put("workflowStatus", (api.getWorkflowStatus() != null ? api.getWorkflowStatus() : null));
|
||||||
|
payload.put("endpointConfig", (api.getEndpointConfig() != null ? api.getEndpointConfig() : null));
|
||||||
|
payload.put("endpointImplementationType", (api.getEndpointImplementationType() != null ? api.getEndpointImplementationType() : null));
|
||||||
|
payload.put("threatProtectionPolicies", (api.getThreatProtectionPolicies() != null ? api.getThreatProtectionPolicies() : null));
|
||||||
|
payload.put("serviceInfo", (api.getServiceInfo() != null ? new JSONObject(gson.toJson(api.getServiceInfo())) : null));
|
||||||
|
payload.put("advertiseInfo", (api.getAdvertiseInfo() != null ? new JSONObject(gson.toJson(api.getAdvertiseInfo())) : null));
|
||||||
|
|
||||||
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(updateAPIEndPoint)
|
.url(updateAPIEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -456,7 +573,6 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -484,11 +600,16 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
String uuid, String asyncApiDefinition)
|
String uuid, String asyncApiDefinition)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid;
|
String saveAsyncAPI = endPointPrefix + Constants.API_ENDPOINT + uuid + "/asyncapi";
|
||||||
|
|
||||||
|
RequestBody requestBody = new MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.addFormDataPart("apiDefinition", asyncApiDefinition)
|
||||||
|
.build();
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, asyncApiDefinition);
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addNewScope)
|
.url(saveAsyncAPI)
|
||||||
|
.addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data")
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
+ accessTokenInfo.getAccess_token())
|
+ accessTokenInfo.getAccess_token())
|
||||||
.put(requestBody)
|
.put(requestBody)
|
||||||
@ -522,11 +643,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
public MediationPolicy[] getAllApiSpecificMediationPolicies(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
APIIdentifier apiIdentifier)
|
String apiUuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getAPIMediationEndPoint = endPointPrefix + Constants.API_ENDPOINT + apiIdentifier.getUUID() + "/mediation-policies";
|
String getAPIMediationEndPoint = endPointPrefix + Constants.API_ENDPOINT + apiUuid + "/mediation-policies";
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(getAPIMediationEndPoint)
|
.url(getAPIMediationEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -537,15 +658,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
JSONArray mediationPolicyList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||||
return jsonObject;
|
return gson.fromJson(mediationPolicyList.toString(), MediationPolicy[].class);
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
||||||
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
//TODO: max attempt count
|
//TODO: max attempt count
|
||||||
return getAllApiSpecificMediationPolicies(apiApplicationKey, refreshedAccessToken, apiIdentifier);
|
return getAllApiSpecificMediationPolicies(apiApplicationKey, refreshedAccessToken, apiUuid);
|
||||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||||
String msg = "Bad Request, Invalid request";
|
String msg = "Bad Request, Invalid request";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -566,12 +687,17 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
String uuid, Mediation mediation)
|
String uuid, Mediation mediation)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String addAPIMediation = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid()
|
String addAPIMediation = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies";
|
||||||
+ "/content";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, String.valueOf(mediation));
|
RequestBody requestBody = new MultipartBody.Builder()
|
||||||
Request request = new Request.Builder()
|
.setType(MultipartBody.FORM)
|
||||||
|
.addFormDataPart("inlineContent", mediation.getConfig())
|
||||||
|
.addFormDataPart("type", mediation.getType())
|
||||||
|
.build();
|
||||||
|
|
||||||
|
Request request = new Builder()
|
||||||
.url(addAPIMediation)
|
.url(addAPIMediation)
|
||||||
|
.addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data")
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
+ accessTokenInfo.getAccess_token())
|
+ accessTokenInfo.getAccess_token())
|
||||||
.post(requestBody)
|
.post(requestBody)
|
||||||
@ -604,26 +730,23 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateApiSpecificMediationPolicyContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
public boolean deleteApiSpecificMediationPolicy(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
String uuid, Mediation mediation)
|
String uuid, Mediation mediation)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String updateApiMediationEndPOint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid()
|
String deleteApiMediationEndPOint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/mediation-policies/" + mediation.getUuid();
|
||||||
+ "/content";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, String.valueOf(mediation));
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(updateApiMediationEndPOint)
|
.url(deleteApiMediationEndPOint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
+ accessTokenInfo.getAccess_token())
|
+ accessTokenInfo.getAccess_token())
|
||||||
.put(requestBody)
|
.delete()
|
||||||
.build();
|
.build();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_CREATED == response.code()) { // Check response status
|
if (HttpStatus.SC_NO_CONTENT == response.code()) { // Check response status
|
||||||
return true;
|
return true;
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
@ -631,7 +754,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
||||||
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
//TODO: max attempt count
|
//TODO: max attempt count
|
||||||
return updateApiSpecificMediationPolicyContent(apiApplicationKey, refreshedAccessToken, uuid, mediation);
|
return deleteApiSpecificMediationPolicy(apiApplicationKey, refreshedAccessToken, uuid, mediation);
|
||||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||||
String msg = "Bad Request, Invalid mediation policy";
|
String msg = "Bad Request, Invalid mediation policy";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
@ -691,8 +814,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
public APIRevision[] getAPIRevisions(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid,
|
||||||
Boolean deploymentStatus)
|
Boolean deploymentStatus)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getAPIRevisionsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions?query=deployed:"
|
String getAPIRevisionsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions?query=deployed:"
|
||||||
@ -708,8 +831,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
JSONArray revisionList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||||
return jsonObject;
|
return gson.fromJson(revisionList.toString(), APIRevision[].class);
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -733,16 +856,15 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
public APIRevision addAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, APIRevision apiRevision)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + apiRevision.getApiUUID() + "/revisions";
|
||||||
|
|
||||||
String apiRevisionDescription = "{\n" +
|
JSONObject payload = new JSONObject();
|
||||||
" \"description\":\"" + apiRevision.getDescription() + "\"\n" +
|
payload.put("description", (apiRevision.getDescription() != null ? apiRevision.getDescription() : null));
|
||||||
"}";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, apiRevisionDescription);
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addNewScope)
|
.url(addNewScope)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -753,8 +875,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_CREATED == response.code()) {
|
if (HttpStatus.SC_CREATED == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
return gson.fromJson(response.body().string(), APIRevision.class);
|
||||||
return jsonObject;
|
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -785,15 +906,14 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId;
|
String deployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/deploy-revision?revisionId=" + apiRevisionId;
|
||||||
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0);
|
APIRevisionDeployment apiRevisionDeployment = apiRevisionDeploymentList.get(0);
|
||||||
|
|
||||||
String revision = "[\n" +
|
JSONArray payload = new JSONArray();
|
||||||
" {\n" +
|
JSONObject revision = new JSONObject();
|
||||||
" \"name\": \"" + apiRevisionDeployment.getDeployment() + "\",\n" +
|
revision.put("name", (apiRevisionDeployment.getName() != null ? apiRevisionDeployment.getName() : ""));
|
||||||
" \"vhost\": \"" + apiRevisionDeployment.getVhost() + "\",\n" +
|
revision.put("vhost", (apiRevisionDeployment.getVhost() != null ? apiRevisionDeployment.getVhost() : ""));
|
||||||
" \"displayOnDevportal\": " + apiRevisionDeployment.isDisplayOnDevportal() + "\n" +
|
revision.put("displayOnDevportal", apiRevisionDeployment.isDisplayOnDevportal());
|
||||||
" }\n" +
|
payload.put(revision);
|
||||||
"]";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, revision);
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(deployAPIRevisionEndPoint)
|
.url(deployAPIRevisionEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -830,23 +950,22 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
public boolean undeployAPIRevisionDeployment(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
JSONObject apiRevisionDeployment, String uuid)
|
APIRevision apiRevisionDeployment, String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId="
|
String undeployAPIRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/undeploy-revision?revisionId="
|
||||||
+ apiRevisionDeployment.getString("id");
|
+ apiRevisionDeployment.getId();
|
||||||
JSONArray array = apiRevisionDeployment.getJSONArray("deploymentInfo");
|
List<APIRevisionDeployment> apiRevisionDeployments = apiRevisionDeployment.getDeploymentInfo();
|
||||||
JSONObject obj = array.getJSONObject(0);
|
APIRevisionDeployment earliestDeployment = apiRevisionDeployments.get(0);
|
||||||
|
|
||||||
String revision = "[\n" +
|
JSONArray payload = new JSONArray();
|
||||||
" {\n" +
|
JSONObject revision = new JSONObject();
|
||||||
" \"name\": \"" + obj.getString("name") + "\",\n" +
|
revision.put("name", (earliestDeployment.getName() != null ? earliestDeployment.getName() : ""));
|
||||||
" \"vhost\": \"" + obj.getString("vhost") + "\",\n" +
|
revision.put("vhost", (earliestDeployment.getVhost() != null ? earliestDeployment.getVhost() : ""));
|
||||||
" \"displayOnDevportal\": " + obj.get("displayOnDevportal") + "\n" +
|
revision.put("displayOnDevportal", earliestDeployment.isDisplayOnDevportal());
|
||||||
" }\n" +
|
payload.put(revision);
|
||||||
"]";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, revision);
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(undeployAPIRevisionEndPoint)
|
.url(undeployAPIRevisionEndPoint)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
@ -882,11 +1001,11 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
public boolean deleteAPIRevision(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
JSONObject apiRevision, String uuid)
|
APIRevision apiRevision, String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" +
|
String apiRevisionEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/revisions/" +
|
||||||
apiRevision.getString("id");
|
apiRevision.getId();
|
||||||
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(apiRevisionEndPoint)
|
.url(apiRevisionEndPoint)
|
||||||
@ -922,7 +1041,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JSONObject getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
|
public Documentation[] getDocumentations(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String uuid)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String getDocumentationsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents?limit=1000";
|
String getDocumentationsEndPoint = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents?limit=1000";
|
||||||
@ -937,8 +1056,8 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
try {
|
try {
|
||||||
Response response = client.newCall(request).execute();
|
Response response = client.newCall(request).execute();
|
||||||
if (HttpStatus.SC_OK == response.code()) {
|
if (HttpStatus.SC_OK == response.code()) {
|
||||||
JSONObject jsonObject = new JSONObject(response.body().string());
|
JSONArray documentList = (JSONArray) new JSONObject(response.body().string()).get("list");
|
||||||
return jsonObject;
|
return gson.fromJson(documentList.toString(), Documentation[].class);
|
||||||
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
} else if (HttpStatus.SC_UNAUTHORIZED == response.code()) {
|
||||||
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
AccessTokenInfo refreshedAccessToken = apiApplicationServices.
|
||||||
@ -1008,19 +1127,19 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents";
|
String addNewScope = endPointPrefix + Constants.API_ENDPOINT + uuid + "/documents";
|
||||||
|
|
||||||
String document = "{\n" +
|
JSONObject payload = new JSONObject();
|
||||||
" \"name\": \" " + documentation.getName() + " \",\n" +
|
payload.put("name", documentation.getName());
|
||||||
" \"type\": \" " + documentation.getType() + " \",\n" +
|
payload.put("type", documentation.getType());
|
||||||
" \"summary\": \" " + documentation.getSummary() + " \",\n" +
|
payload.put("summary", documentation.getSummary());
|
||||||
" \"sourceType\": \" " + documentation.getSourceType() + " \",\n" +
|
payload.put("sourceType", documentation.getSourceType());
|
||||||
" \"inlineContent\": \" " + documentation.getSourceType() + " \",\n" +
|
payload.put("inlineContent", documentation.getSourceType());
|
||||||
" \"visibility\": \" " + documentation.getVisibility() + " \",\n" +
|
payload.put("visibility", documentation.getVisibility());
|
||||||
" \"createdBy\": \" admin \"\n" +
|
payload.put("createdBy", documentation.getCreatedBy());
|
||||||
"}";
|
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, document);
|
RequestBody requestBody = RequestBody.create(JSON, payload.toString());
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addNewScope)
|
.url(addNewScope)
|
||||||
|
.addHeader(Constants.HEADER_CONTENT_TYPE, Constants.APPLICATION_JSON)
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
+ accessTokenInfo.getAccess_token())
|
+ accessTokenInfo.getAccess_token())
|
||||||
.post(requestBody)
|
.post(requestBody)
|
||||||
@ -1054,14 +1173,19 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
public boolean addDocumentationContent(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
APIInfo api, String docId, String docContent)
|
String apiUuid, String docId, String docContent)
|
||||||
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
throws APIServicesException, BadRequestException, UnexpectedResponseException {
|
||||||
|
|
||||||
String addDocumentationContentEndPoint = endPointPrefix + Constants.API_ENDPOINT + api.getId() + "/documents/" + docId;
|
String addDocumentationContentEndPoint = endPointPrefix + Constants.API_ENDPOINT + apiUuid + "/documents/" + docId + "/content";
|
||||||
|
|
||||||
|
RequestBody requestBody = new MultipartBody.Builder()
|
||||||
|
.setType(MultipartBody.FORM)
|
||||||
|
.addFormDataPart("inlineContent", docContent)
|
||||||
|
.build();
|
||||||
|
|
||||||
RequestBody requestBody = RequestBody.create(JSON, docContent);
|
|
||||||
Request request = new Request.Builder()
|
Request request = new Request.Builder()
|
||||||
.url(addDocumentationContentEndPoint)
|
.url(addDocumentationContentEndPoint)
|
||||||
|
.addHeader(Constants.HEADER_CONTENT_TYPE, "multipart/form-data")
|
||||||
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
.addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER
|
||||||
+ accessTokenInfo.getAccess_token())
|
+ accessTokenInfo.getAccess_token())
|
||||||
.post(requestBody)
|
.post(requestBody)
|
||||||
@ -1077,7 +1201,7 @@ public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices {
|
|||||||
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(),
|
||||||
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
//TODO: max attempt count
|
//TODO: max attempt count
|
||||||
return addDocumentationContent(apiApplicationKey, refreshedAccessToken, api, docId, docContent);
|
return addDocumentationContent(apiApplicationKey, refreshedAccessToken, apiUuid, docId, docContent);
|
||||||
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
} else if (HttpStatus.SC_BAD_REQUEST == response.code()) {
|
||||||
String msg = "Bad Request, Invalid documentation request body";
|
String msg = "Bad Request, Invalid documentation request body";
|
||||||
log.error(msg);
|
log.error(msg);
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
@ -19,13 +19,8 @@
|
|||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
import org.wso2.carbon.apimgt.api.model.APICategory;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.CORSConfiguration;
|
|
||||||
import org.wso2.carbon.apimgt.api.model.WebsubSubscriptionConfiguration;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Set;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This class represents the API response.
|
* This class represents the API response.
|
||||||
@ -40,65 +35,75 @@ public class APIInfo {
|
|||||||
private String version;
|
private String version;
|
||||||
private String provider;
|
private String provider;
|
||||||
private String lifeCycleStatus;
|
private String lifeCycleStatus;
|
||||||
private String wsdlInfo;
|
private type wsdlInfo;
|
||||||
private String wsdlUrl;
|
private String wsdlUrl;
|
||||||
private boolean responseCachingEnabled;
|
private boolean responseCachingEnabled;
|
||||||
private int cacheTimeout;
|
private int cacheTimeout;
|
||||||
private boolean hasThumbnail;
|
private boolean hasThumbnail;
|
||||||
private boolean isDefaultVersion;
|
private boolean isDefaultVersion;
|
||||||
private boolean isRevision;
|
private boolean isRevision;
|
||||||
private String revisionedApiId;
|
private String revisionedApiId;
|
||||||
private int revisionId;
|
private int revisionId;
|
||||||
private boolean enableSchemaValidation;
|
private boolean enableSchemaValidation;
|
||||||
|
private boolean enableStore;
|
||||||
private String type;
|
private String type;
|
||||||
private Set<String> transport;
|
private List<String> transport;
|
||||||
private Set<String> tags;
|
private List<String> tags;
|
||||||
private Set<String> policies;
|
private List<String> policies;
|
||||||
private String apiThrottlingPolicy;
|
private String apiThrottlingPolicy;
|
||||||
private String authorizationHeader;
|
private String authorizationHeader;
|
||||||
private String securityScheme;
|
private List<String> securityScheme;
|
||||||
private String maxTps;
|
private APIMaxTps maxTps;
|
||||||
private String visibility;
|
private String visibility;
|
||||||
private String visibleRoles;
|
private List<String> visibleRoles;
|
||||||
private String visibleTenants;
|
private List<String> visibleTenants;
|
||||||
private String mediationPolicies;
|
private List<MediationPolicy> mediationPolicies;
|
||||||
private String subscriptionAvailability;
|
private String subscriptionAvailability;
|
||||||
private String subscriptionAvailableTenants;
|
private List<String> subscriptionAvailableTenants;
|
||||||
private String additionalProperties;
|
private List<AdditionalProperties> additionalProperties;
|
||||||
private String monetization;
|
private Monetization monetization;
|
||||||
private String accessControl;
|
private String accessControl;
|
||||||
private String accessControlRoles;
|
private List<String> accessControlRoles;
|
||||||
private BusinessInformation businessInformation;
|
private BusinessInformation businessInformation;
|
||||||
private CORSConfiguration corsConfiguration;
|
private CORSConfiguration corsConfiguration;
|
||||||
private WebsubSubscriptionConfiguration websubSubscriptionConfiguration;
|
private WebsubSubscriptionConfiguration websubSubscriptionConfiguration;
|
||||||
private String workflowStatus;
|
private String workflowStatus;
|
||||||
private String createdTime;
|
private String createdTime;
|
||||||
private String lastUpdatedTime;
|
private String lastUpdatedTime;
|
||||||
private JSONObject endpointConfig = new JSONObject();
|
private JSONObject endpointConfig;
|
||||||
private String endpointImplementationType;
|
private String endpointImplementationType;
|
||||||
private List<JSONObject> scopes = new ArrayList();
|
private List<JSONObject> scopes;
|
||||||
private List<JSONObject> operations;
|
private List<Operations> operations;
|
||||||
private String threatProtectionPolicies;
|
private JSONObject threatProtectionPolicies;
|
||||||
private List<APICategory> apiCategories;
|
private List<String> categories;
|
||||||
private List<String> keyManagers = new ArrayList();
|
private List<String> keyManagers;
|
||||||
private JSONObject serviceInfo = new JSONObject();
|
private ServiceInfo serviceInfo;
|
||||||
private AdvertiseInfo advertiseInfo;
|
private AdvertiseInfo advertiseInfo;
|
||||||
|
|
||||||
|
public enum type {
|
||||||
|
WSDL, ZIP
|
||||||
|
}
|
||||||
|
|
||||||
public String getId() {
|
public String getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setId(String id) {
|
public void setId(String id) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setName(String name) {
|
public void setName(String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public String getDescription() {
|
||||||
return description;
|
return description;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setDescription(String description) {
|
||||||
this.description = description;
|
this.description = description;
|
||||||
}
|
}
|
||||||
@ -110,12 +115,15 @@ public class APIInfo {
|
|||||||
public void setContext(String context) {
|
public void setContext(String context) {
|
||||||
this.context = context;
|
this.context = context;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVersion() {
|
public String getVersion() {
|
||||||
return version;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVersion(String version) {
|
public void setVersion(String version) {
|
||||||
this.version = version;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProvider() {
|
public String getProvider() {
|
||||||
return provider;
|
return provider;
|
||||||
}
|
}
|
||||||
@ -132,11 +140,11 @@ public class APIInfo {
|
|||||||
this.lifeCycleStatus = lifeCycleStatus;
|
this.lifeCycleStatus = lifeCycleStatus;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getWsdlInfo() {
|
public APIInfo.type getWsdlInfo() {
|
||||||
return wsdlInfo;
|
return wsdlInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setWsdlInfo(String wsdlInfo) {
|
public void setWsdlInfo(APIInfo.type wsdlInfo) {
|
||||||
this.wsdlInfo = wsdlInfo;
|
this.wsdlInfo = wsdlInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -212,6 +220,14 @@ public class APIInfo {
|
|||||||
this.enableSchemaValidation = enableSchemaValidation;
|
this.enableSchemaValidation = enableSchemaValidation;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isEnableStore() {
|
||||||
|
return enableStore;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnableStore(boolean enableStore) {
|
||||||
|
this.enableStore = enableStore;
|
||||||
|
}
|
||||||
|
|
||||||
public String getType() {
|
public String getType() {
|
||||||
return type;
|
return type;
|
||||||
}
|
}
|
||||||
@ -220,27 +236,27 @@ public class APIInfo {
|
|||||||
this.type = type;
|
this.type = type;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getTransport() {
|
public List<String> getTransport() {
|
||||||
return transport;
|
return transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTransport(Set<String> transport) {
|
public void setTransport(List<String> transport) {
|
||||||
this.transport = transport;
|
this.transport = transport;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getTags() {
|
public List<String> getTags() {
|
||||||
return tags;
|
return tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setTags(Set<String> tags) {
|
public void setTags(List<String> tags) {
|
||||||
this.tags = tags;
|
this.tags = tags;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getPolicies() {
|
public List<String> getPolicies() {
|
||||||
return policies;
|
return policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setPolicies(Set<String> policies) {
|
public void setPolicies(List<String> policies) {
|
||||||
this.policies = policies;
|
this.policies = policies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -260,19 +276,19 @@ public class APIInfo {
|
|||||||
this.authorizationHeader = authorizationHeader;
|
this.authorizationHeader = authorizationHeader;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSecurityScheme() {
|
public List<String> getSecurityScheme() {
|
||||||
return securityScheme;
|
return securityScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSecurityScheme(String securityScheme) {
|
public void setSecurityScheme(List<String> securityScheme) {
|
||||||
this.securityScheme = securityScheme;
|
this.securityScheme = securityScheme;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMaxTps() {
|
public APIMaxTps getMaxTps() {
|
||||||
return maxTps;
|
return maxTps;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMaxTps(String maxTps) {
|
public void setMaxTps(APIMaxTps maxTps) {
|
||||||
this.maxTps = maxTps;
|
this.maxTps = maxTps;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -284,27 +300,27 @@ public class APIInfo {
|
|||||||
this.visibility = visibility;
|
this.visibility = visibility;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVisibleRoles() {
|
public List<String> getVisibleRoles() {
|
||||||
return visibleRoles;
|
return visibleRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibleRoles(String visibleRoles) {
|
public void setVisibleRoles(List<String> visibleRoles) {
|
||||||
this.visibleRoles = visibleRoles;
|
this.visibleRoles = visibleRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getVisibleTenants() {
|
public List<String> getVisibleTenants() {
|
||||||
return visibleTenants;
|
return visibleTenants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setVisibleTenants(String visibleTenants) {
|
public void setVisibleTenants(List<String> visibleTenants) {
|
||||||
this.visibleTenants = visibleTenants;
|
this.visibleTenants = visibleTenants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMediationPolicies() {
|
public List<MediationPolicy> getMediationPolicies() {
|
||||||
return mediationPolicies;
|
return mediationPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMediationPolicies(String mediationPolicies) {
|
public void setMediationPolicies(List<MediationPolicy> mediationPolicies) {
|
||||||
this.mediationPolicies = mediationPolicies;
|
this.mediationPolicies = mediationPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -316,27 +332,27 @@ public class APIInfo {
|
|||||||
this.subscriptionAvailability = subscriptionAvailability;
|
this.subscriptionAvailability = subscriptionAvailability;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getSubscriptionAvailableTenants() {
|
public List<String> getSubscriptionAvailableTenants() {
|
||||||
return subscriptionAvailableTenants;
|
return subscriptionAvailableTenants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setSubscriptionAvailableTenants(String subscriptionAvailableTenants) {
|
public void setSubscriptionAvailableTenants(List<String> subscriptionAvailableTenants) {
|
||||||
this.subscriptionAvailableTenants = subscriptionAvailableTenants;
|
this.subscriptionAvailableTenants = subscriptionAvailableTenants;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAdditionalProperties() {
|
public List<AdditionalProperties> getAdditionalProperties() {
|
||||||
return additionalProperties;
|
return additionalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAdditionalProperties(String additionalProperties) {
|
public void setAdditionalProperties(List<AdditionalProperties> additionalProperties) {
|
||||||
this.additionalProperties = additionalProperties;
|
this.additionalProperties = additionalProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getMonetization() {
|
public Monetization getMonetization() {
|
||||||
return monetization;
|
return monetization;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setMonetization(String monetization) {
|
public void setMonetization(Monetization monetization) {
|
||||||
this.monetization = monetization;
|
this.monetization = monetization;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,11 +364,11 @@ public class APIInfo {
|
|||||||
this.accessControl = accessControl;
|
this.accessControl = accessControl;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getAccessControlRoles() {
|
public List<String> getAccessControlRoles() {
|
||||||
return accessControlRoles;
|
return accessControlRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setAccessControlRoles(String accessControlRoles) {
|
public void setAccessControlRoles(List<String> accessControlRoles) {
|
||||||
this.accessControlRoles = accessControlRoles;
|
this.accessControlRoles = accessControlRoles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -420,7 +436,7 @@ public class APIInfo {
|
|||||||
this.endpointImplementationType = endpointImplementationType;
|
this.endpointImplementationType = endpointImplementationType;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JSONObject>getScopes() {
|
public List<JSONObject> getScopes() {
|
||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -428,28 +444,28 @@ public class APIInfo {
|
|||||||
this.scopes = scopes;
|
this.scopes = scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<JSONObject> getOperations() {
|
public List<Operations> getOperations() {
|
||||||
return operations;
|
return operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setOperations(List<JSONObject> operations) {
|
public void setOperations(List<Operations> operations) {
|
||||||
this.operations = operations;
|
this.operations = operations;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getThreatProtectionPolicies() {
|
public JSONObject getThreatProtectionPolicies() {
|
||||||
return threatProtectionPolicies;
|
return threatProtectionPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setThreatProtectionPolicies(String threatProtectionPolicies) {
|
public void setThreatProtectionPolicies(JSONObject threatProtectionPolicies) {
|
||||||
this.threatProtectionPolicies = threatProtectionPolicies;
|
this.threatProtectionPolicies = threatProtectionPolicies;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<APICategory> getApiCategories() {
|
public List<String> getCategories() {
|
||||||
return apiCategories;
|
return categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApiCategories(List<APICategory> apiCategories) {
|
public void setCategories(List<String> categories) {
|
||||||
this.apiCategories = apiCategories;
|
this.categories = categories;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<String> getKeyManagers() {
|
public List<String> getKeyManagers() {
|
||||||
@ -460,11 +476,11 @@ public class APIInfo {
|
|||||||
this.keyManagers = keyManagers;
|
this.keyManagers = keyManagers;
|
||||||
}
|
}
|
||||||
|
|
||||||
public JSONObject getServiceInfo() {
|
public ServiceInfo getServiceInfo() {
|
||||||
return serviceInfo;
|
return serviceInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setServiceInfo(JSONObject serviceInfo) {
|
public void setServiceInfo(ServiceInfo serviceInfo) {
|
||||||
this.serviceInfo = serviceInfo;
|
this.serviceInfo = serviceInfo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -15,42 +15,30 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
#rangeSliderWrapper {
|
import java.io.Serializable;
|
||||||
margin-top: 25px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#chart {
|
public class APIMaxTps implements Serializable {
|
||||||
display: inline-block;
|
|
||||||
}
|
|
||||||
|
|
||||||
#legend {
|
private static final long serialVersionUID = 1L;
|
||||||
display: inline-block;
|
|
||||||
position: relative;
|
|
||||||
left: 8px;
|
|
||||||
}
|
|
||||||
|
|
||||||
#legend_container {
|
int production;
|
||||||
position: absolute;
|
int sandbox;
|
||||||
right: 0;
|
|
||||||
bottom: 26px;
|
|
||||||
width: 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
#chart_container {
|
public int getProduction() {
|
||||||
float: left;
|
return production;
|
||||||
position: relative;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
.ast-container {
|
public void setProduction(int production) {
|
||||||
padding-bottom: 30px;
|
this.production = production;
|
||||||
}
|
}
|
||||||
|
|
||||||
.container {
|
public int getSandbox() {
|
||||||
width: auto;
|
return sandbox;
|
||||||
}
|
}
|
||||||
|
|
||||||
.shrink {
|
public void setSandbox(int sandbox) {
|
||||||
margin-right: 20px;
|
this.sandbox = sandbox;
|
||||||
margin-left: 20px;
|
}
|
||||||
}
|
}
|
||||||
@ -0,0 +1,107 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class APIRevision implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String id;
|
||||||
|
private String apiUUID;
|
||||||
|
private String revisionUUID;
|
||||||
|
private String description;
|
||||||
|
private String displayName;
|
||||||
|
private String createdBy;
|
||||||
|
private String createdTime;
|
||||||
|
private APIInfo apiInfo;
|
||||||
|
private List<APIRevisionDeployment> deploymentInfo;
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApiUUID() {
|
||||||
|
return apiUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiUUID(String apiUUID) {
|
||||||
|
this.apiUUID = apiUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRevisionUUID() {
|
||||||
|
return revisionUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRevisionUUID(String revisionUUID) {
|
||||||
|
this.revisionUUID = revisionUUID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(String createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(String createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<APIRevisionDeployment> getDeploymentInfo() {
|
||||||
|
return deploymentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeploymentInfo(List<APIRevisionDeployment> deploymentInfo) {
|
||||||
|
this.deploymentInfo = deploymentInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIInfo getApiInfo() {
|
||||||
|
return apiInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApiInfo(APIInfo apiInfo) {
|
||||||
|
this.apiInfo = apiInfo;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,79 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
public class APIRevisionDeployment implements Serializable {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private int id;
|
||||||
|
private String revisionUuid;
|
||||||
|
private String name;
|
||||||
|
private String vhost;
|
||||||
|
private boolean displayOnDevportal;
|
||||||
|
private String deployedTime;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRevisionUuid() {
|
||||||
|
return revisionUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRevisionUuid(String revisionUuid) {
|
||||||
|
this.revisionUuid = revisionUuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVhost() {
|
||||||
|
return vhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVhost(String vhost) {
|
||||||
|
this.vhost = vhost;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisplayOnDevportal() {
|
||||||
|
return displayOnDevportal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayOnDevportal(boolean displayOnDevportal) {
|
||||||
|
this.displayOnDevportal = displayOnDevportal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeployedTime() {
|
||||||
|
return deployedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeployedTime(String deployedTime) {
|
||||||
|
this.deployedTime = deployedTime;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,19 +16,35 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function onRequest(context) {
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
|
||||||
var mdmProps = require("/app/modules/conf-reader/main.js")["conf"];
|
|
||||||
var viewModel = {};
|
|
||||||
|
|
||||||
|
public class AdditionalProperties {
|
||||||
|
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/certificates/manage")) {
|
private String name;
|
||||||
viewModel["removePermitted"] = true;
|
private String value;
|
||||||
}
|
private boolean display;
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/certificates/view")) {
|
|
||||||
viewModel["viewPermitted"] = true;
|
public String getName() {
|
||||||
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.adminUser = mdmProps.adminUser;
|
public void setName(String name) {
|
||||||
return viewModel;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getValue() {
|
||||||
|
return value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setValue(String value) {
|
||||||
|
this.value = value;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isDisplay() {
|
||||||
|
return display;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplay(boolean display) {
|
||||||
|
this.display = display;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
@ -15,7 +15,6 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
|
|||||||
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* API CORS Configuration
|
||||||
|
*/
|
||||||
|
public class CORSConfiguration {
|
||||||
|
|
||||||
|
private boolean corsConfigurationEnabled;
|
||||||
|
private List<String> accessControlAllowOrigins;
|
||||||
|
private boolean accessControlAllowCredentials;
|
||||||
|
private List<String> accessControlAllowHeaders;
|
||||||
|
private List<String> accessControlAllowMethods;
|
||||||
|
|
||||||
|
public CORSConfiguration(boolean corsConfigurationEnabled, List<String> accessControlAllowOrigins,
|
||||||
|
boolean accessControlAllowCredentials,
|
||||||
|
List<String> accessControlAllowHeaders, List<String> accessControlAllowMethods) {
|
||||||
|
this.corsConfigurationEnabled = corsConfigurationEnabled;
|
||||||
|
this.accessControlAllowOrigins = accessControlAllowOrigins;
|
||||||
|
this.accessControlAllowCredentials = accessControlAllowCredentials;
|
||||||
|
this.accessControlAllowHeaders = accessControlAllowHeaders;
|
||||||
|
this.accessControlAllowMethods = accessControlAllowMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCorsConfigurationEnabled() {
|
||||||
|
return corsConfigurationEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCorsConfigurationEnabled(boolean corsConfigurationEnabled) {
|
||||||
|
this.corsConfigurationEnabled = corsConfigurationEnabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAccessControlAllowOrigins() {
|
||||||
|
return accessControlAllowOrigins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessControlAllowOrigins(List<String> accessControlAllowOrigins) {
|
||||||
|
this.accessControlAllowOrigins = accessControlAllowOrigins;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isAccessControlAllowCredentials() {
|
||||||
|
return accessControlAllowCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessControlAllowCredentials(boolean accessControlAllowCredentials) {
|
||||||
|
this.accessControlAllowCredentials = accessControlAllowCredentials;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAccessControlAllowHeaders() {
|
||||||
|
return accessControlAllowHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessControlAllowHeaders(List<String> accessControlAllowHeaders) {
|
||||||
|
this.accessControlAllowHeaders = accessControlAllowHeaders;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getAccessControlAllowMethods() {
|
||||||
|
return accessControlAllowMethods;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessControlAllowMethods(List<String> accessControlAllowMethods) {
|
||||||
|
this.accessControlAllowMethods = accessControlAllowMethods;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,237 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import java.util.Date;
|
||||||
|
|
||||||
|
public class Documentation {
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
private String id;
|
||||||
|
private String documentId;
|
||||||
|
private String name;
|
||||||
|
private DocumentationType type;
|
||||||
|
private String summary;
|
||||||
|
private DocumentSourceType sourceType;
|
||||||
|
private String sourceUrl;
|
||||||
|
private String fileName;
|
||||||
|
private String filePath;
|
||||||
|
private String inlineContent;
|
||||||
|
private String otherTypeName;
|
||||||
|
private DocumentVisibility visibility;
|
||||||
|
private String createdTime;
|
||||||
|
private Date createdDate;
|
||||||
|
private String createdBy;
|
||||||
|
private Date lastUpdatedTime;
|
||||||
|
private String lastUpdatedBy;
|
||||||
|
|
||||||
|
public String getOtherTypeName() {
|
||||||
|
return this.otherTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOtherTypeName(String otherTypeName) {
|
||||||
|
this.otherTypeName = otherTypeName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFilePath() {
|
||||||
|
return this.filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFilePath(String filePath) {
|
||||||
|
this.filePath = filePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSourceUrl() {
|
||||||
|
return this.sourceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceUrl(String sourceUrl) {
|
||||||
|
this.sourceUrl = sourceUrl;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Documentation(DocumentationType type, String name) {
|
||||||
|
this.type = type;
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
} else if (o != null && this.getClass() == o.getClass()) {
|
||||||
|
Documentation that = (Documentation)o;
|
||||||
|
return this.name.equals(that.name) && this.type == that.type;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentationType getType() {
|
||||||
|
return this.type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return this.name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSummary() {
|
||||||
|
return this.summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSummary(String summary) {
|
||||||
|
this.summary = summary;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentVisibility getVisibility() {
|
||||||
|
return this.visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVisibility(DocumentVisibility visibility) {
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
|
||||||
|
public DocumentSourceType getSourceType() {
|
||||||
|
return this.sourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSourceType(DocumentSourceType sourceType) {
|
||||||
|
this.sourceType = sourceType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int hashCode() {
|
||||||
|
int result = this.type.hashCode();
|
||||||
|
result = 31 * result + this.name.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getLastUpdatedTime() {
|
||||||
|
return this.lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(Date lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return this.id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDocumentId() {
|
||||||
|
return documentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDocumentId(String documentId) {
|
||||||
|
this.documentId = documentId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Date getCreatedDate() {
|
||||||
|
return this.createdDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedDate(Date createdDate) {
|
||||||
|
this.createdDate = createdDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getFileName() {
|
||||||
|
return fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setFileName(String fileName) {
|
||||||
|
this.fileName = fileName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInlineContent() {
|
||||||
|
return inlineContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInlineContent(String inlineContent) {
|
||||||
|
this.inlineContent = inlineContent;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(String createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedBy() {
|
||||||
|
return createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedBy(String createdBy) {
|
||||||
|
this.createdBy = createdBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastUpdatedBy() {
|
||||||
|
return lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedBy(String lastUpdatedBy) {
|
||||||
|
this.lastUpdatedBy = lastUpdatedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum DocumentVisibility {
|
||||||
|
OWNER_ONLY("owner_only"),
|
||||||
|
PRIVATE("private"),
|
||||||
|
API_LEVEL("api_level");
|
||||||
|
|
||||||
|
private String visibility;
|
||||||
|
|
||||||
|
private DocumentVisibility(String visibility) {
|
||||||
|
this.visibility = visibility;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum DocumentSourceType {
|
||||||
|
INLINE("In line"),
|
||||||
|
MARKDOWN("Markdown"),
|
||||||
|
URL("URL"),
|
||||||
|
FILE("File");
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private DocumentSourceType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static enum DocumentationType {
|
||||||
|
HOWTO("How To"),
|
||||||
|
SAMPLES("Samples"),
|
||||||
|
PUBLIC_FORUM("Public Forum"),
|
||||||
|
SUPPORT_FORUM("Support Forum"),
|
||||||
|
API_MESSAGE_FORMAT("API Message Format"),
|
||||||
|
SWAGGER_DOC("Swagger API Definition"),
|
||||||
|
OTHER("Other");
|
||||||
|
|
||||||
|
private String type;
|
||||||
|
|
||||||
|
private DocumentationType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,54 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
public class Mediation {
|
||||||
|
|
||||||
|
private String uuid;
|
||||||
|
private String name;
|
||||||
|
private String type;
|
||||||
|
private String config;
|
||||||
|
private boolean isGlobal;
|
||||||
|
|
||||||
|
public Mediation(){}
|
||||||
|
|
||||||
|
public void setUuid(String id){
|
||||||
|
this.uuid=id;
|
||||||
|
}
|
||||||
|
public String getUuid(){return uuid;}
|
||||||
|
|
||||||
|
public void setName(String name){this.name=name;}
|
||||||
|
|
||||||
|
public String getName(){return name;}
|
||||||
|
|
||||||
|
public void setType(String mType){this.type=mType;}
|
||||||
|
|
||||||
|
public String getType(){return type;}
|
||||||
|
|
||||||
|
public void setConfig(String mConfig){this.config=mConfig;}
|
||||||
|
|
||||||
|
public String getConfig(){return config;}
|
||||||
|
|
||||||
|
public boolean isGlobal() {
|
||||||
|
return isGlobal;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGlobal(boolean isGlobal) {
|
||||||
|
this.isGlobal = isGlobal;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,16 +16,44 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
// This file is autogenerated via the `commonjs` Grunt task. You can require() this file in a CommonJS environment.
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
require('../../js/transition.js')
|
|
||||||
require('../../js/alert.js')
|
public class MediationPolicy {
|
||||||
require('../../js/button.js')
|
|
||||||
require('../../js/carousel.js')
|
private String id;
|
||||||
require('../../js/collapse.js')
|
private String name;
|
||||||
require('../../js/dropdown.js')
|
private String type;
|
||||||
require('../../js/modal.js')
|
private boolean shared;
|
||||||
require('../../js/tooltip.js')
|
|
||||||
require('../../js/popover.js')
|
public String getId() {
|
||||||
require('../../js/scrollspy.js')
|
return id;
|
||||||
require('../../js/tab.js')
|
}
|
||||||
require('../../js/affix.js')
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getType() {
|
||||||
|
return type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setType(String type) {
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isShared() {
|
||||||
|
return shared;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShared(boolean shared) {
|
||||||
|
this.shared = shared;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,15 +16,27 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function onRequest(context) {
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
var userModule = require("/app/modules/business-controllers/user.js")["userModule"];
|
|
||||||
var utility = require("/app/modules/utility.js")["utility"];
|
|
||||||
var deviceType = request.getParameter("type");
|
|
||||||
|
|
||||||
var canEdit = false;
|
import org.json.JSONObject;
|
||||||
if(userModule.isAuthorized("/permission/admin/device-mgt/policy/manage")) {
|
|
||||||
canEdit = true;
|
public class Monetization {
|
||||||
|
private boolean enabled;
|
||||||
|
private JSONObject properties;
|
||||||
|
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return enabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
return {"deviceTypePolicyView": utility.getTenantedDeviceUnitName(deviceType, "policy-view"), "canEdit": canEdit};
|
public void setEnabled(boolean enabled) {
|
||||||
|
this.enabled = enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
public JSONObject getProperties() {
|
||||||
|
return properties;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProperties(JSONObject properties) {
|
||||||
|
this.properties = properties;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@ -1,12 +1,12 @@
|
|||||||
/*
|
/*
|
||||||
* Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
*
|
*
|
||||||
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
* Version 2.0 (the "License"); you may not use this file except
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
* in compliance with the License.
|
* in compliance with the License.
|
||||||
* You may obtain a copy of the License at
|
* You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
@ -18,7 +18,8 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
import java.util.Set;
|
import org.json.JSONObject;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This hold the api operations information.
|
* This hold the api operations information.
|
||||||
@ -29,8 +30,8 @@ public class Operations {
|
|||||||
private String verb;
|
private String verb;
|
||||||
private String authType;
|
private String authType;
|
||||||
private String throttlingPolicy;
|
private String throttlingPolicy;
|
||||||
private Set<String> scopes;
|
private List<String> scopes;
|
||||||
private String usedProductIds;
|
private List<String> usedProductIds;
|
||||||
private String amznResourceName;
|
private String amznResourceName;
|
||||||
private String amznResourceTimeout;
|
private String amznResourceTimeout;
|
||||||
private String payloadSchema;
|
private String payloadSchema;
|
||||||
@ -78,19 +79,19 @@ public class Operations {
|
|||||||
this.throttlingPolicy = throttlingPolicy;
|
this.throttlingPolicy = throttlingPolicy;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Set<String> getScopes() {
|
public List<String> getScopes() {
|
||||||
return scopes;
|
return scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setScopes(Set<String> scopes) {
|
public void setScopes(List<String> scopes) {
|
||||||
this.scopes = scopes;
|
this.scopes = scopes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUsedProductIds() {
|
public List<String> getUsedProductIds() {
|
||||||
return usedProductIds;
|
return usedProductIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setUsedProductIds(String usedProductIds) {
|
public void setUsedProductIds(List<String> usedProductIds) {
|
||||||
this.usedProductIds = usedProductIds;
|
this.usedProductIds = usedProductIds;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,112 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Objects;
|
||||||
|
import java.util.Set;
|
||||||
|
import java.util.HashSet;
|
||||||
|
|
||||||
|
public class Scope implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
String id;
|
||||||
|
String name;
|
||||||
|
String displayName;
|
||||||
|
String description;
|
||||||
|
List<String> bindings;
|
||||||
|
int usageCount;
|
||||||
|
|
||||||
|
public String getDisplayName() {
|
||||||
|
return displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDisplayName(String displayName) {
|
||||||
|
this.displayName = displayName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getName() {
|
||||||
|
return name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setName(String name) {
|
||||||
|
this.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getBindings() {
|
||||||
|
return bindings;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setBindings(List<String> bindings) {
|
||||||
|
this.bindings = removeDuplicatesFromRoleString(bindings);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(String id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getUsageCount() {
|
||||||
|
return usageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUsageCount(int usageCount) {
|
||||||
|
this.usageCount = usageCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) return true;
|
||||||
|
if (o == null || getClass() != o.getClass()) return false;
|
||||||
|
|
||||||
|
Scope scope = (Scope) o;
|
||||||
|
|
||||||
|
if (id != null ? !id.equals(scope.id) : scope.id != null) return false;
|
||||||
|
if (!name.equals(scope.name)) return false;
|
||||||
|
if (!displayName.equals(scope.displayName)) return false;
|
||||||
|
if (bindings != null ? !bindings.equals(scope.bindings) : scope.bindings != null) return false;
|
||||||
|
return description != null ? description.equals(scope.description) : scope.description == null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
return Objects.hash(name, displayName, bindings, description, id);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> removeDuplicatesFromRoleString(List<String> roles) {
|
||||||
|
Set<String> roleSet = new HashSet<>();
|
||||||
|
for(String role : roles) {
|
||||||
|
roleSet.add(role.trim());
|
||||||
|
}
|
||||||
|
return new ArrayList<>(roleSet);
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,21 +16,14 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package io.entgra.device.mgt.core.apimgt.extension.rest.api.util;
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
/**
|
public class ServiceInfo {
|
||||||
* This class represents the scope data.
|
|
||||||
*/
|
|
||||||
public class ScopeUtils {
|
|
||||||
|
|
||||||
private String key;
|
private String key;
|
||||||
private String name;
|
private String name;
|
||||||
private String roles;
|
private String version;
|
||||||
private String description;
|
private boolean outdated;
|
||||||
private int id;
|
|
||||||
|
|
||||||
public ScopeUtils() {
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
return key;
|
return key;
|
||||||
@ -48,31 +41,19 @@ public class ScopeUtils {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoles() {
|
public String getVersion() {
|
||||||
return roles;
|
return version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoles(String roles) {
|
public void setVersion(String version) {
|
||||||
this.roles = roles;
|
this.version = version;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getDescription() {
|
public boolean isOutdated() {
|
||||||
return description;
|
return outdated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setDescription(String description) {
|
public void setOutdated(boolean outdated) {
|
||||||
this.description = description;
|
this.outdated = outdated;
|
||||||
}
|
|
||||||
|
|
||||||
public String toJSON() {
|
|
||||||
String jsonString = "{\n" +
|
|
||||||
" \"name\":\"" + key + "\",\n" +
|
|
||||||
" \"displayName\":\"" + name + "\",\n" +
|
|
||||||
" \"description\":\"" + description + "\",\n" +
|
|
||||||
" \"bindings\":[\n" +
|
|
||||||
" \"" + roles + "\"\n" +
|
|
||||||
" ]\n" +
|
|
||||||
"}";
|
|
||||||
return jsonString;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -16,17 +16,26 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function onRequest(context) {
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
var deviceTypes = context.unit.params.deviceTypes;
|
|
||||||
var deviceType = context.uriParams.deviceType;
|
|
||||||
|
|
||||||
var deviceTypesList = [];
|
public class ThreatProtectionPolicies {
|
||||||
if (deviceTypes) {
|
|
||||||
for (var i = 0; i < deviceTypes.length; i++) {
|
private String policyID;
|
||||||
deviceTypesList.push(deviceTypes[i].type);
|
private int priority;
|
||||||
}
|
|
||||||
} else if (deviceType) {
|
public String getPolicyID() {
|
||||||
deviceTypesList.push(deviceType);
|
return policyID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPolicyID(String policyID) {
|
||||||
|
this.policyID = policyID;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getPriority() {
|
||||||
|
return priority;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPriority(int priority) {
|
||||||
|
this.priority = priority;
|
||||||
}
|
}
|
||||||
return {"deviceTypes": stringify(deviceTypesList)};
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,440 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
import org.json.simple.JSONValue;
|
||||||
|
import org.wso2.carbon.apimgt.api.dto.ConditionGroupDTO;
|
||||||
|
import org.wso2.carbon.apimgt.api.model.APIProductIdentifier;
|
||||||
|
import org.wso2.carbon.apimgt.api.model.Scope;
|
||||||
|
import org.wso2.carbon.apimgt.api.model.policy.PolicyConstants;
|
||||||
|
|
||||||
|
import java.io.Serializable;
|
||||||
|
import java.util.*;
|
||||||
|
|
||||||
|
public class URITemplate implements Serializable{
|
||||||
|
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
private String uriTemplate;
|
||||||
|
private String resourceURI;
|
||||||
|
private String resourceSandboxURI;
|
||||||
|
private String httpVerb;
|
||||||
|
private String authType;
|
||||||
|
private LinkedHashSet<String> httpVerbs = new LinkedHashSet<String>();
|
||||||
|
private List<String> authTypes = new ArrayList<String>();
|
||||||
|
private List<String> throttlingConditions = new ArrayList<String>();
|
||||||
|
private String applicableLevel;
|
||||||
|
private String throttlingTier;
|
||||||
|
private List<String> throttlingTiers = new ArrayList<String>();
|
||||||
|
private org.wso2.carbon.apimgt.api.model.Scope scope;
|
||||||
|
private String mediationScript;
|
||||||
|
private List<org.wso2.carbon.apimgt.api.model.Scope> scopes = new ArrayList<org.wso2.carbon.apimgt.api.model.Scope>();
|
||||||
|
private Map<String, String> mediationScripts = new HashMap<String, String>();
|
||||||
|
private ConditionGroupDTO[] conditionGroups;
|
||||||
|
private int id;
|
||||||
|
private Set<APIProductIdentifier> usedByProducts = new HashSet<>();
|
||||||
|
private String amznResourceName;
|
||||||
|
private int amznResourceTimeout;
|
||||||
|
|
||||||
|
public ConditionGroupDTO[] getConditionGroups() {
|
||||||
|
return conditionGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConditionGroups(ConditionGroupDTO[] conditionGroups) {
|
||||||
|
this.conditionGroups = conditionGroups;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getMediationScript() {
|
||||||
|
return mediationScript;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public List<String> getThrottlingConditions() {
|
||||||
|
return throttlingConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrottlingConditions(List<String> throttlingConditions) {
|
||||||
|
this.throttlingConditions = throttlingConditions;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMediationScript(String mediationScript) {
|
||||||
|
this.mediationScript = mediationScript;
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* Set mediation script for a given http method
|
||||||
|
* @param method http method name
|
||||||
|
* @param mediationScript mediation script content
|
||||||
|
*/
|
||||||
|
public void setMediationScripts(String method, String mediationScript){
|
||||||
|
if (mediationScript != null && !mediationScript.trim().equals("") && !mediationScript.trim().equals("null")){
|
||||||
|
mediationScripts.put(method, mediationScript);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Generating the script by aggregating scripts of each http method to form a single script in to be
|
||||||
|
* used when generating synapse configuration file.
|
||||||
|
*
|
||||||
|
* @return aggregated script in the following format,
|
||||||
|
* if (http-method = 'GET'){
|
||||||
|
* //script for GET
|
||||||
|
* }
|
||||||
|
* ....
|
||||||
|
* ....
|
||||||
|
* if (http-method = 'POST'){
|
||||||
|
* //script for POST
|
||||||
|
* }
|
||||||
|
*/
|
||||||
|
public String getAggregatedMediationScript(){
|
||||||
|
if (mediationScripts.isEmpty()){
|
||||||
|
return "null";
|
||||||
|
}else if (mediationScripts.size() == 1 && httpVerbs.size() == 1){
|
||||||
|
return mediationScript;
|
||||||
|
}else{
|
||||||
|
StringBuilder aggregatedScript = new StringBuilder();
|
||||||
|
|
||||||
|
for (Map.Entry<String, String> entry : mediationScripts.entrySet()){
|
||||||
|
String httpMethod = entry.getKey();
|
||||||
|
String mediationScript = entry.getValue();
|
||||||
|
|
||||||
|
aggregatedScript.append("if (mc.getProperty('REST_METHOD') == '").append(httpMethod).append("'){");
|
||||||
|
aggregatedScript.append(mediationScript);
|
||||||
|
aggregatedScript.append("}");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return aggregatedScript.toString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThrottlingTier() {
|
||||||
|
return throttlingTier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrottlingTier(String throttlingTier) {
|
||||||
|
this.throttlingTier = throttlingTier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getThrottlingTiers(){
|
||||||
|
return throttlingTiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrottlingTiers(List<String> throttlingTiers) {
|
||||||
|
this.throttlingTiers = throttlingTiers;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getHTTPVerb() {
|
||||||
|
return httpVerb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHTTPVerb(String httpVerb) {
|
||||||
|
this.httpVerb = httpVerb;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthType() {
|
||||||
|
return authType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAuthType(String authType) {
|
||||||
|
this.authType = authType;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResourceURI() {
|
||||||
|
return resourceURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceURI(String resourceURI) {
|
||||||
|
this.resourceURI = resourceURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResourceURIExist(){
|
||||||
|
return this.resourceURI != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResourceSandboxURI() {
|
||||||
|
return resourceSandboxURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setResourceSandboxURI(String resourceSandboxURI) {
|
||||||
|
this.resourceSandboxURI = resourceSandboxURI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isResourceSandboxURIExist(){
|
||||||
|
return this.resourceSandboxURI != null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUriTemplate() {
|
||||||
|
return uriTemplate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUriTemplate(String template) {
|
||||||
|
this.uriTemplate = template;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHttpVerbs(String httpVerb) {
|
||||||
|
|
||||||
|
httpVerbs.add(httpVerb);
|
||||||
|
}
|
||||||
|
|
||||||
|
public LinkedHashSet<String> getHttpVerbs() {
|
||||||
|
|
||||||
|
return httpVerbs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
public void setAuthTypes(String authType) {
|
||||||
|
|
||||||
|
authTypes.add(authType);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthTypes() {
|
||||||
|
|
||||||
|
return authType;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getMethodsAsString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String method : httpVerbs) {
|
||||||
|
stringBuilder.append(method).append(" ");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAuthTypeAsString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String authType : authTypes) {
|
||||||
|
stringBuilder.append(authType).append(" ");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThrottlingConditionsAsString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String authType : throttlingConditions) {
|
||||||
|
stringBuilder.append(authType).append(" ");
|
||||||
|
}
|
||||||
|
return stringBuilder.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThrottlingTiers(String tier) {
|
||||||
|
throttlingTiers.add(tier);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThrottlingTiersAsString() {
|
||||||
|
StringBuilder stringBuilder = new StringBuilder();
|
||||||
|
for (String tier : throttlingTiers) {
|
||||||
|
if (tier.contains(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)) {
|
||||||
|
stringBuilder.append(tier.substring(0,
|
||||||
|
tier.indexOf(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)).trim()).append(" ");
|
||||||
|
} else {
|
||||||
|
stringBuilder.append(tier.trim()).append(" ");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return stringBuilder.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean checkContentAwareFromThrottlingTiers() {
|
||||||
|
// use the content aware property appended to throttling tiers
|
||||||
|
if (!throttlingTiers.isEmpty()) {
|
||||||
|
String throttlingTierWithContentAware = throttlingTiers.get(0);
|
||||||
|
if (throttlingTierWithContentAware != null &&
|
||||||
|
throttlingTierWithContentAware.contains(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR)) {
|
||||||
|
String[] splitThrottlingTiers =
|
||||||
|
throttlingTierWithContentAware.split(PolicyConstants.THROTTLING_TIER_CONTENT_AWARE_SEPERATOR);
|
||||||
|
return Boolean.valueOf(splitThrottlingTiers[splitThrottlingTiers.length - 1]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public org.wso2.carbon.apimgt.api.model.Scope getScope() {
|
||||||
|
return scope;
|
||||||
|
}
|
||||||
|
public List<org.wso2.carbon.apimgt.api.model.Scope> getScopes() {
|
||||||
|
return scopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScope(org.wso2.carbon.apimgt.api.model.Scope scope) {
|
||||||
|
this.scope = scope;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setScopes(org.wso2.carbon.apimgt.api.model.Scope scope){
|
||||||
|
this.scopes.add(scope);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getResourceMap(){
|
||||||
|
Map verbs = new LinkedHashMap();
|
||||||
|
int i = 0;
|
||||||
|
for (String method : httpVerbs) {
|
||||||
|
Map verb = new LinkedHashMap();
|
||||||
|
verb.put("auth_type",authTypes.get(i));
|
||||||
|
verb.put("throttling_tier",throttlingTiers.get(i));
|
||||||
|
//Following parameter is not required as it not need to reflect UI level. If need please enable it.
|
||||||
|
// /verb.put("throttling_conditions", throttlingConditions.get(i));
|
||||||
|
try{
|
||||||
|
org.wso2.carbon.apimgt.api.model.Scope tmpScope = scopes.get(i);
|
||||||
|
if(tmpScope != null){
|
||||||
|
verb.put("scope",tmpScope.getKey());
|
||||||
|
}
|
||||||
|
}catch(IndexOutOfBoundsException e){
|
||||||
|
//todo need to rewrite to prevent this type of exceptions
|
||||||
|
}
|
||||||
|
verbs.put(method,verb);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
//todo this is a hack to make key validation service stub from braking need to rewrite.
|
||||||
|
return JSONValue.toJSONString(verbs);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getApplicableLevel() {
|
||||||
|
return applicableLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setApplicableLevel(String applicableLevel) {
|
||||||
|
this.applicableLevel = applicableLevel;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals(Object o) {
|
||||||
|
if (this == o) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (o == null || getClass() != o.getClass()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
URITemplate that = (URITemplate) o;
|
||||||
|
|
||||||
|
if (!uriTemplate.equals(that.uriTemplate)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (resourceURI != null ? !resourceURI.equals(that.resourceURI) : that.resourceURI != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (resourceSandboxURI != null ? !resourceSandboxURI.equals(that.resourceSandboxURI) : that
|
||||||
|
.resourceSandboxURI != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!httpVerb.equals(that.httpVerb)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!authType.equals(that.authType)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!httpVerbs.equals(that.httpVerbs)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!authTypes.equals(that.authTypes)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (throttlingConditions != null ? !throttlingConditions.equals(that.throttlingConditions) : that
|
||||||
|
.throttlingConditions != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (applicableLevel != null ? !applicableLevel.equals(that.applicableLevel) : that.applicableLevel != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!throttlingTier.equals(that.throttlingTier)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!throttlingTiers.equals(that.throttlingTiers)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (scope != null ? !scope.equals(that.scope) : that.scope != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mediationScript != null ? !mediationScript.equals(that.mediationScript) : that.mediationScript != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (scopes != null ? !scopes.equals(that.scopes) : that.scopes != null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (mediationScripts != null ? !mediationScripts.equals(that.mediationScripts) : that.mediationScripts !=
|
||||||
|
null) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// Probably incorrect - comparing Object[] arrays with Arrays.equals
|
||||||
|
return Arrays.equals(conditionGroups, that.conditionGroups);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode() {
|
||||||
|
int result = uriTemplate.hashCode();
|
||||||
|
result = 31 * result + (resourceURI != null ? resourceURI.hashCode() : 0);
|
||||||
|
result = 31 * result + (resourceSandboxURI != null ? resourceSandboxURI.hashCode() : 0);
|
||||||
|
result = 31 * result + (httpVerb != null ? httpVerb.hashCode() : 0);
|
||||||
|
result = 31 * result + (authType != null ? authType.hashCode() : 0);
|
||||||
|
result = 31 * result + (httpVerbs != null ? httpVerbs.hashCode() : 0);
|
||||||
|
result = 31 * result + (authTypes != null ? authTypes.hashCode() : 0);
|
||||||
|
result = 31 * result + (throttlingConditions != null ? throttlingConditions.hashCode() : 0);
|
||||||
|
result = 31 * result + (applicableLevel != null ? applicableLevel.hashCode() : 0);
|
||||||
|
result = 31 * result + (throttlingTier != null ? throttlingTier.hashCode() : 0);
|
||||||
|
result = 31 * result + (throttlingTiers != null ? throttlingTiers.hashCode() : 0);
|
||||||
|
result = 31 * result + (scope != null ? scope.hashCode() : 0);
|
||||||
|
result = 31 * result + (mediationScript != null ? mediationScript.hashCode() : 0);
|
||||||
|
result = 31 * result + (scopes != null ? scopes.hashCode() : 0);
|
||||||
|
result = 31 * result + (mediationScripts != null ? mediationScripts.hashCode() : 0);
|
||||||
|
result = 31 * result + Arrays.hashCode(conditionGroups);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<org.wso2.carbon.apimgt.api.model.Scope> retrieveAllScopes() {
|
||||||
|
return this.scopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addAllScopes(List<Scope> scopes) {
|
||||||
|
|
||||||
|
this.scopes = scopes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Set<APIProductIdentifier> retrieveUsedByProducts() {
|
||||||
|
return usedByProducts;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addUsedByProduct(APIProductIdentifier usedByProduct) {
|
||||||
|
usedByProducts.add(usedByProduct);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmznResourceName(String amznResourceName) {
|
||||||
|
this.amznResourceName = amznResourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAmznResourceName() {
|
||||||
|
return amznResourceName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmznResourceTimeout(int amznResourceTimeout) {
|
||||||
|
this.amznResourceTimeout = amznResourceTimeout;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmznResourceTimeout() {
|
||||||
|
return amznResourceTimeout;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,61 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This hold the Websub Subscription Configuration of an API.
|
||||||
|
*/
|
||||||
|
public class WebsubSubscriptionConfiguration {
|
||||||
|
private boolean enable;
|
||||||
|
private String secret;
|
||||||
|
private String signingAlgorithm;
|
||||||
|
private String signatureHeader;
|
||||||
|
|
||||||
|
public boolean isEnable() {
|
||||||
|
return enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnable(boolean enable) {
|
||||||
|
this.enable = enable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSecret() {
|
||||||
|
return secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSecret(String secret) {
|
||||||
|
this.secret = secret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSigningAlgorithm() {
|
||||||
|
return signingAlgorithm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSigningAlgorithm(String signingAlgorithm) {
|
||||||
|
this.signingAlgorithm = signingAlgorithm;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getSignatureHeader() {
|
||||||
|
return signatureHeader;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSignatureHeader(String signatureHeader) {
|
||||||
|
this.signatureHeader = signatureHeader;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>apimgt-extensions</artifactId>
|
<artifactId>apimgt-extensions</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -133,6 +133,10 @@
|
|||||||
<groupId>org.json.wso2</groupId>
|
<groupId>org.json.wso2</groupId>
|
||||||
<artifactId>json</artifactId>
|
<artifactId>json</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
|
<artifactId>io.entgra.device.mgt.core.device.mgt.core</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
|
|
||||||
@ -173,6 +177,10 @@
|
|||||||
io.entgra.device.mgt.core.apimgt.webapp.publisher.config,
|
io.entgra.device.mgt.core.apimgt.webapp.publisher.config,
|
||||||
io.entgra.device.mgt.core.apimgt.webapp.publisher.dto,
|
io.entgra.device.mgt.core.apimgt.webapp.publisher.dto,
|
||||||
io.entgra.device.mgt.core.apimgt.webapp.publisher.exception,
|
io.entgra.device.mgt.core.apimgt.webapp.publisher.exception,
|
||||||
|
io.entgra.device.mgt.core.device.mgt.common.exceptions,
|
||||||
|
io.entgra.device.mgt.core.device.mgt.common.metadata.mgt,
|
||||||
|
io.entgra.device.mgt.core.device.mgt.core.config,
|
||||||
|
io.entgra.device.mgt.core.device.mgt.core.config.permission,
|
||||||
io.swagger.annotations;version="[1.6,2)",
|
io.swagger.annotations;version="[1.6,2)",
|
||||||
javax.servlet;version="[2.6,3)",
|
javax.servlet;version="[2.6,3)",
|
||||||
javax.xml.bind;version="[0.0,1)",
|
javax.xml.bind;version="[0.0,1)",
|
||||||
|
|||||||
@ -35,4 +35,22 @@ public interface APIPublisherService {
|
|||||||
void publishAPI(APIConfig api) throws APIManagerPublisherException;
|
void publishAPI(APIConfig api) throws APIManagerPublisherException;
|
||||||
|
|
||||||
void updateScopeRoleMapping() throws APIManagerPublisherException;
|
void updateScopeRoleMapping() throws APIManagerPublisherException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Add default scopes defined in the cdm-config.xml
|
||||||
|
*/
|
||||||
|
void addDefaultScopesIfNotExist();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the permissions are in the permission list, identify the relevant scopes of the supplied permission list
|
||||||
|
* and put the role there; if the permissions are in the removedPermission list, update the relevant scopes by
|
||||||
|
* deleting the role from those scopes.
|
||||||
|
*
|
||||||
|
* @param roleName Role Name
|
||||||
|
* @param permissions List of adding permissions
|
||||||
|
* @param removedPermissions List of removing permissions
|
||||||
|
* @throws APIManagerPublisherException If error occurred while updating the scope role mapping
|
||||||
|
*/
|
||||||
|
void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,13 +17,15 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.annotations.Scopes;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServices;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.APIInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIInfo.*;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException;
|
||||||
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException;
|
||||||
@ -32,19 +34,29 @@ import io.entgra.device.mgt.core.apimgt.webapp.publisher.config.WebappPublisherC
|
|||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiScope;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiScope;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiUriTemplate;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiUriTemplate;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.exception.APIManagerPublisherException;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.internal.APIPublisherDataHolder;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceManagementConfig;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermission;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermissions;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.permission.ScopeMapping;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONArray;
|
import org.json.JSONArray;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
import org.wso2.carbon.CarbonConstants;
|
||||||
import org.wso2.carbon.apimgt.api.APIManagementException;
|
import org.wso2.carbon.apimgt.api.APIManagementException;
|
||||||
import org.wso2.carbon.apimgt.api.APIProvider;
|
import org.wso2.carbon.apimgt.api.APIProvider;
|
||||||
import org.wso2.carbon.apimgt.api.model.*;
|
import org.wso2.carbon.apimgt.api.model.APIIdentifier;
|
||||||
import org.wso2.carbon.apimgt.impl.APIConstants;
|
import org.wso2.carbon.apimgt.impl.APIConstants;
|
||||||
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
import org.wso2.carbon.apimgt.impl.APIManagerFactory;
|
||||||
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
|
import org.wso2.carbon.apimgt.impl.utils.APIUtil;
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
import org.wso2.carbon.user.api.AuthorizationManager;
|
||||||
|
import org.wso2.carbon.user.api.Permission;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
import org.wso2.carbon.user.core.tenant.Tenant;
|
import org.wso2.carbon.user.core.tenant.Tenant;
|
||||||
import org.wso2.carbon.user.core.tenant.TenantSearchResult;
|
import org.wso2.carbon.user.core.tenant.TenantSearchResult;
|
||||||
@ -66,6 +78,7 @@ import java.util.*;
|
|||||||
*/
|
*/
|
||||||
public class APIPublisherServiceImpl implements APIPublisherService {
|
public class APIPublisherServiceImpl implements APIPublisherService {
|
||||||
public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance();
|
public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance();
|
||||||
|
private static final Gson gson = new Gson();
|
||||||
private static final String UNLIMITED_TIER = "Unlimited";
|
private static final String UNLIMITED_TIER = "Unlimited";
|
||||||
private static final String WS_UNLIMITED_TIER = "AsyncUnlimited";
|
private static final String WS_UNLIMITED_TIER = "AsyncUnlimited";
|
||||||
private static final String API_PUBLISH_ENVIRONMENT = "Default";
|
private static final String API_PUBLISH_ENVIRONMENT = "Default";
|
||||||
@ -75,6 +88,7 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
public static final String SUBSCRIPTION_TO_CURRENT_TENANT = "CURRENT_TENANT";
|
public static final String SUBSCRIPTION_TO_CURRENT_TENANT = "CURRENT_TENANT";
|
||||||
public static final String API_GLOBAL_VISIBILITY = "PUBLIC";
|
public static final String API_GLOBAL_VISIBILITY = "PUBLIC";
|
||||||
public static final String API_PRIVATE_VISIBILITY = "PRIVATE";
|
public static final String API_PRIVATE_VISIBILITY = "PRIVATE";
|
||||||
|
private static final String ADMIN_ROLE_KEY = "admin";
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class);
|
private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class);
|
||||||
|
|
||||||
@ -140,37 +154,41 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
apiConfig.getName(), apiConfig.getVersion());
|
apiConfig.getName(), apiConfig.getVersion());
|
||||||
|
|
||||||
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
||||||
JSONArray apiList = (JSONArray) publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo).get("list");
|
APIInfo[] apiList = publisherRESTAPIServices.getApis(apiApplicationKey, accessTokenInfo);
|
||||||
boolean apiFound = false;
|
boolean apiFound = false;
|
||||||
for (int i = 0; i < apiList.length(); i++) {
|
for (int i = 0; i < apiList.length; i++) {
|
||||||
JSONObject apiObj = apiList.getJSONObject(i);
|
APIInfo apiObj = apiList[i];
|
||||||
if (apiObj.getString("name").equals(apiIdentifier.getApiName().replace(Constants.SPACE,
|
if (apiObj.getName().equals(apiIdentifier.getApiName().replace(Constants.SPACE,
|
||||||
Constants.EMPTY_STRING))){
|
Constants.EMPTY_STRING))) {
|
||||||
apiFound = true;
|
apiFound = true;
|
||||||
apiIdentifier.setUuid(apiObj.getString("id"));
|
apiIdentifier.setUuid(apiObj.getId());
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
String apiUuid = apiIdentifier.getUUID();
|
||||||
if (!apiFound) {
|
if (!apiFound) {
|
||||||
// add new scopes as shared scopes
|
// add new scopes as shared scopes
|
||||||
for (ApiScope apiScope : apiConfig.getScopes()) {
|
for (ApiScope apiScope : apiConfig.getScopes()) {
|
||||||
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
|
if (!publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo,
|
||||||
apiScope.getKey())) {
|
apiScope.getKey())) {
|
||||||
Scope scope = new Scope();
|
Scope scope = new Scope();
|
||||||
scope.setName(apiScope.getName());
|
scope.setDisplayName(apiScope.getName());
|
||||||
scope.setDescription(apiScope.getDescription());
|
scope.setDescription(apiScope.getDescription());
|
||||||
scope.setKey(apiScope.getKey());
|
scope.setName(apiScope.getKey());
|
||||||
scope.setRoles(apiScope.getRoles());
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
||||||
|
bindings.add(ADMIN_ROLE_KEY);
|
||||||
|
scope.setBindings(bindings);
|
||||||
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
APIInfo api = getAPI(apiConfig, true);
|
APIInfo api = getAPI(apiConfig, true);
|
||||||
JSONObject createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
|
APIInfo createdAPI = publisherRESTAPIServices.addAPI(apiApplicationKey, accessTokenInfo, api);
|
||||||
|
apiUuid = createdAPI.getId();
|
||||||
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
||||||
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
||||||
createdAPI.getString("id"), apiConfig.getAsyncApiDefinition());
|
apiUuid, apiConfig.getAsyncApiDefinition());
|
||||||
}
|
}
|
||||||
if (CREATED_STATUS.equals(createdAPI.getString("lifeCycleStatus"))) {
|
if (CREATED_STATUS.equals(createdAPI.getLifeCycleStatus())) {
|
||||||
// if endpoint type "dynamic" and then add in sequence
|
// if endpoint type "dynamic" and then add in sequence
|
||||||
if ("dynamic".equals(apiConfig.getEndpointType())) {
|
if ("dynamic".equals(apiConfig.getEndpointType())) {
|
||||||
Mediation mediation = new Mediation();
|
Mediation mediation = new Mediation();
|
||||||
@ -179,26 +197,26 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
mediation.setType("in");
|
mediation.setType("in");
|
||||||
mediation.setGlobal(false);
|
mediation.setGlobal(false);
|
||||||
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
||||||
accessTokenInfo, createdAPI.getString("id"), mediation);
|
accessTokenInfo, apiUuid, mediation);
|
||||||
}
|
}
|
||||||
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
|
||||||
createdAPI.getString("id"), PUBLISH_ACTION);
|
apiUuid, PUBLISH_ACTION);
|
||||||
|
|
||||||
APIRevision apiRevision = new APIRevision();
|
APIRevision apiRevision = new APIRevision();
|
||||||
apiRevision.setApiUUID(createdAPI.getString("id"));
|
apiRevision.setApiUUID(apiUuid);
|
||||||
apiRevision.setDescription("Initial Revision");
|
apiRevision.setDescription("Initial Revision");
|
||||||
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
||||||
accessTokenInfo, apiRevision).getString("id");
|
accessTokenInfo, apiRevision).getId();
|
||||||
|
|
||||||
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
||||||
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT);
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
||||||
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
|
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
|
||||||
apiRevisionDeployment.setDisplayOnDevportal(true);
|
apiRevisionDeployment.setDisplayOnDevportal(true);
|
||||||
|
|
||||||
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
List<APIRevisionDeployment> apiRevisionDeploymentList = new ArrayList<>();
|
||||||
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
||||||
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
||||||
createdAPI.getString("id"), apiRevisionId, apiRevisionDeploymentList);
|
apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
|
if (WebappPublisherConfig.getInstance().isEnabledUpdateApi()) {
|
||||||
@ -231,10 +249,12 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
} else {
|
} else {
|
||||||
// if new scope add as shared scope
|
// if new scope add as shared scope
|
||||||
Scope scope = new Scope();
|
Scope scope = new Scope();
|
||||||
scope.setName(apiScope.getName());
|
scope.setName(apiScope.getKey());
|
||||||
scope.setDescription(apiScope.getDescription());
|
scope.setDescription(apiScope.getDescription());
|
||||||
scope.setKey(apiScope.getKey());
|
scope.setDisplayName(apiScope.getName());
|
||||||
scope.setRoles(apiScope.getRoles());
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
||||||
|
bindings.add(ADMIN_ROLE_KEY);
|
||||||
|
scope.setBindings(bindings);
|
||||||
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -242,33 +262,35 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get existing API
|
// Get existing API
|
||||||
JSONObject existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
|
APIInfo existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo,
|
||||||
apiIdentifier);
|
apiUuid);
|
||||||
if (scopesToMoveAsSharedScopes.size() > 0) {
|
if (scopesToMoveAsSharedScopes.size() > 0) {
|
||||||
// update API to remove local scopes
|
// update API to remove local scopes
|
||||||
APIInfo api = getAPI(apiConfig, false);
|
APIInfo api = getAPI(apiConfig, false);
|
||||||
api.setLifeCycleStatus(existingAPI.getString("lifeCycleStatus"));
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
||||||
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
||||||
|
|
||||||
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
|
for (ApiScope apiScope : scopesToMoveAsSharedScopes) {
|
||||||
Scope scope = new Scope();
|
Scope scope = new Scope();
|
||||||
scope.setName(apiScope.getName());
|
scope.setName(apiScope.getKey());
|
||||||
scope.setDescription(apiScope.getDescription());
|
scope.setDescription(apiScope.getDescription());
|
||||||
scope.setKey(apiScope.getKey());
|
scope.setDisplayName(apiScope.getName());
|
||||||
scope.setRoles(apiScope.getRoles());
|
List<String> bindings = new ArrayList<>(apiScope.getRoles());
|
||||||
|
bindings.add(ADMIN_ROLE_KEY);
|
||||||
|
scope.setBindings(bindings);
|
||||||
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiIdentifier);
|
existingAPI = publisherRESTAPIServices.getApi(apiApplicationKey, accessTokenInfo, apiUuid);
|
||||||
APIInfo api = getAPI(apiConfig, true);
|
APIInfo api = getAPI(apiConfig, true);
|
||||||
api.setLastUpdatedTime(existingAPI.getString("lifeCycleStatus"));
|
api.setLifeCycleStatus(existingAPI.getLifeCycleStatus());
|
||||||
api.setId(existingAPI.getString("id"));
|
api.setId(apiUuid);
|
||||||
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
publisherRESTAPIServices.updateApi(apiApplicationKey, accessTokenInfo, api);
|
||||||
|
|
||||||
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
if (apiConfig.getEndpointType() != null && "WS".equals(apiConfig.getEndpointType())) {
|
||||||
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.saveAsyncApiDefinition(apiApplicationKey, accessTokenInfo,
|
||||||
existingAPI.getString("id"), apiConfig.getAsyncApiDefinition());
|
apiUuid, apiConfig.getAsyncApiDefinition());
|
||||||
}
|
}
|
||||||
|
|
||||||
// if endpoint type "dynamic" and then add /update in sequence
|
// if endpoint type "dynamic" and then add /update in sequence
|
||||||
@ -279,54 +301,58 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
mediation.setType("in");
|
mediation.setType("in");
|
||||||
mediation.setGlobal(false);
|
mediation.setGlobal(false);
|
||||||
|
|
||||||
List<Mediation> mediationList = (List) publisherRESTAPIServices
|
MediationPolicy[] mediationList = publisherRESTAPIServices
|
||||||
.getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo,
|
.getAllApiSpecificMediationPolicies(apiApplicationKey, accessTokenInfo, apiUuid);
|
||||||
apiIdentifier).get("list");
|
|
||||||
|
|
||||||
boolean isMediationPolicyFound = false;
|
boolean isMediationPolicyFound = false;
|
||||||
for (Mediation m : mediationList) {
|
for (int i = 0; i < mediationList.length; i++) {
|
||||||
if (apiConfig.getInSequenceName().equals(m.getName())) {
|
MediationPolicy mediationPolicy = mediationList[i];
|
||||||
m.setConfig(apiConfig.getInSequenceConfig());
|
if (apiConfig.getInSequenceName().equals(mediationPolicy.getName())) {
|
||||||
publisherRESTAPIServices.
|
mediation.setUuid(mediationPolicy.getId());
|
||||||
updateApiSpecificMediationPolicyContent(apiApplicationKey,
|
publisherRESTAPIServices.deleteApiSpecificMediationPolicy(apiApplicationKey,
|
||||||
accessTokenInfo, existingAPI.getString("id"), m);
|
accessTokenInfo, apiUuid, mediation);
|
||||||
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
||||||
|
accessTokenInfo, apiUuid, mediation);
|
||||||
isMediationPolicyFound = true;
|
isMediationPolicyFound = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!isMediationPolicyFound) {
|
if (!isMediationPolicyFound) {
|
||||||
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
publisherRESTAPIServices.addApiSpecificMediationPolicy(apiApplicationKey,
|
||||||
accessTokenInfo, existingAPI.getString("id"), mediation);
|
accessTokenInfo, apiUuid, mediation);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// This will retrieve the deployed revision
|
int apiRevisionCount = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
||||||
JSONArray revisionDeploymentList = (JSONArray) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
accessTokenInfo, apiUuid, null).length;
|
||||||
accessTokenInfo, existingAPI.getString("id"), true).get("list");
|
|
||||||
// This will retrieve the un deployed revision list
|
|
||||||
JSONArray undeployedRevisionList = (JSONArray) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
|
||||||
accessTokenInfo, existingAPI.getString("id"), false).get("list");
|
|
||||||
int apiRevisionCount = (int) publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
|
||||||
accessTokenInfo, existingAPI.getString("id"), null).get("count");
|
|
||||||
|
|
||||||
if (apiRevisionCount >= 5) {
|
if (apiRevisionCount >= 5) {
|
||||||
JSONObject latestRevisionDeployment = revisionDeploymentList.getJSONObject(0);
|
// This will retrieve the deployed revision
|
||||||
JSONObject earliestUndeployRevision = undeployedRevisionList.getJSONObject(0);
|
APIRevision[] revisionDeploymentList = publisherRESTAPIServices.getAPIRevisions(
|
||||||
publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey,
|
apiApplicationKey, accessTokenInfo, apiUuid, true);
|
||||||
accessTokenInfo, latestRevisionDeployment, existingAPI.getString("id"));
|
if (revisionDeploymentList.length > 0) {
|
||||||
publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo,
|
APIRevision latestRevisionDeployment = revisionDeploymentList[0];
|
||||||
earliestUndeployRevision, existingAPI.getString("id"));
|
publisherRESTAPIServices.undeployAPIRevisionDeployment(apiApplicationKey,
|
||||||
|
accessTokenInfo, latestRevisionDeployment, apiUuid);
|
||||||
|
}
|
||||||
|
// This will retrieve the undeployed revision list
|
||||||
|
APIRevision[] undeployedRevisionList = publisherRESTAPIServices.getAPIRevisions(apiApplicationKey,
|
||||||
|
accessTokenInfo, apiUuid, false);
|
||||||
|
if (undeployedRevisionList.length > 0) {
|
||||||
|
APIRevision earliestUndeployRevision = undeployedRevisionList[0];
|
||||||
|
publisherRESTAPIServices.deleteAPIRevision(apiApplicationKey, accessTokenInfo,
|
||||||
|
earliestUndeployRevision, apiUuid);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// create new revision
|
// create new revision
|
||||||
APIRevision apiRevision = new APIRevision();
|
APIRevision apiRevision = new APIRevision();
|
||||||
apiRevision.setApiUUID(existingAPI.getString("id"));
|
apiRevision.setApiUUID(apiUuid);
|
||||||
apiRevision.setDescription("Updated Revision");
|
apiRevision.setDescription("Updated Revision");
|
||||||
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
String apiRevisionId = publisherRESTAPIServices.addAPIRevision(apiApplicationKey,
|
||||||
accessTokenInfo, apiRevision).getString("id");
|
accessTokenInfo, apiRevision).getId();
|
||||||
|
|
||||||
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
APIRevisionDeployment apiRevisionDeployment = new APIRevisionDeployment();
|
||||||
apiRevisionDeployment.setDeployment(API_PUBLISH_ENVIRONMENT);
|
apiRevisionDeployment.setName(API_PUBLISH_ENVIRONMENT);
|
||||||
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
|
apiRevisionDeployment.setVhost(System.getProperty("iot.gateway.host"));
|
||||||
apiRevisionDeployment.setDisplayOnDevportal(true);
|
apiRevisionDeployment.setDisplayOnDevportal(true);
|
||||||
|
|
||||||
@ -334,17 +360,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
apiRevisionDeploymentList.add(apiRevisionDeployment);
|
||||||
|
|
||||||
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.deployAPIRevision(apiApplicationKey, accessTokenInfo,
|
||||||
existingAPI.getString("id"), apiRevisionId, apiRevisionDeploymentList);
|
apiUuid, apiRevisionId, apiRevisionDeploymentList);
|
||||||
|
|
||||||
if (CREATED_STATUS.equals(existingAPI.getString("lifeCycleStatus"))) {
|
if (CREATED_STATUS.equals(existingAPI.getLifeCycleStatus())) {
|
||||||
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey,accessTokenInfo,
|
publisherRESTAPIServices.changeLifeCycleStatus(apiApplicationKey, accessTokenInfo,
|
||||||
existingAPI.getString("id"), PUBLISH_ACTION);
|
apiUuid, PUBLISH_ACTION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (apiConfig.getApiDocumentationSourceFile() != null) {
|
if (apiUuid != null && apiConfig.getApiDocumentationSourceFile() != null) {
|
||||||
APIInfo api = getAPI(apiConfig, true);
|
|
||||||
|
|
||||||
String fileName =
|
String fileName =
|
||||||
CarbonUtils.getCarbonHome() + File.separator + "repository" +
|
CarbonUtils.getCarbonHome() + File.separator + "repository" +
|
||||||
File.separator + "resources" + File.separator + "api-docs" + File.separator +
|
File.separator + "resources" + File.separator + "api-docs" + File.separator +
|
||||||
@ -362,34 +386,36 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
br.close();
|
br.close();
|
||||||
String docContent = stringBuilder.toString();
|
String docContent = stringBuilder.toString();
|
||||||
|
|
||||||
Documentation apiDocumentation = new Documentation(DocumentationType.HOWTO, apiConfig.getApiDocumentationName());
|
Documentation apiDocumentation = new Documentation(Documentation.DocumentationType.HOWTO, apiConfig.getApiDocumentationName());
|
||||||
apiDocumentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL);
|
apiDocumentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL);
|
||||||
apiDocumentation.setSourceType(Documentation.DocumentSourceType.MARKDOWN);
|
apiDocumentation.setSourceType(Documentation.DocumentSourceType.MARKDOWN);
|
||||||
apiDocumentation.setCreatedDate(new Date());
|
apiDocumentation.setCreatedDate(new Date());
|
||||||
apiDocumentation.setLastUpdated(new Date());
|
apiDocumentation.setLastUpdatedTime(new Date());
|
||||||
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
|
apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary());
|
||||||
apiDocumentation.setOtherTypeName(null);
|
apiDocumentation.setOtherTypeName(null);
|
||||||
|
|
||||||
JSONArray documentList = (JSONArray) publisherRESTAPIServices.getDocumentations(apiApplicationKey,
|
Documentation[] documentList = publisherRESTAPIServices.getDocumentations(apiApplicationKey,
|
||||||
accessTokenInfo, api.getId()).get("list");
|
accessTokenInfo, apiUuid);
|
||||||
|
|
||||||
if (documentList.length() > 0) {
|
if (documentList.length > 0) {
|
||||||
for (int i = 0; i < documentList.length(); i++) {
|
for (int i = 0; i < documentList.length; i++) {
|
||||||
JSONObject existingDoc = documentList.getJSONObject(i);
|
Documentation existingDoc = documentList[i];
|
||||||
if (existingDoc.getString("name").equals(apiConfig.getApiDocumentationName())
|
if (existingDoc.getName().equals(apiConfig.getApiDocumentationName())
|
||||||
&& existingDoc.getString("type").equals(DocumentationType.HOWTO)) {
|
&& existingDoc.getType().equals(Documentation.DocumentationType.HOWTO.name())) {
|
||||||
publisherRESTAPIServices.deleteDocumentations(apiApplicationKey, accessTokenInfo,
|
publisherRESTAPIServices.deleteDocumentations(apiApplicationKey, accessTokenInfo,
|
||||||
api.getId(), existingDoc.getString("documentId"));
|
apiUuid, existingDoc.getDocumentId());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.info("There is no any existing api documentation.");
|
log.info("There is no any existing api documentation.");
|
||||||
}
|
}
|
||||||
Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo,
|
|
||||||
api.getId(), apiDocumentation);
|
|
||||||
|
|
||||||
publisherRESTAPIServices.addDocumentationContent(apiApplicationKey, accessTokenInfo, api,
|
Documentation createdDoc = publisherRESTAPIServices.addDocumentation(apiApplicationKey, accessTokenInfo,
|
||||||
createdDoc.getId(), docContent);
|
apiUuid, apiDocumentation);
|
||||||
|
|
||||||
|
publisherRESTAPIServices.addDocumentationContent(apiApplicationKey, accessTokenInfo, apiUuid,
|
||||||
|
createdDoc.getDocumentId(), docContent);
|
||||||
|
|
||||||
}
|
}
|
||||||
} catch (APIManagementException | IOException | APIServicesException |
|
} catch (APIManagementException | IOException | APIServicesException |
|
||||||
BadRequestException | UnexpectedResponseException e) {
|
BadRequestException | UnexpectedResponseException e) {
|
||||||
@ -408,6 +434,39 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void addDefaultScopesIfNotExist() {
|
||||||
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
||||||
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
|
try {
|
||||||
|
APIApplicationKey apiApplicationKey =
|
||||||
|
apiApplicationServices.createAndRetrieveApplicationCredentials();
|
||||||
|
AccessTokenInfo accessTokenInfo =
|
||||||
|
apiApplicationServices.generateAccessTokenFromRegisteredApplication(
|
||||||
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
|
|
||||||
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
||||||
|
|
||||||
|
Scope scope = new Scope();
|
||||||
|
for (DefaultPermission defaultPermission: defaultPermissions.getDefaultPermissions()) {
|
||||||
|
//todo check whether scope is available or not
|
||||||
|
ScopeMapping scopeMapping = defaultPermission.getScopeMapping();
|
||||||
|
|
||||||
|
List<String> bindings = new ArrayList<>(
|
||||||
|
Arrays.asList(scopeMapping.getDefaultRoles().split(",")));
|
||||||
|
bindings.add(ADMIN_ROLE_KEY);
|
||||||
|
scope.setName(scopeMapping.getKey());
|
||||||
|
scope.setDescription(scopeMapping.getName());
|
||||||
|
scope.setDisplayName(scopeMapping.getName());
|
||||||
|
scope.setBindings(bindings);
|
||||||
|
publisherRESTAPIServices.addNewSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
|
}
|
||||||
|
} catch (BadRequestException | UnexpectedResponseException | APIServicesException e) {
|
||||||
|
log.error("Error occurred while adding default scopes");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateScopeRoleMapping()
|
public void updateScopeRoleMapping()
|
||||||
throws APIManagerPublisherException {
|
throws APIManagerPublisherException {
|
||||||
@ -428,89 +487,110 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new APIManagerPublisherException(e);
|
throw new APIManagerPublisherException(e);
|
||||||
}
|
}
|
||||||
|
UserStoreManager userStoreManager;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
for (String tenantDomain : tenants) {
|
for (String tenantDomain : tenants) {
|
||||||
PrivilegedCarbonContext.startTenantFlow();
|
PrivilegedCarbonContext.startTenantFlow();
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true);
|
||||||
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
||||||
JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String fileName =
|
String fileName =
|
||||||
CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc"
|
CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc"
|
||||||
+ File.separator + tenantDomain + ".csv";
|
+ File.separator + tenantDomain + ".csv";
|
||||||
|
try {
|
||||||
|
userStoreManager = APIPublisherDataHolder.getInstance().getUserStoreManager();
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error("Unable to retrieve user store manager for tenant: " + tenantDomain);
|
||||||
|
return;
|
||||||
|
}
|
||||||
if (Files.exists(Paths.get(fileName))) {
|
if (Files.exists(Paths.get(fileName))) {
|
||||||
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
BufferedReader br = new BufferedReader(new FileReader(fileName));
|
||||||
int lineNumber = 0;
|
int lineNumber = 0;
|
||||||
Map<Integer, String> roles = new HashMap<>();
|
Map<Integer, String> roles = new HashMap<>();
|
||||||
String line = "";
|
Map<String, List<String>> rolePermissions = new HashMap<>();
|
||||||
|
String line;
|
||||||
String splitBy = ",";
|
String splitBy = ",";
|
||||||
while ((line = br.readLine()) != null) //returns a Boolean value
|
while ((line = br.readLine()) != null) { //returns a Boolean value
|
||||||
{
|
|
||||||
lineNumber++;
|
lineNumber++;
|
||||||
String[] scopeMapping = line.split(splitBy); // use comma as separator
|
String[] scopeMapping = line.split(splitBy); // use comma as separator
|
||||||
|
String role;
|
||||||
if (lineNumber == 1) { // skip titles
|
if (lineNumber == 1) { // skip titles
|
||||||
for (int i = 0; i < scopeMapping.length; i++) {
|
for (int i = 4; i < scopeMapping.length; i++) {
|
||||||
if (i > 3) {
|
role = scopeMapping[i];
|
||||||
roles.put(i, scopeMapping[i]); // add roles to the map
|
roles.put(i, role); // add roles to the map
|
||||||
|
if (!"admin".equals(role)) {
|
||||||
|
try {
|
||||||
|
if (!userStoreManager.isExistingRole(role)) {
|
||||||
|
try {
|
||||||
|
addRole(role);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error("Error occurred when adding new role: " + role, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error("Error occurred when checking the existence of role: " + role, e);
|
||||||
|
}
|
||||||
|
rolePermissions.put(role, new ArrayList<>());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
Scope scope = new Scope();
|
Scope scope = new Scope();
|
||||||
scope.setName(
|
scope.setDisplayName(
|
||||||
scopeMapping[0] != null ? StringUtils.trim(scopeMapping[0]) : StringUtils.EMPTY);
|
scopeMapping[0] != null ? StringUtils.trim(scopeMapping[0]) : StringUtils.EMPTY);
|
||||||
scope.setDescription(
|
scope.setDescription(
|
||||||
scopeMapping[1] != null ? StringUtils.trim(scopeMapping[1]) : StringUtils.EMPTY);
|
scopeMapping[1] != null ? StringUtils.trim(scopeMapping[1]) : StringUtils.EMPTY);
|
||||||
scope.setKey(
|
scope.setName(
|
||||||
scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY);
|
scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY);
|
||||||
// scope.setPermissions(
|
// scope.setPermissions(
|
||||||
// scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY);
|
// scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY);
|
||||||
|
String permission = scopeMapping[3] != null ? StringUtils.trim(scopeMapping[3]) : StringUtils.EMPTY;
|
||||||
|
|
||||||
String roleString = "";
|
List<String> rolesList = new ArrayList<>();
|
||||||
for (int i = 4; i < scopeMapping.length; i++) {
|
for (int i = 4; i < scopeMapping.length; i++) {
|
||||||
if (scopeMapping[i] != null && StringUtils.trim(scopeMapping[i]).equals("Yes")) {
|
if (scopeMapping[i] != null && StringUtils.trim(scopeMapping[i]).equals("Yes")) {
|
||||||
roleString = roleString + "," + roles.get(i);
|
rolesList.add(roles.get(i));
|
||||||
|
if (rolePermissions.containsKey(roles.get(i)) && StringUtils.isNotEmpty(permission)) {
|
||||||
|
rolePermissions.get(roles.get(i)).add(permission);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (roleString.length() > 1) {
|
//Set scope details which related to the scope key
|
||||||
roleString = roleString.substring(1); // remove first , (comma)
|
Scope[] scopes = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
||||||
}
|
for (int i = 0; i < scopes.length; i++) {
|
||||||
scope.setRoles(roleString);
|
Scope relatedScope = scopes[i];
|
||||||
|
if (relatedScope.getName().equals(scopeMapping[2].toString())) {
|
||||||
//Set scope id which related to the scope key
|
scope.setId(relatedScope.getId());
|
||||||
JSONArray scopeList = (JSONArray) scopeObject.get("list");
|
scope.setUsageCount(relatedScope.getUsageCount());
|
||||||
for (int i = 0; i < scopeList.length(); i++) {
|
//Including already existing roles
|
||||||
JSONObject scopeObj = scopeList.getJSONObject(i);
|
rolesList.addAll(relatedScope.getBindings());
|
||||||
if (scopeObj.getString("name").equals(scopeMapping[2] != null ?
|
|
||||||
StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) {
|
|
||||||
scope.setId(scopeObj.getString("id"));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
scope.setBindings(rolesList);
|
||||||
|
|
||||||
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) {
|
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) {
|
||||||
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
} else {
|
} else {
|
||||||
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
|
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
|
||||||
if (log.isDebugEnabled()) {
|
log.warn(scope.getName() + " not available as shared scope");
|
||||||
log.debug(scope.getKey() + " not available as shared scope");
|
}
|
||||||
}
|
}
|
||||||
|
for (String role : rolePermissions.keySet()) {
|
||||||
|
try {
|
||||||
|
updatePermissions(role, rolePermissions.get(role));
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error("Error occurred when adding permissions to role: " + role, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (IOException | DirectoryIteratorException ex) {
|
} catch (IOException | DirectoryIteratorException ex) {
|
||||||
log.error("failed to read scopes from file.", ex);
|
log.error("failed to read scopes from file.", ex);
|
||||||
} catch (APIServicesException | BadRequestException e) {
|
|
||||||
String errorMsg = "Error while calling APIs";
|
|
||||||
log.error(errorMsg, e);
|
|
||||||
throw new APIManagerPublisherException(e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
} catch (APIServicesException e) {
|
||||||
catch (APIServicesException e) {
|
|
||||||
String errorMsg = "Error while processing Publisher REST API response";
|
String errorMsg = "Error while processing Publisher REST API response";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new APIManagerPublisherException(e);
|
throw new APIManagerPublisherException(e);
|
||||||
@ -522,11 +602,150 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
String errorMsg = "Unexpected response from the server";
|
String errorMsg = "Unexpected response from the server";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new APIManagerPublisherException(e);
|
throw new APIManagerPublisherException(e);
|
||||||
}finally {
|
} finally {
|
||||||
PrivilegedCarbonContext.endTenantFlow();
|
PrivilegedCarbonContext.endTenantFlow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateScopeRoleMapping(String roleName, String[] permissions, String[] removedPermissions) throws APIManagerPublisherException {
|
||||||
|
APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl();
|
||||||
|
APIApplicationKey apiApplicationKey;
|
||||||
|
AccessTokenInfo accessTokenInfo;
|
||||||
|
try {
|
||||||
|
apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials();
|
||||||
|
accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication(
|
||||||
|
apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret());
|
||||||
|
} catch (APIServicesException e) {
|
||||||
|
String errorMsg = "Error occurred while generating the API application";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new APIManagerPublisherException(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl();
|
||||||
|
Scope[] scopeList = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo);
|
||||||
|
|
||||||
|
Map<String, String> permScopeMap = APIPublisherDataHolder.getInstance().getPermScopeMapping();
|
||||||
|
if (permissions.length != 0) {
|
||||||
|
updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, permissions, permScopeMap, false);
|
||||||
|
}
|
||||||
|
if (removedPermissions.length != 0) {
|
||||||
|
updateScopes(roleName, publisherRESTAPIServices, apiApplicationKey, accessTokenInfo, scopeList, removedPermissions, permScopeMap, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
updatePermissions(roleName, Arrays.asList(permissions));
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
String errorMsg = "Error occurred when adding permissions to role: " + roleName;
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new APIManagerPublisherException(errorMsg, e);
|
||||||
|
}
|
||||||
|
} catch (APIServicesException e) {
|
||||||
|
String errorMsg = "Error while processing Publisher REST API response";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new APIManagerPublisherException(errorMsg, e);
|
||||||
|
} catch (BadRequestException e) {
|
||||||
|
String errorMsg = "Error while calling Publisher REST APIs";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new APIManagerPublisherException(errorMsg, e);
|
||||||
|
} catch (UnexpectedResponseException e) {
|
||||||
|
String errorMsg = "Unexpected response from the server";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new APIManagerPublisherException(errorMsg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Update Scopes
|
||||||
|
*
|
||||||
|
* @param roleName Role Name
|
||||||
|
* @param publisherRESTAPIServices {@link PublisherRESTAPIServices}
|
||||||
|
* @param apiApplicationKey {@link APIApplicationKey}
|
||||||
|
* @param accessTokenInfo {@link AccessTokenInfo}
|
||||||
|
* @param scopeList scope list returning from APIM
|
||||||
|
* @param permissions List of permissions
|
||||||
|
* @param permScopeMap Permission Scope map
|
||||||
|
* @param removingPermissions if list of permissions has to be removed from the role send true, otherwise sends false.
|
||||||
|
* @throws APIManagerPublisherException If the method receives invalid permission to update.
|
||||||
|
*/
|
||||||
|
private void updateScopes (String roleName, PublisherRESTAPIServices publisherRESTAPIServices,
|
||||||
|
APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo,
|
||||||
|
Scope[] scopeList, String[] permissions, Map<String, String> permScopeMap, boolean removingPermissions )
|
||||||
|
throws APIManagerPublisherException {
|
||||||
|
for (String permission : permissions) {
|
||||||
|
String scopeValue = permScopeMap.get(permission);
|
||||||
|
if (scopeValue == null) {
|
||||||
|
String msg = "Found invalid permission: " + permission + ". Hence aborting the scope role " +
|
||||||
|
"mapping process";
|
||||||
|
log.error(msg);
|
||||||
|
throw new APIManagerPublisherException(msg);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int i = 0; i < scopeList.length; i++) {
|
||||||
|
Scope scopeObj = scopeList[i];
|
||||||
|
if (scopeObj.getName().equals(scopeValue)) {
|
||||||
|
Scope scope = new Scope();
|
||||||
|
scope.setName(scopeObj.getName());
|
||||||
|
scope.setDisplayName(scopeObj.getDisplayName());
|
||||||
|
scope.setDescription(scopeObj.getDescription());
|
||||||
|
scope.setId(scopeObj.getId());
|
||||||
|
|
||||||
|
// Including already existing roles
|
||||||
|
List<String> existingRoleList = new ArrayList<>();
|
||||||
|
existingRoleList.addAll(scopeObj.getBindings());
|
||||||
|
|
||||||
|
if (!existingRoleList.contains(roleName)) {
|
||||||
|
existingRoleList.add(roleName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removingPermissions) {
|
||||||
|
existingRoleList.remove(roleName);
|
||||||
|
} else {
|
||||||
|
if (!existingRoleList.contains(roleName)) {
|
||||||
|
existingRoleList.add(roleName);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
scope.setBindings(existingRoleList);
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getName())) {
|
||||||
|
publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope);
|
||||||
|
} else {
|
||||||
|
// todo: come to this level means, that scope is removed from API, but haven't removed from the scope-role-permission-mappings list
|
||||||
|
log.warn(scope.getName() + " not available as shared scope");
|
||||||
|
}
|
||||||
|
} catch (APIServicesException | BadRequestException | UnexpectedResponseException e) {
|
||||||
|
log.error("Error occurred while updating role scope mapping via APIM REST endpoint.", e);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void updatePermissions(String role, List<String> permissions) throws UserStoreException {
|
||||||
|
AuthorizationManager authorizationManager = APIPublisherDataHolder.getInstance().getUserRealm()
|
||||||
|
.getAuthorizationManager();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Updating the role '" + role + "'");
|
||||||
|
}
|
||||||
|
if (permissions != null && !permissions.isEmpty()) {
|
||||||
|
authorizationManager.clearRoleAuthorization(role);
|
||||||
|
for (String permission : permissions) {
|
||||||
|
authorizationManager.authorizeRole(role, permission, CarbonConstants.UI_PERMISSION_ACTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void addRole(String role) throws UserStoreException {
|
||||||
|
UserStoreManager userStoreManager = APIPublisherDataHolder.getInstance().getUserStoreManager();
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Persisting the role " + role + " in the underlying user store");
|
||||||
|
}
|
||||||
|
userStoreManager.addRole(role, new String[]{"admin"}, new Permission[0]);
|
||||||
|
}
|
||||||
|
|
||||||
private APIInfo getAPI(APIConfig config, boolean includeScopes) {
|
private APIInfo getAPI(APIConfig config, boolean includeScopes) {
|
||||||
|
|
||||||
APIInfo apiInfo = new APIInfo();
|
APIInfo apiInfo = new APIInfo();
|
||||||
@ -546,57 +765,55 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
apiInfo.setRevisionedApiId(null);
|
apiInfo.setRevisionedApiId(null);
|
||||||
apiInfo.setEnableSchemaValidation(false);
|
apiInfo.setEnableSchemaValidation(false);
|
||||||
|
|
||||||
Set<String> tags = new HashSet<>();
|
List<String> tags = new ArrayList<>();
|
||||||
tags.addAll(Arrays.asList(config.getTags()));
|
tags.addAll(Arrays.asList(config.getTags()));
|
||||||
apiInfo.setTags(tags);
|
apiInfo.setTags(tags);
|
||||||
|
|
||||||
Set<String> availableTiers = new HashSet<>();
|
List<String> availableTiers = new ArrayList<>();
|
||||||
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
|
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
|
||||||
availableTiers.add(WS_UNLIMITED_TIER);
|
availableTiers.add(WS_UNLIMITED_TIER);
|
||||||
} else {
|
} else {
|
||||||
availableTiers.add(UNLIMITED_TIER);
|
availableTiers.add(UNLIMITED_TIER);
|
||||||
}
|
}
|
||||||
apiInfo.setPolicies(availableTiers);
|
apiInfo.setPolicies(availableTiers);
|
||||||
|
apiInfo.setApiThrottlingPolicy(UNLIMITED_TIER);
|
||||||
|
|
||||||
if (config.getEndpointType() == null) {
|
//set operations and scopes
|
||||||
List<JSONObject> operations = new ArrayList();
|
List<Operations> operations = new ArrayList();
|
||||||
List<JSONObject> scopeSet = new ArrayList();
|
List<JSONObject> scopeSet = new ArrayList();
|
||||||
Iterator<ApiUriTemplate> iterator;
|
Iterator<ApiUriTemplate> iterator;
|
||||||
for (iterator = config.getUriTemplates().iterator(); iterator.hasNext(); ) {
|
|
||||||
ApiUriTemplate apiUriTemplate = iterator.next();
|
|
||||||
JSONObject operation = new JSONObject();
|
|
||||||
operation.put("target", apiUriTemplate.getUriTemplate());
|
|
||||||
operation.put("verb", apiUriTemplate.getHttpVerb());
|
|
||||||
operation.put("authType", apiUriTemplate.getAuthType());
|
|
||||||
operation.put("throttlingPolicy", UNLIMITED_TIER);
|
|
||||||
if (includeScopes) {
|
|
||||||
if (apiUriTemplate.getScope() != null) {
|
|
||||||
String scopeString = "{\n" +
|
|
||||||
" \"scope\": {\n" +
|
|
||||||
" \"id\": null,\n" +
|
|
||||||
" \"name\": \"" + apiUriTemplate.getScope().getKey() + "\",\n" +
|
|
||||||
" \"displayName\": \"" + apiUriTemplate.getScope().getName() + "\",\n" +
|
|
||||||
" \"description\": \"" + apiUriTemplate.getScope().getDescription() + "\",\n" +
|
|
||||||
" \"bindings\": [\n" +
|
|
||||||
" \"" + apiUriTemplate.getScope().getRoles() + "\"\n" +
|
|
||||||
" ],\n" +
|
|
||||||
" \"usageCount\": null\n" +
|
|
||||||
" },\n" +
|
|
||||||
" \"shared\": true\n" +
|
|
||||||
" }";
|
|
||||||
JSONObject scope = new JSONObject(scopeString);
|
|
||||||
scopeSet.add(scope);
|
|
||||||
|
|
||||||
Set<String> scopes = new HashSet<>();
|
for (iterator = config.getUriTemplates().iterator(); iterator.hasNext(); ) {
|
||||||
scopes.add(apiUriTemplate.getScope().getKey());
|
ApiUriTemplate apiUriTemplate = iterator.next();
|
||||||
operation.put("scopes", scopes);
|
Operations operation = new Operations();
|
||||||
}
|
operation.setTarget(apiUriTemplate.getUriTemplate());
|
||||||
|
operation.setVerb(apiUriTemplate.getHttpVerb());
|
||||||
|
operation.setAuthType(apiUriTemplate.getAuthType());
|
||||||
|
operation.setThrottlingPolicy(UNLIMITED_TIER);
|
||||||
|
operation.setUriMapping(apiUriTemplate.getUriMapping());
|
||||||
|
if (includeScopes) {
|
||||||
|
if (apiUriTemplate.getScope() != null) {
|
||||||
|
Scope scope = new Scope();
|
||||||
|
scope.setName(apiUriTemplate.getScope().getKey());
|
||||||
|
scope.setDisplayName(apiUriTemplate.getScope().getName());
|
||||||
|
scope.setDescription(apiUriTemplate.getScope().getDescription());
|
||||||
|
scope.setBindings(apiUriTemplate.getScope().getRoles());
|
||||||
|
|
||||||
|
JSONObject scopeObject = new JSONObject();
|
||||||
|
scopeObject.put("scope", new JSONObject(gson.toJson(scope)));
|
||||||
|
scopeObject.put("shared", true);
|
||||||
|
|
||||||
|
scopeSet.add(scopeObject);
|
||||||
|
|
||||||
|
List<String> scopes = new ArrayList<>();
|
||||||
|
scopes.addAll(Arrays.asList(apiUriTemplate.getScope().getKey()));
|
||||||
|
operation.setScopes(scopes);
|
||||||
}
|
}
|
||||||
operations.add(operation);
|
|
||||||
}
|
}
|
||||||
apiInfo.setScopes(scopeSet);
|
operations.add(operation);
|
||||||
apiInfo.setOperations(operations);
|
|
||||||
}
|
}
|
||||||
|
apiInfo.setScopes(scopeSet);
|
||||||
|
apiInfo.setOperations(operations);
|
||||||
|
|
||||||
if (config.isSharedWithAllTenants()) {
|
if (config.isSharedWithAllTenants()) {
|
||||||
apiInfo.setSubscriptionAvailability(SUBSCRIPTION_TO_ALL_TENANTS);
|
apiInfo.setSubscriptionAvailability(SUBSCRIPTION_TO_ALL_TENANTS);
|
||||||
@ -618,15 +835,15 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
" }";
|
" }";
|
||||||
JSONObject endPointConfig = new JSONObject(endpointConfig);
|
JSONObject endPointConfig = new JSONObject(endpointConfig);
|
||||||
|
|
||||||
Set<String> transports = new HashSet<>();
|
List<String> transports = new ArrayList<>();
|
||||||
transports.addAll(Arrays.asList(config.getTransports()));
|
transports.addAll(Arrays.asList(config.getTransports().split(",")));
|
||||||
apiInfo.setTransport(transports);
|
apiInfo.setTransport(transports);
|
||||||
|
|
||||||
apiInfo.setType("HTTP");
|
apiInfo.setType("HTTP");
|
||||||
|
|
||||||
if (config.getEndpointType() != null && "dynamic".equals(config.getEndpointType())) {
|
if (config.getEndpointType() != null && "dynamic".equals(config.getEndpointType())) {
|
||||||
endpointConfig = "{\n" +
|
endpointConfig = "{\n" +
|
||||||
" \"endpoint_type\": \"http\",\n" +
|
" \"endpoint_type\": \"default\",\n" +
|
||||||
" \"sandbox_endpoints\": {\n" +
|
" \"sandbox_endpoints\": {\n" +
|
||||||
" \"url\": \" default \"\n" +
|
" \"url\": \" default \"\n" +
|
||||||
" },\n" +
|
" },\n" +
|
||||||
@ -635,13 +852,12 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
" }\n" +
|
" }\n" +
|
||||||
" }";
|
" }";
|
||||||
endPointConfig = new JSONObject(endpointConfig);
|
endPointConfig = new JSONObject(endpointConfig);
|
||||||
//TODO: Will be used in dynamic endpoints
|
apiInfo.setEndpointImplementationType("ENDPOINT");
|
||||||
// apiInfo.setInSequence(config.getInSequenceName());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// if ws endpoint
|
// if ws endpoint
|
||||||
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
|
if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
|
||||||
endpointConfig = "{\n" +
|
endpointConfig = "{\n" +
|
||||||
" \"endpoint_type\": \"ws\",\n" +
|
" \"endpoint_type\": \"ws\",\n" +
|
||||||
" \"sandbox_endpoints\": {\n" +
|
" \"sandbox_endpoints\": {\n" +
|
||||||
" \"url\": \"" + config.getEndpoint() + "\"\n" +
|
" \"url\": \"" + config.getEndpoint() + "\"\n" +
|
||||||
@ -652,7 +868,8 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
" }";
|
" }";
|
||||||
endPointConfig = new JSONObject(endpointConfig);
|
endPointConfig = new JSONObject(endpointConfig);
|
||||||
|
|
||||||
transports.addAll(Arrays.asList("wss,ws"));
|
transports.add("wss");
|
||||||
|
transports.add("ws");
|
||||||
apiInfo.setTransport(transports);
|
apiInfo.setTransport(transports);
|
||||||
apiInfo.setType("WS");
|
apiInfo.setType("WS");
|
||||||
}
|
}
|
||||||
@ -686,44 +903,22 @@ public class APIPublisherServiceImpl implements APIPublisherService {
|
|||||||
apiInfo.setEnableSchemaValidation(false);
|
apiInfo.setEnableSchemaValidation(false);
|
||||||
apiInfo.setMonetization(null);
|
apiInfo.setMonetization(null);
|
||||||
apiInfo.setServiceInfo(null);
|
apiInfo.setServiceInfo(null);
|
||||||
|
apiInfo.setWebsubSubscriptionConfiguration(null);
|
||||||
|
apiInfo.setAdvertiseInfo(null);
|
||||||
|
|
||||||
return apiInfo;
|
return apiInfo;
|
||||||
|
}
|
||||||
|
|
||||||
//TODO: Will be used in WS or dynamic endpoints
|
/**
|
||||||
// if (config.getEndpointType() != null && "WS".equals(config.getEndpointType())) {
|
* This method will construct the permission scope mapping hash map. This will call in each API publish call.
|
||||||
// api.setAsyncApiDefinition(config.getAsyncApiDefinition());
|
* @param scopes API Scopes
|
||||||
// AsyncApiParser asyncApiParser = new AsyncApiParser();
|
*/
|
||||||
// try {
|
private void constructPemScopeMap(Set<ApiScope> scopes) {
|
||||||
// api.setUriTemplates(asyncApiParser.getURITemplates(config.getAsyncApiDefinition(), true));
|
APIPublisherDataHolder apiPublisherDataHolder = APIPublisherDataHolder.getInstance();
|
||||||
// } catch (APIManagementException e) {
|
Map<String, String> permScopeMap = apiPublisherDataHolder.getPermScopeMapping();
|
||||||
//
|
for (ApiScope scope : scopes) {
|
||||||
// }
|
permScopeMap.put(scope.getPermissions(), scope.getKey());
|
||||||
// api.setWsUriMapping(asyncApiParser.buildWSUriMapping(config.getAsyncApiDefinition()));
|
}
|
||||||
// } else {
|
apiPublisherDataHolder.setPermScopeMapping(permScopeMap);
|
||||||
// api.setSwaggerDefinition(APIPublisherUtil.getSwaggerDefinition(config));
|
|
||||||
//
|
|
||||||
// Set<URITemplate> uriTemplates = new HashSet<>();
|
|
||||||
// Iterator<ApiUriTemplate> iterator;
|
|
||||||
// for (iterator = config.getUriTemplates().iterator(); iterator.hasNext(); ) {
|
|
||||||
// ApiUriTemplate apiUriTemplate = iterator.next();
|
|
||||||
// URITemplate uriTemplate = new URITemplate();
|
|
||||||
// uriTemplate.setAuthType(apiUriTemplate.getAuthType());
|
|
||||||
// uriTemplate.setHTTPVerb(apiUriTemplate.getHttpVerb());
|
|
||||||
// uriTemplate.setResourceURI(apiUriTemplate.getResourceURI());
|
|
||||||
// uriTemplate.setUriTemplate(apiUriTemplate.getUriTemplate());
|
|
||||||
// if (includeScopes) {
|
|
||||||
// Scope scope = new Scope();
|
|
||||||
// if (apiUriTemplate.getScope() != null) {
|
|
||||||
// scope.setName(apiUriTemplate.getScope().getName());
|
|
||||||
// scope.setDescription(apiUriTemplate.getScope().getDescription());
|
|
||||||
// scope.setKey(apiUriTemplate.getScope().getKey());
|
|
||||||
// scope.setRoles(apiUriTemplate.getScope().getRoles());
|
|
||||||
// uriTemplate.setScopes(scope);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// uriTemplates.add(uriTemplate);
|
|
||||||
// }
|
|
||||||
// api.setUriTemplates(uriTemplates);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -86,6 +86,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
publisher.updateScopeRoleMapping();
|
publisher.updateScopeRoleMapping();
|
||||||
|
publisher.addDefaultScopesIfNotExist();
|
||||||
} catch (APIManagerPublisherException e) {
|
} catch (APIManagerPublisherException e) {
|
||||||
log.error("failed to update scope role mapping.", e);
|
log.error("failed to update scope role mapping.", e);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,11 +18,13 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.apimgt.webapp.publisher.dto;
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class ApiScope {
|
public class ApiScope {
|
||||||
|
|
||||||
String key;
|
String key;
|
||||||
String name;
|
String name;
|
||||||
String roles;
|
List<String> roles;
|
||||||
String permissions;
|
String permissions;
|
||||||
String description;
|
String description;
|
||||||
int id;
|
int id;
|
||||||
@ -46,11 +48,11 @@ public class ApiScope {
|
|||||||
this.name = name;
|
this.name = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRoles() {
|
public List<String> getRoles() {
|
||||||
return this.roles;
|
return this.roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setRoles(String roles) {
|
public void setRoles(List<String> roles) {
|
||||||
this.roles = roles;
|
this.roles = roles;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -28,4 +28,12 @@ public class APIManagerPublisherException extends Exception {
|
|||||||
public APIManagerPublisherException(Throwable cause) {
|
public APIManagerPublisherException(Throwable cause) {
|
||||||
super(cause);
|
super(cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public APIManagerPublisherException(String errorMessage) {
|
||||||
|
super(errorMessage);
|
||||||
|
}
|
||||||
|
|
||||||
|
public APIManagerPublisherException(String errorMessage, Throwable cause) {
|
||||||
|
super(errorMessage, cause);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,11 +19,19 @@ package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal;
|
|||||||
|
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
import org.wso2.carbon.user.api.UserStoreManager;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
import org.wso2.carbon.user.core.tenant.TenantManager;
|
import org.wso2.carbon.user.core.tenant.TenantManager;
|
||||||
import org.wso2.carbon.utils.ConfigurationContextService;
|
import org.wso2.carbon.utils.ConfigurationContextService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Stack;
|
import java.util.Stack;
|
||||||
|
|
||||||
public class APIPublisherDataHolder {
|
public class APIPublisherDataHolder {
|
||||||
@ -35,6 +43,10 @@ public class APIPublisherDataHolder {
|
|||||||
private RegistryService registryService;
|
private RegistryService registryService;
|
||||||
private boolean isServerStarted;
|
private boolean isServerStarted;
|
||||||
private Stack<APIConfig> unpublishedApis = new Stack<>();
|
private Stack<APIConfig> unpublishedApis = new Stack<>();
|
||||||
|
private Map<String, String> permScopeMapping;
|
||||||
|
|
||||||
|
private MetadataManagementService metadataManagementService;
|
||||||
|
|
||||||
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
|
private static APIPublisherDataHolder thisInstance = new APIPublisherDataHolder();
|
||||||
|
|
||||||
private APIPublisherDataHolder() {
|
private APIPublisherDataHolder() {
|
||||||
@ -79,6 +91,25 @@ public class APIPublisherDataHolder {
|
|||||||
realmService.getTenantManager() : null);
|
realmService.getTenantManager() : null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public UserStoreManager getUserStoreManager() throws UserStoreException {
|
||||||
|
if (realmService == null) {
|
||||||
|
String msg = "Realm service has not initialized.";
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
return realmService.getTenantUserRealm(tenantId).getUserStoreManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
public UserRealm getUserRealm() throws UserStoreException {
|
||||||
|
UserRealm realm;
|
||||||
|
if (realmService == null) {
|
||||||
|
throw new IllegalStateException("Realm service not initialized");
|
||||||
|
}
|
||||||
|
int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
realm = realmService.getTenantUserRealm(tenantId);
|
||||||
|
return realm;
|
||||||
|
}
|
||||||
|
|
||||||
private void setTenantManager(TenantManager tenantManager) {
|
private void setTenantManager(TenantManager tenantManager) {
|
||||||
this.tenantManager = tenantManager;
|
this.tenantManager = tenantManager;
|
||||||
}
|
}
|
||||||
@ -114,4 +145,15 @@ public class APIPublisherDataHolder {
|
|||||||
this.unpublishedApis = unpublishedApis;
|
this.unpublishedApis = unpublishedApis;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> getPermScopeMapping() {return permScopeMapping;}
|
||||||
|
|
||||||
|
public void setPermScopeMapping(Map<String, String> permScopeMapping) {this.permScopeMapping = permScopeMapping;}
|
||||||
|
|
||||||
|
public MetadataManagementService getMetadataManagementService() {
|
||||||
|
return metadataManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMetadataManagementService(MetadataManagementService metadataManagementService) {
|
||||||
|
this.metadataManagementService = metadataManagementService;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,19 +17,22 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal;
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher.internal;
|
||||||
|
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherServiceImpl;
|
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherStartupHandler;
|
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.osgi.framework.BundleContext;
|
import org.osgi.framework.BundleContext;
|
||||||
import org.osgi.service.component.ComponentContext;
|
import org.osgi.service.component.ComponentContext;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherServiceImpl;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherStartupHandler;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.config.WebappPublisherConfig;
|
||||||
import org.osgi.service.component.annotations.*;
|
import org.osgi.service.component.annotations.*;
|
||||||
import org.wso2.carbon.core.ServerStartupObserver;
|
import org.wso2.carbon.core.ServerStartupObserver;
|
||||||
import org.wso2.carbon.registry.core.service.RegistryService;
|
import org.wso2.carbon.registry.core.service.RegistryService;
|
||||||
import org.wso2.carbon.user.core.service.RealmService;
|
import org.wso2.carbon.user.core.service.RealmService;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
@Component(
|
@Component(
|
||||||
name = "io.entgra.device.mgt.core.apimgt.webapp.publisher.internal.APIPublisherServiceComponent",
|
name = "io.entgra.device.mgt.core.apimgt.webapp.publisher.internal.APIPublisherServiceComponent",
|
||||||
immediate = true)
|
immediate = true)
|
||||||
@ -52,6 +55,7 @@ public class APIPublisherServiceComponent {
|
|||||||
|
|
||||||
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
/* Registering declarative service instances exposed by DeviceManagementServiceComponent */
|
||||||
this.registerServices(componentContext);
|
this.registerServices(componentContext);
|
||||||
|
APIPublisherDataHolder.getInstance().setPermScopeMapping(new HashMap<>());
|
||||||
|
|
||||||
if (log.isDebugEnabled()) {
|
if (log.isDebugEnabled()) {
|
||||||
log.debug("Webapp publisher bundle has been successfully initialized");
|
log.debug("Webapp publisher bundle has been successfully initialized");
|
||||||
@ -116,4 +120,21 @@ public class APIPublisherServiceComponent {
|
|||||||
APIPublisherDataHolder.getInstance().setRegistryService(null);
|
APIPublisherDataHolder.getInstance().setRegistryService(null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Reference(
|
||||||
|
name = "io.entgra.meta.mgt",
|
||||||
|
service = io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService.class,
|
||||||
|
cardinality = ReferenceCardinality.OPTIONAL,
|
||||||
|
policy = ReferencePolicy.DYNAMIC,
|
||||||
|
unbind = "unsetMetaDataMgtService")
|
||||||
|
protected void setMetaDataMgtService(MetadataManagementService metadataManagementService) {
|
||||||
|
if (metadataManagementService != null && log.isDebugEnabled()) {
|
||||||
|
log.debug("Meta data mgt mgt service initialized");
|
||||||
|
}
|
||||||
|
APIPublisherDataHolder.getInstance().setMetadataManagementService(metadataManagementService);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void unsetMetaDataMgtService(MetadataManagementService metadataManagementService) {
|
||||||
|
APIPublisherDataHolder.getInstance().setMetadataManagementService(null);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,6 +17,21 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.apimgt.webapp.publisher.lifecycle.listener;
|
package io.entgra.device.mgt.core.apimgt.webapp.publisher.lifecycle.listener;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.dto.ApiScope;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceConfigurationManager;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.DeviceManagementConfig;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermission;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.config.permission.DefaultPermissions;
|
||||||
|
import org.apache.catalina.Lifecycle;
|
||||||
|
import org.apache.catalina.LifecycleEvent;
|
||||||
|
import org.apache.catalina.LifecycleListener;
|
||||||
|
import org.apache.catalina.core.StandardContext;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIConfig;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherService;
|
||||||
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherUtil;
|
import io.entgra.device.mgt.core.apimgt.webapp.publisher.APIPublisherUtil;
|
||||||
@ -35,7 +50,9 @@ import org.wso2.carbon.user.api.UserStoreException;
|
|||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@ -49,68 +66,123 @@ public class APIPublisherLifecycleListener implements LifecycleListener {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
|
public void lifecycleEvent(LifecycleEvent lifecycleEvent) {
|
||||||
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType()) && WebappPublisherConfig.getInstance()
|
if (Lifecycle.AFTER_START_EVENT.equals(lifecycleEvent.getType()) ) {
|
||||||
.isPublished()) {
|
if (WebappPublisherConfig.getInstance()
|
||||||
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
.isPublished()) {
|
||||||
ServletContext servletContext = context.getServletContext();
|
StandardContext context = (StandardContext) lifecycleEvent.getLifecycle();
|
||||||
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
ServletContext servletContext = context.getServletContext();
|
||||||
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
String param = servletContext.getInitParameter(PARAM_MANAGED_API_ENABLED);
|
||||||
|
boolean isManagedApi = (param != null && !param.isEmpty()) && Boolean.parseBoolean(param);
|
||||||
|
|
||||||
String profile = System.getProperty(PROPERTY_PROFILE);
|
String profile = System.getProperty(PROPERTY_PROFILE);
|
||||||
if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase())
|
if (WebappPublisherConfig.getInstance().getProfiles().getProfile().contains(profile.toLowerCase())
|
||||||
&& isManagedApi) {
|
&& isManagedApi) {
|
||||||
try {
|
try {
|
||||||
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
|
AnnotationProcessor annotationProcessor = new AnnotationProcessor(context);
|
||||||
Set<String> annotatedSwaggerAPIClasses = annotationProcessor.
|
Set<String> annotatedSwaggerAPIClasses = annotationProcessor.
|
||||||
scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName());
|
scanStandardContext(io.swagger.annotations.SwaggerDefinition.class.getName());
|
||||||
List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
|
List<APIResourceConfiguration> apiDefinitions = annotationProcessor.extractAPIInfo(servletContext,
|
||||||
annotatedSwaggerAPIClasses);
|
annotatedSwaggerAPIClasses);
|
||||||
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
|
|
||||||
APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
|
|
||||||
APIPublisherUtil.setResourceAuthTypes(servletContext,apiConfig);
|
|
||||||
try {
|
|
||||||
int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
|
|
||||||
getTenantId(apiConfig.getTenantDomain());
|
|
||||||
|
|
||||||
boolean isTenantActive = APIPublisherDataHolder.getInstance().
|
APIPublisherDataHolder apiPublisherDataHolder = APIPublisherDataHolder.getInstance();
|
||||||
getTenantManager().isTenantActive(tenantId);
|
MetadataManagementService metadataManagementService =
|
||||||
if (isTenantActive) {
|
apiPublisherDataHolder.getMetadataManagementService();
|
||||||
boolean isServerStarted = APIPublisherDataHolder.getInstance().isServerStarted();
|
Metadata metadata = metadataManagementService.retrieveMetadata("perm-scope-mapping");
|
||||||
if (isServerStarted) {
|
if (metadata != null) {
|
||||||
APIPublisherService apiPublisherService =
|
HashMap<String, String> permScopeMapping =
|
||||||
APIPublisherDataHolder.getInstance().getApiPublisherService();
|
new Gson().fromJson(metadata.getMetaValue().toString(), HashMap.class);
|
||||||
if (apiPublisherService == null) {
|
apiPublisherDataHolder.setPermScopeMapping(permScopeMapping);
|
||||||
throw new IllegalStateException(
|
|
||||||
"API Publisher service is not initialized properly");
|
|
||||||
}
|
|
||||||
apiPublisherService.publishAPI(apiConfig);
|
|
||||||
} else {
|
|
||||||
if (log.isDebugEnabled()) {
|
|
||||||
log.debug("Server has not started yet. Hence adding API '" +
|
|
||||||
apiConfig.getName() + "' to the queue");
|
|
||||||
}
|
|
||||||
APIPublisherDataHolder.getInstance().getUnpublishedApis().push(apiConfig);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
log.error("No tenant [" + apiConfig.getTenantDomain() + "] " +
|
|
||||||
"found when publishing the Web app");
|
|
||||||
}
|
|
||||||
} catch (Throwable e) {
|
|
||||||
log.error("Error occurred while publishing API '" + apiConfig.getName() +
|
|
||||||
"' with the context '" + apiConfig.getContext() +
|
|
||||||
"' and version '" + apiConfig.getVersion() + "'", e);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Map<String, String> permScopeMap = apiPublisherDataHolder.getPermScopeMapping();
|
||||||
|
for (APIResourceConfiguration apiDefinition : apiDefinitions) {
|
||||||
|
APIConfig apiConfig = APIPublisherUtil.buildApiConfig(servletContext, apiDefinition);
|
||||||
|
for (ApiScope scope : apiConfig.getScopes()) {
|
||||||
|
permScopeMap.put(scope.getPermissions(), scope.getKey());
|
||||||
|
}
|
||||||
|
APIPublisherUtil.setResourceAuthTypes(servletContext,apiConfig);
|
||||||
|
try {
|
||||||
|
int tenantId = APIPublisherDataHolder.getInstance().getTenantManager().
|
||||||
|
getTenantId(apiConfig.getTenantDomain());
|
||||||
|
|
||||||
|
boolean isTenantActive = APIPublisherDataHolder.getInstance().
|
||||||
|
getTenantManager().isTenantActive(tenantId);
|
||||||
|
if (isTenantActive) {
|
||||||
|
boolean isServerStarted = APIPublisherDataHolder.getInstance().isServerStarted();
|
||||||
|
if (isServerStarted) {
|
||||||
|
APIPublisherService apiPublisherService =
|
||||||
|
APIPublisherDataHolder.getInstance().getApiPublisherService();
|
||||||
|
if (apiPublisherService == null) {
|
||||||
|
throw new IllegalStateException(
|
||||||
|
"API Publisher service is not initialized properly");
|
||||||
|
}
|
||||||
|
apiPublisherService.publishAPI(apiConfig);
|
||||||
|
} else {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Server has not started yet. Hence adding API '" +
|
||||||
|
apiConfig.getName() + "' to the queue");
|
||||||
|
}
|
||||||
|
APIPublisherDataHolder.getInstance().getUnpublishedApis().push(apiConfig);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
log.error("No tenant [" + apiConfig.getTenantDomain() + "] " +
|
||||||
|
"found when publishing the Web app");
|
||||||
|
}
|
||||||
|
} catch (Throwable e) {
|
||||||
|
log.error("Error occurred while publishing API '" + apiConfig.getName() +
|
||||||
|
"' with the context '" + apiConfig.getContext() +
|
||||||
|
"' and version '" + apiConfig.getVersion() + "'", e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Metadata existingMetaData = metadataManagementService.retrieveMetadata("perm-scope" +
|
||||||
|
"-mapping");
|
||||||
|
if (existingMetaData != null) {
|
||||||
|
existingMetaData.setMetaValue(new Gson().toJson(permScopeMap));
|
||||||
|
metadataManagementService.updateMetadata(existingMetaData);
|
||||||
|
} else {
|
||||||
|
Metadata newMetaData = new Metadata();
|
||||||
|
newMetaData.setMetaKey("perm-scope-mapping");
|
||||||
|
|
||||||
|
DeviceManagementConfig deviceManagementConfig = DeviceConfigurationManager.getInstance().getDeviceManagementConfig();
|
||||||
|
DefaultPermissions defaultPermissions = deviceManagementConfig.getDefaultPermissions();
|
||||||
|
|
||||||
|
for (DefaultPermission defaultPermission : defaultPermissions.getDefaultPermissions()) {
|
||||||
|
permScopeMap.put(defaultPermission.getName(), defaultPermission.getScopeMapping().getKey());
|
||||||
|
}
|
||||||
|
newMetaData.setMetaValue(new Gson().toJson(permScopeMap));
|
||||||
|
metadataManagementService.createMetadata(newMetaData);
|
||||||
|
}
|
||||||
|
apiPublisherDataHolder.setPermScopeMapping(permScopeMap);
|
||||||
|
} catch (IOException e) {
|
||||||
|
log.error("Error encountered while discovering annotated classes", e);
|
||||||
|
} catch (ClassNotFoundException e) {
|
||||||
|
log.error("Error while scanning class for annotations", e);
|
||||||
|
} catch (UserStoreException e) {
|
||||||
|
log.error("Error while retrieving tenant admin user for the tenant domain"
|
||||||
|
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(), e);
|
||||||
|
} catch (Throwable e) {
|
||||||
|
// This is done to stop tomcat failure if a webapp failed to publish apis.
|
||||||
|
log.error("Failed to Publish api from " + servletContext.getContextPath(), e);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
}
|
||||||
log.error("Error encountered while discovering annotated classes", e);
|
} else {
|
||||||
} catch (ClassNotFoundException e) {
|
APIPublisherDataHolder apiPublisherDataHolder = APIPublisherDataHolder.getInstance();
|
||||||
log.error("Error while scanning class for annotations", e);
|
MetadataManagementService metadataManagementService =
|
||||||
} catch (UserStoreException e) {
|
apiPublisherDataHolder.getMetadataManagementService();
|
||||||
log.error("Error while retrieving tenant admin user for the tenant domain"
|
try {
|
||||||
+ PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain(), e);
|
Metadata existingMetaData = metadataManagementService.retrieveMetadata("perm-scope" +
|
||||||
} catch (Throwable e) {
|
"-mapping");
|
||||||
// This is done to stop tomcat failure if a webapp failed to publish apis.
|
if (existingMetaData != null) {
|
||||||
log.error("Failed to Publish api from " + servletContext.getContextPath(), e);
|
existingMetaData.setMetaValue(new Gson().toJson(apiPublisherDataHolder.getPermScopeMapping()
|
||||||
|
));
|
||||||
|
metadataManagementService.updateMetadata(existingMetaData);
|
||||||
|
} else {
|
||||||
|
log.error("Couldn't find 'perm-scope-mapping' Meta entry while API publishing has been turned" +
|
||||||
|
" off.");
|
||||||
|
}
|
||||||
|
} catch (MetadataManagementException e) {
|
||||||
|
log.error("Failed to Load Meta-Mgt data.", e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -54,7 +54,7 @@ public class AnnotationProcessor {
|
|||||||
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
private static final String PACKAGE_ORG_APACHE = "org.apache";
|
||||||
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus";
|
||||||
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework";
|
||||||
public static final String WILD_CARD = "/*";
|
public static final String WILD_CARD = "/";
|
||||||
private static final String SWAGGER_ANNOTATIONS_INFO = "info";
|
private static final String SWAGGER_ANNOTATIONS_INFO = "info";
|
||||||
private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";
|
private static final String SWAGGER_ANNOTATIONS_TAGS = "tags";
|
||||||
private static final String SWAGGER_ANNOTATIONS_EXTENSIONS = "extensions";
|
private static final String SWAGGER_ANNOTATIONS_EXTENSIONS = "extensions";
|
||||||
@ -77,7 +77,7 @@ public class AnnotationProcessor {
|
|||||||
private static final String ANNOTATIONS_SCOPES = "scopes";
|
private static final String ANNOTATIONS_SCOPES = "scopes";
|
||||||
private static final String ANNOTATIONS_SCOPE = "scope";
|
private static final String ANNOTATIONS_SCOPE = "scope";
|
||||||
private static final String DEFAULT_SCOPE_NAME = "default admin scope";
|
private static final String DEFAULT_SCOPE_NAME = "default admin scope";
|
||||||
private static final String DEFAULT_SCOPE_KEY = "perm:admin";
|
private static final String DEFAULT_SCOPE_KEY = "dm:admin";
|
||||||
private static final String DEFAULT_SCOPE_PERMISSION = "/permision/device-mgt";
|
private static final String DEFAULT_SCOPE_PERMISSION = "/permision/device-mgt";
|
||||||
private static final String DEFAULT_SCOPE_ROLE = "admin";
|
private static final String DEFAULT_SCOPE_ROLE = "admin";
|
||||||
|
|
||||||
@ -219,10 +219,9 @@ public class AnnotationProcessor {
|
|||||||
String permissions[];
|
String permissions[];
|
||||||
StringBuilder aggregatedPermissions;
|
StringBuilder aggregatedPermissions;
|
||||||
String roles[];
|
String roles[];
|
||||||
StringBuilder aggregatedRoles;
|
List<String> aggregatedRoles;
|
||||||
for (int i = 0; i < annotatedScopes.length; i++) {
|
for (int i = 0; i < annotatedScopes.length; i++) {
|
||||||
aggregatedPermissions = new StringBuilder();
|
aggregatedPermissions = new StringBuilder();
|
||||||
aggregatedRoles = new StringBuilder();
|
|
||||||
methodHandler = Proxy.getInvocationHandler(annotatedScopes[i]);
|
methodHandler = Proxy.getInvocationHandler(annotatedScopes[i]);
|
||||||
scope = new ApiScope();
|
scope = new ApiScope();
|
||||||
scope.setName(invokeMethod(scopeClass
|
scope.setName(invokeMethod(scopeClass
|
||||||
@ -241,11 +240,8 @@ public class AnnotationProcessor {
|
|||||||
scope.setPermissions(aggregatedPermissions.toString().trim());
|
scope.setPermissions(aggregatedPermissions.toString().trim());
|
||||||
roles = (String[]) methodHandler.invoke(annotatedScopes[i], scopeClass
|
roles = (String[]) methodHandler.invoke(annotatedScopes[i], scopeClass
|
||||||
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_ROLES, null), null);
|
.getMethod(SWAGGER_ANNOTATIONS_PROPERTIES_ROLES, null), null);
|
||||||
for (String role : roles) {
|
aggregatedRoles = Arrays.asList(roles);
|
||||||
aggregatedRoles.append(role);
|
scope.setRoles(aggregatedRoles);
|
||||||
aggregatedRoles.append(",");
|
|
||||||
}
|
|
||||||
scope.setRoles(aggregatedRoles.substring(0, aggregatedRoles.lastIndexOf(",")));
|
|
||||||
scopes.put(scope.getKey(), scope);
|
scopes.put(scope.getKey(), scope);
|
||||||
}
|
}
|
||||||
return scopes;
|
return scopes;
|
||||||
@ -296,11 +292,13 @@ public class AnnotationProcessor {
|
|||||||
// } else {
|
// } else {
|
||||||
// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) +
|
// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) +
|
||||||
// makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope");
|
// makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope");
|
||||||
|
// List<String> roles = new ArrayList<>();
|
||||||
|
// roles.add(DEFAULT_SCOPE_ROLE);
|
||||||
// scope = new ApiScope();
|
// scope = new ApiScope();
|
||||||
// scope.setName(DEFAULT_SCOPE_NAME);
|
// scope.setName(DEFAULT_SCOPE_NAME);
|
||||||
// scope.setDescription(DEFAULT_SCOPE_NAME);
|
// scope.setDescription(DEFAULT_SCOPE_NAME);
|
||||||
// scope.setKey(DEFAULT_SCOPE_KEY);
|
// scope.setKey(DEFAULT_SCOPE_KEY);
|
||||||
// scope.setRoles(DEFAULT_SCOPE_ROLE);
|
// scope.setRoles(roles);
|
||||||
// scope.setPermissions(DEFAULT_SCOPE_PERMISSION);
|
// scope.setPermissions(DEFAULT_SCOPE_PERMISSION);
|
||||||
// resource.setScope(scope);
|
// resource.setScope(scope);
|
||||||
// }
|
// }
|
||||||
@ -534,11 +532,13 @@ public class AnnotationProcessor {
|
|||||||
} else {
|
} else {
|
||||||
// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) +
|
// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) +
|
||||||
// makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope");
|
// makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope");
|
||||||
|
List<String> roles = new ArrayList<>();
|
||||||
|
roles.add(DEFAULT_SCOPE_ROLE);
|
||||||
scope = new ApiScope();
|
scope = new ApiScope();
|
||||||
scope.setName(DEFAULT_SCOPE_NAME);
|
scope.setName(DEFAULT_SCOPE_NAME);
|
||||||
scope.setDescription(DEFAULT_SCOPE_NAME);
|
scope.setDescription(DEFAULT_SCOPE_NAME);
|
||||||
scope.setKey(DEFAULT_SCOPE_KEY);
|
scope.setKey(DEFAULT_SCOPE_KEY);
|
||||||
scope.setRoles(DEFAULT_SCOPE_ROLE);
|
scope.setRoles(roles);
|
||||||
scope.setPermissions(DEFAULT_SCOPE_PERMISSION);
|
scope.setPermissions(DEFAULT_SCOPE_PERMISSION);
|
||||||
apiResource.setScope(scope);
|
apiResource.setScope(scope);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,9 +37,9 @@ public class TestUtils {
|
|||||||
template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot");
|
template.setResourceURI("https://localhost:9443/api/device-mgt/windows/v1.0/admin/devices/reboot");
|
||||||
template.setUriTemplate(uriTemplate);
|
template.setUriTemplate(uriTemplate);
|
||||||
ApiScope scope = new ApiScope();
|
ApiScope scope = new ApiScope();
|
||||||
scope.setKey("perm:windows:reboot");
|
scope.setKey("win:ops:reboot");
|
||||||
scope.setName("Reboot");
|
scope.setName("Reboot");
|
||||||
scope.setRoles("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot");
|
scope.setPermissions("/permission/admin/device-mgt/devices/owning-device/operations/windows/reboot");
|
||||||
scope.setDescription("Lock reset on Windows devices");
|
scope.setDescription("Lock reset on Windows devices");
|
||||||
template.setScope(scope);
|
template.setScope(scope);
|
||||||
uriTemplates.add(template);
|
uriTemplates.add(template);
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -0,0 +1,86 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common;
|
||||||
|
|
||||||
|
public class DepConfig {
|
||||||
|
|
||||||
|
private String agentPackageName;
|
||||||
|
private String consumerKey;
|
||||||
|
private String consumerSecret;
|
||||||
|
private String accessToken;
|
||||||
|
private String accessSecret;
|
||||||
|
private String accessTokenExpiry;
|
||||||
|
private String vppToken;
|
||||||
|
|
||||||
|
public String getAgentPackageName() {
|
||||||
|
return agentPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAgentPackageName(String agentPackageName) {
|
||||||
|
this.agentPackageName = agentPackageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerKey() {
|
||||||
|
return consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerKey(String consumerKey) {
|
||||||
|
this.consumerKey = consumerKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getConsumerSecret() {
|
||||||
|
return consumerSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setConsumerSecret(String consumerSecret) {
|
||||||
|
this.consumerSecret = consumerSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessToken() {
|
||||||
|
return accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessToken(String accessToken) {
|
||||||
|
this.accessToken = accessToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVppToken() {
|
||||||
|
return vppToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVppToken(String vppToken) {
|
||||||
|
this.vppToken = vppToken;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessSecret() {
|
||||||
|
return accessSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessSecret(String accessSecret) {
|
||||||
|
this.accessSecret = accessSecret;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAccessTokenExpiry() {
|
||||||
|
return accessTokenExpiry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAccessTokenExpiry(String accessTokenExpiry) {
|
||||||
|
this.accessTokenExpiry = accessTokenExpiry;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,95 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class ItuneAppDTO {
|
||||||
|
int id;
|
||||||
|
String packageName;
|
||||||
|
String version;
|
||||||
|
String description;
|
||||||
|
String title;
|
||||||
|
String paymentMethod;
|
||||||
|
String iconURL;
|
||||||
|
String category;
|
||||||
|
|
||||||
|
public String getCategory() {
|
||||||
|
return category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCategory(String category) {
|
||||||
|
this.category = category;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getIconURL() {
|
||||||
|
return iconURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setIconURL(String iconURL) {
|
||||||
|
this.iconURL = iconURL;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPackageName() {
|
||||||
|
return packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPackageName(String packageName) {
|
||||||
|
this.packageName = packageName;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public String getVersion() {
|
||||||
|
return version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersion(String version) {
|
||||||
|
this.version = version;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDescription() {
|
||||||
|
return description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDescription(String description) {
|
||||||
|
this.description = description;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPaymentMethod() {
|
||||||
|
return paymentMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPaymentMethod(String paymentMethod) {
|
||||||
|
this.paymentMethod = paymentMethod;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,29 +15,23 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class ProxyResponse {
|
||||||
|
|
||||||
|
private int code;
|
||||||
|
private String data;
|
||||||
|
private String executorResponse;
|
||||||
|
|
||||||
.dontfloat {
|
public int getCode() { return code; }
|
||||||
clear:both;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden-div {
|
public void setCode(int code) { this.code = code; }
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.hidden-input {
|
public String getData() { return data; }
|
||||||
display: none;
|
|
||||||
}
|
|
||||||
|
|
||||||
.event-wrapper{
|
public void setData(String data) { this.data = data; }
|
||||||
margin-top: 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wr-btn-horizontal{
|
public String getExecutorResponse() { return executorResponse; }
|
||||||
padding: 7px 10px;
|
|
||||||
}
|
|
||||||
|
|
||||||
.wr-btn-secondary{
|
public void setExecutorResponse(String executorResponse) { this.executorResponse = executorResponse; }
|
||||||
background-color: #617d8b;
|
|
||||||
}
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class VppAssetDTO extends VppItuneAssetDTO {
|
||||||
|
int id;
|
||||||
|
int appId;
|
||||||
|
int tenantId;
|
||||||
|
String createdTime;
|
||||||
|
String lastUpdatedTime;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAppId() {
|
||||||
|
return appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAppId(int appId) {
|
||||||
|
this.appId = appId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(String createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,113 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class VppAssociationDTO {
|
||||||
|
int id;
|
||||||
|
String adamId;
|
||||||
|
String clientUserId;
|
||||||
|
String pricingParam;
|
||||||
|
String associationType;
|
||||||
|
|
||||||
|
int assetId;
|
||||||
|
int clientId;
|
||||||
|
int tenantId;
|
||||||
|
String createdTime;
|
||||||
|
String lastUpdatedTime;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdamId() {
|
||||||
|
return adamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdamId(String adamId) {
|
||||||
|
this.adamId = adamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getClientUserId() {
|
||||||
|
return clientUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientUserId(String clientUserId) {
|
||||||
|
this.clientUserId = clientUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPricingParam() {
|
||||||
|
return pricingParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricingParam(String pricingParam) {
|
||||||
|
this.pricingParam = pricingParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAssociationType() {
|
||||||
|
return associationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssociationType(String associationType) {
|
||||||
|
this.associationType = associationType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAssetId() {
|
||||||
|
return assetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssetId(int assetId) {
|
||||||
|
this.assetId = assetId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getClientId() {
|
||||||
|
return clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientId(int clientId) {
|
||||||
|
this.clientId = clientId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(String createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,109 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the String LicenseString ); 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
|
||||||
|
* String AS ISString BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VppItuneAssetDTO {
|
||||||
|
|
||||||
|
|
||||||
|
String adamId;
|
||||||
|
String assignedCount;
|
||||||
|
String availableCount;
|
||||||
|
String deviceAssignable;
|
||||||
|
String pricingParam;
|
||||||
|
String productType;
|
||||||
|
String retiredCount;
|
||||||
|
String revocable;
|
||||||
|
|
||||||
|
List<String> supportedPlatforms;
|
||||||
|
|
||||||
|
public List<String> getSupportedPlatforms() {
|
||||||
|
return supportedPlatforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSupportedPlatforms(List<String> supportedPlatforms) {
|
||||||
|
this.supportedPlatforms = supportedPlatforms;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAdamId() {
|
||||||
|
return adamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAdamId(String adamId) {
|
||||||
|
this.adamId = adamId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAssignedCount() {
|
||||||
|
return assignedCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssignedCount(String assignedCount) {
|
||||||
|
this.assignedCount = assignedCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getAvailableCount() {
|
||||||
|
return availableCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAvailableCount(String availableCount) {
|
||||||
|
this.availableCount = availableCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDeviceAssignable() {
|
||||||
|
return deviceAssignable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceAssignable(String deviceAssignable) {
|
||||||
|
this.deviceAssignable = deviceAssignable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPricingParam() {
|
||||||
|
return pricingParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPricingParam(String pricingParam) {
|
||||||
|
this.pricingParam = pricingParam;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getProductType() {
|
||||||
|
return productType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setProductType(String productType) {
|
||||||
|
this.productType = productType;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRetiredCount() {
|
||||||
|
return retiredCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRetiredCount(String retiredCount) {
|
||||||
|
this.retiredCount = retiredCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRevocable() {
|
||||||
|
return revocable;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRevocable(String revocable) {
|
||||||
|
this.revocable = revocable;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,67 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class VppItuneUserDTO {
|
||||||
|
String clientUserId;
|
||||||
|
String inviteCode;
|
||||||
|
String status;
|
||||||
|
String email;
|
||||||
|
String managedId;
|
||||||
|
|
||||||
|
public String getClientUserId() {
|
||||||
|
return clientUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientUserId(String clientUserId) {
|
||||||
|
this.clientUserId = clientUserId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getInviteCode() {
|
||||||
|
return inviteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInviteCode(String inviteCode) {
|
||||||
|
this.inviteCode = inviteCode;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getStatus() {
|
||||||
|
return status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setStatus(String status) {
|
||||||
|
this.status = status;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getManagedId() {
|
||||||
|
return managedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setManagedId(String managedId) {
|
||||||
|
this.managedId = managedId;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -0,0 +1,85 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class VppPaginationDTO {
|
||||||
|
|
||||||
|
int currentPageIndex;
|
||||||
|
int size;
|
||||||
|
String tokenExpirationDate;
|
||||||
|
int nextPageIndex;
|
||||||
|
int totalPages;
|
||||||
|
String uId;
|
||||||
|
String versionId;
|
||||||
|
|
||||||
|
public int getCurrentPageIndex() {
|
||||||
|
return currentPageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCurrentPageIndex(int currentPageIndex) {
|
||||||
|
this.currentPageIndex = currentPageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getSize() {
|
||||||
|
return size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSize(int size) {
|
||||||
|
this.size = size;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTokenExpirationDate() {
|
||||||
|
return tokenExpirationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTokenExpirationDate(String tokenExpirationDate) {
|
||||||
|
this.tokenExpirationDate = tokenExpirationDate;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getNextPageIndex() {
|
||||||
|
return nextPageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setNextPageIndex(int nextPageIndex) {
|
||||||
|
this.nextPageIndex = nextPageIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTotalPages() {
|
||||||
|
return totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTotalPages(int totalPages) {
|
||||||
|
this.totalPages = totalPages;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getuId() {
|
||||||
|
return uId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setuId(String uId) {
|
||||||
|
this.uId = uId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVersionId() {
|
||||||
|
return versionId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVersionId(String versionId) {
|
||||||
|
this.versionId = versionId;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,92 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.dto;
|
||||||
|
|
||||||
|
public class VppUserDTO extends VppItuneUserDTO {
|
||||||
|
int id;
|
||||||
|
String dmUsername;
|
||||||
|
int tenantId;
|
||||||
|
String createdTime;
|
||||||
|
String lastUpdatedTime;
|
||||||
|
String tmpPassword;
|
||||||
|
|
||||||
|
public int getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(int id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getDmUsername() {
|
||||||
|
return dmUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDmUsername(String dmUsername) {
|
||||||
|
this.dmUsername = dmUsername;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getTenantId() {
|
||||||
|
return tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTenantId(int tenantId) {
|
||||||
|
this.tenantId = tenantId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCreatedTime() {
|
||||||
|
return createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCreatedTime(String createdTime) {
|
||||||
|
this.createdTime = createdTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getLastUpdatedTime() {
|
||||||
|
return lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setLastUpdatedTime(String lastUpdatedTime) {
|
||||||
|
this.lastUpdatedTime = lastUpdatedTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTmpPassword() {
|
||||||
|
return tmpPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setTmpPassword(String tmpPassword) {
|
||||||
|
this.tmpPassword = tmpPassword;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String toString() {
|
||||||
|
return "VppUserDTO{" +
|
||||||
|
"id=" + id +
|
||||||
|
", dmUsername='" + dmUsername + '\'' +
|
||||||
|
", tenantId=" + tenantId +
|
||||||
|
", createdTime='" + createdTime + '\'' +
|
||||||
|
", lastUpdatedTime='" + lastUpdatedTime + '\'' +
|
||||||
|
", tmpPassword='" + tmpPassword + '\'' +
|
||||||
|
", clientUserId='" + clientUserId + '\'' +
|
||||||
|
", inviteCode='" + inviteCode + '\'' +
|
||||||
|
", status='" + status + '\'' +
|
||||||
|
", email='" + email + '\'' +
|
||||||
|
", managedId='" + managedId + '\'' +
|
||||||
|
'}';
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -108,6 +108,12 @@ public class Application {
|
|||||||
value = "if the app is favoured by the user")
|
value = "if the app is favoured by the user")
|
||||||
private boolean isFavourite;
|
private boolean isFavourite;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "isExternalAppStoreApp",
|
||||||
|
value = "Is the app coming from an external application store",
|
||||||
|
required = true,
|
||||||
|
example = "true or false")
|
||||||
|
private boolean isExternalAppStoreApp;
|
||||||
|
|
||||||
public String getPackageName() {
|
public String getPackageName() {
|
||||||
return packageName;
|
return packageName;
|
||||||
}
|
}
|
||||||
@ -194,4 +200,12 @@ public class Application {
|
|||||||
public void setFavourite(boolean favourite) {
|
public void setFavourite(boolean favourite) {
|
||||||
isFavourite = favourite;
|
isFavourite = favourite;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public boolean isExternalAppStoreApp() {
|
||||||
|
return isExternalAppStoreApp;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setExternalAppStoreApp(boolean externalAppStoreApp) {
|
||||||
|
isExternalAppStoreApp = externalAppStoreApp;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -17,14 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.application.mgt.common.services;
|
package io.entgra.device.mgt.core.application.mgt.common.services;
|
||||||
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationType;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.Filter;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.LifecycleState;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ResourceManagementException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.ResourceManagementException;
|
||||||
@ -34,8 +27,21 @@ import io.entgra.device.mgt.core.application.mgt.common.response.Category;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.response.Tag;
|
import io.entgra.device.mgt.core.application.mgt.common.response.Tag;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationReleaseDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.Filter;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.LifecycleState;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.CustomAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.EntAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppReleaseWrapper;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -269,6 +275,17 @@ public interface ApplicationManager {
|
|||||||
*/
|
*/
|
||||||
ApplicationDTO getApplication(int applicationId) throws ApplicationManagementException;
|
ApplicationDTO getApplication(int applicationId) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This method is responsible to provide application data for given deviceId.
|
||||||
|
*
|
||||||
|
* @param deviceId id of the device
|
||||||
|
* @return {@link ApplicationDTO}
|
||||||
|
* @throws ApplicationManagementException
|
||||||
|
* if an error occurred while getting subscribed app details for relevant device id,
|
||||||
|
*/
|
||||||
|
ApplicationList getSubscribedAppsOfDevice(int deviceId, PaginationRequest request)
|
||||||
|
throws ApplicationManagementException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get the Application for given Id.
|
* To get the Application for given Id.
|
||||||
*
|
*
|
||||||
|
|||||||
@ -27,6 +27,7 @@ import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
|||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
|
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
@ -207,4 +208,13 @@ public interface SubscriptionManager {
|
|||||||
*/
|
*/
|
||||||
PaginationResult getAppInstalledSubscribeDevices(PaginationRequest request, String appUUID, String subType,
|
PaginationResult getAppInstalledSubscribeDevices(PaginationRequest request, String appUUID, String subType,
|
||||||
String subTypeName) throws ApplicationManagementException;
|
String subTypeName) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* This method is responsible for retrieving application details of the passed operation id.
|
||||||
|
* @param id ID of the related operation
|
||||||
|
* @return {@link Activity} Activity result of the app information.
|
||||||
|
* @throws {@link SubscriptionManagementException} Exception of the subscription management
|
||||||
|
*/
|
||||||
|
Activity getOperationAppDetails(String id) throws SubscriptionManagementException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,52 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.services;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface VPPApplicationManager {
|
||||||
|
|
||||||
|
VppUserDTO addUser(VppUserDTO userDTO) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
void updateUser(VppUserDTO userDTO) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
void syncUsers(String clientId) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
void syncAssets(int nextPageIndex) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
VppAssetDTO getAssetByAppId(int appId) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
ProxyResponse callVPPBackend(String url, String payload, String accessToken, String method) throws IOException;
|
||||||
|
|
||||||
|
boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
|
||||||
|
ApplicationManagementException;
|
||||||
|
|
||||||
|
VppAssociationDTO getAssociation(int assetId, int userId) throws ApplicationManagementException;
|
||||||
|
|
||||||
|
VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws ApplicationManagementException;
|
||||||
|
}
|
||||||
@ -0,0 +1,47 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VppAssociateRequestWrapper {
|
||||||
|
|
||||||
|
List<VppItuneAssetDTO> assets;
|
||||||
|
List<String> clientUserIds;
|
||||||
|
|
||||||
|
public List<VppItuneAssetDTO> getAssets() {
|
||||||
|
return assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAssets(List<VppItuneAssetDTO> assets) {
|
||||||
|
this.assets = assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<String> getClientUserIds() {
|
||||||
|
return clientUserIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setClientUserIds(List<String> clientUserIds) {
|
||||||
|
this.clientUserIds = clientUserIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,22 +15,25 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||||
|
|
||||||
function onRequest(context) {
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
var deviceModule = require("/app/modules/business-controllers/device.js")["deviceModule"];
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||||
var deviceMgtProps = require("/app/modules/conf-reader/main.js")["conf"];
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppPaginationDTO;
|
||||||
|
|
||||||
context["permissions"] = userModule.getUIPermissions();
|
import java.util.ArrayList;
|
||||||
if (userModule.isAuthorized("/permission/admin/device-mgt/admin/device-type")) {
|
import java.util.List;
|
||||||
context["editPermitted"] = true;
|
|
||||||
}
|
|
||||||
var deviceTypeCount = deviceModule.getDeviceTypeCount();
|
|
||||||
|
|
||||||
if (deviceTypeCount > 0) {
|
public class VppItuneAssetResponseWrapper extends VppPaginationDTO {
|
||||||
context["hasDeviceTypes"] = true;
|
|
||||||
} else {
|
List<VppAssetDTO> assets;
|
||||||
context["hasDeviceTypes"] = false;
|
|
||||||
|
public List<VppAssetDTO> getAssets() {
|
||||||
|
return assets;
|
||||||
}
|
}
|
||||||
|
|
||||||
return context;
|
public void setAssets(List<VppAssetDTO> assets) {
|
||||||
}
|
this.assets = assets;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,13 +15,26 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||||
|
|
||||||
function reformatRadius(val){
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||||
if(val != "" && !isNaN(val)){
|
|
||||||
$("#fRadius" ).val(parseFloat(Math.round(val * 100) / 100).toFixed(2));
|
import java.util.ArrayList;
|
||||||
} else{
|
import java.util.List;
|
||||||
var message = "Invalid Fluctuation Radius Provided.";
|
|
||||||
noty({text: message, type: 'error'});
|
public class VppItuneUserRequestWrapper {
|
||||||
}
|
|
||||||
|
List<VppItuneUserDTO> users;
|
||||||
|
|
||||||
|
public VppItuneUserRequestWrapper() {
|
||||||
|
users = new ArrayList<>();
|
||||||
|
}
|
||||||
|
public List<VppItuneUserDTO> getUser() {
|
||||||
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setUser(List<VppItuneUserDTO> users) {
|
||||||
|
this.users = users;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -15,21 +15,26 @@
|
|||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.common.wrapper;
|
||||||
|
|
||||||
function onRequest(context) {
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||||
var Encode = Packages.org.owasp.encoder.Encode;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppPaginationDTO;
|
||||||
session.invalidate();
|
|
||||||
var viewModel = {};
|
|
||||||
|
|
||||||
var stat = request.getParameter("status");
|
import java.util.ArrayList;
|
||||||
var statusMessage = request.getParameter("statusMsg");
|
import java.util.List;
|
||||||
|
|
||||||
if (!stat || !statusMessage) {
|
public class VppItuneUserResponseWrapper extends VppPaginationDTO {
|
||||||
stat = "Authentication Error!";
|
|
||||||
statusMessage = "Something went wrong during the authentication process.Please try signing in again.";
|
List<VppItuneUserDTO> users;
|
||||||
|
|
||||||
|
public VppItuneUserResponseWrapper() {
|
||||||
|
users = new ArrayList<>();
|
||||||
|
}
|
||||||
|
public List<VppItuneUserDTO> getUser() {
|
||||||
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
viewModel.stat = Encode.forHtmlContent(stat);
|
public void setUser(List<VppItuneUserDTO> users) {
|
||||||
viewModel.statusMessage = Encode.forHtmlContent(statusMessage);
|
this.users = users;
|
||||||
return viewModel;
|
}
|
||||||
}
|
}
|
||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>application-mgt</artifactId>
|
<artifactId>application-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -173,6 +173,11 @@
|
|||||||
</build>
|
</build>
|
||||||
|
|
||||||
<dependencies>
|
<dependencies>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.apache.httpcomponents</groupId>
|
||||||
|
<artifactId>httpclient</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.apache.felix</groupId>
|
<groupId>org.apache.felix</groupId>
|
||||||
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
|
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
|
||||||
|
|||||||
@ -22,6 +22,7 @@ import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.CategoryDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.CategoryDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.TagDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.TagDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
@ -150,6 +151,16 @@ public interface ApplicationDAO {
|
|||||||
*/
|
*/
|
||||||
ApplicationDTO getApplication(int applicationId, int tenantId) throws ApplicationManagementDAOException;
|
ApplicationDTO getApplication(int applicationId, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the application with the given id
|
||||||
|
*
|
||||||
|
* @param deviceId ID of the device which the apps are installed on.
|
||||||
|
* @param tenantId ID of the tenant.
|
||||||
|
* @return the application
|
||||||
|
* @throws ApplicationManagementDAOException ApplicationDTO Management DAO Exception.
|
||||||
|
*/
|
||||||
|
List<ApplicationDTO> getSubscribedAppsOfDevice(int deviceId, int tenantId, PaginationRequest request) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get the application with the given uuid
|
* To get the application with the given uuid
|
||||||
*
|
*
|
||||||
|
|||||||
@ -23,6 +23,7 @@ import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDT
|
|||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.SubscriptionManagementException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -252,4 +253,15 @@ public interface SubscriptionDAO {
|
|||||||
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
|
* @throws {@link ApplicationManagementDAOException} if connections establishment fails.
|
||||||
*/
|
*/
|
||||||
Map<Integer,String> getCurrentInstalledAppVersion(int appId, List<Integer> deviceIdList, String installedVersion) throws ApplicationManagementDAOException;
|
Map<Integer,String> getCurrentInstalledAppVersion(int appId, List<Integer> deviceIdList, String installedVersion) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves app details by operation id.
|
||||||
|
*
|
||||||
|
* @param operationId ID of the operation which app details needs to be retrieved
|
||||||
|
* @param tenantId ID of tenant
|
||||||
|
* @return {@link Activity}
|
||||||
|
* @throws ApplicationManagementDAOException if error occurred while retrieving the app details
|
||||||
|
*/
|
||||||
|
Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,46 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.dao;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
|
||||||
|
public interface VppApplicationDAO {
|
||||||
|
|
||||||
|
int addVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppUserDTO getUserByDMUsername(String emmUsername, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppAssetDTO getAssetByAppId(int appId, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
int addAsset(VppAssetDTO vppAssetDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppAssociationDTO getAssociation(int assetId, int userId, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
int addAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
|
||||||
|
VppAssociationDTO updateAssociation(VppAssociationDTO vppAssociationDTO, int tenantId) throws ApplicationManagementDAOException;
|
||||||
|
}
|
||||||
@ -17,25 +17,36 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.application.mgt.core.dao.common;
|
package io.entgra.device.mgt.core.application.mgt.core.dao.common;
|
||||||
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.UnsupportedDatabaseEngineException;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.*;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.*;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.PostgreSQLApplicationDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.SQLServerApplicationDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.OracleApplicationReleaseDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.PostgreSQLApplicationReleaseDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.SQLServerApplicationReleaseDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.GenericSPApplicationDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.GenericSPApplicationDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.OracleSPApplicationDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.OracleSPApplicationDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.PostgreSQLSPApplicationDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.PostgreSQLSPApplicationDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.SQLServerSPApplicationDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.spapplication.SQLServerSPApplicationDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.OracleVisibilityDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.PostgreSQLVisibilityDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.SQLServerVisibilityDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp.GenericVppApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp.OracleVppApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp.PostgreSQLVppApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp.SQLServerVppApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.UnsupportedDatabaseEngineException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.PostgreSQLApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.SQLServerApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.OracleApplicationReleaseDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.PostgreSQLApplicationReleaseDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.SQLServerApplicationReleaseDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.OracleLifecycleStateDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.OracleLifecycleStateDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.PostgreSQLLifecycleStateDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.PostgreSQLLifecycleStateDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.SQLServerLifecycleStateDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.SQLServerLifecycleStateDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.GenericReviewDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.GenericReviewDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.GenericApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.release.GenericApplicationReleaseDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.application.OracleApplicationDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.lifecyclestate.GenericLifecycleStateDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.OracleReviewDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.OracleReviewDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.PostgreSQLReviewDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.PostgreSQLReviewDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.SQLServerReviewDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.review.SQLServerReviewDAOImpl;
|
||||||
@ -43,14 +54,7 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.Gene
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.OracleSubscriptionDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.OracleSubscriptionDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.PostgreSQLSubscriptionDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.PostgreSQLSubscriptionDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.SQLServerSubscriptionDAOImpl;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription.SQLServerSubscriptionDAOImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.GenericVisibilityDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.OracleVisibilityDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.PostgreSQLVisibilityDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.visibility.SQLServerVisibilityDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import javax.sql.DataSource;
|
import javax.sql.DataSource;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
@ -226,4 +230,28 @@ public class ApplicationManagementDAOFactory {
|
|||||||
}
|
}
|
||||||
throw new IllegalStateException("Database engine has not initialized properly.");
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* To get the instance of VppApplicationImplementation of the particular database engine.
|
||||||
|
* @return specific VppApplicationImplementation
|
||||||
|
*/
|
||||||
|
public static VppApplicationDAO getVppApplicationDAO() {
|
||||||
|
if (databaseEngine != null) {
|
||||||
|
switch (databaseEngine) {
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_H2:
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MYSQL:
|
||||||
|
return new GenericVppApplicationDAOImpl();
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_POSTGRESQL:
|
||||||
|
return new PostgreSQLVppApplicationDAO();
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_ORACLE:
|
||||||
|
return new OracleVppApplicationDAOImpl();
|
||||||
|
case Constants.DataBaseTypes.DB_TYPE_MSSQL:
|
||||||
|
return new SQLServerVppApplicationDAOImpl();
|
||||||
|
default:
|
||||||
|
throw new UnsupportedDatabaseEngineException("Unsupported database engine : " + databaseEngine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw new IllegalStateException("Database engine has not initialized properly.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -29,6 +29,7 @@ import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManag
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
@ -652,6 +653,84 @@ public class GenericApplicationDAOImpl extends AbstractDAOImpl implements Applic
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<ApplicationDTO> getSubscribedAppsOfDevice(int deviceId, int tenantId, PaginationRequest request) throws
|
||||||
|
ApplicationManagementDAOException {
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.debug("Getting all installed apps of device " + deviceId
|
||||||
|
+ " from the database");
|
||||||
|
}
|
||||||
|
List<ApplicationDTO> appList = null;
|
||||||
|
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "AP_APP.ID AS APP_ID, "
|
||||||
|
+ "AP_APP.NAME AS APP_NAME, "
|
||||||
|
+ "AP_APP.DESCRIPTION AS APP_DESCRIPTION, "
|
||||||
|
+ "AP_APP.TYPE AS APP_TYPE, "
|
||||||
|
+ "AP_APP.STATUS AS APP_STATUS, "
|
||||||
|
+ "AP_APP.SUB_TYPE AS APP_SUB_TYPE, "
|
||||||
|
+ "AP_APP.CURRENCY AS APP_CURRENCY, "
|
||||||
|
+ "AP_APP.RATING AS APP_RATING, "
|
||||||
|
+ "AP_APP.DEVICE_TYPE_ID AS APP_DEVICE_TYPE_ID, "
|
||||||
|
+ "AP_APP_RELEASE.ID AS RELEASE_ID, "
|
||||||
|
+ "AP_APP_RELEASE.DESCRIPTION AS RELEASE_DESCRIPTION, "
|
||||||
|
+ "AP_APP_RELEASE.VERSION AS RELEASE_VERSION, "
|
||||||
|
+ "AP_APP_RELEASE.UUID AS RELEASE_UUID, "
|
||||||
|
+ "AP_APP_RELEASE.RELEASE_TYPE AS RELEASE_TYPE, "
|
||||||
|
+ "AP_APP_RELEASE.INSTALLER_LOCATION AS AP_RELEASE_STORED_LOC, "
|
||||||
|
+ "AP_APP_RELEASE.ICON_LOCATION AS AP_RELEASE_ICON_LOC, "
|
||||||
|
+ "AP_APP_RELEASE.BANNER_LOCATION AS AP_RELEASE_BANNER_LOC, "
|
||||||
|
+ "AP_APP_RELEASE.SC_1_LOCATION AS AP_RELEASE_SC1, "
|
||||||
|
+ "AP_APP_RELEASE.SC_2_LOCATION AS AP_RELEASE_SC2, "
|
||||||
|
+ "AP_APP_RELEASE.SC_3_LOCATION AS AP_RELEASE_SC3, "
|
||||||
|
+ "AP_APP_RELEASE.APP_HASH_VALUE AS RELEASE_HASH_VALUE, "
|
||||||
|
+ "AP_APP_RELEASE.APP_PRICE AS RELEASE_PRICE, "
|
||||||
|
+ "AP_APP_RELEASE.APP_META_INFO AS RELEASE_META_INFO, "
|
||||||
|
+ "AP_APP_RELEASE.PACKAGE_NAME AS PACKAGE_NAME, "
|
||||||
|
+ "AP_APP_RELEASE.SUPPORTED_OS_VERSIONS AS RELEASE_SUP_OS_VERSIONS, "
|
||||||
|
+ "AP_APP_RELEASE.RATING AS RELEASE_RATING, "
|
||||||
|
+ "AP_APP_RELEASE.CURRENT_STATE AS RELEASE_CURRENT_STATE, "
|
||||||
|
+ "AP_APP_RELEASE.RATED_USERS AS RATED_USER_COUNT "
|
||||||
|
+ "FROM AP_APP "
|
||||||
|
+ "JOIN AP_APP_RELEASE ON AP_APP.ID = AP_APP_RELEASE.AP_APP_ID "
|
||||||
|
+ "JOIN AP_DEVICE_SUBSCRIPTION ON AP_APP_RELEASE.ID = AP_DEVICE_SUBSCRIPTION.AP_APP_RELEASE_ID "
|
||||||
|
+ "WHERE AP_DEVICE_SUBSCRIPTION.DM_DEVICE_ID = ? AND AP_DEVICE_SUBSCRIPTION.TENANT_ID= ? "
|
||||||
|
+"AND AP_DEVICE_SUBSCRIPTION.STATUS= 'COMPLETED'";
|
||||||
|
|
||||||
|
if (request != null) {
|
||||||
|
sql = sql + " LIMIT ?,?";
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, deviceId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
if (request != null) {
|
||||||
|
stmt.setInt(3, request.getStartIndex());
|
||||||
|
stmt.setInt(4, request.getRowCount());
|
||||||
|
}
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
appList = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
ApplicationDTO app = DAOUtil.loadDeviceApp(rs);
|
||||||
|
appList.add(app);
|
||||||
|
}
|
||||||
|
return appList;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining the DB connection for getting all apps installed on the device of "
|
||||||
|
+ "device Id: " + deviceId + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred while while running SQL to get all installed apps of device with device Id: " + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId)
|
public boolean updateApplication(ApplicationDTO applicationDTO, int tenantId)
|
||||||
throws ApplicationManagementDAOException {
|
throws ApplicationManagementDAOException {
|
||||||
|
|||||||
@ -17,19 +17,20 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
|
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.subscription;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
|
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubAction;
|
import io.entgra.device.mgt.core.application.mgt.common.SubAction;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.DeviceSubscriptionDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ScheduledSubscriptionDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
|
|
||||||
import java.sql.*;
|
import java.sql.*;
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
@ -1425,4 +1426,44 @@ public class GenericSubscriptionDAOImpl extends AbstractDAOImpl implements Subsc
|
|||||||
throw new ApplicationManagementDAOException(msg, e);
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Activity getOperationAppDetails(int operationId, int tenantId) throws ApplicationManagementDAOException {
|
||||||
|
try {
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "AP.NAME, "
|
||||||
|
+ "AP.TYPE, "
|
||||||
|
+ "AR.PACKAGE_NAME, "
|
||||||
|
+ "AR.VERSION, "
|
||||||
|
+ "DS.SUBSCRIBED_BY, "
|
||||||
|
+ "DS.STATUS, "
|
||||||
|
+ "DS.ACTION_TRIGGERED_FROM "
|
||||||
|
+ "FROM AP_APP_SUB_OP_MAPPING SOP "
|
||||||
|
+ "JOIN AP_DEVICE_SUBSCRIPTION DS ON SOP.AP_DEVICE_SUBSCRIPTION_ID = DS.ID "
|
||||||
|
+ "JOIN AP_APP_RELEASE AR ON DS.AP_APP_RELEASE_ID = AR.ID "
|
||||||
|
+ "JOIN AP_APP AP ON AP.ID = AR.AP_APP_ID "
|
||||||
|
+ " WHERE SOP.OPERATION_ID = ? AND SOP.TENANT_ID = ?";
|
||||||
|
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, operationId);
|
||||||
|
stmt.setInt(2,tenantId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
return DAOUtil.loadOperationActivity(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg =
|
||||||
|
"Error occurred while getting the app details from the database related to operation " + operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to retrieve app details of operation" + operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (UnexpectedServerErrorException e) {
|
||||||
|
String msg = "More than one app for operation " + operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,508 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.impl.AbstractDAOImpl;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.DAOUtil;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class GenericVppApplicationDAOImpl extends AbstractDAOImpl implements VppApplicationDAO {
|
||||||
|
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
int vppUserId = -1;
|
||||||
|
String sql = "INSERT INTO "
|
||||||
|
+ "AP_VPP_USER("
|
||||||
|
+ "CLIENT_USER_ID, "
|
||||||
|
+ "DM_USERNAME, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "EMAIL, "
|
||||||
|
+ "INVITE_CODE, "
|
||||||
|
+ "STATUS,"
|
||||||
|
+ "CREATED_TIME,"
|
||||||
|
+ "LAST_UPDATED_TIME,"
|
||||||
|
+ "MANAGED_ID,"
|
||||||
|
+ "TEMP_PASSWORD) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
stmt.setString(1, userDTO.getClientUserId());
|
||||||
|
stmt.setString(2, userDTO.getDmUsername());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setString(4, userDTO.getEmail());
|
||||||
|
stmt.setString(5, userDTO.getInviteCode());
|
||||||
|
stmt.setString(6, userDTO.getStatus());
|
||||||
|
stmt.setLong(7, currentTime);
|
||||||
|
stmt.setLong(8, currentTime);
|
||||||
|
stmt.setString(9, userDTO.getManagedId());
|
||||||
|
stmt.setString(10, userDTO.getTmpPassword());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
vppUserId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vppUserId;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppUserDTO updateVppUser(VppUserDTO userDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
|
||||||
|
String sql = "UPDATE AP_VPP_USER SET ";
|
||||||
|
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
|
||||||
|
sql += "CLIENT_USER_ID = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
|
||||||
|
sql += "DM_USERNAME = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
|
||||||
|
sql += "EMAIL = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
|
||||||
|
sql += "INVITE_CODE = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
|
||||||
|
sql += "STATUS = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
|
||||||
|
sql += "MANAGED_ID = ?,";
|
||||||
|
}
|
||||||
|
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
|
||||||
|
sql += "TEMP_PASSWORD = ?,";
|
||||||
|
}
|
||||||
|
|
||||||
|
sql += " TENANT_ID = ?, LAST_UPDATED_TIME = ? WHERE ID = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
long updatedTime = System.currentTimeMillis();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
int x = 0;
|
||||||
|
|
||||||
|
if (userDTO.getClientUserId() != null && !userDTO.getClientUserId().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getClientUserId());
|
||||||
|
}
|
||||||
|
if (userDTO.getDmUsername() != null && !userDTO.getDmUsername().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getDmUsername());
|
||||||
|
}
|
||||||
|
if (userDTO.getEmail() != null && !userDTO.getEmail().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getEmail());
|
||||||
|
}
|
||||||
|
if (userDTO.getInviteCode() != null && !userDTO.getInviteCode().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getInviteCode());
|
||||||
|
}
|
||||||
|
if (userDTO.getStatus() != null && !userDTO.getStatus().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getStatus());
|
||||||
|
}
|
||||||
|
if (userDTO.getManagedId() != null && !userDTO.getManagedId().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getManagedId());
|
||||||
|
}
|
||||||
|
if (userDTO.getTmpPassword() != null && !userDTO.getTmpPassword().isEmpty()) {
|
||||||
|
stmt.setString(++x, userDTO.getTmpPassword());
|
||||||
|
}
|
||||||
|
stmt.setInt(++x, tenantId);
|
||||||
|
stmt.setLong(++x, updatedTime);
|
||||||
|
stmt.setInt(++x, userDTO.getId());
|
||||||
|
if (stmt.executeUpdate() == 1) {
|
||||||
|
return userDTO;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppUserDTO getUserByDMUsername(String emmUsername, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "ID, "
|
||||||
|
+ "CLIENT_USER_ID, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "EMAIL, "
|
||||||
|
+ "INVITE_CODE, "
|
||||||
|
+ "STATUS, "
|
||||||
|
+ "CREATED_TIME, "
|
||||||
|
+ "LAST_UPDATED_TIME, "
|
||||||
|
+ "MANAGED_ID, "
|
||||||
|
+ "TEMP_PASSWORD, "
|
||||||
|
+ "DM_USERNAME "
|
||||||
|
+ "FROM AP_VPP_USER "
|
||||||
|
+ "WHERE DM_USERNAME = ? AND TENANT_ID = ?";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setString(1, emmUsername);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
return DAOUtil.loadVppUser(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when retrieving vpp user by EMM Username.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to retrieve vpp user by EMM Username.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (UnexpectedServerErrorException e) {
|
||||||
|
String msg = "Found more than one user for: " + emmUsername;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssetDTO getAssetByAppId(int appId, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "ID, "
|
||||||
|
+ "APP_ID, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "CREATED_TIME, "
|
||||||
|
+ "LAST_UPDATED_TIME, "
|
||||||
|
+ "ADAM_ID, "
|
||||||
|
+ "ASSIGNED_COUNT, "
|
||||||
|
+ "DEVICE_ASSIGNABLE, "
|
||||||
|
+ "PRICING_PARAMS, "
|
||||||
|
+ "PRODUCT_TYPE, "
|
||||||
|
+ "RETIRED_COUNT, "
|
||||||
|
+ "REVOCABLE "
|
||||||
|
// + "SUPPORTED_PLATFORMS "
|
||||||
|
+ "FROM AP_ASSETS "
|
||||||
|
+ "WHERE APP_ID = ? AND TENANT_ID = ?";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, appId);
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
return DAOUtil.loadAsset(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when retrieving asset data of app id "+ appId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to retrieve asset by app id.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (UnexpectedServerErrorException e) {
|
||||||
|
String msg = "Found more than one app for app id: " + appId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addAsset(VppAssetDTO vppAssetDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
int assetId = -1;
|
||||||
|
String sql = "INSERT INTO "
|
||||||
|
+ "AP_ASSETS("
|
||||||
|
+ "APP_ID, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "CREATED_TIME,"
|
||||||
|
+ "LAST_UPDATED_TIME,"
|
||||||
|
+ "ADAM_ID,"
|
||||||
|
+ "ASSIGNED_COUNT,"
|
||||||
|
+ "DEVICE_ASSIGNABLE,"
|
||||||
|
+ "PRICING_PARAMS,"
|
||||||
|
+ "PRODUCT_TYPE,"
|
||||||
|
+ "RETIRED_COUNT,"
|
||||||
|
+ "REVOCABLE, "
|
||||||
|
+ "SUPPORTED_PLATFORMS) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
stmt.setInt(1, vppAssetDTO.getAppId());
|
||||||
|
stmt.setInt(2, tenantId);
|
||||||
|
stmt.setLong(3, currentTime);
|
||||||
|
stmt.setLong(4, currentTime);
|
||||||
|
stmt.setString(5, vppAssetDTO.getAdamId());
|
||||||
|
stmt.setString(6, vppAssetDTO.getAssignedCount());
|
||||||
|
stmt.setString(7, vppAssetDTO.getDeviceAssignable());
|
||||||
|
stmt.setString(8, vppAssetDTO.getPricingParam());
|
||||||
|
stmt.setString(9, vppAssetDTO.getProductType());
|
||||||
|
stmt.setString(10, vppAssetDTO.getRetiredCount());
|
||||||
|
stmt.setString(11, vppAssetDTO.getRevocable());
|
||||||
|
List<String> platformList = vppAssetDTO.getSupportedPlatforms();
|
||||||
|
String platformString = String.join(",", platformList);
|
||||||
|
stmt.setString(12, platformString);
|
||||||
|
stmt.executeUpdate();
|
||||||
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
assetId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return assetId;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when adding the asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to add the asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssetDTO updateAsset(VppAssetDTO vppAssetDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
|
||||||
|
String sql = "UPDATE AP_ASSETS SET ";
|
||||||
|
|
||||||
|
if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
|
||||||
|
sql += "ADAM_ID = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
|
||||||
|
sql += "ASSIGNED_COUNT = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
|
||||||
|
sql += "DEVICE_ASSIGNABLE = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
|
||||||
|
sql += "PRICING_PARAMS = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
|
||||||
|
sql += "PRODUCT_TYPE = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
|
||||||
|
sql += "RETIRED_COUNT = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
|
||||||
|
sql += "REVOCABLE = ?, ";
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
|
||||||
|
sql += "SUPPORTED_PLATFORMS = ?,";
|
||||||
|
}
|
||||||
|
sql += "APP_ID = ?, LAST_UPDATED_TIME = ? WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
long updatedTime = System.currentTimeMillis();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
int x = 0;
|
||||||
|
|
||||||
|
if (vppAssetDTO.getAdamId() != null && !vppAssetDTO.getAdamId().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getAdamId());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getAssignedCount() != null && !vppAssetDTO.getAssignedCount().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getAssignedCount());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getDeviceAssignable() != null && !vppAssetDTO.getDeviceAssignable().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getDeviceAssignable());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getPricingParam() != null && !vppAssetDTO.getPricingParam().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getPricingParam());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getProductType() != null && !vppAssetDTO.getProductType().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getProductType());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getRetiredCount() != null && !vppAssetDTO.getRetiredCount().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getRetiredCount());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getRevocable() != null && !vppAssetDTO.getRevocable().isEmpty()) {
|
||||||
|
stmt.setString(++x, vppAssetDTO.getRevocable());
|
||||||
|
}
|
||||||
|
if (vppAssetDTO.getSupportedPlatforms() != null && !vppAssetDTO.getSupportedPlatforms().isEmpty()) {
|
||||||
|
List<String> platformList = vppAssetDTO.getSupportedPlatforms();
|
||||||
|
String platformString = String.join(",", platformList);
|
||||||
|
stmt.setString(++x, platformString);
|
||||||
|
}
|
||||||
|
|
||||||
|
stmt.setInt(++x, vppAssetDTO.getAppId());
|
||||||
|
stmt.setLong(++x, updatedTime);
|
||||||
|
stmt.setInt(++x, vppAssetDTO.getId());
|
||||||
|
stmt.setLong(++x, tenantId);
|
||||||
|
if (stmt.executeUpdate() == 1) {
|
||||||
|
return vppAssetDTO;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssociationDTO getAssociation(int assetId, int userId, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
String sql = "SELECT "
|
||||||
|
+ "ID, "
|
||||||
|
+ "ASSOCIATION_TYPE, "
|
||||||
|
+ "CREATED_TIME, "
|
||||||
|
+ "LAST_UPDATED_TIME, "
|
||||||
|
+ "PRICING_PARAMS "
|
||||||
|
+ "FROM AP_VPP_ASSOCIATION "
|
||||||
|
+ "WHERE ASSET_ID = ? AND USER_ID = ? AND TENANT_ID = ?";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, assetId);
|
||||||
|
stmt.setInt(2, userId);
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
return DAOUtil.loadAssignment(rs);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when retrieving assignment data of user with id "+ userId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to retrieve assignment by asset id and user id.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (UnexpectedServerErrorException e) {
|
||||||
|
String msg = "Found more than one assignment for user id: " + userId + " and asset id: " + assetId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addAssociation(VppAssociationDTO vppAssociationDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
int associationId = -1;
|
||||||
|
String sql = "INSERT INTO "
|
||||||
|
+ "AP_VPP_ASSOCIATION("
|
||||||
|
+ "ASSET_ID, "
|
||||||
|
+ "USER_ID, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "ASSOCIATION_TYPE,"
|
||||||
|
+ "CREATED_TIME,"
|
||||||
|
+ "LAST_UPDATED_TIME,"
|
||||||
|
+ "PRICING_PARAMS) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
stmt.setInt(1, vppAssociationDTO.getAssetId());
|
||||||
|
stmt.setInt(2, vppAssociationDTO.getClientId());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setString(4, vppAssociationDTO.getAssociationType());
|
||||||
|
stmt.setLong(5, currentTime);
|
||||||
|
stmt.setLong(6, currentTime);
|
||||||
|
stmt.setString(7, vppAssociationDTO.getPricingParam());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
associationId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return associationId;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when adding the asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to add the asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssociationDTO updateAssociation(VppAssociationDTO vppAssociationDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
|
||||||
|
String sql = "UPDATE "
|
||||||
|
+ "AP_VPP_ASSOCIATION "
|
||||||
|
+ "SET "
|
||||||
|
+ "ASSET_ID = ?,"
|
||||||
|
+ "USER_ID = ?, "
|
||||||
|
+ "ASSOCIATION_TYPE = ?, "
|
||||||
|
+ "LAST_UPDATED_TIME = ?, "
|
||||||
|
+ "PRICING_PARAMS = ? "
|
||||||
|
+ "WHERE ID = ? AND TENANT_ID = ?";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
long updatedTime = System.currentTimeMillis();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, vppAssociationDTO.getAssetId());
|
||||||
|
stmt.setInt(2, vppAssociationDTO.getClientId());
|
||||||
|
stmt.setString(3, vppAssociationDTO.getAssociationType());
|
||||||
|
stmt.setLong(4, updatedTime);
|
||||||
|
stmt.setString(5, vppAssociationDTO.getPricingParam());
|
||||||
|
stmt.setInt(6, vppAssociationDTO.getId());
|
||||||
|
stmt.setLong(7, tenantId);
|
||||||
|
if (stmt.executeUpdate() == 1) {
|
||||||
|
return vppAssociationDTO;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when updating the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to updating the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,82 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class OracleVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
int vppUserId = -1;
|
||||||
|
String sql = "INSERT INTO "
|
||||||
|
+ "AP_VPP_USER("
|
||||||
|
+ "CLIENT_USER_ID, "
|
||||||
|
+ "DM_USERNAME, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "EMAIL, "
|
||||||
|
+ "INVITE_CODE, "
|
||||||
|
+ "STATUS,"
|
||||||
|
+ "CREATED_TIME,"
|
||||||
|
+ "LAST_UPDATED_TIME,"
|
||||||
|
+ "MANAGED_ID,"
|
||||||
|
+ "TEMP_PASSWORD) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[] {"ID"})) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
stmt.setString(1, userDTO.getClientUserId());
|
||||||
|
stmt.setString(2, userDTO.getDmUsername());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setString(4, userDTO.getEmail());
|
||||||
|
stmt.setString(5, userDTO.getInviteCode());
|
||||||
|
stmt.setString(6, userDTO.getStatus());
|
||||||
|
stmt.setLong(7, currentTime);
|
||||||
|
stmt.setLong(8, currentTime);
|
||||||
|
stmt.setString(9, userDTO.getManagedId());
|
||||||
|
stmt.setString(10, userDTO.getTmpPassword());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
vppUserId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vppUserId;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -0,0 +1,81 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
import java.sql.*;
|
||||||
|
|
||||||
|
public class PostgreSQLVppApplicationDAO extends GenericVppApplicationDAOImpl {
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(GenericVppApplicationDAOImpl.class);
|
||||||
|
|
||||||
|
public int addVppUser(VppUserDTO userDTO, int tenantId)
|
||||||
|
throws ApplicationManagementDAOException {
|
||||||
|
int vppUserId = -1;
|
||||||
|
String sql = "INSERT INTO "
|
||||||
|
+ "AP_VPP_USER("
|
||||||
|
+ "CLIENT_USER_ID, "
|
||||||
|
+ "DM_USERNAME, "
|
||||||
|
+ "TENANT_ID, "
|
||||||
|
+ "EMAIL, "
|
||||||
|
+ "INVITE_CODE, "
|
||||||
|
+ "STATUS,"
|
||||||
|
+ "CREATED_TIME,"
|
||||||
|
+ "LAST_UPDATED_TIME,"
|
||||||
|
+ "MANAGED_ID,"
|
||||||
|
+ "TEMP_PASSWORD) "
|
||||||
|
+ "VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
|
||||||
|
try {
|
||||||
|
Connection conn = this.getDBConnection();
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql, new String[]{"ID"})) {
|
||||||
|
long currentTime = System.currentTimeMillis();
|
||||||
|
stmt.setString(1, userDTO.getClientUserId());
|
||||||
|
stmt.setString(2, userDTO.getDmUsername());
|
||||||
|
stmt.setInt(3, tenantId);
|
||||||
|
stmt.setString(4, userDTO.getEmail());
|
||||||
|
stmt.setString(5, userDTO.getInviteCode());
|
||||||
|
stmt.setString(6, userDTO.getStatus());
|
||||||
|
stmt.setLong(7, currentTime);
|
||||||
|
stmt.setLong(8, currentTime);
|
||||||
|
stmt.setString(9, userDTO.getManagedId());
|
||||||
|
stmt.setString(10, userDTO.getTmpPassword());
|
||||||
|
stmt.executeUpdate();
|
||||||
|
try (ResultSet rs = stmt.getGeneratedKeys()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
vppUserId = rs.getInt(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return vppUserId;
|
||||||
|
}
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while obtaining database connection when adding the vpp user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String msg = "Error occurred when processing SQL to add the vpp user.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementDAOException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -16,10 +16,7 @@
|
|||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.dao.impl.vpp;
|
||||||
|
|
||||||
|
public class SQLServerVppApplicationDAOImpl extends GenericVppApplicationDAOImpl {
|
||||||
div.FixedHeader_Cloned th,
|
|
||||||
div.FixedHeader_Cloned td {
|
|
||||||
background-color: white !important;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -18,6 +18,24 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
||||||
|
import org.apache.commons.codec.digest.DigestUtils;
|
||||||
|
import org.apache.commons.io.IOUtils;
|
||||||
|
import org.apache.commons.lang.StringEscapeUtils;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.validator.routines.UrlValidator;
|
||||||
|
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.wso2.carbon.context.CarbonContext;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstaller;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstaller;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationList;
|
||||||
@ -60,12 +78,10 @@ import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManage
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationReleaseDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.LifecycleStateDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.LifecycleStateDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.VisibilityDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.VisibilityDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.LifeCycleManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.LifeCycleManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
||||||
@ -73,27 +89,12 @@ import io.entgra.device.mgt.core.application.mgt.core.exception.VisibilityManage
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
|
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.DeviceManagementException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagementException;
|
import io.entgra.device.mgt.core.device.mgt.core.common.exception.StorageManagementException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
|
import io.entgra.device.mgt.core.device.mgt.core.dto.DeviceType;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
import org.apache.commons.codec.digest.DigestUtils;
|
|
||||||
import org.apache.commons.io.IOUtils;
|
|
||||||
import org.apache.commons.lang.StringEscapeUtils;
|
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.apache.commons.validator.routines.UrlValidator;
|
|
||||||
import org.apache.cxf.jaxrs.ext.multipart.Attachment;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.context.CarbonContext;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
|
||||||
import org.wso2.carbon.user.api.UserRealm;
|
import org.wso2.carbon.user.api.UserRealm;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
@ -1443,6 +1444,43 @@ public class ApplicationManagerImpl implements ApplicationManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ApplicationList getSubscribedAppsOfDevice(int deviceId, PaginationRequest request) throws ApplicationManagementException {
|
||||||
|
ApplicationList applicationList = new ApplicationList();
|
||||||
|
List<Application> applications = new ArrayList<>();
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.openDBConnection();
|
||||||
|
List<ApplicationDTO> applicationDTOS = this.applicationDAO.getSubscribedAppsOfDevice(deviceId, tenantId, request);
|
||||||
|
for (ApplicationDTO applicationDTO: applicationDTOS) {
|
||||||
|
applicationDTO.setTags(this.applicationDAO.getAppTags(applicationDTO.getId(), tenantId));
|
||||||
|
applicationDTO.setAppCategories(this.applicationDAO.getAppCategories(applicationDTO.getId(), tenantId));
|
||||||
|
applications.add(APIUtil.appDtoToAppResponse(applicationDTO));
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ApplicationDTO> totalApplications = this.applicationDAO.getSubscribedAppsOfDevice(deviceId, tenantId, null);
|
||||||
|
Pagination pagination = new Pagination();
|
||||||
|
pagination.setCount(totalApplications.size());
|
||||||
|
pagination.setSize(applications.size());
|
||||||
|
pagination.setOffset(request.getStartIndex());
|
||||||
|
pagination.setLimit(request.getRowCount());
|
||||||
|
applicationList.setApplications(applications);
|
||||||
|
applicationList.setPagination(pagination);
|
||||||
|
return applicationList;
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error occurred when getting installed apps of device with device id: "
|
||||||
|
+ deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "DB Connection error occurred while getting installed apps of device with device id: " + deviceId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Check whether given OS range is valid or invalid
|
* Check whether given OS range is valid or invalid
|
||||||
*
|
*
|
||||||
|
|||||||
@ -19,6 +19,29 @@
|
|||||||
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
|
||||||
|
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
|
||||||
|
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
|
||||||
|
import org.apache.commons.httpclient.HttpClient;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
|
||||||
|
import org.apache.http.ssl.SSLContextBuilder;
|
||||||
|
import org.apache.http.conn.ssl.TrustSelfSignedStrategy;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONObject;
|
||||||
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
|
import io.entgra.device.mgt.core.apimgt.application.extension.dto.ApiApplicationKey;
|
||||||
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
|
import io.entgra.device.mgt.core.apimgt.application.extension.exception.APIManagerException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationInstallResponse;
|
||||||
@ -46,7 +69,6 @@ import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
|||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SubscriptionDAO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ForbiddenException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.NotFoundException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
||||||
@ -60,10 +82,7 @@ import io.entgra.device.mgt.core.device.mgt.common.Device;
|
|||||||
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
|
import io.entgra.device.mgt.core.device.mgt.common.EnrolmentInfo;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
|
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.MDMAppConstants;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationRequest;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
import io.entgra.device.mgt.core.device.mgt.common.PaginationResult;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
|
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.App;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.MobileAppTypes;
|
import io.entgra.device.mgt.core.device.mgt.common.app.mgt.MobileAppTypes;
|
||||||
@ -82,18 +101,11 @@ import io.entgra.device.mgt.core.device.mgt.core.service.GroupManagementProvider
|
|||||||
import io.entgra.device.mgt.core.device.mgt.core.util.MDMAndroidOperationUtil;
|
import io.entgra.device.mgt.core.device.mgt.core.util.MDMAndroidOperationUtil;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.util.MDMIOSOperationUtil;
|
import io.entgra.device.mgt.core.device.mgt.core.util.MDMIOSOperationUtil;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.util.MDMWindowsOperationUtil;
|
import io.entgra.device.mgt.core.device.mgt.core.util.MDMWindowsOperationUtil;
|
||||||
import io.entgra.device.mgt.core.device.mgt.extensions.logger.spi.EntgraLogger;
|
|
||||||
import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo;
|
import io.entgra.device.mgt.core.identity.jwt.client.extension.dto.AccessTokenInfo;
|
||||||
import io.entgra.device.mgt.core.notification.logger.AppInstallLogContext;
|
|
||||||
import io.entgra.device.mgt.core.notification.logger.impl.EntgraAppInstallLoggerImpl;
|
|
||||||
import org.apache.commons.httpclient.HttpClient;
|
|
||||||
import org.apache.commons.httpclient.HttpException;
|
import org.apache.commons.httpclient.HttpException;
|
||||||
import org.apache.commons.httpclient.HttpMethodBase;
|
import org.apache.commons.httpclient.HttpMethodBase;
|
||||||
import org.apache.commons.httpclient.methods.PostMethod;
|
import org.apache.commons.httpclient.methods.PostMethod;
|
||||||
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
import org.apache.commons.httpclient.methods.StringRequestEntity;
|
||||||
import org.apache.commons.lang.StringUtils;
|
|
||||||
import org.json.JSONArray;
|
|
||||||
import org.json.JSONObject;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
import org.wso2.carbon.user.api.UserStoreException;
|
import org.wso2.carbon.user.api.UserStoreException;
|
||||||
|
|
||||||
@ -105,6 +117,9 @@ import java.io.InputStreamReader;
|
|||||||
import java.net.HttpURLConnection;
|
import java.net.HttpURLConnection;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
|
import java.security.KeyManagementException;
|
||||||
|
import java.security.KeyStoreException;
|
||||||
|
import java.security.NoSuchAlgorithmException;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
@ -124,12 +139,14 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
private static final EntgraLogger log = new EntgraAppInstallLoggerImpl(SubscriptionManagerImpl.class);
|
private static final EntgraLogger log = new EntgraAppInstallLoggerImpl(SubscriptionManagerImpl.class);
|
||||||
private SubscriptionDAO subscriptionDAO;
|
private SubscriptionDAO subscriptionDAO;
|
||||||
private ApplicationDAO applicationDAO;
|
private ApplicationDAO applicationDAO;
|
||||||
|
private VppApplicationDAO vppApplicationDAO;
|
||||||
private LifecycleStateManager lifecycleStateManager;
|
private LifecycleStateManager lifecycleStateManager;
|
||||||
|
|
||||||
public SubscriptionManagerImpl() {
|
public SubscriptionManagerImpl() {
|
||||||
this.lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
this.lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||||
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
this.subscriptionDAO = ApplicationManagementDAOFactory.getSubscriptionDAO();
|
||||||
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||||
|
this.vppApplicationDAO = ApplicationManagementDAOFactory.getVppApplicationDAO();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -154,6 +171,7 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
ApplicationDTO applicationDTO = getApplicationDTO(applicationUUID);
|
||||||
ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
|
ApplicationSubscriptionInfo applicationSubscriptionInfo = getAppSubscriptionInfo(applicationDTO, subType,
|
||||||
params);
|
params);
|
||||||
|
performExternalStoreSubscription(applicationDTO, applicationSubscriptionInfo);
|
||||||
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
|
ApplicationInstallResponse applicationInstallResponse = performActionOnDevices(
|
||||||
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
|
applicationSubscriptionInfo.getAppSupportingDeviceTypeName(), applicationSubscriptionInfo.getDevices(),
|
||||||
applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action, properties, isOperationReExecutingDisabled);
|
applicationDTO, subType, applicationSubscriptionInfo.getSubscribers(), action, properties, isOperationReExecutingDisabled);
|
||||||
@ -162,6 +180,51 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
return applicationInstallResponse;
|
return applicationInstallResponse;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void performExternalStoreSubscription(ApplicationDTO applicationDTO,
|
||||||
|
ApplicationSubscriptionInfo
|
||||||
|
applicationSubscriptionInfo) throws ApplicationManagementException {
|
||||||
|
try {
|
||||||
|
// Only for iOS devices
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
if (DeviceTypes.IOS.toString().equalsIgnoreCase(APIUtil.getDeviceTypeData(applicationDTO
|
||||||
|
.getDeviceTypeId()).getName())) {
|
||||||
|
// TODO: replace getAssetByAppId with the correct one in DAO
|
||||||
|
// Check if the app trying to subscribe is a VPP asset.
|
||||||
|
VppAssetDTO storedAsset = vppApplicationDAO.getAssetByAppId(applicationDTO.getId(), tenantId);
|
||||||
|
if (storedAsset != null) { // This is a VPP asset
|
||||||
|
List<VppUserDTO> users = new ArrayList<>();
|
||||||
|
List<Device> devices = applicationSubscriptionInfo.getDevices();// get
|
||||||
|
// subscribed device list, so that we can extract the users of those devices.
|
||||||
|
for (Device device : devices) {
|
||||||
|
VppUserDTO user = vppApplicationDAO.getUserByDMUsername(device.getEnrolmentInfo()
|
||||||
|
.getOwner(), PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||||
|
.getTenantId(true));
|
||||||
|
users.add(user);
|
||||||
|
}
|
||||||
|
VPPApplicationManager vppManager = APIUtil.getVPPManager();
|
||||||
|
vppManager.addAssociation(storedAsset, users);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (BadRequestException e) {
|
||||||
|
String msg = "Device Type not found";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (UnexpectedServerErrorException e) {
|
||||||
|
String msg = "Unexpected error while getting device type";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error while getting the device user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
String msg = "Error while associating user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void createScheduledSubscription(ScheduledSubscriptionDTO subscriptionDTO)
|
public void createScheduledSubscription(ScheduledSubscriptionDTO subscriptionDTO)
|
||||||
throws SubscriptionManagementException {
|
throws SubscriptionManagementException {
|
||||||
@ -1268,38 +1331,37 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private int invokeIOTCoreAPI(HttpMethodBase request) throws UserStoreException, APIManagerException, IOException {
|
private int invokeIOTCoreAPI(HttpPost request) throws UserStoreException, APIManagerException, IOException,
|
||||||
HttpClient httpClient;
|
ApplicationManagementException {
|
||||||
|
CloseableHttpClient httpClient = getHttpClient();
|
||||||
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
String tenantDomain = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantDomain();
|
||||||
ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain);
|
ApiApplicationKey apiApplicationKey = OAuthUtils.getClientCredentials(tenantDomain);
|
||||||
String username =
|
String username =
|
||||||
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
|
PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration()
|
||||||
.getAdminUserName() + Constants.ApplicationInstall.AT + tenantDomain;
|
.getAdminUserName() + Constants.ApplicationInstall.AT + tenantDomain;
|
||||||
AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username);
|
AccessTokenInfo tokenInfo = OAuthUtils.getOAuthCredentials(apiApplicationKey, username);
|
||||||
request.addRequestHeader(Constants.ApplicationInstall.AUTHORIZATION,
|
request.addHeader(Constants.ApplicationInstall.AUTHORIZATION,
|
||||||
Constants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken());
|
Constants.ApplicationInstall.AUTHORIZATION_HEADER_VALUE + tokenInfo.getAccessToken());
|
||||||
httpClient = new HttpClient();
|
HttpResponse response = httpClient.execute(request);
|
||||||
httpClient.executeMethod(request);
|
return response.getStatusLine().getStatusCode();
|
||||||
return request.getStatusCode();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO)
|
public int installEnrollmentApplications(ApplicationPolicyDTO applicationPolicyDTO)
|
||||||
throws ApplicationManagementException {
|
throws ApplicationManagementException {
|
||||||
|
String requestUrl =null;
|
||||||
PostMethod request;
|
|
||||||
try {
|
try {
|
||||||
String requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
|
requestUrl = Constants.ApplicationInstall.ENROLLMENT_APP_INSTALL_PROTOCOL + System
|
||||||
.getProperty(Constants.ApplicationInstall.IOT_CORE_HOST) + Constants.ApplicationInstall.COLON
|
.getProperty(Constants.ApplicationInstall.IOT_GATEWAY_HOST) + Constants.ApplicationInstall.COLON
|
||||||
+ System.getProperty(Constants.ApplicationInstall.IOT_CORE_PORT)
|
+ System.getProperty(Constants.ApplicationInstall.IOT_CORE_PORT)
|
||||||
+ Constants.ApplicationInstall.GOOGLE_APP_INSTALL_URL;
|
+ Constants.ApplicationInstall.GOOGLE_APP_INSTALL_URL;
|
||||||
Gson gson = new Gson();
|
Gson gson = new Gson();
|
||||||
String payload = gson.toJson(applicationPolicyDTO);
|
String payload = gson.toJson(applicationPolicyDTO);
|
||||||
|
HttpPost httpPost = new HttpPost(requestUrl);
|
||||||
|
|
||||||
StringRequestEntity requestEntity = new StringRequestEntity(payload, MediaType.APPLICATION_JSON,
|
StringEntity stringEntity = new StringEntity(payload, Constants.ApplicationInstall.ENCODING);
|
||||||
Constants.ApplicationInstall.ENCODING);
|
httpPost.addHeader("Content-Type",MediaType.APPLICATION_JSON);
|
||||||
request = new PostMethod(requestUrl);
|
httpPost.setEntity(stringEntity);
|
||||||
request.setRequestEntity(requestEntity);
|
return invokeIOTCoreAPI(httpPost);
|
||||||
return invokeIOTCoreAPI(request);
|
|
||||||
} catch (UserStoreException e) {
|
} catch (UserStoreException e) {
|
||||||
String msg = "Error while accessing user store for user with Android device.";
|
String msg = "Error while accessing user store for user with Android device.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
@ -1308,18 +1370,38 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
String msg = "Error while retrieving access token for Android device";
|
String msg = "Error while retrieving access token for Android device";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new ApplicationManagementException(msg, e);
|
throw new ApplicationManagementException(msg, e);
|
||||||
} catch (HttpException e) {
|
|
||||||
String msg = "Error while calling the app store to install enrollment app with id: " + applicationPolicyDTO
|
|
||||||
.getApplicationDTO().getId() + " on device";
|
|
||||||
log.error(msg, e);
|
|
||||||
throw new ApplicationManagementException(msg, e);
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
String msg =
|
String msg =
|
||||||
"Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId()
|
"Error while installing the enrollment with id: " + applicationPolicyDTO.getApplicationDTO().getId()
|
||||||
+ " on device";
|
+ " on device: request URL: " + requestUrl;
|
||||||
|
log.error(msg + "request url: " + requestUrl, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private CloseableHttpClient getHttpClient() throws ApplicationManagementException {
|
||||||
|
try {
|
||||||
|
SSLContextBuilder builder = new SSLContextBuilder();
|
||||||
|
builder.loadTrustMaterial(null, new TrustSelfSignedStrategy());
|
||||||
|
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build());
|
||||||
|
return HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build();
|
||||||
|
} catch (NoSuchAlgorithmException e) {
|
||||||
|
String msg = "Failed while building the http client for EntApp installation. " +
|
||||||
|
"Used SSL algorithm not available";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (KeyStoreException e) {
|
||||||
|
String msg = "Failed while building the http client for EntApp installation. " +
|
||||||
|
"Failed to load required key stores";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (KeyManagementException e) {
|
||||||
|
String msg = "Failed while building the http client for EntApp installation. " +
|
||||||
|
"Failed while building SSL context";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new ApplicationManagementException(msg, e);
|
throw new ApplicationManagementException(msg, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getIOTCoreBaseUrl() {
|
private String getIOTCoreBaseUrl() {
|
||||||
@ -1594,4 +1676,29 @@ public class SubscriptionManagerImpl implements SubscriptionManager {
|
|||||||
ConnectionManagerUtil.closeDBConnection();
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Activity getOperationAppDetails(String id) throws SubscriptionManagementException {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
int operationId = Integer.parseInt(
|
||||||
|
id.replace(DeviceManagementConstants.OperationAttributes.ACTIVITY, ""));
|
||||||
|
if (operationId == 0) {
|
||||||
|
throw new IllegalArgumentException("Operation ID cannot be null or zero (0).");
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.openDBConnection();
|
||||||
|
return subscriptionDAO.getOperationAppDetails(operationId, tenantId);
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while retrieving app details of operation: " + operationId;
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new SubscriptionManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new SubscriptionManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -0,0 +1,610 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.impl;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import com.google.gson.JsonObject;
|
||||||
|
import com.google.gson.JsonParser;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.DepConfig;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ItuneAppDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppItuneUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.DBConnectionException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.exception.TransactionManagementException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppAssociateRequestWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneAssetResponseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneUserRequestWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.VppItuneUserResponseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.ApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.SPApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.VisibilityDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.VppApplicationDAO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.exception.ApplicationManagementDAOException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.internal.DataHolder;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.ApplicationManagementUtil;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.ConnectionManagerUtil;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.Constants;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.VppHttpUtil;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.util.APIUtil;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.exceptions.MetadataManagementException;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.Metadata;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.DeviceManagementConstants;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.internal.DeviceManagementDataHolder;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class VppApplicationManagerImpl implements VPPApplicationManager {
|
||||||
|
private static final String APP_API = "https://vpp.itunes.apple.com/mdm/v2";
|
||||||
|
private static final String ASSETS = APP_API + "/assets";
|
||||||
|
private static final String USER_CREATE = APP_API + "/users/create";
|
||||||
|
private static final String USER_UPDATE = APP_API + "/users/update";
|
||||||
|
private static final String USER_GET = APP_API + "/users";
|
||||||
|
private static final String ASSIGNMENTS_POST = APP_API + "/assets/associate";
|
||||||
|
private static final String ASSIGNMENTS_GET = APP_API + "/assignments";
|
||||||
|
private static final String TOKEN = "";
|
||||||
|
private static final String LOOKUP_API = "https://uclient-api.itunes.apple" +
|
||||||
|
".com/WebObjects/MZStorePlatform.woa/wa/lookup?version=2&id=";
|
||||||
|
private static final String LOOKUP_API_PREFIX =
|
||||||
|
"&p=mdm-lockup&caller=MDM&platform=enterprisestore&cc=us&l=en";
|
||||||
|
|
||||||
|
|
||||||
|
private static final Log log = LogFactory.getLog(VppApplicationManagerImpl.class);
|
||||||
|
|
||||||
|
private ApplicationDAO applicationDAO;
|
||||||
|
private SPApplicationDAO spApplicationDAO;
|
||||||
|
private VisibilityDAO visibilityDAO;
|
||||||
|
private final LifecycleStateManager lifecycleStateManager;
|
||||||
|
private VppApplicationDAO vppApplicationDAO;
|
||||||
|
|
||||||
|
public VppApplicationManagerImpl() {
|
||||||
|
initDataAccessObjects();
|
||||||
|
lifecycleStateManager = DataHolder.getInstance().getLifecycleStateManager();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void initDataAccessObjects() {
|
||||||
|
this.applicationDAO = ApplicationManagementDAOFactory.getApplicationDAO();
|
||||||
|
this.visibilityDAO = ApplicationManagementDAOFactory.getVisibilityDAO();
|
||||||
|
this.spApplicationDAO = ApplicationManagementDAOFactory.getSPApplicationDAO();
|
||||||
|
this.vppApplicationDAO = ApplicationManagementDAOFactory.getVppApplicationDAO();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppUserDTO addUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||||
|
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
|
||||||
|
// Call the API to add
|
||||||
|
try {
|
||||||
|
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||||
|
VppItuneUserRequestWrapper wrapper = new VppItuneUserRequestWrapper();
|
||||||
|
wrapper.getUser().add(ituneUserDTO);
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String userPayload = gson.toJson(wrapper);
|
||||||
|
|
||||||
|
ProxyResponse proxyResponse = callVPPBackend(USER_CREATE, userPayload, getVppToken(), Constants.VPP.POST);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||||
|
// Create user does not return any useful data. Its needed to call the backend again
|
||||||
|
ProxyResponse getUserResponse = callVPPBackend(USER_GET + Constants.VPP.CLIENT_USER_ID_PARAM +
|
||||||
|
userDTO.getClientUserId(), userPayload, getVppToken(), Constants.VPP.GET);
|
||||||
|
if ((getUserResponse.getCode() == HttpStatus.SC_OK || getUserResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && getUserResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||||
|
VppItuneUserResponseWrapper vppItuneUserResponseWrapper = gson.fromJson
|
||||||
|
(getUserResponse.getData(), VppItuneUserResponseWrapper.class);
|
||||||
|
userDTO.setInviteCode(vppItuneUserResponseWrapper.getUser().get(0)
|
||||||
|
.getInviteCode());
|
||||||
|
userDTO.setStatus(vppItuneUserResponseWrapper.getUser().get(0).getStatus());
|
||||||
|
log.error("userDTO " + userDTO.toString());
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
int id = vppApplicationDAO.addVppUser(userDTO, tenantId);
|
||||||
|
if (id != -1) {
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
userDTO.setId(id);
|
||||||
|
userDTO.setTenantId(PrivilegedCarbonContext
|
||||||
|
.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
return userDTO;
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
return null;
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while adding the Vpp User.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for adding Vpp User.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for adding Vpp User.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while calling VPP backend to add user";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppUserDTO getUserByDMUsername(String emmUsername) throws ApplicationManagementException {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.openDBConnection();
|
||||||
|
return vppApplicationDAO.getUserByDMUsername(emmUsername, tenantId);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "DB Connection error occurs while getting vpp User data related to EMM user " + emmUsername + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting vpp User data related to EMM user " + emmUsername + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void updateUser(VppUserDTO userDTO) throws ApplicationManagementException {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
VppItuneUserDTO ituneUserDTO = userDTO;
|
||||||
|
VppItuneUserRequestWrapper wrapper = new VppItuneUserRequestWrapper();
|
||||||
|
wrapper.getUser().add(ituneUserDTO);
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String userPayload = gson.toJson(wrapper);
|
||||||
|
try {
|
||||||
|
ProxyResponse proxyResponse = callVPPBackend(USER_UPDATE, userPayload, getVppToken(), Constants.VPP.POST);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||||
|
VppUserDTO currentUserDTO = getUserByDMUsername(userDTO.getDmUsername());
|
||||||
|
if (currentUserDTO != null) {
|
||||||
|
userDTO.setId(currentUserDTO.getId());
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
if (vppApplicationDAO.updateVppUser(userDTO, tenantId) == null) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Unable to update the Vpp user " +userDTO.getId();
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg);
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while updating the Vpp User.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for Vpp User update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for Vpp User update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while calling VPP backend to update";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void syncUsers(String clientId) throws ApplicationManagementException {
|
||||||
|
ProxyResponse proxyResponse = null;
|
||||||
|
try {
|
||||||
|
proxyResponse = callVPPBackend(USER_GET, null, getVppToken(), Constants
|
||||||
|
.VPP.GET);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||||
|
log.error("proxyResponse " + proxyResponse.getData());
|
||||||
|
Gson gson = new Gson();
|
||||||
|
VppItuneUserResponseWrapper vppUserResponseWrapper = gson.fromJson
|
||||||
|
(proxyResponse.getData(), VppItuneUserResponseWrapper.class);
|
||||||
|
// TODO: to implement later
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while syncing VPP users with backend";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void syncAssets(int nextPageIndex) throws ApplicationManagementException {
|
||||||
|
ProxyResponse proxyResponse = null;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
String url = ASSETS;
|
||||||
|
if (nextPageIndex > 0) { // Not the first page
|
||||||
|
url += "?pageIndex=" + nextPageIndex;
|
||||||
|
}
|
||||||
|
proxyResponse = callVPPBackend(url, null, getVppToken(), Constants.VPP.GET);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
VppItuneAssetResponseWrapper vppItuneAssetResponse = gson.fromJson
|
||||||
|
(proxyResponse.getData(), VppItuneAssetResponseWrapper.class);
|
||||||
|
if (vppItuneAssetResponse.getSize() > 0) {
|
||||||
|
for (VppAssetDTO vppAssetDTO : vppItuneAssetResponse.getAssets()) {
|
||||||
|
vppAssetDTO.setTenantId(PrivilegedCarbonContext
|
||||||
|
.getThreadLocalCarbonContext().getTenantId());
|
||||||
|
vppAssetDTO.setCreatedTime(String.valueOf(System.currentTimeMillis()));
|
||||||
|
vppAssetDTO.setLastUpdatedTime(String.valueOf(System.currentTimeMillis()));
|
||||||
|
}
|
||||||
|
|
||||||
|
for (VppAssetDTO vppAssetDTO : vppItuneAssetResponse.getAssets()) {
|
||||||
|
ItuneAppDTO ituneAppDTO = lookupAsset(vppAssetDTO.getAdamId());
|
||||||
|
ApplicationManagementUtil.persistApp(ituneAppDTO);
|
||||||
|
List<Application> applications = ApplicationManagementUtil.getAppDetails(vppAssetDTO.getAdamId());
|
||||||
|
for (Application application :applications) {
|
||||||
|
VppAssetDTO vppAssetDTOs = getAssetByAppId(application.getId());
|
||||||
|
if (vppAssetDTOs == null) {
|
||||||
|
vppAssetDTOs = new VppAssetDTO();
|
||||||
|
vppAssetDTO.setAppId(application.getId());
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
if (vppApplicationDAO.addAsset(vppAssetDTO, tenantId) != -1) {
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while adding the Asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for adding Asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for adding Asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
vppAssetDTOs.setAppId(application.getId());
|
||||||
|
vppAssetDTOs.setSupportedPlatforms(vppAssetDTO.getSupportedPlatforms());
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
if (vppApplicationDAO.updateAsset(vppAssetDTOs, tenantId) == null) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Unable to update the asset: " +vppAssetDTOs.getAdamId();
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg);
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while updating the Asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for Asset update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for Asset update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (vppItuneAssetResponse.getCurrentPageIndex() == (vppItuneAssetResponse
|
||||||
|
.getTotalPages() - 1)) {
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
syncAssets(vppItuneAssetResponse.getNextPageIndex());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while syncing VPP users with backend";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private ItuneAppDTO lookupAsset(String packageName) throws ApplicationManagementException {
|
||||||
|
String lookupURL = LOOKUP_API + packageName + LOOKUP_API_PREFIX;
|
||||||
|
try {
|
||||||
|
ProxyResponse proxyResponse = callVPPBackend(lookupURL, null, getVppToken(), Constants.VPP.GET);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.GET_APP_DATA_RESPONSE_START)) {
|
||||||
|
String responseData = proxyResponse.getData();
|
||||||
|
JsonObject responseJson = new JsonParser().parse(responseData)
|
||||||
|
.getAsJsonObject();
|
||||||
|
|
||||||
|
JsonObject results = responseJson.getAsJsonObject(Constants.ApplicationProperties.RESULTS);
|
||||||
|
JsonObject result = results.getAsJsonObject(packageName);
|
||||||
|
|
||||||
|
String iconUrl = result.getAsJsonObject(Constants.ApplicationProperties.ARTWORK)
|
||||||
|
.get(Constants.ApplicationProperties.URL).getAsString();
|
||||||
|
int lastSlashIndex = iconUrl.lastIndexOf("/");
|
||||||
|
if (lastSlashIndex != -1) {
|
||||||
|
iconUrl = iconUrl.substring(0, lastSlashIndex + 1) + Constants.VPP.REMOTE_FILE_NAME;
|
||||||
|
}
|
||||||
|
|
||||||
|
String descriptionStandard = result.getAsJsonObject(Constants.ApplicationProperties.DESCRIPTION)
|
||||||
|
.get(Constants.ApplicationProperties.STANDARD).getAsString();
|
||||||
|
if (descriptionStandard != null && !descriptionStandard.isEmpty()) {
|
||||||
|
descriptionStandard = descriptionStandard.substring(0, 199);
|
||||||
|
}
|
||||||
|
String name = result.get(Constants.ApplicationProperties.NAME).getAsString();
|
||||||
|
double price = result.getAsJsonArray(Constants.ApplicationProperties.OFFERS).get(0)
|
||||||
|
.getAsJsonObject().get(Constants.ApplicationProperties.PRICE).getAsDouble();
|
||||||
|
String version = result.getAsJsonArray(Constants.ApplicationProperties.OFFERS)
|
||||||
|
.get(0).getAsJsonObject().get(Constants.ApplicationProperties.VERSION)
|
||||||
|
.getAsJsonObject().get(Constants.ApplicationProperties.DISPLAY).getAsString();
|
||||||
|
|
||||||
|
String[] genreNames = new Gson().fromJson(result.getAsJsonArray(Constants.ApplicationProperties.GENRE_NAMES),
|
||||||
|
String[].class);
|
||||||
|
|
||||||
|
ItuneAppDTO ituneAppDTO = new ItuneAppDTO();
|
||||||
|
ituneAppDTO.setPackageName(packageName);
|
||||||
|
ituneAppDTO.setVersion(version);
|
||||||
|
ituneAppDTO.setDescription(descriptionStandard);
|
||||||
|
ituneAppDTO.setTitle(name);
|
||||||
|
|
||||||
|
if (Constants.ApplicationProperties.PRICE_ZERO.equalsIgnoreCase(String.valueOf(price))) {
|
||||||
|
ituneAppDTO.setPaymentMethod(Constants.ApplicationProperties.FREE_SUB_METHOD);
|
||||||
|
} else {
|
||||||
|
ituneAppDTO.setPaymentMethod(Constants.ApplicationProperties.PAID_SUB_METHOD);
|
||||||
|
}
|
||||||
|
ituneAppDTO.setIconURL(iconUrl);
|
||||||
|
ituneAppDTO.setCategory(genreNames[0]);
|
||||||
|
|
||||||
|
return ituneAppDTO;
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while looking up the app details";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssetDTO getAssetByAppId(int appId) throws ApplicationManagementException {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.openDBConnection();
|
||||||
|
return vppApplicationDAO.getAssetByAppId(appId, tenantId);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "DB Connection error occurs while getting asset related to app with app id " + appId + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting asset data related to app with app id " + appId + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean addAssociation(VppAssetDTO asset, List<VppUserDTO> vppUsers) throws
|
||||||
|
ApplicationManagementException {
|
||||||
|
|
||||||
|
List<VppAssociationDTO> associations = new ArrayList<>(); // To save to UEM DBs
|
||||||
|
List<String> clientUserIds = new ArrayList<>(); // Need this to send to vpp backend.
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
if (asset != null) {
|
||||||
|
for (VppUserDTO vppUserDTO : vppUsers) {
|
||||||
|
VppAssociationDTO associationDTO = VppHttpUtil.getAssociation(vppUserDTO, asset);
|
||||||
|
associations.add(associationDTO);
|
||||||
|
clientUserIds.add(vppUserDTO.getClientUserId());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (associations.size() > 0) {
|
||||||
|
//TODO: Add or Update associations
|
||||||
|
try {
|
||||||
|
|
||||||
|
// Create the VPP backend payload
|
||||||
|
List<VppItuneAssetDTO> assets = new ArrayList<>();
|
||||||
|
VppItuneAssetDTO assetDTO = new VppItuneAssetDTO();
|
||||||
|
assetDTO.setAdamId(asset.getAdamId());
|
||||||
|
assetDTO.setPricingParam(asset.getPricingParam());
|
||||||
|
assets.add(assetDTO);
|
||||||
|
|
||||||
|
VppAssociateRequestWrapper vppAssociate = new VppAssociateRequestWrapper();
|
||||||
|
vppAssociate.setAssets(assets);
|
||||||
|
vppAssociate.setClientUserIds(clientUserIds);
|
||||||
|
|
||||||
|
Gson gson = new Gson();
|
||||||
|
String payload = gson.toJson(vppAssociate);
|
||||||
|
|
||||||
|
ProxyResponse proxyResponse = callVPPBackend(ASSIGNMENTS_POST, payload, getVppToken(),
|
||||||
|
Constants.VPP.POST);
|
||||||
|
if ((proxyResponse.getCode() == HttpStatus.SC_OK || proxyResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && proxyResponse.getData().contains(Constants.VPP.EVENT_ID)) {
|
||||||
|
// Create assignment does not return any useful data. Its needed to call the backend again
|
||||||
|
ProxyResponse getAssignmentResponse = callVPPBackend(ASSIGNMENTS_GET, null, getVppToken(), Constants.VPP.GET);
|
||||||
|
if ((getAssignmentResponse.getCode() == HttpStatus.SC_OK || getAssignmentResponse.getCode() ==
|
||||||
|
HttpStatus.SC_CREATED) && getAssignmentResponse.getData().contains(Constants.VPP.TOTAL_PAGES)) {
|
||||||
|
// VppAssociateResponseWrapper vppAssociateResponseWrapper = gson.fromJson
|
||||||
|
// (getAssignmentResponse.getData(), VppAssociateResponseWrapper.class);
|
||||||
|
for (VppAssociationDTO association : associations) {
|
||||||
|
|
||||||
|
VppAssociationDTO vppAssociation = getAssociation(association.getAssetId(), association.getClientId());
|
||||||
|
|
||||||
|
if (vppAssociation == null) {
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
if (vppApplicationDAO.addAssociation(association, tenantId) != -1) {
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
return false;
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while adding the Assignment.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for adding Assignment.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for adding Assignment.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.beginDBTransaction();
|
||||||
|
if (vppApplicationDAO.updateAssociation(association, tenantId) == null) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Unable to update the assignment: " +association.getAssetId();
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg);
|
||||||
|
}
|
||||||
|
ConnectionManagerUtil.commitDBTransaction();
|
||||||
|
return true;
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
ConnectionManagerUtil.rollbackDBTransaction();
|
||||||
|
String msg = "Error occurred while updating the Asset.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (TransactionManagementException e) {
|
||||||
|
String msg = "Error occurred while executing database transaction for Asset update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "Error occurred while retrieving the database connection for Asset update.";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while adding associations";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public VppAssociationDTO getAssociation(int assetId, int userId) throws ApplicationManagementException {
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(true);
|
||||||
|
try {
|
||||||
|
ConnectionManagerUtil.openDBConnection();
|
||||||
|
return vppApplicationDAO.getAssociation(assetId, userId, tenantId);
|
||||||
|
} catch (DBConnectionException e) {
|
||||||
|
String msg = "DB Connection error occurs while getting assignment related to user of id " + userId + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} catch (ApplicationManagementDAOException e) {
|
||||||
|
String msg = "Error occurred while getting assignment data related to user of id " + userId + ".";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
ConnectionManagerUtil.closeDBConnection();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ProxyResponse callVPPBackend(String url,
|
||||||
|
String payload,
|
||||||
|
String accessToken,
|
||||||
|
String method) throws IOException {
|
||||||
|
return VppHttpUtil.execute(url, payload, accessToken, method);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getVppToken() throws ApplicationManagementException {
|
||||||
|
String token = "";
|
||||||
|
MetadataManagementService meta = APIUtil.getMetadataManager();
|
||||||
|
Metadata metadata = null;
|
||||||
|
try {
|
||||||
|
metadata = meta.retrieveMetadata("DEP_META_KEY");
|
||||||
|
if (metadata != null) {
|
||||||
|
|
||||||
|
Gson g = new Gson();
|
||||||
|
DepConfig depConfigs = g.fromJson(metadata.getMetaValue(), DepConfig.class);
|
||||||
|
token = depConfigs.getVppToken();
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
}catch (MetadataManagementException e) {
|
||||||
|
String msg = "Error when retrieving metadata of vpp feature";
|
||||||
|
log.error(msg, e);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
return token;
|
||||||
|
}
|
||||||
|
|
||||||
|
public VppAssociationDTO getUserAssociation(String adamId, String emmUsername) throws ApplicationManagementException {
|
||||||
|
// Todo: Join the 3 tables and find a matching association
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -18,6 +18,13 @@
|
|||||||
package io.entgra.device.mgt.core.application.mgt.core.internal;
|
package io.entgra.device.mgt.core.application.mgt.core.internal;
|
||||||
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.config.LifecycleState;
|
import io.entgra.device.mgt.core.application.mgt.common.config.LifecycleState;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
|
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
import io.entgra.device.mgt.core.application.mgt.core.dao.common.ApplicationManagementDAOFactory;
|
||||||
@ -89,6 +96,12 @@ public class ApplicationManagementServiceComponent {
|
|||||||
DataHolder.getInstance().setConfigManager(configManager);
|
DataHolder.getInstance().setConfigManager(configManager);
|
||||||
bundleContext.registerService(AppmDataHandler.class.getName(), configManager, null);
|
bundleContext.registerService(AppmDataHandler.class.getName(), configManager, null);
|
||||||
|
|
||||||
|
// TODO: Get the new instance from extension like others
|
||||||
|
VPPApplicationManager vppApplicationManager = ApplicationManagementUtil
|
||||||
|
.getVPPManagerInstance();
|
||||||
|
DataHolder.getInstance().setVppApplicationManager(vppApplicationManager);
|
||||||
|
bundleContext.registerService(VPPApplicationManager.class.getName(), vppApplicationManager, null);
|
||||||
|
|
||||||
ScheduledAppSubscriptionTaskManager taskManager = new ScheduledAppSubscriptionTaskManager();
|
ScheduledAppSubscriptionTaskManager taskManager = new ScheduledAppSubscriptionTaskManager();
|
||||||
// todo: taskManager.scheduleCleanupTask();
|
// todo: taskManager.scheduleCleanupTask();
|
||||||
|
|
||||||
|
|||||||
@ -17,6 +17,13 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.application.mgt.core.internal;
|
package io.entgra.device.mgt.core.application.mgt.core.internal;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.AppmDataHandler;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
import io.entgra.device.mgt.core.device.mgt.core.service.DeviceManagementProviderService;
|
||||||
@ -34,6 +41,8 @@ public class DataHolder {
|
|||||||
|
|
||||||
private SPApplicationManager SPApplicationManager;
|
private SPApplicationManager SPApplicationManager;
|
||||||
|
|
||||||
|
private VPPApplicationManager vppApplicationManager;
|
||||||
|
|
||||||
private ApplicationManager applicationManager;
|
private ApplicationManager applicationManager;
|
||||||
|
|
||||||
private ReviewManager reviewManager;
|
private ReviewManager reviewManager;
|
||||||
@ -137,4 +146,12 @@ public class DataHolder {
|
|||||||
public void setISApplicationManager(SPApplicationManager SPApplicationManager) {
|
public void setISApplicationManager(SPApplicationManager SPApplicationManager) {
|
||||||
this.SPApplicationManager = SPApplicationManager;
|
this.SPApplicationManager = SPApplicationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VPPApplicationManager getVppApplicationManager() {
|
||||||
|
return vppApplicationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setVppApplicationManager(VPPApplicationManager vppApplicationManager) {
|
||||||
|
this.vppApplicationManager = vppApplicationManager;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -65,6 +65,7 @@ public class APIUtil {
|
|||||||
private static volatile SubscriptionManager subscriptionManager;
|
private static volatile SubscriptionManager subscriptionManager;
|
||||||
private static volatile ReviewManager reviewManager;
|
private static volatile ReviewManager reviewManager;
|
||||||
private static volatile AppmDataHandler appmDataHandler;
|
private static volatile AppmDataHandler appmDataHandler;
|
||||||
|
private static volatile VPPApplicationManager vppApplicationManager;
|
||||||
private static volatile MetadataManagementService metadataManagementService;
|
private static volatile MetadataManagementService metadataManagementService;
|
||||||
|
|
||||||
public static SPApplicationManager getSPApplicationManager() {
|
public static SPApplicationManager getSPApplicationManager() {
|
||||||
@ -107,6 +108,24 @@ public class APIUtil {
|
|||||||
return applicationManager;
|
return applicationManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static MetadataManagementService getMetadataManager() {
|
||||||
|
if (metadataManagementService == null) {
|
||||||
|
synchronized (APIUtil.class) {
|
||||||
|
if (metadataManagementService == null) {
|
||||||
|
PrivilegedCarbonContext ctx = PrivilegedCarbonContext.getThreadLocalCarbonContext();
|
||||||
|
metadataManagementService =
|
||||||
|
(MetadataManagementService) ctx.getOSGiService(MetadataManagementService.class, null);
|
||||||
|
if (metadataManagementService == null) {
|
||||||
|
String msg = "MetadataManagement Manager service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return metadataManagementService;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get the ApplicationDTO Storage Manager from the osgi context.
|
* To get the ApplicationDTO Storage Manager from the osgi context.
|
||||||
* @return ApplicationStoreManager instance in the current osgi context.
|
* @return ApplicationStoreManager instance in the current osgi context.
|
||||||
@ -195,6 +214,29 @@ public class APIUtil {
|
|||||||
return reviewManager;
|
return reviewManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VPPApplicationManager getVPPManager() {
|
||||||
|
try {
|
||||||
|
if (vppApplicationManager == null) {
|
||||||
|
synchronized (APIUtil.class) {
|
||||||
|
if (vppApplicationManager == null) {
|
||||||
|
vppApplicationManager = ApplicationManagementUtil.getVPPManagerInstance();
|
||||||
|
if (vppApplicationManager == null) {
|
||||||
|
String msg = "Vpp Manager service has not initialized.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
String msg = "Error occurred while getting the vpp manager";
|
||||||
|
log.error(msg);
|
||||||
|
throw new IllegalStateException(msg);
|
||||||
|
}
|
||||||
|
return vppApplicationManager;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* To get the DataHandler from the osgi context.
|
* To get the DataHandler from the osgi context.
|
||||||
* @return AppmDataHandler instance in the current osgi context.
|
* @return AppmDataHandler instance in the current osgi context.
|
||||||
@ -419,9 +461,13 @@ public class APIUtil {
|
|||||||
}
|
}
|
||||||
List<ApplicationRelease> applicationReleases = new ArrayList<>();
|
List<ApplicationRelease> applicationReleases = new ArrayList<>();
|
||||||
if (ApplicationType.PUBLIC.toString().equals(applicationDTO.getType()) && application.getCategories()
|
if (ApplicationType.PUBLIC.toString().equals(applicationDTO.getType()) && application.getCategories()
|
||||||
.contains("GooglePlaySyncedApp")) {
|
.contains(Constants.GOOGLE_PLAY_SYNCED_APP)) {
|
||||||
application.setAndroidEnterpriseApp(true);
|
application.setAndroidEnterpriseApp(true);
|
||||||
}
|
}
|
||||||
|
if (ApplicationType.PUBLIC.toString().equals(applicationDTO.getType()) && application.getCategories()
|
||||||
|
.contains(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY)) {
|
||||||
|
application.setExternalAppStoreApp(true);
|
||||||
|
}
|
||||||
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
for (ApplicationReleaseDTO applicationReleaseDTO : applicationDTO.getApplicationReleaseDTOs()) {
|
||||||
applicationReleases.add(releaseDtoToRelease(applicationReleaseDTO));
|
applicationReleases.add(releaseDtoToRelease(applicationReleaseDTO));
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,24 +19,64 @@ package io.entgra.device.mgt.core.application.mgt.core.util;
|
|||||||
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
import io.entgra.device.mgt.core.application.mgt.common.ApplicationArtifact;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.FileDataHolder;
|
import io.entgra.device.mgt.core.application.mgt.common.FileDataHolder;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.LifecycleChanger;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ApplicationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ItuneAppDTO;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.ApplicationManagementException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.InvalidConfigurationException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.InvalidConfigurationException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
|
import io.entgra.device.mgt.core.application.mgt.common.exception.RequestValidatingException;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
import io.entgra.device.mgt.core.application.mgt.common.response.Application;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
|
import io.entgra.device.mgt.core.application.mgt.common.response.Category;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ApplicationStorageManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.ReviewManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.SubscriptionManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.VPPApplicationManager;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ApplicationUpdateWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.ApplicationWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.CustomAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.CustomAppWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.EntAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.PublicAppWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppReleaseWrapper;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.WebAppWrapper;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
|
import io.entgra.device.mgt.core.application.mgt.core.config.ConfigurationManager;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.config.Extension;
|
import io.entgra.device.mgt.core.application.mgt.core.config.Extension;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.BadRequestException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.core.impl.VppApplicationManagerImpl;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
import io.entgra.device.mgt.core.application.mgt.core.lifecycle.LifecycleStateManager;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
import io.entgra.device.mgt.core.device.mgt.common.Base64File;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.DeviceManagementConstants;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.metadata.mgt.MetadataManagementService;
|
||||||
import io.entgra.device.mgt.core.device.mgt.core.common.util.FileUtil;
|
import io.entgra.device.mgt.core.device.mgt.core.common.util.FileUtil;
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.core.metadata.mgt.MetadataManagementServiceImpl;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.services.*;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.wrapper.*;
|
||||||
|
|
||||||
|
import java.io.ByteArrayOutputStream;
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.FileInputStream;
|
||||||
|
import java.io.FileNotFoundException;
|
||||||
|
import java.io.FileOutputStream;
|
||||||
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Constructor;
|
||||||
import java.util.*;
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.nio.channels.Channels;
|
||||||
|
import java.nio.channels.ReadableByteChannel;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.Base64;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This DAOUtil class is responsible for making sure single instance of each Extension Manager is used throughout for
|
* This DAOUtil class is responsible for making sure single instance of each Extension Manager is used throughout for
|
||||||
@ -168,6 +208,10 @@ public class ApplicationManagementUtil {
|
|||||||
return getInstance(extension, LifecycleStateManager.class);
|
return getInstance(extension, LifecycleStateManager.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static VPPApplicationManager getVPPManagerInstance() {
|
||||||
|
// TODO: implement as an extension
|
||||||
|
return new VppApplicationManagerImpl();
|
||||||
|
}
|
||||||
/**
|
/**
|
||||||
* This is useful to delete application artifacts if any error occurred while creating release/application
|
* This is useful to delete application artifacts if any error occurred while creating release/application
|
||||||
* after uploading the artifacts
|
* after uploading the artifacts
|
||||||
@ -232,4 +276,265 @@ public class ApplicationManagementUtil {
|
|||||||
throw new InvalidConfigurationException(msg, e);
|
throw new InvalidConfigurationException(msg, e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void persistApp(ItuneAppDTO product) throws ApplicationManagementException {
|
||||||
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
|
List<Category> categories = applicationManager.getRegisteredCategories();
|
||||||
|
if (product != null && product.getVersion() != null) {
|
||||||
|
// Generate artifacts
|
||||||
|
ApplicationArtifact applicationArtifact = generateArtifacts(product);
|
||||||
|
|
||||||
|
List<String> packageNamesOfApps = new ArrayList<>();
|
||||||
|
packageNamesOfApps.add(product.getPackageName());
|
||||||
|
|
||||||
|
List<Application> existingApps = applicationManager.getApplications(packageNamesOfApps);
|
||||||
|
|
||||||
|
if (existingApps != null && existingApps.size() > 0) {
|
||||||
|
Application app = existingApps.get(0);
|
||||||
|
if (product.getPackageName().equals(app.getPackageName())) {
|
||||||
|
ApplicationUpdateWrapper applicationUpdateWrapper = generatePubAppUpdateWrapper(product, categories);
|
||||||
|
applicationManager.updateApplication(app.getId(), applicationUpdateWrapper);
|
||||||
|
|
||||||
|
PublicAppReleaseWrapper publicAppReleaseWrapper = new PublicAppReleaseWrapper();
|
||||||
|
if (app.getSubMethod()
|
||||||
|
.equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
|
||||||
|
publicAppReleaseWrapper.setPrice(0.0);
|
||||||
|
} else {
|
||||||
|
publicAppReleaseWrapper.setPrice(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
publicAppReleaseWrapper.setDescription(product.getDescription());
|
||||||
|
publicAppReleaseWrapper.setReleaseType("ga");
|
||||||
|
publicAppReleaseWrapper.setVersion(product.getVersion());
|
||||||
|
publicAppReleaseWrapper.setSupportedOsVersions("4.0-12.3");
|
||||||
|
applicationManager.updatePubAppRelease(app.getApplicationReleases().get(0).getUuid(),
|
||||||
|
publicAppReleaseWrapper, applicationArtifact);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
|
||||||
|
// Generate App wrapper
|
||||||
|
PublicAppWrapper publicAppWrapper = generatePubAppWrapper(product, categories);
|
||||||
|
PublicAppReleaseWrapper appReleaseWrapper = new PublicAppReleaseWrapper();
|
||||||
|
|
||||||
|
if (publicAppWrapper.getSubMethod()
|
||||||
|
.equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
|
||||||
|
appReleaseWrapper.setPrice(0.0);
|
||||||
|
} else {
|
||||||
|
appReleaseWrapper.setPrice(1.0);
|
||||||
|
}
|
||||||
|
|
||||||
|
appReleaseWrapper.setDescription(product.getDescription());
|
||||||
|
appReleaseWrapper.setReleaseType("ga");
|
||||||
|
appReleaseWrapper.setVersion(product.getVersion());
|
||||||
|
appReleaseWrapper.setPackageName(product.getPackageName());
|
||||||
|
appReleaseWrapper.setSupportedOsVersions("4.0-12.3");
|
||||||
|
|
||||||
|
publicAppWrapper.setPublicAppReleaseWrappers(
|
||||||
|
Arrays.asList(new PublicAppReleaseWrapper[]{appReleaseWrapper}));
|
||||||
|
|
||||||
|
try {
|
||||||
|
updateImages(appReleaseWrapper, applicationArtifact.getIconName(),
|
||||||
|
applicationArtifact.getIconStream(), applicationArtifact.getScreenshots());
|
||||||
|
|
||||||
|
Application application = applicationManager.createApplication(publicAppWrapper, false);
|
||||||
|
if (application != null && (application.getApplicationReleases().get(0).getCurrentStatus() == null
|
||||||
|
|| application.getApplicationReleases().get(0).getCurrentStatus().equals("CREATED"))) {
|
||||||
|
String uuid = application.getApplicationReleases().get(0).getUuid();
|
||||||
|
LifecycleChanger lifecycleChanger = new LifecycleChanger();
|
||||||
|
lifecycleChanger.setAction("IN-REVIEW");
|
||||||
|
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
|
||||||
|
lifecycleChanger.setAction("APPROVED");
|
||||||
|
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
|
||||||
|
lifecycleChanger.setAction("PUBLISHED");
|
||||||
|
applicationManager.changeLifecycleState(uuid, lifecycleChanger);
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while downloading images of release.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static PublicAppWrapper generatePubAppWrapper(ItuneAppDTO product, List<Category> categories) {
|
||||||
|
PublicAppWrapper publicAppWrapper = new PublicAppWrapper();
|
||||||
|
publicAppWrapper.setName(product.getTitle());
|
||||||
|
publicAppWrapper.setDescription(product.getDescription());
|
||||||
|
publicAppWrapper.setCategories(
|
||||||
|
Collections.singletonList(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY));//Default category
|
||||||
|
for (Category category : categories) {
|
||||||
|
if (product.getCategory() == null) {
|
||||||
|
List<String> pubAppCategories = new ArrayList<>();
|
||||||
|
pubAppCategories.add(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY);
|
||||||
|
publicAppWrapper.setCategories(pubAppCategories);
|
||||||
|
break;
|
||||||
|
} else if (product.getCategory().equalsIgnoreCase(category.getCategoryName())) {
|
||||||
|
List<String> pubAppCategories = new ArrayList<>();
|
||||||
|
pubAppCategories.add(category.getCategoryName());
|
||||||
|
pubAppCategories.add(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY);
|
||||||
|
publicAppWrapper.setCategories(pubAppCategories);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (product.getPaymentMethod().equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
|
||||||
|
publicAppWrapper.setSubMethod(Constants.ApplicationProperties.FREE_SUB_METHOD);
|
||||||
|
} else {
|
||||||
|
publicAppWrapper.setSubMethod(Constants.ApplicationProperties.PAID_SUB_METHOD);
|
||||||
|
}
|
||||||
|
// TODO: purchase an app from app store and see how to capture the real value for price
|
||||||
|
// field.
|
||||||
|
publicAppWrapper.setPaymentCurrency("$");
|
||||||
|
publicAppWrapper.setDeviceType(DeviceManagementConstants.MobileDeviceTypes.MOBILE_DEVICE_TYPE_IOS);
|
||||||
|
return publicAppWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ApplicationUpdateWrapper generatePubAppUpdateWrapper(ItuneAppDTO product, List<Category> categories) {
|
||||||
|
ApplicationUpdateWrapper applicationUpdateWrapper = new ApplicationUpdateWrapper();
|
||||||
|
applicationUpdateWrapper.setName(product.getTitle());
|
||||||
|
applicationUpdateWrapper.setDescription(product.getDescription());
|
||||||
|
applicationUpdateWrapper.setCategories(
|
||||||
|
Collections.singletonList(Constants
|
||||||
|
.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY));//Default
|
||||||
|
// add the default APPLE_STORE_SYNCED_APP_CATEGORY
|
||||||
|
for (Category category : categories) {
|
||||||
|
if (product.getCategory() == null) {
|
||||||
|
List<String> pubAppCategories = new ArrayList<>();
|
||||||
|
pubAppCategories.add(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY);
|
||||||
|
applicationUpdateWrapper.setCategories(pubAppCategories);
|
||||||
|
break;
|
||||||
|
} else if (product.getCategory().equalsIgnoreCase(category.getCategoryName())) {
|
||||||
|
List<String> pubAppCategories = new ArrayList<>();
|
||||||
|
pubAppCategories.add(category.getCategoryName());
|
||||||
|
pubAppCategories.add(Constants.ApplicationProperties.APPLE_STORE_SYNCED_APP_CATEGORY);
|
||||||
|
applicationUpdateWrapper.setCategories(pubAppCategories);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (product.getPaymentMethod().equalsIgnoreCase(Constants.ApplicationProperties.FREE_SUB_METHOD)) {
|
||||||
|
applicationUpdateWrapper.setSubMethod(Constants.ApplicationProperties.FREE_SUB_METHOD);
|
||||||
|
} else {
|
||||||
|
applicationUpdateWrapper.setSubMethod(Constants.ApplicationProperties.PAID_SUB_METHOD);
|
||||||
|
}
|
||||||
|
// TODO: purchase an app from Playstore and see how to capture the real value for price field.
|
||||||
|
applicationUpdateWrapper.setPaymentCurrency("$");
|
||||||
|
return applicationUpdateWrapper;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static ApplicationArtifact generateArtifacts(ItuneAppDTO product) throws ApplicationManagementException {
|
||||||
|
ApplicationArtifact applicationArtifact = new ApplicationArtifact();
|
||||||
|
String prefix = product.getPackageName();
|
||||||
|
try {
|
||||||
|
String iconName = prefix + "_icon";
|
||||||
|
applicationArtifact.setIconName(iconName);
|
||||||
|
InputStream iconInputStream = getInputStream(iconName, product.getIconURL());
|
||||||
|
applicationArtifact.setIconStream(iconInputStream);
|
||||||
|
Map<String, InputStream> screenshotMap = new HashMap<>();
|
||||||
|
// TODO: look for a way to get screenshots
|
||||||
|
|
||||||
|
for (int a = 0; a < 3; a++) {
|
||||||
|
String screenshotName = product.getPackageName() + a;
|
||||||
|
InputStream screenshotInputStream = getInputStream(screenshotName, product.getIconURL());
|
||||||
|
screenshotMap.put(screenshotName, screenshotInputStream);
|
||||||
|
}
|
||||||
|
|
||||||
|
applicationArtifact.setScreenshots(screenshotMap);
|
||||||
|
return applicationArtifact;
|
||||||
|
} catch (ApplicationManagementException e) {
|
||||||
|
String msg = "Error occurred while generating Application artifact";
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static InputStream getInputStream(String filename, String url) throws ApplicationManagementException {
|
||||||
|
URL website;
|
||||||
|
try {
|
||||||
|
website = new URL(url);
|
||||||
|
} catch (MalformedURLException e) {
|
||||||
|
String msg = "Error occurred while converting the url " + url;
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
ReadableByteChannel rbc = null;
|
||||||
|
FileOutputStream fos = null;
|
||||||
|
try {
|
||||||
|
rbc = Channels.newChannel(website.openStream());
|
||||||
|
fos = new FileOutputStream(System.getProperty("java.io.tmpdir")
|
||||||
|
+ File.separator + filename);
|
||||||
|
fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE);
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error occurred while opening stream for url " + url;
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
fos.close();
|
||||||
|
rbc.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
File file = new File(System.getProperty("java.io.tmpdir") + File.separator + filename);
|
||||||
|
InputStream targetStream;
|
||||||
|
try {
|
||||||
|
targetStream = new FileInputStream(file);
|
||||||
|
} catch (FileNotFoundException e) {
|
||||||
|
String msg = "Error occurred while reading the tmp file " + System.getProperty("java.io.tmpdir")
|
||||||
|
+ File.separator + filename;
|
||||||
|
log.error(msg);
|
||||||
|
throw new ApplicationManagementException(msg, e);
|
||||||
|
}
|
||||||
|
file.deleteOnExit();
|
||||||
|
return targetStream;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void updateImages(PublicAppReleaseWrapper appReleaseWrapper, String iconName,
|
||||||
|
InputStream iconStream, Map<String, InputStream>
|
||||||
|
screenshotsMaps) throws IOException {
|
||||||
|
List<Base64File> screenshots = new ArrayList<>();
|
||||||
|
Base64File iconFile = new Base64File(iconName,
|
||||||
|
convertStreamToBase64(iconStream));
|
||||||
|
appReleaseWrapper.setIcon(iconFile);
|
||||||
|
if (screenshotsMaps.size() > 0) {
|
||||||
|
for (Map.Entry<String, InputStream> screenshotEntry : screenshotsMaps.entrySet()) {
|
||||||
|
Base64File screenshot = new Base64File(screenshotEntry.getKey(),
|
||||||
|
convertStreamToBase64(screenshotEntry.getValue()));
|
||||||
|
screenshots.add(screenshot);
|
||||||
|
}
|
||||||
|
appReleaseWrapper.setScreenshots(screenshots);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String convertStreamToBase64(InputStream inputStream) throws IOException {
|
||||||
|
final int bufLen = 4 * 0x400; // 4KB
|
||||||
|
byte[] buf = new byte[bufLen];
|
||||||
|
int readLen;
|
||||||
|
|
||||||
|
try {
|
||||||
|
try (ByteArrayOutputStream outputStream = new ByteArrayOutputStream()) {
|
||||||
|
while ((readLen = inputStream.read(buf, 0, bufLen)) != -1)
|
||||||
|
outputStream.write(buf, 0, readLen);
|
||||||
|
|
||||||
|
return Base64.getEncoder().encodeToString(outputStream.toByteArray());
|
||||||
|
}
|
||||||
|
} catch (IOException e) {
|
||||||
|
String msg = "Error while converting image to base64";
|
||||||
|
log.error(msg);
|
||||||
|
throw e;
|
||||||
|
} finally {
|
||||||
|
try {
|
||||||
|
inputStream.close();
|
||||||
|
} catch (IOException e) {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Application> getAppDetails(String adamId) throws ApplicationManagementException {
|
||||||
|
ApplicationManager applicationManager = APIUtil.getApplicationManager();
|
||||||
|
List<String> packageNamesOfApps = new ArrayList<>();
|
||||||
|
packageNamesOfApps.add(adamId);
|
||||||
|
return applicationManager.getApplications(packageNamesOfApps);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -74,6 +74,7 @@ public class Constants {
|
|||||||
public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles";
|
public static final String IS_USER_ABLE_TO_VIEW_ALL_ROLES = "isUserAbleToViewAllRoles";
|
||||||
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
|
public static final String GOOGLE_PLAY_STORE_URL = "https://play.google.com/store/apps/details?id=";
|
||||||
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
|
public static final String APPLE_STORE_URL = "https://itunes.apple.com/country/app/app-name/id";
|
||||||
|
public static final String GOOGLE_PLAY_SYNCED_APP = "GooglePlaySyncedApp";
|
||||||
|
|
||||||
// Subscription task related constants
|
// Subscription task related constants
|
||||||
public static final String SUBSCRIBERS = "SUBSCRIBERS";
|
public static final String SUBSCRIBERS = "SUBSCRIBERS";
|
||||||
@ -104,6 +105,25 @@ public class Constants {
|
|||||||
}
|
}
|
||||||
public static final Map<String, String> AGENT_FILE_NAMES = Collections.unmodifiableMap(AGENT_DATA);
|
public static final Map<String, String> AGENT_FILE_NAMES = Collections.unmodifiableMap(AGENT_DATA);
|
||||||
|
|
||||||
|
public static final class VPP {
|
||||||
|
public static final String GET = "GET";
|
||||||
|
public static final String BEARER = "Bearer ";
|
||||||
|
public static final String EXECUTOR_EXCEPTION_PREFIX = "ExecutorException-";
|
||||||
|
public static final String TOKEN_IS_EXPIRED = "ACCESS_TOKEN_IS_EXPIRED";
|
||||||
|
public static final int INTERNAL_ERROR_CODE = 500;
|
||||||
|
public static final String POST = "POST";
|
||||||
|
public static final String PUT = "PUT";
|
||||||
|
public static final String DELETE = "DELETE";
|
||||||
|
public static final String EVENT_ID = "eventId";
|
||||||
|
public static final String CLIENT_USER_ID_PARAM = "?clientUserId=";
|
||||||
|
public static final String TOTAL_PAGES = "totalPages";
|
||||||
|
public static final String GET_APP_DATA_RESPONSE_START = "results";
|
||||||
|
public static final String REMOTE_FILE_NAME = "512x512w.png";
|
||||||
|
|
||||||
|
private VPP() {
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Database types supported by Application Management.
|
* Database types supported by Application Management.
|
||||||
@ -161,6 +181,8 @@ public class Constants {
|
|||||||
public static final String DEVICE_TYPE_ANDROID = "android";
|
public static final String DEVICE_TYPE_ANDROID = "android";
|
||||||
public static final String COLON = ":";
|
public static final String COLON = ":";
|
||||||
public static final String IOT_CORE_HOST = "iot.core.host";
|
public static final String IOT_CORE_HOST = "iot.core.host";
|
||||||
|
|
||||||
|
public static final String IOT_GATEWAY_HOST = "iot.gateway.host";
|
||||||
public static final String IOT_CORE_PORT = "iot.core.https.port";
|
public static final String IOT_CORE_PORT = "iot.core.https.port";
|
||||||
public static final String ENROLLMENT_APP_INSTALL_PROTOCOL = "https://";
|
public static final String ENROLLMENT_APP_INSTALL_PROTOCOL = "https://";
|
||||||
public static final String GOOGLE_APP_INSTALL_URL = "/api/device-mgt/android/v1.0/enterprise/change-app";
|
public static final String GOOGLE_APP_INSTALL_URL = "/api/device-mgt/android/v1.0/enterprise/change-app";
|
||||||
@ -168,4 +190,31 @@ public class Constants {
|
|||||||
public static final String AUTHORIZATION = "Authorization";
|
public static final String AUTHORIZATION = "Authorization";
|
||||||
public static final String AUTHORIZATION_HEADER_VALUE = "Bearer ";
|
public static final String AUTHORIZATION_HEADER_VALUE = "Bearer ";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public final class ApplicationProperties {
|
||||||
|
private ApplicationProperties() {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final String NAME = "name";
|
||||||
|
public static final String VERSION = "version";
|
||||||
|
public static final String FREE_SUB_METHOD = "FREE";
|
||||||
|
public static final String PAID_SUB_METHOD = "PAID";
|
||||||
|
public static final String TYPE = "type";;
|
||||||
|
public static final String PACKAGE_NAME = "packageName";
|
||||||
|
public static final String APPLE_STORE_SYNCED_APP_CATEGORY = "AppleStoreSyncedApp";
|
||||||
|
|
||||||
|
public static final String RESULTS = "results";
|
||||||
|
public static final String ARTWORK = "artwork";
|
||||||
|
public static final String URL = "url";
|
||||||
|
public static final String DESCRIPTION = "description";
|
||||||
|
public static final String STANDARD = "standard";
|
||||||
|
public static final String OFFERS = "offers";
|
||||||
|
public static final String PRICE = "price";
|
||||||
|
public static final String DISPLAY = "display";
|
||||||
|
public static final String GENRE_NAMES = "genreNames";
|
||||||
|
public static final String PRICE_ZERO = "0.0";
|
||||||
|
public static final String ASSOCIATION_DEVICE = "ASSOCIATION_DEVICE";
|
||||||
|
public static final String ASSOCIATION_USER = "ASSOCIATION_USER";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -19,24 +19,28 @@ package io.entgra.device.mgt.core.application.mgt.core.util;
|
|||||||
|
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.google.gson.reflect.TypeToken;
|
import com.google.gson.reflect.TypeToken;
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
|
|
||||||
import io.entgra.device.mgt.core.application.mgt.common.dto.*;
|
import io.entgra.device.mgt.core.application.mgt.common.dto.*;
|
||||||
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
import io.entgra.device.mgt.core.application.mgt.core.exception.UnexpectedServerErrorException;
|
||||||
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
import io.entgra.device.mgt.core.device.mgt.common.operation.mgt.Activity;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.json.JSONException;
|
import org.json.JSONException;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.ExecutionStatus;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.SubscriptionType;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.DeviceIdentifier;
|
||||||
|
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.ResultSet;
|
import java.sql.ResultSet;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.sql.Timestamp;
|
import java.sql.Timestamp;
|
||||||
|
import java.text.SimpleDateFormat;
|
||||||
import java.time.Instant;
|
import java.time.Instant;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Date;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@ -235,6 +239,26 @@ public class DAOUtil {
|
|||||||
return applicationDTOs.get(0);
|
return applicationDTOs.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static ApplicationDTO loadDeviceApp(ResultSet rs) throws SQLException {
|
||||||
|
ApplicationDTO application = new ApplicationDTO();
|
||||||
|
application.setId( rs.getInt("APP_ID"));
|
||||||
|
application.setName(rs.getString("APP_NAME"));
|
||||||
|
application.setDescription(rs.getString("APP_DESCRIPTION"));
|
||||||
|
application.setType(rs.getString("APP_TYPE"));
|
||||||
|
application.setSubType(rs.getString("APP_SUB_TYPE"));
|
||||||
|
application.setPaymentCurrency(rs.getString("APP_CURRENCY"));
|
||||||
|
application.setStatus(rs.getString("APP_STATUS"));
|
||||||
|
application.setAppRating(rs.getDouble("APP_RATING"));
|
||||||
|
application.setDeviceTypeId(rs.getInt("APP_DEVICE_TYPE_ID"));
|
||||||
|
ApplicationReleaseDTO releaseDTO = constructAppReleaseDTO(rs);
|
||||||
|
List<ApplicationReleaseDTO> releaseDtoList = new ArrayList<>();
|
||||||
|
if (releaseDTO != null) {
|
||||||
|
releaseDtoList.add(constructAppReleaseDTO(rs));
|
||||||
|
application.setApplicationReleaseDTOs(releaseDtoList);
|
||||||
|
}
|
||||||
|
return application;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Populates {@link ApplicationReleaseDTO} object with the result obtained from the database.
|
* Populates {@link ApplicationReleaseDTO} object with the result obtained from the database.
|
||||||
*
|
*
|
||||||
@ -338,6 +362,185 @@ public class DAOUtil {
|
|||||||
return subscriptionDTOS;
|
return subscriptionDTOS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static Activity loadOperationActivity(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
|
||||||
|
List<Activity> activity = loadOperationActivities(rs);
|
||||||
|
if (activity.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (activity.size() > 1) {
|
||||||
|
String msg = "Internal server error. Found more than one app for operation";
|
||||||
|
log.error(msg);
|
||||||
|
throw new UnexpectedServerErrorException(msg);
|
||||||
|
}
|
||||||
|
return activity.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<Activity> loadOperationActivities (ResultSet rs) throws SQLException {
|
||||||
|
List<Activity> activities = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
Activity activity = new Activity();
|
||||||
|
activity.setAppName(rs.getString("NAME"));
|
||||||
|
activity.setAppType(rs.getString("TYPE"));
|
||||||
|
activity.setUsername(rs.getString("SUBSCRIBED_BY"));
|
||||||
|
activity.setPackageName(rs.getString("PACKAGE_NAME"));
|
||||||
|
activity.setStatus(rs.getString("STATUS"));
|
||||||
|
activity.setVersion(rs.getString("VERSION"));
|
||||||
|
activity.setTriggeredBy(rs.getString("ACTION_TRIGGERED_FROM"));
|
||||||
|
activities.add(activity);
|
||||||
|
}
|
||||||
|
return activities;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VppUserDTO loadVppUser(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
|
||||||
|
List<VppUserDTO> vppUserDTOS = loadVppUsers(rs);
|
||||||
|
if (vppUserDTOS.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (vppUserDTOS.size() > 1) {
|
||||||
|
String msg = "Internal server error. Found more than one vpp user for requested emmUsername";
|
||||||
|
log.error(msg);
|
||||||
|
throw new UnexpectedServerErrorException(msg);
|
||||||
|
}
|
||||||
|
return vppUserDTOS.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<VppUserDTO> loadVppUsers (ResultSet rs) throws SQLException {
|
||||||
|
List<VppUserDTO> vppUserDTOS = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
VppUserDTO vppUserDTO = new VppUserDTO();
|
||||||
|
vppUserDTO.setId(rs.getInt("ID"));
|
||||||
|
vppUserDTO.setClientUserId(rs.getString("CLIENT_USER_ID"));
|
||||||
|
vppUserDTO.setTenantId(rs.getInt("TENANT_ID"));
|
||||||
|
vppUserDTO.setEmail(rs.getString("EMAIL"));
|
||||||
|
vppUserDTO.setInviteCode(rs.getString("INVITE_CODE"));
|
||||||
|
if (columnExist(rs,"STATUS")) {
|
||||||
|
vppUserDTO.setStatus(rs.getString("STATUS"));
|
||||||
|
}
|
||||||
|
if (columnExist(rs,"MANAGED_ID")) {
|
||||||
|
vppUserDTO.setManagedId(rs.getString("MANAGED_ID"));
|
||||||
|
}
|
||||||
|
if (columnExist(rs,"TEMP_PASSWORD")) {
|
||||||
|
vppUserDTO.setTmpPassword(rs.getString("TEMP_PASSWORD"));
|
||||||
|
}
|
||||||
|
if (columnExist(rs,"DM_USERNAME")) {
|
||||||
|
vppUserDTO.setDmUsername(rs.getString("DM_USERNAME"));
|
||||||
|
}
|
||||||
|
if (rs.getLong("CREATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("CREATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppUserDTO.setCreatedTime(dateString);
|
||||||
|
}
|
||||||
|
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppUserDTO.setLastUpdatedTime(dateString);
|
||||||
|
}
|
||||||
|
vppUserDTOS.add(vppUserDTO);
|
||||||
|
}
|
||||||
|
return vppUserDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static boolean columnExist(ResultSet rs, String column){
|
||||||
|
try{
|
||||||
|
rs.findColumn(column);
|
||||||
|
return true;
|
||||||
|
} catch (SQLException sqlex){
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VppAssetDTO loadAsset(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
|
||||||
|
List<VppAssetDTO> vppAssetDTOS = loadAssets(rs);
|
||||||
|
if (vppAssetDTOS.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (vppAssetDTOS.size() > 1) {
|
||||||
|
String msg = "Internal server error. Found more than one asset for given app id.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new UnexpectedServerErrorException(msg);
|
||||||
|
}
|
||||||
|
return vppAssetDTOS.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<VppAssetDTO> loadAssets (ResultSet rs) throws SQLException {
|
||||||
|
List<VppAssetDTO> vppAssetDTOS = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
VppAssetDTO vppAssetDTO = new VppAssetDTO();
|
||||||
|
vppAssetDTO.setId(rs.getInt("ID"));
|
||||||
|
vppAssetDTO.setAppId(rs.getInt("APP_ID"));
|
||||||
|
vppAssetDTO.setTenantId(rs.getInt("TENANT_ID"));
|
||||||
|
if (rs.getLong("CREATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("CREATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppAssetDTO.setCreatedTime(dateString);
|
||||||
|
}
|
||||||
|
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppAssetDTO.setLastUpdatedTime(dateString);
|
||||||
|
}
|
||||||
|
vppAssetDTO.setAdamId(rs.getString("ADAM_ID"));
|
||||||
|
vppAssetDTO.setAssignedCount(rs.getString("ASSIGNED_COUNT"));
|
||||||
|
vppAssetDTO.setDeviceAssignable(rs.getString("DEVICE_ASSIGNABLE"));
|
||||||
|
vppAssetDTO.setPricingParam(rs.getString("PRICING_PARAMS"));
|
||||||
|
vppAssetDTO.setProductType(rs.getString("PRODUCT_TYPE"));
|
||||||
|
vppAssetDTO.setRetiredCount(rs.getString("RETIRED_COUNT"));
|
||||||
|
vppAssetDTO.setRevocable(rs.getString("REVOCABLE"));
|
||||||
|
// String jsonString = rs.getString("SUPPORTED_PLATFORMS");
|
||||||
|
// ObjectMapper objectMapper = new ObjectMapper();
|
||||||
|
// try {
|
||||||
|
// List<String> platformList = objectMapper.readValue(jsonString, new TypeReference<List<String>>() {});
|
||||||
|
// vppAssetDTO.setSupportedPlatforms(platformList);
|
||||||
|
// } catch (IOException e) {
|
||||||
|
// e.printStackTrace();
|
||||||
|
// }
|
||||||
|
vppAssetDTOS.add(vppAssetDTO);
|
||||||
|
}
|
||||||
|
return vppAssetDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VppAssociationDTO loadAssignment(ResultSet rs) throws SQLException, UnexpectedServerErrorException {
|
||||||
|
List<VppAssociationDTO> vppAssociationDTOS = loadAssignments(rs);
|
||||||
|
if (vppAssociationDTOS.isEmpty()) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (vppAssociationDTOS.size() > 1) {
|
||||||
|
String msg = "Internal server error. Found more than one asset for given app id.";
|
||||||
|
log.error(msg);
|
||||||
|
throw new UnexpectedServerErrorException(msg);
|
||||||
|
}
|
||||||
|
return vppAssociationDTOS.get(0);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static List<VppAssociationDTO> loadAssignments (ResultSet rs) throws SQLException {
|
||||||
|
List<VppAssociationDTO> vppAssociationDTOS = new ArrayList<>();
|
||||||
|
while (rs.next()) {
|
||||||
|
VppAssociationDTO vppAssociationDTO = new VppAssociationDTO();
|
||||||
|
vppAssociationDTO.setId(rs.getInt("ID"));
|
||||||
|
vppAssociationDTO.setAssociationType(rs.getString("ASSOCIATION_TYPE"));
|
||||||
|
if (rs.getLong("CREATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("CREATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppAssociationDTO.setCreatedTime(dateString);
|
||||||
|
}
|
||||||
|
if (rs.getLong("LAST_UPDATED_TIME") != 0) {
|
||||||
|
Date date = new Date(rs.getLong("LAST_UPDATED_TIME"));
|
||||||
|
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
|
||||||
|
String dateString = dateFormat.format(date);
|
||||||
|
vppAssociationDTO.setLastUpdatedTime(dateString);
|
||||||
|
}
|
||||||
|
vppAssociationDTO.setPricingParam(rs.getString("PRICING_PARAMS"));
|
||||||
|
vppAssociationDTOS.add(vppAssociationDTO);
|
||||||
|
}
|
||||||
|
return vppAssociationDTOS;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cleans up the statement and resultset after executing the query
|
* Cleans up the statement and resultset after executing the query
|
||||||
*
|
*
|
||||||
|
|||||||
@ -0,0 +1,305 @@
|
|||||||
|
/*
|
||||||
|
* Copyright (c) 2018 - 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved.
|
||||||
|
*
|
||||||
|
* Entgra (Pvt) Ltd. licenses this file to you under the Apache License,
|
||||||
|
* Version 2.0 (the "License"); you may not use this file except
|
||||||
|
* in compliance with the License.
|
||||||
|
* You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
*/
|
||||||
|
|
||||||
|
package io.entgra.device.mgt.core.application.mgt.core.util;
|
||||||
|
|
||||||
|
import com.google.gson.Gson;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.ProxyResponse;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssetDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppAssociationDTO;
|
||||||
|
import io.entgra.device.mgt.core.application.mgt.common.dto.VppUserDTO;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
import org.apache.http.Consts;
|
||||||
|
import org.apache.http.HttpEntity;
|
||||||
|
import org.apache.http.HttpHeaders;
|
||||||
|
import org.apache.http.HttpResponse;
|
||||||
|
import org.apache.http.HttpStatus;
|
||||||
|
import org.apache.http.client.methods.HttpGet;
|
||||||
|
import org.apache.http.client.methods.HttpPost;
|
||||||
|
import org.apache.http.client.methods.HttpPut;
|
||||||
|
import org.apache.http.client.methods.HttpRequestBase;
|
||||||
|
import org.apache.http.entity.ContentType;
|
||||||
|
import org.apache.http.entity.StringEntity;
|
||||||
|
import org.apache.http.impl.client.CloseableHttpClient;
|
||||||
|
import org.apache.http.impl.client.HttpClients;
|
||||||
|
import org.json.JSONArray;
|
||||||
|
import org.json.JSONException;
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
import java.io.BufferedReader;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.io.InputStreamReader;
|
||||||
|
import java.io.PrintWriter;
|
||||||
|
|
||||||
|
public class VppHttpUtil {
|
||||||
|
private static final Log log = LogFactory.getLog(VppHttpUtil.class);
|
||||||
|
|
||||||
|
public static ProxyResponse execute(String url,
|
||||||
|
String payload,
|
||||||
|
String accessToken,
|
||||||
|
String method) throws IOException {
|
||||||
|
|
||||||
|
HttpRequestBase endpoint = null;
|
||||||
|
if (Constants.VPP.GET.equalsIgnoreCase(method) || Constants.VPP.DELETE.equalsIgnoreCase(method)) {
|
||||||
|
endpoint = new HttpGet(url);
|
||||||
|
addHeaders(endpoint, accessToken);
|
||||||
|
return VppHttpUtil.execute(endpoint);
|
||||||
|
} else if (Constants.VPP.POST.equalsIgnoreCase(method)) {
|
||||||
|
endpoint = new HttpPost(url);
|
||||||
|
} else if (Constants.VPP.PUT.equalsIgnoreCase(method)) {
|
||||||
|
endpoint = new HttpPut(url);
|
||||||
|
}
|
||||||
|
addHeaders(endpoint, accessToken);
|
||||||
|
|
||||||
|
|
||||||
|
if (payload != null) {
|
||||||
|
HttpEntity forwardRequestBody = new StringEntity(payload, ContentType.APPLICATION_JSON.toString(), "utf-8");
|
||||||
|
if (Constants.VPP.POST.equalsIgnoreCase(method)) {
|
||||||
|
((HttpPost) endpoint).setEntity(forwardRequestBody);
|
||||||
|
} else if (Constants.VPP.PUT.equalsIgnoreCase(method)) {
|
||||||
|
((HttpPut) endpoint).setEntity(forwardRequestBody);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
if (log.isDebugEnabled()) {
|
||||||
|
log.info("Forwarding request to " + url);
|
||||||
|
}
|
||||||
|
return VppHttpUtil.execute(endpoint);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void addHeaders(HttpRequestBase endpoint, String accessToken) {
|
||||||
|
endpoint.setHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString());
|
||||||
|
endpoint.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.toString());
|
||||||
|
endpoint.setHeader(HttpHeaders.AUTHORIZATION, Constants.VPP.BEARER + accessToken);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* @param httpRequest - httpMethod e.g:- HttpPost, HttpGet
|
||||||
|
* @return response as string
|
||||||
|
* @throws IOException IO exception returns if error occurs when executing the httpMethod
|
||||||
|
*/
|
||||||
|
private static ProxyResponse execute(HttpRequestBase httpRequest) throws IOException {
|
||||||
|
try (CloseableHttpClient client = getHttpClient()) {
|
||||||
|
HttpResponse response = client.execute(httpRequest);
|
||||||
|
ProxyResponse proxyResponse = new ProxyResponse();
|
||||||
|
|
||||||
|
if (response == null) {
|
||||||
|
log.error("Received null response for http request : " + httpRequest.getMethod() + " " + httpRequest
|
||||||
|
.getURI().toString());
|
||||||
|
proxyResponse.setCode(Constants.VPP.INTERNAL_ERROR_CODE);
|
||||||
|
proxyResponse.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(
|
||||||
|
Constants.VPP.INTERNAL_ERROR_CODE));
|
||||||
|
return proxyResponse;
|
||||||
|
} else {
|
||||||
|
int statusCode = response.getStatusLine().getStatusCode();
|
||||||
|
try (BufferedReader rd = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
|
||||||
|
StringBuilder result = new StringBuilder();
|
||||||
|
String line;
|
||||||
|
while ((line = rd.readLine()) != null) {
|
||||||
|
result.append(line);
|
||||||
|
}
|
||||||
|
|
||||||
|
String jsonString = result.toString();
|
||||||
|
if (statusCode == HttpStatus.SC_OK || statusCode == HttpStatus.SC_CREATED) {
|
||||||
|
proxyResponse.setCode(statusCode);
|
||||||
|
proxyResponse.setData(jsonString);
|
||||||
|
proxyResponse.setExecutorResponse("SUCCESS");
|
||||||
|
return proxyResponse;
|
||||||
|
} else if (statusCode == HttpStatus.SC_UNAUTHORIZED) {
|
||||||
|
if (jsonString.contains("Access token expired") || jsonString
|
||||||
|
.contains("Invalid input. Access token validation failed")) {
|
||||||
|
proxyResponse.setCode(statusCode);
|
||||||
|
proxyResponse.setExecutorResponse(Constants.VPP.TOKEN_IS_EXPIRED);
|
||||||
|
return proxyResponse;
|
||||||
|
} else {
|
||||||
|
log.error(
|
||||||
|
"Received " + statusCode + " response for http request : " + httpRequest.getMethod()
|
||||||
|
+ " " + httpRequest.getURI().toString() + ". Error message: " + jsonString);
|
||||||
|
proxyResponse.setCode(statusCode);
|
||||||
|
proxyResponse.setData(jsonString);
|
||||||
|
proxyResponse.setExecutorResponse(
|
||||||
|
Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(statusCode));
|
||||||
|
return proxyResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
log.error("Received " + statusCode +
|
||||||
|
" response for http request : " + httpRequest.getMethod() + " " + httpRequest.getURI()
|
||||||
|
.toString() + ". Error message: " + jsonString);
|
||||||
|
proxyResponse.setCode(statusCode);
|
||||||
|
proxyResponse.setData(jsonString);
|
||||||
|
proxyResponse
|
||||||
|
.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + getStatusKey(statusCode));
|
||||||
|
return proxyResponse;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* @param statusCode Provide status code, e.g:- 400, 401, 500 etc
|
||||||
|
* @return relative status code key for given status code.
|
||||||
|
*/
|
||||||
|
public static String getStatusKey(int statusCode) {
|
||||||
|
String statusCodeKey;
|
||||||
|
|
||||||
|
switch (statusCode) {
|
||||||
|
case HttpStatus.SC_INTERNAL_SERVER_ERROR:
|
||||||
|
statusCodeKey = "internalServerError";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_BAD_REQUEST:
|
||||||
|
statusCodeKey = "badRequest";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_UNAUTHORIZED:
|
||||||
|
statusCodeKey = "unauthorized";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_FORBIDDEN:
|
||||||
|
statusCodeKey = "forbidden";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_NOT_FOUND:
|
||||||
|
statusCodeKey = "notFound";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_METHOD_NOT_ALLOWED:
|
||||||
|
statusCodeKey = "methodNotAllowed";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_NOT_ACCEPTABLE:
|
||||||
|
statusCodeKey = "notAcceptable";
|
||||||
|
break;
|
||||||
|
case HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE:
|
||||||
|
statusCodeKey = "unsupportedMediaType";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
statusCodeKey = "defaultPage";
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
return statusCodeKey;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Handle error requests.
|
||||||
|
*
|
||||||
|
* @param resp {@link HttpServletResponse}
|
||||||
|
* @param proxyResponse {@link ProxyResponse}
|
||||||
|
* @throws IOException If error occurred when trying to send the error response.
|
||||||
|
*/
|
||||||
|
public static void handleError(HttpServletResponse resp, ProxyResponse proxyResponse) throws IOException {
|
||||||
|
Gson gson = new Gson();
|
||||||
|
if (proxyResponse == null) {
|
||||||
|
proxyResponse = new ProxyResponse();
|
||||||
|
proxyResponse.setCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
|
||||||
|
proxyResponse.setExecutorResponse(Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + VppHttpUtil
|
||||||
|
.getStatusKey(Constants.VPP.INTERNAL_ERROR_CODE));
|
||||||
|
}
|
||||||
|
resp.setStatus(proxyResponse.getCode());
|
||||||
|
resp.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||||
|
resp.setCharacterEncoding(Consts.UTF_8.name());
|
||||||
|
|
||||||
|
proxyResponse.setExecutorResponse(null);
|
||||||
|
try (PrintWriter writer = resp.getWriter()) {
|
||||||
|
writer.write(gson.toJson(proxyResponse));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle error requests with custom error codes.
|
||||||
|
*
|
||||||
|
* @param resp {@link HttpServletResponse}
|
||||||
|
* @param errorCode HTTP error status code
|
||||||
|
* @throws IOException If error occurred when trying to send the error response.
|
||||||
|
*/
|
||||||
|
public static void handleError(HttpServletResponse resp, int errorCode)
|
||||||
|
throws IOException {
|
||||||
|
ProxyResponse proxyResponse = new ProxyResponse();
|
||||||
|
proxyResponse.setCode(errorCode);
|
||||||
|
proxyResponse.setExecutorResponse(
|
||||||
|
Constants.VPP.EXECUTOR_EXCEPTION_PREFIX + VppHttpUtil.getStatusKey(errorCode));
|
||||||
|
VppHttpUtil.handleError(resp, proxyResponse);
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
*
|
||||||
|
* @param resp {@link HttpServletResponse}
|
||||||
|
* Return Success Response.
|
||||||
|
*/
|
||||||
|
public static void handleSuccess(HttpServletResponse resp, ProxyResponse proxyResponse) throws IOException {
|
||||||
|
if (proxyResponse == null) {
|
||||||
|
handleError(resp, null);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
resp.setStatus(proxyResponse.getCode());
|
||||||
|
resp.setContentType(ContentType.APPLICATION_JSON.getMimeType());
|
||||||
|
resp.setCharacterEncoding(Consts.UTF_8.name());
|
||||||
|
JSONObject response = new JSONObject();
|
||||||
|
String responseData = proxyResponse.getData();
|
||||||
|
|
||||||
|
if (!StringUtils.isEmpty(responseData)) {
|
||||||
|
try {
|
||||||
|
if (responseData.startsWith("{")) {
|
||||||
|
JSONObject responseDataJsonObj = new JSONObject(responseData);
|
||||||
|
response.put("data", responseDataJsonObj);
|
||||||
|
} else if (responseData.startsWith("[")) {
|
||||||
|
JSONArray responseDataJsonArr = new JSONArray(responseData);
|
||||||
|
response.put("data", responseDataJsonArr);
|
||||||
|
} else {
|
||||||
|
log.warn("Response data is not valid json string >> " + responseData);
|
||||||
|
response.put("data", responseData);
|
||||||
|
}
|
||||||
|
} catch (JSONException e) {
|
||||||
|
log.error("Response data is not passable");
|
||||||
|
response.put("data", responseData);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PrintWriter writer = resp.getWriter()) {
|
||||||
|
writer.write(response.toString());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve Http client based on hostname verification.
|
||||||
|
*
|
||||||
|
* @return {@link CloseableHttpClient} http client
|
||||||
|
*/
|
||||||
|
public static CloseableHttpClient getHttpClient() {
|
||||||
|
return HttpClients.custom().setMaxConnTotal(1).setMaxConnPerRoute(1).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static VppAssociationDTO getAssociation(VppUserDTO user, VppAssetDTO asset) {
|
||||||
|
VppAssociationDTO associationDTO = new VppAssociationDTO();
|
||||||
|
associationDTO.setAdamId(asset.getAdamId());
|
||||||
|
associationDTO.setClientUserId(user.getClientUserId());
|
||||||
|
associationDTO.setPricingParam(asset.getPricingParam());
|
||||||
|
associationDTO.setAssociationType(Constants.ApplicationProperties.ASSOCIATION_USER);
|
||||||
|
|
||||||
|
associationDTO.setAssetId(asset.getId());
|
||||||
|
associationDTO.setClientId(user.getId());
|
||||||
|
associationDTO.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext()
|
||||||
|
.getTenantId(true));
|
||||||
|
associationDTO.setCreatedTime(String.valueOf(System.currentTimeMillis()));
|
||||||
|
associationDTO.setLastUpdatedTime(String.valueOf(System.currentTimeMillis()));
|
||||||
|
return associationDTO;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
<artifactId>io.entgra.device.mgt.core.parent</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../../pom.xml</relativePath>
|
<relativePath>../../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -58,7 +58,7 @@ import javax.ws.rs.core.Response;
|
|||||||
@Scope(
|
@Scope(
|
||||||
name = "Sign CSR",
|
name = "Sign CSR",
|
||||||
description = "Sign CSR",
|
description = "Sign CSR",
|
||||||
key = "perm:sign-csr",
|
key = "dm:sign-csr",
|
||||||
roles = {"Internal/devicemgt-user"},
|
roles = {"Internal/devicemgt-user"},
|
||||||
permissions = {"/device-mgt/certificates/manage"}
|
permissions = {"/device-mgt/certificates/manage"}
|
||||||
)
|
)
|
||||||
@ -87,7 +87,7 @@ public interface CertificateMgtService {
|
|||||||
tags = "Device Management",
|
tags = "Device Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:sign-csr")
|
@ExtensionProperty(name = SCOPE, value = "dm:sign-csr")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -22,7 +22,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
|
|||||||
@ -62,35 +62,35 @@ import javax.ws.rs.core.Response;
|
|||||||
@Scope(
|
@Scope(
|
||||||
name = "Adding a new SSL certificate",
|
name = "Adding a new SSL certificate",
|
||||||
description = "Adding a new SSL certificate",
|
description = "Adding a new SSL certificate",
|
||||||
key = "perm:admin:certificates:add",
|
key = "cm:cert:add",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/certificates/add"}
|
permissions = {"/device-mgt/admin/certificates/add"}
|
||||||
),
|
),
|
||||||
@Scope(
|
@Scope(
|
||||||
name = "Getting Details of an SSL Certificate",
|
name = "Getting Details of an SSL Certificate",
|
||||||
description = "Getting Details of an SSL Certificate",
|
description = "Getting Details of an SSL Certificate",
|
||||||
key = "perm:admin:certificates:details",
|
key = "cm:cert:details:get",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/certificates/details"}
|
permissions = {"/device-mgt/admin/certificates/details"}
|
||||||
),
|
),
|
||||||
@Scope(
|
@Scope(
|
||||||
name = "Getting Details of Certificates",
|
name = "Getting Details of Certificates",
|
||||||
description = "Getting Details of Certificates",
|
description = "Getting Details of Certificates",
|
||||||
key = "perm:admin:certificates:view",
|
key = "cm:cert:view",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/certificates/view"}
|
permissions = {"/device-mgt/admin/certificates/view"}
|
||||||
),
|
),
|
||||||
@Scope(
|
@Scope(
|
||||||
name = "Deleting an SSL Certificate",
|
name = "Deleting an SSL Certificate",
|
||||||
description = "Deleting an SSL Certificate",
|
description = "Deleting an SSL Certificate",
|
||||||
key = "perm:admin:certificates:delete",
|
key = "cm:cert:delete",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/certificates/delete"}
|
permissions = {"/device-mgt/admin/certificates/delete"}
|
||||||
),
|
),
|
||||||
@Scope(
|
@Scope(
|
||||||
name = "Verify SSL certificate",
|
name = "Verify SSL certificate",
|
||||||
description = "Verify SSL certificate",
|
description = "Verify SSL certificate",
|
||||||
key = "perm:admin:certificates:verify",
|
key = "cm:cert:verify",
|
||||||
roles = {"Internal/devicemgt-admin"},
|
roles = {"Internal/devicemgt-admin"},
|
||||||
permissions = {"/device-mgt/admin/certificates/verify"}
|
permissions = {"/device-mgt/admin/certificates/verify"}
|
||||||
)
|
)
|
||||||
@ -119,7 +119,7 @@ public interface CertificateManagementAdminService {
|
|||||||
tags = "Certificate Management",
|
tags = "Certificate Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:admin:certificates:add")
|
@ExtensionProperty(name = SCOPE, value = "cm:cert:add")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -188,7 +188,7 @@ public interface CertificateManagementAdminService {
|
|||||||
tags = "Certificate Management",
|
tags = "Certificate Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:admin:certificates:details")
|
@ExtensionProperty(name = SCOPE, value = "cm:cert:details:get")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -247,19 +247,20 @@ public interface CertificateManagementAdminService {
|
|||||||
*
|
*
|
||||||
* @return paginated result of certificate.
|
* @return paginated result of certificate.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@GET
|
@GET
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
consumes = MediaType.APPLICATION_JSON,
|
consumes = MediaType.APPLICATION_JSON,
|
||||||
produces = MediaType.APPLICATION_JSON,
|
produces = MediaType.APPLICATION_JSON,
|
||||||
httpMethod = "GET",
|
httpMethod = "GET",
|
||||||
value = "Getting Details of Certificates",
|
value = "Getting Details of search Certificates",
|
||||||
notes = "Get all the details of the certificates you have used for mutual SSL. In a situation where you wish to "
|
notes = "Get all the details of the search certificates you have used for mutual SSL. In a situation where you wish to "
|
||||||
+ "view all the certificate details, it is not feasible to show all the details on one "
|
+ "view all the search certificate details, it is not feasible to show all the details on one "
|
||||||
+ "page. Therefore, the details are paginated.",
|
+ "page. Therefore, the details are paginated.",
|
||||||
tags = "Certificate Management",
|
tags = "Certificate Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:admin:certificates:view")
|
@ExtensionProperty(name = SCOPE, value = "cm:cert:view")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -307,6 +308,28 @@ public interface CertificateManagementAdminService {
|
|||||||
response = ErrorResponse.class)
|
response = ErrorResponse.class)
|
||||||
})
|
})
|
||||||
Response getAllCertificates(
|
Response getAllCertificates(
|
||||||
|
@ApiParam(
|
||||||
|
name = "serialNumber",
|
||||||
|
value = "The serial number of the certificates",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("serialNumber") String serialNumber,
|
||||||
|
@ApiParam(
|
||||||
|
name = "deviceIdentifier",
|
||||||
|
value = "The device identifier of the certificates",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("deviceIdentifier") String deviceIdentifier,
|
||||||
|
@ApiParam(
|
||||||
|
name = "username",
|
||||||
|
value = "User name of the certificate added user",
|
||||||
|
required = false)
|
||||||
|
@QueryParam("username") String username,
|
||||||
|
@ApiParam(
|
||||||
|
name = "If-Modified-Since",
|
||||||
|
value = "Checks if the requested variant was modified, since the specified date-time. \n" +
|
||||||
|
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
|
||||||
|
"Example: Mon, 05 Jan 2014 15:10:00 +0200",
|
||||||
|
required = false)
|
||||||
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@ApiParam(
|
@ApiParam(
|
||||||
name = "offset",
|
name = "offset",
|
||||||
value = "The starting pagination index for the complete list of qualified items.",
|
value = "The starting pagination index for the complete list of qualified items.",
|
||||||
@ -318,14 +341,7 @@ public interface CertificateManagementAdminService {
|
|||||||
value = "Provide how many certificate details you require from the starting pagination index/offset.",
|
value = "Provide how many certificate details you require from the starting pagination index/offset.",
|
||||||
required = false,
|
required = false,
|
||||||
defaultValue = "5")
|
defaultValue = "5")
|
||||||
@QueryParam("limit") int limit,
|
@QueryParam("limit") int limit);
|
||||||
@ApiParam(
|
|
||||||
name = "If-Modified-Since",
|
|
||||||
value = "Checks if the requested variant was modified, since the specified date-time. \n" +
|
|
||||||
"Provide the value in the following format: EEE, d MMM yyyy HH:mm:ss Z.\n" +
|
|
||||||
"Example: Mon, 05 Jan 2014 15:10:00 +0200",
|
|
||||||
required = false)
|
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince);
|
|
||||||
|
|
||||||
@DELETE
|
@DELETE
|
||||||
@ApiOperation(
|
@ApiOperation(
|
||||||
@ -337,7 +353,7 @@ public interface CertificateManagementAdminService {
|
|||||||
tags = "Certificate Management",
|
tags = "Certificate Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:admin:certificates:delete")
|
@ExtensionProperty(name = SCOPE, value = "cm:cert:delete")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
@ -383,7 +399,7 @@ public interface CertificateManagementAdminService {
|
|||||||
tags = "Certificate Management",
|
tags = "Certificate Management",
|
||||||
extensions = {
|
extensions = {
|
||||||
@Extension(properties = {
|
@Extension(properties = {
|
||||||
@ExtensionProperty(name = SCOPE, value = "perm:admin:certificates:verify")
|
@ExtensionProperty(name = SCOPE, value = "cm:cert:verify")
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|||||||
@ -18,7 +18,6 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.impl;
|
package io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.impl;
|
||||||
|
|
||||||
import javax.ws.rs.Consumes;
|
|
||||||
import javax.ws.rs.DELETE;
|
import javax.ws.rs.DELETE;
|
||||||
import javax.ws.rs.GET;
|
import javax.ws.rs.GET;
|
||||||
import javax.ws.rs.HeaderParam;
|
import javax.ws.rs.HeaderParam;
|
||||||
@ -26,7 +25,9 @@ import javax.ws.rs.POST;
|
|||||||
import javax.ws.rs.Path;
|
import javax.ws.rs.Path;
|
||||||
import javax.ws.rs.PathParam;
|
import javax.ws.rs.PathParam;
|
||||||
import javax.ws.rs.QueryParam;
|
import javax.ws.rs.QueryParam;
|
||||||
import javax.ws.rs.core.MediaType;
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.CertificateManagementAdminService;
|
import io.entgra.device.mgt.core.certificate.mgt.cert.admin.api.CertificateManagementAdminService;
|
||||||
@ -87,6 +88,13 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
certificate.setTenantId(PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId());
|
||||||
certificate.setSerial(enrollmentCertificate.getSerial());
|
certificate.setSerial(enrollmentCertificate.getSerial());
|
||||||
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem()));
|
certificate.setCertificate(certificateService.pemToX509Certificate(enrollmentCertificate.getPem()));
|
||||||
|
CertificateResponse existingCertificate = certificateService.getCertificateBySerial(enrollmentCertificate.getSerial());
|
||||||
|
if (existingCertificate != null) {
|
||||||
|
return Response.status(Response.Status.BAD_REQUEST)
|
||||||
|
.entity("Certificate with serial number " + enrollmentCertificate.getSerial() + " already exists.")
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
certificates.add(certificate);
|
certificates.add(certificate);
|
||||||
}
|
}
|
||||||
certificateService.saveCertificate(certificates);
|
certificateService.saveCertificate(certificates);
|
||||||
@ -134,13 +142,27 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
*/
|
*/
|
||||||
@GET
|
@GET
|
||||||
public Response getAllCertificates(
|
public Response getAllCertificates(
|
||||||
|
@QueryParam("serialNumber") String serialNumber,
|
||||||
|
@QueryParam("deviceIdentifier") String deviceIdentifier,
|
||||||
|
@QueryParam("username") String username,
|
||||||
|
@HeaderParam("If-Modified-Since") String ifModifiedSince,
|
||||||
@QueryParam("offset") int offset,
|
@QueryParam("offset") int offset,
|
||||||
@QueryParam("limit") int limit,
|
@QueryParam("limit") int limit) {
|
||||||
@HeaderParam("If-Modified-Since") String ifModifiedSince) {
|
|
||||||
RequestValidationUtil.validatePaginationInfo(offset, limit);
|
RequestValidationUtil.validatePaginationInfo(offset, limit);
|
||||||
CertificateManagementService certificateService = CertificateMgtAPIUtils.getCertificateManagementService();
|
CertificateManagementService certificateService = CertificateMgtAPIUtils.getCertificateManagementService();
|
||||||
|
CertificatePaginationRequest request = new CertificatePaginationRequest(offset, limit);
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
request.setSerialNumber(serialNumber);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)){
|
||||||
|
request.setDeviceIdentifier(deviceIdentifier);
|
||||||
|
}
|
||||||
|
if (StringUtils.isNotEmpty(username)){
|
||||||
|
request.setUsername(username);
|
||||||
|
}
|
||||||
try {
|
try {
|
||||||
PaginationResult result = certificateService.getAllCertificates(offset, limit);
|
PaginationResult result = certificateService.getAllCertificates(request);
|
||||||
CertificateList certificates = new CertificateList();
|
CertificateList certificates = new CertificateList();
|
||||||
certificates.setCount(result.getRecordsTotal());
|
certificates.setCount(result.getRecordsTotal());
|
||||||
certificates.setList((List<CertificateResponse>) result.getData());
|
certificates.setList((List<CertificateResponse>) result.getData());
|
||||||
@ -159,18 +181,33 @@ public class CertificateManagementAdminServiceImpl implements CertificateManagem
|
|||||||
|
|
||||||
CertificateManagementService certificateService = CertificateMgtAPIUtils.getCertificateManagementService();
|
CertificateManagementService certificateService = CertificateMgtAPIUtils.getCertificateManagementService();
|
||||||
try {
|
try {
|
||||||
boolean status = certificateService.removeCertificate(serialNumber);
|
boolean decision = certificateService.getValidateMetaValue();
|
||||||
if (!status) {
|
if (decision) {
|
||||||
return Response.status(Response.Status.NOT_FOUND).entity(
|
try {
|
||||||
"No certificate is found with the given " +
|
boolean status = certificateService.removeCertificate(serialNumber);
|
||||||
"serial number '" + serialNumber + "'").build();
|
if (!status) {
|
||||||
|
return Response.status(Response.Status.NOT_FOUND).entity(
|
||||||
|
"No certificate is found with the given " +
|
||||||
|
"serial number '" + serialNumber + "'").build();
|
||||||
|
} else {
|
||||||
|
return Response.status(Response.Status.OK).entity(
|
||||||
|
"Certificate that carries the serial number '" +
|
||||||
|
serialNumber + "' has been removed").build();
|
||||||
|
}
|
||||||
|
} catch (CertificateManagementException e) {
|
||||||
|
String msg = "Error occurred while removing certificate with the given " +
|
||||||
|
"serial number '" + serialNumber + "'";
|
||||||
|
log.error(msg, e);
|
||||||
|
return Response.serverError().entity(
|
||||||
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return Response.status(Response.Status.OK).entity(
|
return Response.status(Response.Status.UNAUTHORIZED).entity(
|
||||||
"Certificate that carries the serial number '" +
|
"User unauthorized to delete certificate with " +
|
||||||
serialNumber + "' has been removed").build();
|
"serial number '" + serialNumber + "'").build();
|
||||||
}
|
}
|
||||||
} catch (CertificateManagementException e) {
|
} catch (CertificateManagementException e) {
|
||||||
String msg = "Error occurred while converting PEM file to X509Certificate";
|
String msg = "Error occurred while getting the metadata entry for certificate deletion.";
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
return Response.serverError().entity(
|
return Response.serverError().entity(
|
||||||
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
new ErrorResponse.ErrorResponseBuilder().setMessage(msg).build()).build();
|
||||||
|
|||||||
@ -21,7 +21,7 @@
|
|||||||
<parent>
|
<parent>
|
||||||
<groupId>io.entgra.device.mgt.core</groupId>
|
<groupId>io.entgra.device.mgt.core</groupId>
|
||||||
<artifactId>certificate-mgt</artifactId>
|
<artifactId>certificate-mgt</artifactId>
|
||||||
<version>5.0.29-SNAPSHOT</version>
|
<version>5.0.31-SNAPSHOT</version>
|
||||||
<relativePath>../pom.xml</relativePath>
|
<relativePath>../pom.xml</relativePath>
|
||||||
</parent>
|
</parent>
|
||||||
|
|
||||||
@ -57,6 +57,62 @@
|
|||||||
io.entgra.device.mgt.core.certificate.mgt.core.util
|
io.entgra.device.mgt.core.certificate.mgt.core.util
|
||||||
</Private-Package>
|
</Private-Package>
|
||||||
<Import-Package>
|
<Import-Package>
|
||||||
|
<!-- org.osgi.framework.*;version="${imp.package.version.osgi.framework}",-->
|
||||||
|
<!-- org.osgi.service.*;version="${imp.package.version.osgi.service}",-->
|
||||||
|
<!-- org.apache.commons.lang,-->
|
||||||
|
<!-- org.apache.commons.logging,-->
|
||||||
|
<!-- org.apache.commons.collections.map,-->
|
||||||
|
<!-- io.entgra.device.mgt.core.certificate.mgt.core.*,-->
|
||||||
|
<!-- io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",-->
|
||||||
|
<!-- io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",-->
|
||||||
|
<!-- io.entgra.device.mgt.core.device.mgt.core.config;version="[5.0,6)",-->
|
||||||
|
<!-- io.entgra.device.mgt.core.device.mgt.core.config.cache;version="[5.0,6)",-->
|
||||||
|
<!-- io.entgra.device.mgt.core.device.mgt.core.service;version="[5.0,6)",-->
|
||||||
|
<!-- io.swagger.annotations;version="[1.6,2)",-->
|
||||||
|
<!-- javax.cache;version="[1.0,2)",-->
|
||||||
|
<!-- javax.naming,-->
|
||||||
|
<!-- javax.naming.ldap,-->
|
||||||
|
<!-- javax.security.auth.x500,-->
|
||||||
|
<!-- javax.xml.bind;version="[0.0,1)",-->
|
||||||
|
<!-- javax.xml.bind.annotation;version="[0.0,1)",-->
|
||||||
|
<!-- javax.xml.parsers;version="${javax.xml.parsers.import.pkg.version}",-->
|
||||||
|
<!-- org.apache.commons.codec.binary;version="[1.4,2)",-->
|
||||||
|
<!-- org.apache.commons.collections.map;version="[3.2,4)",-->
|
||||||
|
<!-- org.apache.commons.logging;version="[1.2,2)",-->
|
||||||
|
<!-- org.bouncycastle.asn1;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.asn1.pkcs;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.asn1.x500;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.asn1.x500.style;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.asn1.x509;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.cert;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.cert.jcajce;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.cms;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.jce.provider;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.operator;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.operator.jcajce;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.pkcs;version="[1.70,2)",-->
|
||||||
|
<!-- org.bouncycastle.util;version="[1.70,2)",-->
|
||||||
|
<!-- org.jscep.message,-->
|
||||||
|
<!-- org.jscep.transaction,-->
|
||||||
|
<!-- org.w3c.dom,-->
|
||||||
|
<!-- org.xml.sax,-->
|
||||||
|
<!-- javax.sql,-->
|
||||||
|
<!-- <!–javax.cache,–>-->
|
||||||
|
<!-- javax.naming,-->
|
||||||
|
<!-- javax.xml.bind.annotation,-->
|
||||||
|
<!-- javax.xml.bind,-->
|
||||||
|
<!-- org.wso2.carbon.utils.*,-->
|
||||||
|
<!--<!– io.entgra.device.mgt.core.device.mgt.common.*,–>-->
|
||||||
|
<!--<!– io.swagger.annotations.*;resolution:=optional,–>-->
|
||||||
|
<!--<!– io.entgra.device.mgt.core.device.mgt.core.*,–>-->
|
||||||
|
<!-- org.wso2.carbon.registry.indexing.*,-->
|
||||||
|
<!-- <!–org.bouncycastle.pkcs.jcajce–>-->
|
||||||
|
<!-- org.w3c.dom,org.wso2.carbon.context;version="[4.8,5)",-->
|
||||||
|
<!-- org.wso2.carbon.user.api;version="[1.0,2)",-->
|
||||||
|
<!-- org.wso2.carbon.user.core.service;version="[4.8,5)",-->
|
||||||
|
<!-- org.wso2.carbon.user.core.tenant;version="[4.8,5)",-->
|
||||||
|
<!-- org.wso2.carbon.utils;version="[4.8,5)",-->
|
||||||
|
<!-- org.wso2.carbon.utils.dbcreator;version="[4.8,5)"-->
|
||||||
io.entgra.device.mgt.core.certificate.mgt.core.*,
|
io.entgra.device.mgt.core.certificate.mgt.core.*,
|
||||||
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
|
io.entgra.device.mgt.core.device.mgt.common;version="[5.0,6)",
|
||||||
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
|
io.entgra.device.mgt.core.device.mgt.common.exceptions;version="[5.0,6)",
|
||||||
@ -253,6 +309,10 @@
|
|||||||
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
|
<groupId>org.wso2.orbit.javax.xml.bind</groupId>
|
||||||
<artifactId>jaxb-api</artifactId>
|
<artifactId>jaxb-api</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>com.googlecode.json-simple.wso2</groupId>
|
||||||
|
<artifactId>json-simple</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</project>
|
</project>
|
||||||
|
|
||||||
|
|||||||
@ -18,8 +18,10 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.dao;
|
package io.entgra.device.mgt.core.certificate.mgt.core.dao;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.bean.Certificate;
|
import io.entgra.device.mgt.core.certificate.mgt.core.bean.Certificate;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.exception.CertificateManagementException;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -75,13 +77,12 @@ public interface CertificateDAO {
|
|||||||
/**
|
/**
|
||||||
* Get all the certificates in a paginated manner.
|
* Get all the certificates in a paginated manner.
|
||||||
*
|
*
|
||||||
* @param rowNum Stating index of the paginated result.
|
* @param request index of the paginated result.
|
||||||
* @param limit Number of records to return.
|
|
||||||
* @return Pagination result with data and the count of results.
|
* @return Pagination result with data and the count of results.
|
||||||
* @throws CertificateManagementDAOException
|
* @throws CertificateManagementDAOException
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException;
|
PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementDAOException;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Get all the certificates.
|
* Get all the certificates.
|
||||||
@ -95,7 +96,7 @@ public interface CertificateDAO {
|
|||||||
/**
|
/**
|
||||||
* Delete a certificate identified by a serial number()
|
* Delete a certificate identified by a serial number()
|
||||||
*
|
*
|
||||||
* @param serialNumber serial number
|
* @param serialNumber number
|
||||||
* @return whether the certificate was removed or not.
|
* @return whether the certificate was removed or not.
|
||||||
*/
|
*/
|
||||||
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
|
boolean removeCertificate(String serialNumber) throws CertificateManagementDAOException;
|
||||||
|
|||||||
@ -279,7 +279,7 @@ public abstract class AbstractCertificateDAOImpl implements CertificateDAO{
|
|||||||
|
|
||||||
return stmt.executeUpdate() > 0;
|
return stmt.executeUpdate() > 0;
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String msg = "Unable to get the read the certificate with serial" + serialNumber;
|
String msg = "Unable to get the read the certificate with serialNumber" + serialNumber;
|
||||||
log.error(msg, e);
|
log.error(msg, e);
|
||||||
throw new CertificateManagementDAOException(msg, e);
|
throw new CertificateManagementDAOException(msg, e);
|
||||||
} finally {
|
} finally {
|
||||||
|
|||||||
@ -18,14 +18,16 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -48,45 +50,133 @@ public class GenericCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
return CertificateManagementDAOFactory.getConnection();
|
return CertificateManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCertificateCount(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
|
int certificateCount = 0;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getConnection();
|
||||||
|
String sql = "SELECT COUNT(*) AS DEVICE_CERTIFICATE_COUNT " +
|
||||||
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
|
"WHERE TENANT_ID = ?";
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
sql += " AND SERIAL_NUMBER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
sql += " AND DEVICE_IDENTIFIER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
sql += " AND USERNAME LIKE ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 2;
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
stmt.setString(paramIdx, "%" + username + "%");
|
||||||
|
}
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
certificateCount = rs.getInt("DEVICE_CERTIFICATE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the certificate count.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return certificateCount;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
public PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
ResultSet resultSet = null;
|
|
||||||
CertificateResponse certificateResponse;
|
CertificateResponse certificateResponse;
|
||||||
List<CertificateResponse> certificates = new ArrayList<>();
|
List<CertificateResponse> certificates = new ArrayList<>();
|
||||||
PaginationResult paginationResult;
|
PaginationResult paginationResult;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
boolean isCertificateSerialNumberProvided = false;
|
||||||
|
boolean isCertificateDeviceIdentifierProvided = false;
|
||||||
|
boolean isCertificateUsernameProvided = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
String query = "SELECT * " +
|
||||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC LIMIT ?,?";
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
stmt = conn.prepareStatement(sql);
|
"WHERE TENANT_ID = ? ";
|
||||||
stmt.setInt(1, tenantId);
|
|
||||||
stmt.setInt(2, rowNum);
|
|
||||||
stmt.setInt(3, limit);
|
|
||||||
resultSet = stmt.executeQuery();
|
|
||||||
|
|
||||||
int resultCount = 0;
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
while (resultSet.next()) {
|
query += "AND SERIAL_NUMBER = ? ";
|
||||||
certificateResponse = new CertificateResponse();
|
isCertificateSerialNumberProvided = true;
|
||||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
}
|
||||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
|
||||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
query += "AND DEVICE_IDENTIFIER = ? ";
|
||||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
isCertificateDeviceIdentifierProvided = true;
|
||||||
certificates.add(certificateResponse);
|
}
|
||||||
resultCount++;
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
query += "AND USERNAME LIKE ? ";
|
||||||
|
isCertificateUsernameProvided = true;
|
||||||
|
}
|
||||||
|
|
||||||
|
query += "ORDER BY ID LIMIT ?,?";
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||||
|
int paramIdx = 1;
|
||||||
|
stmt.setInt(paramIdx++, tenantId);
|
||||||
|
if (isCertificateSerialNumberProvided) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
if (isCertificateDeviceIdentifierProvided) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
if (isCertificateUsernameProvided) {
|
||||||
|
stmt.setString(paramIdx++, "%" + username + "%");
|
||||||
|
}
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
certificateResponse = new CertificateResponse();
|
||||||
|
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||||
|
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||||
|
certificateResponse.setCertificateId(resultSet.getString("ID"));
|
||||||
|
certificateResponse.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFIER"));
|
||||||
|
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||||
|
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||||
|
certificates.add(certificateResponse);
|
||||||
|
}
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
paginationResult.setData(certificates);
|
||||||
|
paginationResult.setRecordsTotal(this.getCertificateCount(request));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
paginationResult = new PaginationResult();
|
|
||||||
paginationResult.setData(certificates);
|
|
||||||
paginationResult.setRecordsTotal(resultCount);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
||||||
}
|
}
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -18,14 +18,16 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -44,43 +46,75 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private static final Log log = LogFactory.getLog(OracleCertificateDAOImpl.class);
|
private static final Log log = LogFactory.getLog(OracleCertificateDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
public PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
ResultSet resultSet = null;
|
|
||||||
CertificateResponse certificateResponse;
|
CertificateResponse certificateResponse;
|
||||||
List<CertificateResponse> certificates = new ArrayList<>();
|
List<CertificateResponse> certificates = new ArrayList<>();
|
||||||
PaginationResult paginationResult;
|
PaginationResult paginationResult;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
boolean isCertificateSerialNumberProvided = false;
|
||||||
|
boolean isCertificateDeviceIdentifierProvided = false;
|
||||||
|
boolean isCertificateUsernameProvided = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
String query = "SELECT * " +
|
||||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
stmt = conn.prepareStatement(sql);
|
"WHERE TENANT_ID = ? ";
|
||||||
stmt.setInt(1, tenantId);
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
stmt.setInt(2, rowNum);
|
query += "AND SERIAL_NUMBER = ? ";
|
||||||
stmt.setInt(3, limit);
|
isCertificateSerialNumberProvided = true;
|
||||||
resultSet = stmt.executeQuery();
|
}
|
||||||
|
|
||||||
int resultCount = 0;
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
while (resultSet.next()) {
|
query += "AND DEVICE_IDENTIFIER = ? ";
|
||||||
certificateResponse = new CertificateResponse();
|
isCertificateDeviceIdentifierProvided = true;
|
||||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
}
|
||||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
|
||||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
query += "AND USERNAME LIKE ? ";
|
||||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
isCertificateUsernameProvided = true;
|
||||||
certificates.add(certificateResponse);
|
}
|
||||||
resultCount++;
|
|
||||||
|
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||||
|
int paramIdx = 1;
|
||||||
|
stmt.setInt(paramIdx++, tenantId);
|
||||||
|
if (isCertificateSerialNumberProvided) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
if (isCertificateDeviceIdentifierProvided) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
if (isCertificateUsernameProvided) {
|
||||||
|
stmt.setString(paramIdx++, "%" + username + "%");
|
||||||
|
}
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
certificateResponse = new CertificateResponse();
|
||||||
|
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||||
|
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||||
|
certificateResponse.setCertificateId(resultSet.getString("ID"));
|
||||||
|
certificateResponse.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFIER"));
|
||||||
|
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||||
|
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||||
|
certificates.add(certificateResponse);
|
||||||
|
}
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
paginationResult.setData(certificates);
|
||||||
|
paginationResult.setRecordsTotal(this.getCertificateCount(request));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
paginationResult = new PaginationResult();
|
|
||||||
paginationResult.setData(certificates);
|
|
||||||
paginationResult.setRecordsTotal(resultCount);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
||||||
}
|
}
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
@ -88,4 +122,60 @@ public class OracleCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
return CertificateManagementDAOFactory.getConnection();
|
return CertificateManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCertificateCount(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
|
int certificateCount = 0;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getConnection();
|
||||||
|
String sql = "SELECT COUNT(*) AS DEVICE_CERTIFICATE_COUNT " +
|
||||||
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
|
"WHERE TENANT_ID = ?";
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
sql += " AND SERIAL_NUMBER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
sql += " AND DEVICE_IDENTIFIER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
sql += " AND USERNAME LIKE ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 2;
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
stmt.setString(paramIdx, "%" + username + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
certificateCount = rs.getInt("DEVICE_CERTIFICATE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the certificate count.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return certificateCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,14 +18,16 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -44,43 +46,75 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private static final Log log = LogFactory.getLog(PostgreSQLCertificateDAOImpl.class);
|
private static final Log log = LogFactory.getLog(PostgreSQLCertificateDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
public PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
ResultSet resultSet = null;
|
|
||||||
CertificateResponse certificateResponse;
|
CertificateResponse certificateResponse;
|
||||||
List<CertificateResponse> certificates = new ArrayList<>();
|
List<CertificateResponse> certificates = new ArrayList<>();
|
||||||
PaginationResult paginationResult;
|
PaginationResult paginationResult;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
boolean isCertificateSerialNumberProvided = false;
|
||||||
|
boolean isCertificateDeviceIdentifierProvided = false;
|
||||||
|
boolean isCertificateUsernameProvided = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
String query = "SELECT * " +
|
||||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC LIMIT ? OFFSET ?";
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
stmt = conn.prepareStatement(sql);
|
"WHERE TENANT_ID = ? ";
|
||||||
stmt.setInt(1, tenantId);
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
stmt.setInt(2, limit);
|
query += "AND SERIAL_NUMBER = ? ";
|
||||||
stmt.setInt(3, rowNum);
|
isCertificateSerialNumberProvided = true;
|
||||||
resultSet = stmt.executeQuery();
|
}
|
||||||
|
|
||||||
int resultCount = 0;
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
while (resultSet.next()) {
|
query += "AND DEVICE_IDENTIFIER = ? ";
|
||||||
certificateResponse = new CertificateResponse();
|
isCertificateDeviceIdentifierProvided = true;
|
||||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
}
|
||||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
|
||||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
query += "AND USERNAME LIKE ? ";
|
||||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
isCertificateUsernameProvided = true;
|
||||||
certificates.add(certificateResponse);
|
}
|
||||||
resultCount++;
|
|
||||||
|
query += "ORDER BY ID LIMIT ? OFFSET ?";
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||||
|
int paramIdx = 1;
|
||||||
|
stmt.setInt(paramIdx++, tenantId);
|
||||||
|
if (isCertificateSerialNumberProvided) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
if (isCertificateDeviceIdentifierProvided) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
if (isCertificateUsernameProvided) {
|
||||||
|
stmt.setString(paramIdx++, "%" + username + "%");
|
||||||
|
}
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
certificateResponse = new CertificateResponse();
|
||||||
|
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||||
|
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||||
|
certificateResponse.setCertificateId(resultSet.getString("ID"));
|
||||||
|
certificateResponse.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFIER"));
|
||||||
|
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||||
|
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||||
|
certificates.add(certificateResponse);
|
||||||
|
}
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
paginationResult.setData(certificates);
|
||||||
|
paginationResult.setRecordsTotal(this.getCertificateCount(request));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
paginationResult = new PaginationResult();
|
|
||||||
paginationResult.setData(certificates);
|
|
||||||
paginationResult.setRecordsTotal(resultCount);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
||||||
}
|
}
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
@ -88,4 +122,60 @@ public class PostgreSQLCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
return CertificateManagementDAOFactory.getConnection();
|
return CertificateManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCertificateCount(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
|
int certificateCount = 0;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getConnection();
|
||||||
|
String sql = "SELECT COUNT(*) AS DEVICE_CERTIFICATE_COUNT " +
|
||||||
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
|
"WHERE TENANT_ID = ?";
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
sql += " AND SERIAL_NUMBER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
sql += " AND DEVICE_IDENTIFIER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
sql += " AND USERNAME ILIKE ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 2;
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
stmt.setString(paramIdx, "%" + username + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
certificateCount = rs.getInt("DEVICE_CERTIFICATE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the certificate count.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return certificateCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,14 +18,16 @@
|
|||||||
|
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
package io.entgra.device.mgt.core.certificate.mgt.core.dao.impl;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
|
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
||||||
|
import org.apache.commons.lang.StringUtils;
|
||||||
|
import org.apache.commons.logging.Log;
|
||||||
|
import org.apache.commons.logging.LogFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOException;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOFactory;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dao.CertificateManagementDAOUtil;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.impl.CertificateGenerator;
|
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
import io.entgra.device.mgt.core.certificate.mgt.core.service.PaginationResult;
|
||||||
import org.apache.commons.logging.Log;
|
|
||||||
import org.apache.commons.logging.LogFactory;
|
|
||||||
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
import org.wso2.carbon.context.PrivilegedCarbonContext;
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
@ -44,43 +46,75 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private static final Log log = LogFactory.getLog(SQLServerCertificateDAOImpl.class);
|
private static final Log log = LogFactory.getLog(SQLServerCertificateDAOImpl.class);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementDAOException {
|
public PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
PreparedStatement stmt = null;
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
ResultSet resultSet = null;
|
|
||||||
CertificateResponse certificateResponse;
|
CertificateResponse certificateResponse;
|
||||||
List<CertificateResponse> certificates = new ArrayList<>();
|
List<CertificateResponse> certificates = new ArrayList<>();
|
||||||
PaginationResult paginationResult;
|
PaginationResult paginationResult;
|
||||||
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
boolean isCertificateSerialNumberProvided = false;
|
||||||
|
boolean isCertificateDeviceIdentifierProvided = false;
|
||||||
|
boolean isCertificateUsernameProvided = false;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Connection conn = this.getConnection();
|
Connection conn = this.getConnection();
|
||||||
String sql = "SELECT CERTIFICATE, SERIAL_NUMBER, TENANT_ID, USERNAME FROM "
|
String query = "SELECT * " +
|
||||||
+ "DM_DEVICE_CERTIFICATE WHERE TENANT_ID = ? ORDER BY ID DESC OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
stmt = conn.prepareStatement(sql);
|
"WHERE TENANT_ID = ? ";
|
||||||
stmt.setInt(1, tenantId);
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
stmt.setInt(2, rowNum);
|
query += "AND SERIAL_NUMBER = ? ";
|
||||||
stmt.setInt(3, limit);
|
isCertificateSerialNumberProvided = true;
|
||||||
resultSet = stmt.executeQuery();
|
}
|
||||||
|
|
||||||
int resultCount = 0;
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
while (resultSet.next()) {
|
query += "AND DEVICE_IDENTIFIER = ? ";
|
||||||
certificateResponse = new CertificateResponse();
|
isCertificateDeviceIdentifierProvided = true;
|
||||||
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
}
|
||||||
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
|
||||||
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
query += "AND USERNAME LIKE ? ";
|
||||||
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
isCertificateUsernameProvided = true;
|
||||||
certificates.add(certificateResponse);
|
}
|
||||||
resultCount++;
|
|
||||||
|
query += "ORDER BY ID OFFSET ? ROWS FETCH NEXT ? ROWS ONLY";
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(query)) {
|
||||||
|
int paramIdx = 1;
|
||||||
|
stmt.setInt(paramIdx++, tenantId);
|
||||||
|
if (isCertificateSerialNumberProvided) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
if (isCertificateDeviceIdentifierProvided) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
if (isCertificateUsernameProvided) {
|
||||||
|
stmt.setString(paramIdx++, "%" + username + "%");
|
||||||
|
}
|
||||||
|
stmt.setInt(paramIdx++, request.getStartIndex());
|
||||||
|
stmt.setInt(paramIdx++, request.getRowCount());
|
||||||
|
try (ResultSet resultSet = stmt.executeQuery()) {
|
||||||
|
while (resultSet.next()) {
|
||||||
|
certificateResponse = new CertificateResponse();
|
||||||
|
byte[] certificateBytes = resultSet.getBytes("CERTIFICATE");
|
||||||
|
certificateResponse.setSerialNumber(resultSet.getString("SERIAL_NUMBER"));
|
||||||
|
certificateResponse.setCertificateId(resultSet.getString("ID"));
|
||||||
|
certificateResponse.setDeviceIdentifier(resultSet.getString("DEVICE_IDENTIFIER"));
|
||||||
|
certificateResponse.setTenantId(resultSet.getInt("TENANT_ID"));
|
||||||
|
certificateResponse.setUsername(resultSet.getString("USERNAME"));
|
||||||
|
CertificateGenerator.extractCertificateDetails(certificateBytes, certificateResponse);
|
||||||
|
certificates.add(certificateResponse);
|
||||||
|
}
|
||||||
|
paginationResult = new PaginationResult();
|
||||||
|
paginationResult.setData(certificates);
|
||||||
|
paginationResult.setRecordsTotal(this.getCertificateCount(request));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
paginationResult = new PaginationResult();
|
|
||||||
paginationResult.setData(certificates);
|
|
||||||
paginationResult.setRecordsTotal(resultCount);
|
|
||||||
} catch (SQLException e) {
|
} catch (SQLException e) {
|
||||||
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
String errorMsg = "SQL error occurred while retrieving the certificates.";
|
||||||
log.error(errorMsg, e);
|
log.error(errorMsg, e);
|
||||||
throw new CertificateManagementDAOException(errorMsg, e);
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
} finally {
|
|
||||||
CertificateManagementDAOUtil.cleanupResources(stmt, resultSet);
|
|
||||||
}
|
}
|
||||||
return paginationResult;
|
return paginationResult;
|
||||||
}
|
}
|
||||||
@ -88,4 +122,60 @@ public class SQLServerCertificateDAOImpl extends AbstractCertificateDAOImpl {
|
|||||||
private Connection getConnection() throws SQLException {
|
private Connection getConnection() throws SQLException {
|
||||||
return CertificateManagementDAOFactory.getConnection();
|
return CertificateManagementDAOFactory.getConnection();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getCertificateCount(CertificatePaginationRequest request) throws CertificateManagementDAOException {
|
||||||
|
int certificateCount = 0;
|
||||||
|
int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId();
|
||||||
|
String serialNumber = request.getSerialNumber();
|
||||||
|
String deviceIdentifier = request.getDeviceIdentifier();
|
||||||
|
String username = request.getUsername();
|
||||||
|
|
||||||
|
try {
|
||||||
|
Connection conn = this.getConnection();
|
||||||
|
String sql = "SELECT COUNT(*) AS DEVICE_CERTIFICATE_COUNT " +
|
||||||
|
"FROM DM_DEVICE_CERTIFICATE " +
|
||||||
|
"WHERE TENANT_ID = ?";
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
sql += " AND SERIAL_NUMBER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
sql += " AND DEVICE_IDENTIFIER = ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
sql += " AND USERNAME LIKE ?";
|
||||||
|
}
|
||||||
|
|
||||||
|
try (PreparedStatement stmt = conn.prepareStatement(sql)) {
|
||||||
|
stmt.setInt(1, tenantId);
|
||||||
|
|
||||||
|
int paramIdx = 2;
|
||||||
|
if (StringUtils.isNotEmpty(serialNumber)) {
|
||||||
|
stmt.setString(paramIdx++, serialNumber);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(deviceIdentifier)) {
|
||||||
|
stmt.setString(paramIdx++, deviceIdentifier);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (StringUtils.isNotEmpty(username)) {
|
||||||
|
stmt.setString(paramIdx, "%" + username + "%");
|
||||||
|
}
|
||||||
|
|
||||||
|
try (ResultSet rs = stmt.executeQuery()) {
|
||||||
|
if (rs.next()) {
|
||||||
|
certificateCount = rs.getInt("DEVICE_CERTIFICATE_COUNT");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} catch (SQLException e) {
|
||||||
|
String errorMsg = "SQL error occurred while retrieving the certificate count.";
|
||||||
|
log.error(errorMsg, e);
|
||||||
|
throw new CertificateManagementDAOException(errorMsg, e);
|
||||||
|
}
|
||||||
|
return certificateCount;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -32,6 +32,12 @@ public class CertificateResponse {
|
|||||||
@ApiModelProperty(name = "serialNumber", value = "It is the unique ID that is used to identify a certificate", required = true)
|
@ApiModelProperty(name = "serialNumber", value = "It is the unique ID that is used to identify a certificate", required = true)
|
||||||
String serialNumber;
|
String serialNumber;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "deviceIdentifier", value = "It is use to identify a certificate list", required = true)
|
||||||
|
String deviceIdentifier;
|
||||||
|
|
||||||
|
@ApiModelProperty(name = "certificateId", value = "It is the unique ID that is used to identify a certificate", required = true)
|
||||||
|
String certificateId;
|
||||||
|
|
||||||
@ApiModelProperty(name = "tenantId", value = "The ID of the tenant who adds the certificate", required = true)
|
@ApiModelProperty(name = "tenantId", value = "The ID of the tenant who adds the certificate", required = true)
|
||||||
int tenantId;
|
int tenantId;
|
||||||
|
|
||||||
@ -44,8 +50,8 @@ public class CertificateResponse {
|
|||||||
@ApiModelProperty(name = "notBefore", value = "The date from when the certificate is valid", required = true)
|
@ApiModelProperty(name = "notBefore", value = "The date from when the certificate is valid", required = true)
|
||||||
long notBefore;
|
long notBefore;
|
||||||
|
|
||||||
@ApiModelProperty(name = "certificateserial", value = "The serial number of the certificate", required = true)
|
@ApiModelProperty(name = "certificateSerial", value = "The serial number of the certificate", required = true)
|
||||||
BigInteger certificateserial;
|
BigInteger certificateSerial;
|
||||||
|
|
||||||
@ApiModelProperty(name = "issuer", value = "The identity of the authority that signs the SSL certificate", required = true)
|
@ApiModelProperty(name = "issuer", value = "The identity of the authority that signs the SSL certificate", required = true)
|
||||||
String issuer;
|
String issuer;
|
||||||
@ -83,12 +89,12 @@ public class CertificateResponse {
|
|||||||
this.notBefore = notBefore;
|
this.notBefore = notBefore;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigInteger getCertificateserial() {
|
public BigInteger getCertificateSerial() {
|
||||||
return certificateserial;
|
return certificateSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCertificateserial(BigInteger certificateserial) {
|
public void setCertificateSerial(BigInteger certificateSerial) {
|
||||||
this.certificateserial = certificateserial;
|
this.certificateSerial = certificateSerial;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getIssuer() {
|
public String getIssuer() {
|
||||||
@ -146,4 +152,20 @@ public class CertificateResponse {
|
|||||||
public void setTenantId(int tenantId) {
|
public void setTenantId(int tenantId) {
|
||||||
this.tenantId = tenantId;
|
this.tenantId = tenantId;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getDeviceIdentifier() {
|
||||||
|
return deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDeviceIdentifier(String deviceIdentifier) {
|
||||||
|
this.deviceIdentifier = deviceIdentifier;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getCertificateId() {
|
||||||
|
return certificateId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCertificateId(String certificateId) {
|
||||||
|
this.certificateId = certificateId;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -108,7 +108,7 @@ public class CertificateGenerator {
|
|||||||
X509Certificate certificate = (X509Certificate) x509Certificate;
|
X509Certificate certificate = (X509Certificate) x509Certificate;
|
||||||
certificateResponse.setNotAfter(certificate.getNotAfter().getTime());
|
certificateResponse.setNotAfter(certificate.getNotAfter().getTime());
|
||||||
certificateResponse.setNotBefore(certificate.getNotBefore().getTime());
|
certificateResponse.setNotBefore(certificate.getNotBefore().getTime());
|
||||||
certificateResponse.setCertificateserial(certificate.getSerialNumber());
|
certificateResponse.setCertificateSerial(certificate.getSerialNumber());
|
||||||
certificateResponse.setIssuer(certificate.getIssuerDN().getName());
|
certificateResponse.setIssuer(certificate.getIssuerDN().getName());
|
||||||
certificateResponse.setSubject(certificate.getSubjectDN().getName());
|
certificateResponse.setSubject(certificate.getSubjectDN().getName());
|
||||||
certificateResponse.setCertificateVersion(certificate.getVersion());
|
certificateResponse.setCertificateVersion(certificate.getVersion());
|
||||||
|
|||||||
@ -17,6 +17,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.entgra.device.mgt.core.certificate.mgt.core.service;
|
package io.entgra.device.mgt.core.certificate.mgt.core.service;
|
||||||
|
|
||||||
|
import io.entgra.device.mgt.core.device.mgt.common.CertificatePaginationRequest;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.CertificateResponse;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.dto.SCEPResponse;
|
import io.entgra.device.mgt.core.certificate.mgt.core.dto.SCEPResponse;
|
||||||
import io.entgra.device.mgt.core.certificate.mgt.core.exception.CertificateManagementException;
|
import io.entgra.device.mgt.core.certificate.mgt.core.exception.CertificateManagementException;
|
||||||
@ -71,10 +72,12 @@ public interface CertificateManagementService {
|
|||||||
|
|
||||||
CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementException;
|
CertificateResponse retrieveCertificate(String serialNumber) throws CertificateManagementException;
|
||||||
|
|
||||||
PaginationResult getAllCertificates(int rowNum, int limit) throws CertificateManagementException;
|
PaginationResult getAllCertificates(CertificatePaginationRequest request) throws CertificateManagementException;
|
||||||
|
|
||||||
boolean removeCertificate(String serialNumber) throws CertificateManagementException;
|
boolean removeCertificate(String serialNumber) throws CertificateManagementException;
|
||||||
|
|
||||||
|
boolean getValidateMetaValue() throws CertificateManagementException;
|
||||||
|
|
||||||
List<CertificateResponse> getCertificates() throws CertificateManagementException;
|
List<CertificateResponse> getCertificates() throws CertificateManagementException;
|
||||||
|
|
||||||
List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementException;
|
List<CertificateResponse> searchCertificates(String serialNumber) throws CertificateManagementException;
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user