From ee64c3edcab08a663561292a9f84b65fc3cbadc6 Mon Sep 17 00:00:00 2001 From: dilini Date: Thu, 20 Apr 2023 19:06:18 +0530 Subject: [PATCH 01/22] Fix : Custom app update permission issue --- .../application/mgt/core/impl/ApplicationManagerImpl.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java index 98a50e427a1..3861744c567 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/impl/ApplicationManagerImpl.java @@ -3244,7 +3244,7 @@ public class ApplicationManagerImpl implements ApplicationManager { AtomicReference applicationReleaseDTO = new AtomicReference<>( applicationDTO.getApplicationReleaseDTOs().get(0)); validateAppReleaseUpdating(customAppReleaseWrapper, applicationDTO, applicationArtifact, - ApplicationType.ENTERPRISE.toString()); + ApplicationType.CUSTOM.toString()); applicationReleaseDTO.get().setPrice(customAppReleaseWrapper.getPrice()); applicationReleaseDTO.get() .setIsSharedWithAllTenants(applicationReleaseDTO.get().getIsSharedWithAllTenants()); From 7324acb8d37f4af7a4e032dbd96a0facfbd205cc Mon Sep 17 00:00:00 2001 From: Sasini Sandamali Date: Tue, 25 Apr 2023 08:15:47 +0000 Subject: [PATCH 02/22] Add API doc while publishing APIs (#79) Co-authored-by: Sasini_Sandamali Co-authored-by: Pahansith Gunathilake Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/79 Co-authored-by: Sasini Sandamali Co-committed-by: Sasini Sandamali --- .../apimgt/webapp/publisher/APIConfig.java | 43 +++++- .../publisher/APIPublisherServiceImpl.java | 47 ++++++- .../webapp/publisher/APIPublisherUtil.java | 35 ++++- .../config/APIResourceConfiguration.java | 129 +++++++++++------- .../lifecycle/util/AnnotationProcessor.java | 88 ++++++------ 5 files changed, 239 insertions(+), 103 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java index b3b880b2519..dd3efdeac83 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIConfig.java @@ -28,17 +28,16 @@ import java.util.Set; /** * This bean class carries the properties used by some API that needs to be published within the underlying * API-Management infrastructure. - * * A sample API configuration accepted by this particular bean class would look like what's shown below. * e.g. * * - * enrollment - * admin - * /enrol - * 1.0.0 - * http://localhost:9763/ - * http,https + * enrollment + * admin + * /enrol + * 1.0.0 + * http://localhost:9763/ + * http,https * */ @XmlRootElement(name = "API") @@ -47,6 +46,9 @@ public class APIConfig { private String name; private String owner; private String context; + private String apiDocumentationName; + private String apiDocumentationSummary; + private String apiDocumentationSourceFile; private String endpoint; private String version; private String policy; @@ -82,6 +84,33 @@ public class APIConfig { this.name = name; } + @XmlElement(name = "ApiDocumentationName", required = false) + public String getApiDocumentationName() { + return apiDocumentationName; + } + + public void setApiDocumentationName(String apiDocumentationName) { + this.apiDocumentationName = apiDocumentationName; + } + + @XmlElement(name = "ApiDocumentationSummary", required = false) + public String getApiDocumentationSummary() { + return apiDocumentationSummary; + } + + public void setApiDocumentationSummary(String apiDocumentationSummary) { + this.apiDocumentationSummary = apiDocumentationSummary; + } + + @XmlElement(name = "ApiDocumentationSourceFile", required = false) + public String getApiDocumentationSourceFile() { + return apiDocumentationSourceFile; + } + + public void setApiDocumentationSourceFile(String apiDocumentationSourceFile) { + this.apiDocumentationSourceFile = apiDocumentationSourceFile; + } + @XmlElement(name = "Owner", required = true) public String getOwner() { return owner; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 5135e439bdf..0dcc92e6381 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -21,6 +21,8 @@ package org.wso2.carbon.apimgt.webapp.publisher; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.api.model.Documentation; +import org.wso2.carbon.apimgt.api.model.DocumentationType; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.APIProvider; import org.wso2.carbon.apimgt.api.FaultGatewaysException; @@ -66,18 +68,19 @@ import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.Date; /** * This class represents the concrete implementation of the APIPublisherService that corresponds to providing all * API publishing related operations. */ public class APIPublisherServiceImpl implements APIPublisherService { + public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance(); private static final String UNLIMITED_TIER = "Unlimited"; private static final String WS_UNLIMITED_TIER = "AsyncUnlimited"; private static final String API_PUBLISH_ENVIRONMENT = "Default"; private static final String CREATED_STATUS = "CREATED"; private static final String PUBLISH_ACTION = "Publish"; - public static final APIManagerFactory API_MANAGER_FACTORY = APIManagerFactory.getInstance(); private static final Log log = LogFactory.getLog(APIPublisherServiceImpl.class); @Override @@ -293,7 +296,45 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } } - } catch (FaultGatewaysException | APIManagementException e) { + if (apiConfig.getApiDocumentationSourceFile() != null) { + API api = getAPI(apiConfig, true); + + String fileName = + CarbonUtils.getCarbonHome() + File.separator + "repository" + + File.separator + "resources" + File.separator + "api-docs" + File.separator + + apiConfig.getApiDocumentationSourceFile(); + + BufferedReader br = new BufferedReader(new FileReader(fileName)); + StringBuilder stringBuilder = new StringBuilder(); + String line = null; + String ls = System.lineSeparator(); + while ((line = br.readLine()) != null) { + stringBuilder.append(line); + stringBuilder.append(ls); + } + stringBuilder.deleteCharAt(stringBuilder.length() - 1); + br.close(); + String docContent = stringBuilder.toString(); + + Documentation apiDocumentation = new Documentation(DocumentationType.HOWTO, apiConfig.getApiDocumentationName()); + apiDocumentation.setVisibility(Documentation.DocumentVisibility.API_LEVEL); + apiDocumentation.setSourceType(Documentation.DocumentSourceType.MARKDOWN); + apiDocumentation.setCreatedDate(new Date()); + apiDocumentation.setLastUpdated(new Date()); + apiDocumentation.setSummary(apiConfig.getApiDocumentationSummary()); + apiDocumentation.setOtherTypeName(null); + + try { + //Including below code lines inside the try block because 'getDocumentation' method returns an APIManagementException exception when it doesn't have any existing doc + Documentation existingDoc = apiProvider.getDocumentation(api.getId(), DocumentationType.HOWTO, apiConfig.getApiDocumentationName()); + apiProvider.removeDocumentation(api.getId(), existingDoc.getId(), null); + } catch (APIManagementException e) { + log.info("There is no any existing api documentation."); + } + apiProvider.addDocumentation(api.getId(), apiDocumentation); + apiProvider.addDocumentationContent(api, apiConfig.getApiDocumentationName(), docContent); + } + } catch (FaultGatewaysException | APIManagementException | IOException e) { String msg = "Error occurred while publishing api"; log.error(msg, e); throw new APIManagerPublisherException(e); @@ -327,7 +368,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { try { String fileName = CarbonUtils.getCarbonConfigDirPath() + File.separator + "etc" - + File.separator + tenantDomain + ".csv"; + + File.separator + tenantDomain + ".csv"; if (Files.exists(Paths.get(fileName))) { BufferedReader br = new BufferedReader(new FileReader(fileName)); int lineNumber = 0; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java index b7ad837ed80..2b6a86fb069 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherUtil.java @@ -64,7 +64,7 @@ public class APIPublisherUtil { } public static String getWsServerBaseUrl() { - return getServerBaseUrl().replace("https","wss"); + return getServerBaseUrl().replace("https", "wss"); } public static String getApiEndpointUrl(String context) { @@ -104,7 +104,32 @@ public class APIPublisherUtil { } apiConfig.setVersion(version); + String apiDocumentationName = apiDef.getApiDocumentationName(); + if (apiDocumentationName == null || apiDocumentationName.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("'API Documentation not set in @SwaggerDefinition Annotation'"); + } + } else { + apiConfig.setApiDocumentationName(apiDef.getApiDocumentationName()); + } + String apiDocumentationSummary = apiDef.getApiDocumentationSummary(); + if (apiDocumentationSummary == null || apiDocumentationSummary.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("'API Documentation summary not set in @SwaggerDefinition Annotation'"); + } + } else { + apiConfig.setApiDocumentationSummary(apiDef.getApiDocumentationSummary()); + } + + String apiDocumentationSourceFile = apiDef.getApiDocumentationSourceFile(); + if (apiDocumentationSourceFile == null || apiDocumentationSourceFile.isEmpty()) { + if (log.isDebugEnabled()) { + log.debug("'API Documentation source file not set in @SwaggerDefinition Annotation'"); + } + } else { + apiConfig.setApiDocumentationSourceFile(apiDef.getApiDocumentationSourceFile()); + } String context = apiDef.getContext(); if (context == null || context.isEmpty()) { if (log.isDebugEnabled()) { @@ -302,20 +327,20 @@ public class APIPublisherUtil { public static void setResourceAuthTypes(ServletContext servletContext, APIConfig apiConfig) { List resourcesList = null; String nonSecuredResources = servletContext.getInitParameter(NON_SECURED_RESOURCES); - if(null != nonSecuredResources){ + if (null != nonSecuredResources) { resourcesList = Arrays.asList(nonSecuredResources.split(",")); } Set templates = apiConfig.getUriTemplates(); - if(null != resourcesList) { + if (null != resourcesList) { for (ApiUriTemplate template : templates) { String fullPaath = ""; if (!template.getUriTemplate().equals(AnnotationProcessor.WILD_CARD)) { fullPaath = apiConfig.getContext() + template.getUriTemplate(); } - else{ + else { fullPaath = apiConfig.getContext(); } - for(String context : resourcesList) { + for (String context : resourcesList) { if (context.trim().equals(fullPaath)) { template.setAuthType(AUTH_TYPE_NON_SECURED); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/APIResourceConfiguration.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/APIResourceConfiguration.java index 49b66e6db9e..1fb2ab7880d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/APIResourceConfiguration.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/config/APIResourceConfiguration.java @@ -25,60 +25,92 @@ import java.util.List; @XmlRootElement(name = "ResourceConfiguration") public class APIResourceConfiguration { - private String name; - private String context; - private String version; - private List resources; - private String[] tags; + private String name; + private String context; + private String apiDocumentationName; + private String apiDocumentationSummary; + private String apiDocumentationSourceFile; + private String version; + private List resources; + private String[] tags; private String endpointType; private String inSequenceName; private String inSequenceConfig; private String asyncApiDefinition; public List getResources() { - return resources; - } - - @XmlElement(name = "Resources", required = true) - public void setResources(List resources) { - this.resources = resources; - } - - public String getContext() { - return context; - } - - @XmlElement(name = "Context", required = true) - public void setContext(String context) { - this.context = context; - } - - public String getName() { - return name; - } - - @XmlElement(name = "Name") - public void setName(String name) { - this.name = name; - } - - public String getVersion() { - return version; - } - - @XmlElement(name = "Version") - public void setVersion(String version) { - this.version = version; - } - - public String[] getTags() { - return tags; - } - - @XmlElement(name = "Tags") - public void setTags(String[] tags) { - this.tags = tags; - } + return resources; + } + + @XmlElement(name = "Resources", required = true) + public void setResources(List resources) { + this.resources = resources; + } + + public String getContext() { + return context; + } + + @XmlElement(name = "Context", required = true) + public void setContext(String context) { + this.context = context; + } + + public String getName() { + return name; + } + + @XmlElement(name = "Name") + public void setName(String name) { + this.name = name; + } + + public String getApiDocumentationName() { + return apiDocumentationName; + } + + @XmlElement(name = "ApiDocumentation") + + + public void setApiDocumentationName(String apiDocumentationName) { + this.apiDocumentationName = apiDocumentationName; + } + + public String getApiDocumentationSummary() { + return apiDocumentationSummary; + } + + @XmlElement(name = "ApiDocumentationSummary") + public void setApiDocumentationSummary(String apiDocumentationSummary) { + this.apiDocumentationSummary = apiDocumentationSummary; + } + + public String getApiDocumentationSourceFile() { + return apiDocumentationSourceFile; + } + + @XmlElement(name = "ApiDocumentationSourceFile") + public void setApiDocumentationSourceFile(String apiDocumentationSourceFile) { + this.apiDocumentationSourceFile = apiDocumentationSourceFile; + } + + public String getVersion() { + return version; + } + + @XmlElement(name = "Version") + public void setVersion(String version) { + this.version = version; + } + + public String[] getTags() { + return tags; + } + + @XmlElement(name = "Tags") + public void setTags(String[] tags) { + this.tags = tags; + } public String getEndpointType() { return endpointType; @@ -110,6 +142,7 @@ public class APIResourceConfiguration { public String getAsyncApiDefinition() { return asyncApiDefinition; } + @XmlElement(name = "asyncApiDefinition") public void setAsyncApiDefinition(String asyncApiDefinition) { this.asyncApiDefinition = asyncApiDefinition; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index 6774aa29bd4..f41c07967a5 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -53,7 +53,6 @@ import java.util.*; public class AnnotationProcessor { private static final Log log = LogFactory.getLog(AnnotationProcessor.class); - private static final String AUTH_TYPE = "Application & Application User"; private static final String STRING_ARR = "string_arr"; private static final String STRING = "string"; @@ -61,7 +60,6 @@ public class AnnotationProcessor { private static final String PACKAGE_ORG_CODEHAUS = "org.codehaus"; private static final String PACKAGE_ORG_SPRINGFRAMEWORK = "org.springframework"; public static final String WILD_CARD = "/*"; - private static final String SWAGGER_ANNOTATIONS_INFO = "info"; private static final String SWAGGER_ANNOTATIONS_TAGS = "tags"; private static final String SWAGGER_ANNOTATIONS_EXTENSIONS = "extensions"; @@ -73,6 +71,9 @@ public class AnnotationProcessor { private static final String SWAGGER_ANNOTATIONS_PROPERTIES_ROLES = "roles"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_VERSION = "version"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_CONTEXT = "context"; + private static final String SWAGGER_ANNOTATIONS_PROPERTIES_API_DOCUMENTATION_NAME = "apiDocumentationName"; + private static final String SWAGGER_ANNOTATIONS_PROPERTIES_API_DOCUMENTATION_SUMMARY = "apiDocumentationSummary"; + private static final String SWAGGER_ANNOTATIONS_PROPERTIES_API_DOCUMENTATION_SOURCE_FILE = "apiDocumentationSourceFile"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_ENDPOINT_TYPE = "endpointType"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_IN_SEQUENCE_NAME = "inSequenceName"; private static final String SWAGGER_ANNOTATIONS_PROPERTIES_IN_SEQUENCE_CONFIG = "inSequenceConfig"; @@ -112,26 +113,25 @@ public class AnnotationProcessor { pathClazz = (Class) classLoader.loadClass(Path.class.getName()); consumesClass = (Class) classLoader.loadClass(Consumes.class.getName()); producesClass = (Class) classLoader.loadClass(Produces.class.getName()); - apiClazz= (Class)classLoader.loadClass((SwaggerDefinition.class.getName())); - infoClass = (Class)classLoader + apiClazz = (Class) classLoader.loadClass((SwaggerDefinition.class.getName())); + infoClass = (Class) classLoader .loadClass((io.swagger.annotations.Info.class.getName())); - tagClass = (Class)classLoader + tagClass = (Class) classLoader .loadClass((io.swagger.annotations.Tag.class.getName())); - extensionClass = (Class)classLoader + extensionClass = (Class) classLoader .loadClass((io.swagger.annotations.Extension.class.getName())); - extensionPropertyClass = (Class)classLoader + extensionPropertyClass = (Class) classLoader .loadClass(io.swagger.annotations.ExtensionProperty.class.getName()); scopeClass = (Class) classLoader .loadClass(org.wso2.carbon.apimgt.annotations.api.Scope.class.getName()); scopesClass = (Class) classLoader .loadClass(org.wso2.carbon.apimgt.annotations.api.Scopes.class.getName()); - apiOperation = (Class)classLoader + apiOperation = (Class) classLoader .loadClass((ApiOperation.class.getName())); } catch (ClassNotFoundException e) { log.error("An error has occurred while loading classes ", e); } } - public Set scanStandardContext(String className) throws IOException { ExtendedAnnotationDB db = new ExtendedAnnotationDB(); db.addIgnoredPackages(PACKAGE_ORG_APACHE); @@ -166,7 +166,7 @@ public class AnnotationProcessor { if (Scopes != null) { apiScopes = processAPIScopes(Scopes); } - if(apiResourceConfig != null){ + if (apiResourceConfig != null) { String rootContext = servletContext.getContextPath(); pathClazzMethods = pathClazz.getMethods(); Annotation rootContectAnno = clazz.getAnnotation(pathClazz); @@ -199,21 +199,21 @@ public class AnnotationProcessor { " This API will not be published."; log.error(msg, e1); } catch (RuntimeException e) { - log.error("Unexpected error has been occurred while publishing "+ className - +"hence, this API will not be published."); + log.error("Unexpected error has been occurred while publishing " + className + + "hence, this API will not be published."); throw new RuntimeException(e); } return apiResourceConfig; } }); - if(apiResourceConfiguration !=null) + if (apiResourceConfiguration != null) apiResourceConfigs.add(apiResourceConfiguration); } } return apiResourceConfigs; } - private Map processAPIScopes(Annotation annotation) throws Throwable { + private Map processAPIScopes(Annotation annotation) throws Throwable { Map scopes = new HashMap<>(); InvocationHandler methodHandler = Proxy.getInvocationHandler(annotation); @@ -225,7 +225,7 @@ public class AnnotationProcessor { StringBuilder aggregatedPermissions; String roles[]; StringBuilder aggregatedRoles; - for(int i=0; i Date: Tue, 25 Apr 2023 08:25:27 +0000 Subject: [PATCH 03/22] Add subtype-mgt feature (#74) ## Purpose To seperate out component with main generic things of subtype management. ## Goals This subtype-mgt component enables the dynamic implementation of any subtypes using APIs. PFA ## Approach * Add generic methods to subtype management component. * Add cacheloader mechanism to optimum data loading part. * Add unit test cases for all subtype's methods. ## Documentation Requirement & Design Approach of Subtype Management -> https://docs.google.com/document/d/1Cp7LqFKuV2FZOhN-cOCveLYcjyrzbZTDA0gNPYuV918/edit?usp=sharing ## Automation tests - Unit tests - service test - service negative test - DAO test - DAO negative test - Integration tests > N/A ## Security checks > N/A ## Related MRs > N/A ## Test environment Linux 22.04 ## Learning > N/A Co-authored-by: kavindya_devindi Co-authored-by: Pahansith Gunathilake Reviewed-on: https://repository.entgra.net/community/device-mgt-core/pulls/74 Co-authored-by: Kavindya Devindi Co-committed-by: Kavindya Devindi --- .../io.entgra.device.mgt.subtype.mgt/pom.xml | 412 ++++++ .../cache/GetDeviceSubTypeCacheLoader.java | 78 ++ .../mgt/subtype/mgt/dao/DeviceSubTypeDAO.java | 45 + .../mgt/dao/DeviceSubTypeDAOFactory.java | 53 + .../mgt/dao/impl/DeviceSubTypeDAOImpl.java | 253 ++++ .../dao/impl/DeviceSubTypeMySQLDAOImpl.java | 25 + .../mgt/dao/util/ConnectionManagerUtil.java | 219 +++ .../mgt/subtype/mgt/dao/util/DAOUtil.java | 55 + .../mgt/subtype/mgt/dto/DeviceSubType.java | 80 ++ .../mgt/dto/DeviceSubTypeCacheKey.java | 49 + .../mgt/exception/BadRequestException.java | 35 + .../mgt/exception/DBConnectionException.java | 35 + .../mgt/exception/SubTypeMgtDAOException.java | 56 + .../exception/SubTypeMgtPluginException.java | 57 + .../mgt/impl/DeviceSubTypeServiceImpl.java | 246 ++++ .../internal/DeviceSubTypeMgtDataHolder.java | 63 + .../DeviceSubTypeMgtServiceComponent.java | 137 ++ .../subtype/mgt/spi/DeviceSubTypeService.java | 46 + .../mgt/util/DeviceSubTypeMgtUtil.java | 41 + .../mgt/subtype/mgt/DAONegativeTest.java | 162 +++ .../device/mgt/subtype/mgt/DAOTest.java | 142 ++ .../mgt/subtype/mgt/DataSourceConfig.java | 78 ++ .../mgt/subtype/mgt/ServiceNegativeTest.java | 102 ++ .../device/mgt/subtype/mgt/ServiceTest.java | 127 ++ .../device/mgt/subtype/mgt/TestUtils.java | 99 ++ .../mgt/mock/BaseDeviceSubTypePluginTest.java | 157 +++ .../mgt/subtype/mgt/mock/MockConnection.java | 343 +++++ .../mgt/subtype/mgt/mock/MockDataSource.java | 123 ++ .../mgt/mock/MockDatabaseMetaData.java | 941 +++++++++++++ .../mgt/subtype/mgt/mock/MockResultSet.java | 1113 +++++++++++++++ .../mgt/subtype/mgt/mock/MockStatement.java | 561 ++++++++ .../carbon-home/dbscripts/dm-db-h2.sql | 789 +++++++++++ .../resources/carbon-home/dbscripts/h2.sql | 21 + .../repository/conf/axis2/axis2.xml | 726 ++++++++++ .../repository/conf/axis2/axis2_client.xml | 302 ++++ .../repository/conf/axis2/tenant-axis2.xml | 287 ++++ .../carbon-home/repository/conf/carbon.xml | 659 +++++++++ .../repository/conf/cdm-config.xml | 171 +++ .../conf/datasources/data-source-config.xml | 25 + .../conf/etc/bundle-config/README.txt | 12 + .../carboncontext-osgi-services.properties | 19 + .../repository/conf/etc/config-validation.xml | 55 + .../carbon-home/repository/conf/etc/jmx.xml | 34 + .../repository/conf/etc/launch.ini | 258 ++++ .../conf/etc/logging-bridge.properties | 70 + .../repository/conf/etc/mime.mappings | 27 + .../repository/conf/etc/mime.types | 734 ++++++++++ .../repository/conf/etc/osgi-debug.options | 95 ++ .../repository/conf/etc/tasks-config.xml | 69 + .../repository/conf/log4j.properties | 30 + .../carbon-home/repository/conf/registry.xml | 108 ++ .../conf/security/authenticators.xml | 75 + .../conf/tomcat/carbon/META-INF/context.xml | 36 + .../conf/tomcat/carbon/WEB-INF/web.xml | 62 + .../conf/tomcat/catalina-server.xml | 99 ++ .../repository/conf/tomcat/tomcat-users.xml | 35 + .../repository/conf/tomcat/web.xml | 1223 +++++++++++++++++ .../carbon-home/repository/conf/user-mgt.xml | 382 +++++ .../src/test/resources/testng.xml | 37 + components/subtype-mgt/pom.xml | 38 + .../src/main/resources/dbscripts/cdm/h2.sql | 11 + .../main/resources/dbscripts/cdm/mssql.sql | 12 + .../main/resources/dbscripts/cdm/mysql.sql | 11 + .../main/resources/dbscripts/cdm/oracle.sql | 11 + .../resources/dbscripts/cdm/postgresql.sql | 12 + .../pom.xml | 106 ++ .../src/main/resources/build.properties | 1 + .../src/main/resources/p2.inf | 1 + features/subtype-mgt/pom.xml | 40 + pom.xml | 20 + 70 files changed, 12636 insertions(+) create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAO.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAOFactory.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeMySQLDAOImpl.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/ConnectionManagerUtil.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/DAOUtil.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubType.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubTypeCacheKey.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/BadRequestException.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/DBConnectionException.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtDAOException.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtPluginException.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/impl/DeviceSubTypeServiceImpl.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtDataHolder.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtServiceComponent.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/spi/DeviceSubTypeService.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/util/DeviceSubTypeMgtUtil.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAONegativeTest.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAOTest.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DataSourceConfig.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceNegativeTest.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceTest.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/TestUtils.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/BaseDeviceSubTypePluginTest.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockConnection.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDataSource.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDatabaseMetaData.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockResultSet.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockStatement.java create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/carbon.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/cdm-config.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/jmx.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/launch.ini create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.mappings create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.types create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/tasks-config.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/log4j.properties create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/registry.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/security/authenticators.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/web.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/user-mgt.xml create mode 100644 components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/testng.xml create mode 100644 components/subtype-mgt/pom.xml create mode 100644 features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml create mode 100644 features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/build.properties create mode 100644 features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/p2.inf create mode 100644 features/subtype-mgt/pom.xml diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml new file mode 100644 index 00000000000..905ed65f0f8 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml @@ -0,0 +1,412 @@ + + + + + org.wso2.carbon.devicemgt + subtype-mgt + 5.0.25-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.device.mgt.subtype.mgt + Entgra IoT - Subtype Mgt Impl + bundle + Entgra IoT - Subtype Management Component Implementation + http://entgra.io + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.maven.plugins + maven-compiler-plugin + + + org.apache.felix + maven-bundle-plugin + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Subtype Management Bundle + io.entgra.device.mgt.subtype.mgt.internal + + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", + org.apache.commons.logging, + org.apache.commons.lang, + javax.xml, + javax.xml.stream, + javax.xml.bind.*, + javax.sql, + javax.xml.parsers; version=0.0.0, + org.w3c.dom, + javax.naming, + org.wso2.carbon.context, + org.wso2.carbon.base, + org.wso2.carbon.utils.*, + org.wso2.carbon.device.mgt.common.*, + org.wso2.carbon.device.mgt.core.*, + org.wso2.carbon.ndatasource.core, + org.wso2.carbon.registry.core, + org.wso2.carbon.registry.core.session, + org.wso2.carbon.registry.core.service, + org.wso2.carbon.registry.api, + org.wso2.carbon.device.mgt.extensions.license.mgt.registry, + javax.net.ssl, + org.wso2.carbon.core.util, + okhttp3, + org.json.*, + com.google.gson.*, + com.fasterxml.jackson.core.*, + com.fasterxml.jackson.databind.*, + com.fasterxml.jackson.annotation.* + + + !io.entgra.device.mgt.subtype.mgt.internal, + io.entgra.device.mgt.subtype.mgt.* + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + file:src/test/resources/carbon-home/repository/conf/log4j.properties + + + + src/test/resources/testng.xml + + + + + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.common + provided + + + org.wso2.carbon.identity.inbound.auth.oauth2 + org.wso2.carbon.identity.oauth.stub + + + org.apache.axis2.wso2 + axis2-client + + + org.apache.geronimo.specs.wso2 + geronimo-stax-api_1.0_spec + + + org.apache.ws.commons.axiom.wso2 + axiom + + + org.codehaus.woodstox + woodstox-core-asl + + + org.codehaus.woodstox + wstx-asl + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.analytics.data.publisher + + + org.wso2.carbon.analytics + org.wso2.carbon.analytics.api + + + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.extensions + provided + + + org.codehaus.woodstox + stax2-api + + + org.codehaus.woodstox + woodstox-core-asl + + + org.wso2.carbon + org.wso2.carbon.securevault + + + org.apache.ws.commons.axiom.wso2 + axiom + + + + + org.wso2.carbon + org.wso2.carbon.ndatasource.core + provided + + + org.wso2.securevault + org.wso2.securevault + + + + + org.wso2.carbon + org.wso2.carbon.base + provided + + + org.wso2.securevault + org.wso2.securevault + + + org.apache.ws.commons.axiom.wso2 + axiom + + + org.mockito + mockito-core + + + + + org.eclipse.osgi + org.eclipse.osgi + provided + + + org.eclipse.osgi + org.eclipse.osgi.services + provided + + + org.wso2.carbon + org.wso2.carbon.core + provided + + + org.wso2.carbon + org.wso2.carbon.logging + provided + + + org.wso2.carbon + org.wso2.carbon.utils + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.device.mgt.core + provided + + + org.wso2.carbon + org.wso2.carbon.registry.api + provided + + + org.wso2.carbon + org.wso2.carbon.registry.core + provided + + + org.apache.tomcat.wso2 + jdbc-pool + provided + + + com.google.code.gson + gson + provided + + + io.github.openfeign + feign-core + provided + + + io.github.openfeign + feign-jackson + provided + + + io.github.openfeign + feign-jaxrs + provided + + + io.github.openfeign + feign-gson + provided + + + io.github.openfeign + feign-okhttp + provided + + + io.github.openfeign + feign-slf4j + provided + + + org.wso2.carbon.devicemgt + org.wso2.carbon.identity.jwt.client.extension + provided + + + commons-validator + commons-validator + provided + + + org.apache.cxf + cxf-rt-frontend-jaxws + provided + + + org.apache.cxf + cxf-rt-frontend-jaxrs + provided + + + org.apache.cxf + cxf-rt-transports-http + provided + + + commons-lang.wso2 + commons-lang + provided + + + com.google.guava + guava + + + org.json + json + ${json.version} + provided + + + com.fasterxml.jackson.core + jackson-databind + ${fasterxml.jackson.version} + provided + + + org.powermock + powermock-module-testng + test + + + org.powermock + powermock-api-mockito + test + + + org.testng + testng + test + + + com.h2database.wso2 + h2-database-engine + test + + + org.apache.httpcomponents.wso2 + httpcore + test + + + org.wso2.apache.httpcomponents + httpclient + test + + + org.wso2.securevault + org.wso2.securevault + test + + + xerces.wso2 + xercesImpl + test + + + org.apache.axis2.wso2 + axis2 + test + + + org.wso2.carbon + org.wso2.carbon.queuing + test + + + javax.xml.bind + jaxb-api + test + + + \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java new file mode 100644 index 00000000000..d6296e4a734 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/cache/GetDeviceSubTypeCacheLoader.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.cache; + +import com.google.common.cache.CacheLoader; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAO; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubTypeCacheKey; +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtPluginException; +import io.entgra.device.mgt.subtype.mgt.util.DeviceSubTypeMgtUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + + +public class GetDeviceSubTypeCacheLoader extends CacheLoader { + + private static final Log log = LogFactory.getLog(GetDeviceSubTypeCacheLoader.class); + + private final DeviceSubTypeDAO deviceSubTypeDAO; + + public GetDeviceSubTypeCacheLoader() { + this.deviceSubTypeDAO = DeviceSubTypeDAOFactory.getDeviceSubTypeDAO(); + } + + @Override + public DeviceSubType load(String key) throws SubTypeMgtPluginException { + DeviceSubTypeCacheKey deviceSubTypeCacheKey = DeviceSubTypeMgtUtil.getDeviceSubTypeCacheKey(key); + int tenantId = deviceSubTypeCacheKey.getTenantId(); + String subTypeId = deviceSubTypeCacheKey.getSubTypeId(); + DeviceSubType.DeviceType deviceType = deviceSubTypeCacheKey.getDeviceType(); + + if (log.isTraceEnabled()) { + log.trace("Loading Device subtype for " + deviceType + " subtype & subtype Id : " + subTypeId); + } + try { + ConnectionManagerUtil.openDBConnection(); + return deviceSubTypeDAO.getDeviceSubType(subTypeId, tenantId, deviceType); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the database connection to retrieve device subtype for " + + deviceType + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (InvalidCacheLoadException e) { + String msg = "CacheLoader returned null for device subtype: " + deviceType + " subtype & subtype Id: " + + subTypeId; + log.error(msg, e); + return null; + } catch (SubTypeMgtDAOException e) { + String msg = "Error occurred in the database level while retrieving device subtype for " + deviceType + + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAO.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAO.java new file mode 100644 index 00000000000..9e3b889713d --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAO.java @@ -0,0 +1,45 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; + +import java.util.List; + +public interface DeviceSubTypeDAO { + boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtDAOException; + + boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, String subTypeName, + String typeDefinition) throws SubTypeMgtDAOException; + + DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException; + + List getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException; + + int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtDAOException; + + boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException; + + DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException; +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAOFactory.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAOFactory.java new file mode 100644 index 00000000000..79ab3f304a9 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/DeviceSubTypeDAOFactory.java @@ -0,0 +1,53 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao; + +import io.entgra.device.mgt.subtype.mgt.dao.impl.DeviceSubTypeDAOImpl; +import io.entgra.device.mgt.subtype.mgt.dao.impl.DeviceSubTypeMySQLDAOImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; + +public class DeviceSubTypeDAOFactory { + private static final Log log = LogFactory.getLog(DeviceSubTypeDAOFactory.class); + private static String databaseEngine; + + public static void init(DataSourceConfig dataSourceConfiguration) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device SubType Mgt Data Source"); + } + ConnectionManagerUtil.resolveDataSource(dataSourceConfiguration); + databaseEngine = ConnectionManagerUtil.getDatabaseType(); + } + + public static DeviceSubTypeDAO getDeviceSubTypeDAO() { + if (databaseEngine != null) { + //noinspection SwitchStatementWithTooFewBranches + switch (databaseEngine) { + case DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL: + return new DeviceSubTypeMySQLDAOImpl(); + default: + return new DeviceSubTypeDAOImpl(); + } + } + throw new IllegalStateException("Database engine has not initialized properly."); + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java new file mode 100644 index 00000000000..2b18e261b7c --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeDAOImpl.java @@ -0,0 +1,253 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao.impl; + +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAO; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.dao.util.DAOUtil; +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.List; + + +public class DeviceSubTypeDAOImpl implements DeviceSubTypeDAO { + private static final Log log = LogFactory.getLog(DeviceSubTypeDAOImpl.class); + + @Override + public boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtDAOException { + try { + String sql = "INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, " + + "TYPE_DEFINITION) VALUES (?, ?, ?, ?, ?)"; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, deviceSubType.getSubTypeId()); + stmt.setInt(2, deviceSubType.getTenantId()); + stmt.setString(3, deviceSubType.getDeviceType().toString()); + stmt.setString(4, deviceSubType.getSubTypeName()); + stmt.setString(5, deviceSubType.getTypeDefinition()); + return stmt.executeUpdate() > 0; + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to insert device sub type for " + + deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId(); + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to insert device sub type for " + + deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId(); + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, + String subTypeName, String typeDefinition) + throws SubTypeMgtDAOException { + try { + String sql = "UPDATE DM_DEVICE_SUB_TYPE SET TYPE_DEFINITION = ? , SUB_TYPE_NAME = ? WHERE SUB_TYPE_ID = ? " + + "AND TENANT_ID = ? AND DEVICE_TYPE = ?"; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, typeDefinition); + stmt.setString(2, subTypeName); + stmt.setString(3, subTypeId); + stmt.setInt(4, tenantId); + stmt.setString(5, deviceType.toString()); + return stmt.executeUpdate() > 0; + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to update device sub type for " + + deviceType + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to update device sub type for " + + deviceType + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException { + try { + String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_ID = ? AND TENANT_ID = ? AND DEVICE_TYPE = ?"; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, subTypeId); + stmt.setInt(2, tenantId); + stmt.setString(3, deviceType.toString()); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + return DAOUtil.loadDeviceSubType(rs); + } + return null; + } + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to retrieve device subtype for " + deviceType + + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to retrieve device subtype for " + deviceType + " " + + "subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public List getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException { + try { + String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE TENANT_ID = ? AND DEVICE_TYPE = ? ORDER BY " + + "SUB_TYPE_ID"; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setInt(1, tenantId); + stmt.setString(2, deviceType.toString()); + try (ResultSet rs = stmt.executeQuery()) { + return DAOUtil.loadDeviceSubTypes(rs); + } + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to retrieve all device sub types for " + + deviceType + " subtypes"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to retrieve all device sub types for " + deviceType + " " + + "subtypes"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtDAOException { + try { + String sql = "SELECT COUNT(*) as DEVICE_COUNT FROM DM_DEVICE_SUB_TYPE WHERE DEVICE_TYPE = ? "; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, deviceType.toString()); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + return rs.getInt("DEVICE_COUNT"); + } + return 0; + } + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to retrieve device sub types count for " + + deviceType + " subtypes"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to retrieve device sub types count for " + deviceType + + " subtypes"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException { + try { + String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_ID = ? AND TENANT_ID = ? AND DEVICE_TYPE " + + "= ? "; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, subTypeId); + stmt.setInt(2, tenantId); + stmt.setString(3, deviceType.toString()); + try (ResultSet rs = stmt.executeQuery()) { + return rs.next(); + } + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to check device subtype exist for " + deviceType + + " subtype & subtype id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to check device subtype exist for " + deviceType + " " + + "subtype & subtype id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } + + @Override + public DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, + DeviceSubType.DeviceType deviceType) + throws SubTypeMgtDAOException { + try { + String sql = "SELECT * FROM DM_DEVICE_SUB_TYPE WHERE SUB_TYPE_NAME = ? AND TENANT_ID = ? AND DEVICE_TYPE " + + "= ? "; + + Connection conn = ConnectionManagerUtil.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql)) { + stmt.setString(1, subTypeName); + stmt.setInt(2, tenantId); + stmt.setString(3, deviceType.toString()); + try (ResultSet rs = stmt.executeQuery()) { + if (rs.next()) { + return DAOUtil.loadDeviceSubType(rs); + } + return null; + } + } + + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to retrieve device subtype for " + deviceType + + " subtype & subtype name: " + subTypeName; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while processing SQL to retrieve device subtype for " + deviceType + " " + + "subtype & subtype name: " + subTypeName; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeMySQLDAOImpl.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeMySQLDAOImpl.java new file mode 100644 index 00000000000..972d16e1c58 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/impl/DeviceSubTypeMySQLDAOImpl.java @@ -0,0 +1,25 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao.impl; + +/** + * Implementation for MySQL + */ +public class DeviceSubTypeMySQLDAOImpl extends DeviceSubTypeDAOImpl { +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/ConnectionManagerUtil.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/ConnectionManagerUtil.java new file mode 100644 index 00000000000..7663ae94fc1 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/ConnectionManagerUtil.java @@ -0,0 +1,219 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao.util; + +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.device.mgt.common.exceptions.IllegalTransactionStateException; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.mgt.core.config.datasource.JNDILookupDefinition; + +import javax.naming.InitialContext; +import javax.sql.DataSource; +import java.sql.Connection; +import java.sql.SQLException; +import java.util.Hashtable; +import java.util.List; + +public class ConnectionManagerUtil { + + private static final Log log = LogFactory.getLog(ConnectionManagerUtil.class); + private static final ThreadLocal currentConnection = new ThreadLocal<>(); + private static DataSource dataSource; + + public static void openDBConnection() throws DBConnectionException { + Connection conn = currentConnection.get(); + if (conn != null) { + throw new IllegalTransactionStateException("Database connection has already been obtained."); + } + try { + conn = dataSource.getConnection(); + } catch (SQLException e) { + throw new DBConnectionException("Failed to get a database connection.", e); + } + currentConnection.set(conn); + } + + public static Connection getDBConnection() throws DBConnectionException { + Connection conn = currentConnection.get(); + if (conn == null) { + try { + conn = dataSource.getConnection(); + currentConnection.set(conn); + } catch (SQLException e) { + throw new DBConnectionException("Failed to get database connection.", e); + } + } + return conn; + } + + public static void beginDBTransaction() throws DBConnectionException { + Connection conn = currentConnection.get(); + if (conn == null) { + conn = getDBConnection(); + } else if (inTransaction(conn)) { + throw new IllegalTransactionStateException("Transaction has already been started."); + } + + try { + conn.setAutoCommit(false); + } catch (SQLException e) { + throw new DBConnectionException("Error occurred while starting a database transaction.", e); + } + } + + public static void endDBTransaction() throws DBConnectionException { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("Database connection is not active."); + } + + if (!inTransaction(conn)) { + throw new IllegalTransactionStateException("Transaction has not been started."); + } + + try { + conn.setAutoCommit(true); + } catch (SQLException e) { + throw new DBConnectionException("Error occurred while ending database transaction.", e); + } + } + + public static void commitDBTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("Database connection is not active."); + } + + if (!inTransaction(conn)) { + throw new IllegalTransactionStateException("Transaction has not been started."); + } + + try { + conn.commit(); + } catch (SQLException e) { + log.error("Error occurred while committing the transaction", e); + } + } + + public static void rollbackDBTransaction() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("Database connection is not active."); + } + + if (!inTransaction(conn)) { + throw new IllegalTransactionStateException("Transaction has not been started."); + } + + try { + conn.rollback(); + } catch (SQLException e) { + log.warn("Error occurred while roll-backing the transaction", e); + } + } + + public static void closeDBConnection() { + Connection conn = currentConnection.get(); + if (conn == null) { + throw new IllegalTransactionStateException("Database connection is not active."); + } + try { + conn.close(); + } catch (SQLException e) { + log.error("Error occurred while closing the connection", e); + } + currentConnection.remove(); + } + + private static boolean inTransaction(Connection conn) { + boolean inTransaction = true; + try { + if (conn.getAutoCommit()) { + inTransaction = false; + } + } catch (SQLException e) { + throw new IllegalTransactionStateException("Failed to get transaction state."); + } + return inTransaction; + } + + public static boolean isTransactionStarted() throws DBConnectionException { + Connection connection = getDBConnection(); + return inTransaction(connection); + } + + /** + * Resolve data source from the data source definition. + * + * @param config Data source configuration + * @return data source resolved from the data source definition + */ + public static DataSource resolveDataSource(DataSourceConfig config) { + if (config == null) { + throw new RuntimeException("Device Management Repository data source configuration " + + "is null and thus, is not initialized"); + } + JNDILookupDefinition jndiConfig = config.getJndiLookupDefinition(); + if (jndiConfig != null) { + if (log.isDebugEnabled()) { + log.debug("Initializing Device Management Repository data source using the JNDI " + + "Lookup Definition"); + } + List jndiPropertyList = + jndiConfig.getJndiProperties(); + if (jndiPropertyList != null) { + Hashtable jndiProperties = new Hashtable<>(); + for (JNDILookupDefinition.JNDIProperty prop : jndiPropertyList) { + jndiProperties.put(prop.getName(), prop.getValue()); + } + dataSource = ConnectionManagerUtil.lookupDataSource(jndiConfig.getJndiName(), jndiProperties); + } else { + dataSource = ConnectionManagerUtil.lookupDataSource(jndiConfig.getJndiName(), null); + } + } + return dataSource; + } + + public static DataSource lookupDataSource(String dataSourceName, + final Hashtable jndiProperties) { + + try { + if (jndiProperties == null || jndiProperties.isEmpty()) { + return (DataSource) InitialContext.doLookup(dataSourceName); + } + final InitialContext context = new InitialContext(jndiProperties); + return (DataSource) context.lookup(dataSourceName); + } catch (Exception e) { + String msg = "Error in looking up data source: " + e.getMessage(); + log.error(msg, e); + throw new RuntimeException(msg + e.getMessage(), e); + } + } + + public static String getDatabaseType() { + try { + return dataSource.getConnection().getMetaData().getDatabaseProductName(); + } catch (SQLException e) { + log.error("Error occurred while retrieving config.datasource connection", e); + } + return null; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/DAOUtil.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/DAOUtil.java new file mode 100644 index 00000000000..a50c75f703e --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dao/util/DAOUtil.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dao.util; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; + +import java.sql.ResultSet; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; + +public class DAOUtil { + + public static DeviceSubType loadDeviceSubType(ResultSet rs) throws SQLException { + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { return null; } + }; + deviceSubType.setTenantId(rs.getInt("TENANT_ID")); + deviceSubType.setSubTypeId(rs.getString("SUB_TYPE_ID")); + deviceSubType.setSubTypeName(rs.getString("SUB_TYPE_NAME")); + deviceSubType.setDeviceType(DeviceSubType.DeviceType.valueOf(rs.getString("DEVICE_TYPE"))); + deviceSubType.setTypeDefinition(rs.getString("TYPE_DEFINITION")); + return deviceSubType; + } + + public static List loadDeviceSubTypes(ResultSet rs) throws SQLException { + List deviceSubTypes = new ArrayList<>(); + while (rs.next()) { + deviceSubTypes.add(loadDeviceSubType(rs)); + } + return deviceSubTypes; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubType.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubType.java new file mode 100644 index 00000000000..8918588f6c6 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubType.java @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dto; + + +import com.fasterxml.jackson.core.JsonProcessingException; + + +public abstract class DeviceSubType { + + private String subTypeId; + private int tenantId; + private DeviceType deviceType; + private String subTypeName; + private String typeDefinition; + + public String getSubTypeId() { + return subTypeId; + } + + public void setSubTypeId(String subTypeId) { + this.subTypeId = subTypeId; + } + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceType deviceType) { + this.deviceType = deviceType; + } + + public String getSubTypeName() { + return subTypeName; + } + + public void setSubTypeName(String subTypeName) { + this.subTypeName = subTypeName; + } + + public String getTypeDefinition() { + return typeDefinition; + } + + public void setTypeDefinition(String typeDefinition) { + this.typeDefinition = typeDefinition; + } + + public abstract DeviceSubType setDeviceSubType(T objType, String typeDef); + + public abstract String parseSubTypeToJson(Object objType) throws JsonProcessingException; + + public enum DeviceType { + COM, METER, SIM + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubTypeCacheKey.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubTypeCacheKey.java new file mode 100644 index 00000000000..206a57461d3 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/dto/DeviceSubTypeCacheKey.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.dto; + +public class DeviceSubTypeCacheKey { + int tenantId; + String subTypeId; + DeviceSubType.DeviceType deviceType; + + public int getTenantId() { + return tenantId; + } + + public void setTenantId(int tenantId) { + this.tenantId = tenantId; + } + + public String getSubTypeId() { + return subTypeId; + } + + public void setSubTypeId(String subTypeId) { + this.subTypeId = subTypeId; + } + + public DeviceSubType.DeviceType getDeviceType() { + return deviceType; + } + + public void setDeviceType(DeviceSubType.DeviceType deviceType) { + this.deviceType = deviceType; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/BadRequestException.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/BadRequestException.java new file mode 100644 index 00000000000..57138e35f81 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/BadRequestException.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.exception; + +/** + * Represents the exception thrown during validating the request. + */ +public class BadRequestException extends SubTypeMgtPluginException { + + private static final long serialVersionUID = 4082332498085984791L; + + public BadRequestException(String message, Throwable ex) { + super(message, ex); + } + + public BadRequestException(String message) { + super(message); + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/DBConnectionException.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/DBConnectionException.java new file mode 100644 index 00000000000..ec2920d8fbc --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/DBConnectionException.java @@ -0,0 +1,35 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.exception; + +/** + * Exception thrown due to Database Connection issues. + */ +public class DBConnectionException extends Exception { + + private static final long serialVersionUID = 8568807205814328601L; + + public DBConnectionException(String message, Throwable cause) { + super(message, cause); + } + + public DBConnectionException(String msg) { + super(msg); + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtDAOException.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtDAOException.java new file mode 100644 index 00000000000..d80793b7780 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtDAOException.java @@ -0,0 +1,56 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.exception; + +public class SubTypeMgtDAOException extends Exception { + + private static final long serialVersionUID = 3031989080569168761L; + private String errorMessage; + + public SubTypeMgtDAOException() { + super(); + } + + public SubTypeMgtDAOException(Throwable cause) { + super(cause); + } + + public SubTypeMgtDAOException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public SubTypeMgtDAOException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public SubTypeMgtDAOException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtPluginException.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtPluginException.java new file mode 100644 index 00000000000..5b0c3551846 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/exception/SubTypeMgtPluginException.java @@ -0,0 +1,57 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.exception; + +public class SubTypeMgtPluginException extends Exception { + + private static final long serialVersionUID = -8034442883708462443L; + private String errorMessage; + + public SubTypeMgtPluginException() { + super(); + } + + public SubTypeMgtPluginException(Throwable cause) { + super(cause); + } + + public SubTypeMgtPluginException(String msg, Exception nestedEx) { + super(msg, nestedEx); + setErrorMessage(msg); + } + + public SubTypeMgtPluginException(String message, Throwable cause) { + super(message, cause); + setErrorMessage(message); + } + + public SubTypeMgtPluginException(String msg) { + super(msg); + setErrorMessage(msg); + } + + public String getErrorMessage() { + return errorMessage; + } + + public void setErrorMessage(String errorMessage) { + this.errorMessage = errorMessage; + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/impl/DeviceSubTypeServiceImpl.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/impl/DeviceSubTypeServiceImpl.java new file mode 100644 index 00000000000..24c5f2750a1 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/impl/DeviceSubTypeServiceImpl.java @@ -0,0 +1,246 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.impl; + +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import io.entgra.device.mgt.subtype.mgt.cache.GetDeviceSubTypeCacheLoader; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAO; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.spi.DeviceSubTypeService; +import io.entgra.device.mgt.subtype.mgt.util.DeviceSubTypeMgtUtil; +import io.entgra.device.mgt.subtype.mgt.exception.BadRequestException; +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtPluginException; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.context.CarbonContext; + +import java.util.List; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.TimeUnit; + +public class DeviceSubTypeServiceImpl implements DeviceSubTypeService { + private static final Log log = LogFactory.getLog(DeviceSubTypeServiceImpl.class); + private static final LoadingCache deviceSubTypeCache = CacheBuilder.newBuilder() + .expireAfterWrite(15, TimeUnit.MINUTES).build(new GetDeviceSubTypeCacheLoader()); + private final DeviceSubTypeDAO deviceSubTypeDAO; + + public DeviceSubTypeServiceImpl() { + this.deviceSubTypeDAO = DeviceSubTypeDAOFactory.getDeviceSubTypeDAO(); + } + + @Override + public boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtPluginException { + String msg = ""; + int tenantId = CarbonContext.getThreadLocalCarbonContext().getTenantId(); + deviceSubType.setTenantId(tenantId); + + try { + ConnectionManagerUtil.beginDBTransaction(); + boolean result = deviceSubTypeDAO.addDeviceSubType(deviceSubType); + if (result) { + msg = "Device subtype added successfully,for " + deviceSubType.getDeviceType() + " subtype & subtype " + + "Id: " + deviceSubType.getSubTypeId(); + if (log.isDebugEnabled()) { + log.debug(msg); + } + } else { + ConnectionManagerUtil.rollbackDBTransaction(); + msg = "Device subtype failed to add,for " + deviceSubType.getDeviceType() + " subtype & subtype Id: " + + deviceSubType.getSubTypeId(); + throw new SubTypeMgtPluginException(msg); + } + ConnectionManagerUtil.commitDBTransaction(); + String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, deviceSubType.getSubTypeId(), + deviceSubType.getDeviceType()); + deviceSubTypeCache.put(key, deviceSubType); + return true; + } catch (DBConnectionException e) { + msg = "Error occurred while obtaining the database connection to add device subtype for " + + deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId(); + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + msg = "Error occurred in the database level while adding device subtype for " + + deviceSubType.getDeviceType() + " subtype & subtype Id: " + deviceSubType.getSubTypeId(); + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, + String subTypeName, String typeDefinition) + throws SubTypeMgtPluginException { + String msg = ""; + DeviceSubType deviceSubTypeOld = getDeviceSubType(subTypeId, tenantId, deviceType); + + if (deviceSubTypeOld == null) { + String errorMsg = "Cannot find device subtype for " + deviceType + " subtype & subtype Id: " + subTypeId; + log.error(errorMsg); + throw new BadRequestException(errorMsg); + } + try { + ConnectionManagerUtil.beginDBTransaction(); + boolean result = deviceSubTypeDAO.updateDeviceSubType(subTypeId, tenantId, deviceType, subTypeName, + typeDefinition); + if (result) { + msg = "Device subtype updated successfully,for " + deviceType + " subtype & subtype Id: " + subTypeId; + if (log.isDebugEnabled()) { + log.debug(msg); + } + } else { + ConnectionManagerUtil.rollbackDBTransaction(); + msg = "Device subtype failed to update,for " + deviceType + " subtype & subtype Id: " + subTypeId; + throw new SubTypeMgtPluginException(msg); + } + ConnectionManagerUtil.commitDBTransaction(); + return true; + } catch (DBConnectionException e) { + msg = "Error occurred while obtaining the database connection to update device subtype for " + deviceType + + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + msg = "Error occurred in the database level while updating device subtype for " + deviceType + + " subtype & subtype Id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, subTypeId, deviceType); + deviceSubTypeCache.refresh(key); + } + } + + @Override + public DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException { + try { + String key = DeviceSubTypeMgtUtil.setDeviceSubTypeCacheKey(tenantId, subTypeId, deviceType); + return deviceSubTypeCache.get(key); + } catch (CacheLoader.InvalidCacheLoadException e) { + String msg = "Not having any sim subtype for subtype id: " + subTypeId; + log.error(msg, e); + return null; + } catch (ExecutionException e) { + String msg = "Error occurred while obtaining device subtype for subtype id: " + subTypeId; + log.error(msg, e); + throw new SubTypeMgtPluginException(msg, e); + } + } + + @Override + public List getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException { + try { + ConnectionManagerUtil.openDBConnection(); + return deviceSubTypeDAO.getAllDeviceSubTypes(tenantId, deviceType); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the database connection to retrieve all device subtype for " + + deviceType + " subtypes"; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + String msg = "Error occurred in the database level while retrieving all device subtype for " + deviceType + + " subtypes"; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtPluginException { + try { + ConnectionManagerUtil.openDBConnection(); + int result = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType); + if (result <= 0) { + String msg = "There are no any subtypes for device type: " + deviceType; + log.error(msg); + } + return result; + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the database connection to retrieve device subtypes count " + + "for " + deviceType + " subtypes"; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + String msg = "Error occurred in the database level while retrieving device subtypes count for " + deviceType + + " subtypes"; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, + DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException { + try { + ConnectionManagerUtil.openDBConnection(); + return deviceSubTypeDAO.getDeviceSubTypeByProvider(subTypeName, tenantId, deviceType); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the database connection to retrieve device subtype for " + + deviceType + " subtype & subtype name: " + subTypeName; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + String msg = "Error occurred in the database level while retrieving device subtype for " + deviceType + + " subtype & subtype name: " + subTypeName; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Override + public boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException { + try { + ConnectionManagerUtil.openDBConnection(); + return deviceSubTypeDAO.checkDeviceSubTypeExist(subTypeId, tenantId, deviceType); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining the database connection to check device subtype exist for " + + deviceType + " subtype & subtype id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } catch (SubTypeMgtDAOException e) { + String msg = "Error occurred in the database level while checking device subtype exist for " + deviceType + + " subtype & subtype id: " + subTypeId; + log.error(msg); + throw new SubTypeMgtPluginException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtDataHolder.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtDataHolder.java new file mode 100644 index 00000000000..58652dfafb3 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtDataHolder.java @@ -0,0 +1,63 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.internal; + +import io.entgra.device.mgt.subtype.mgt.spi.DeviceSubTypeService; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.registry.core.service.RegistryService; + +public class DeviceSubTypeMgtDataHolder { + + public static final DeviceSubTypeMgtDataHolder thisInstance = new DeviceSubTypeMgtDataHolder(); + + private RegistryService registryService; + private DeviceManagementProviderService deviceManagementProviderService; + private DeviceSubTypeService deviceSubTypeService; + + private DeviceSubTypeMgtDataHolder() { + } + + public static DeviceSubTypeMgtDataHolder getInstance() { + return thisInstance; + } + + public RegistryService getRegistryService() { + return registryService; + } + + public void setRegistryService(RegistryService registryService) { + this.registryService = registryService; + } + + public DeviceManagementProviderService getDeviceManagementProviderService() { + return deviceManagementProviderService; + } + + public void setDeviceManagementProviderService(DeviceManagementProviderService deviceManagementProviderService) { + this.deviceManagementProviderService = deviceManagementProviderService; + } + + public DeviceSubTypeService getDeviceSubTypeService() { + return deviceSubTypeService; + } + + public void setDeviceSubTypeService(DeviceSubTypeService deviceSubTypeService) { + this.deviceSubTypeService = deviceSubTypeService; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtServiceComponent.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtServiceComponent.java new file mode 100644 index 00000000000..ecf22a65819 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/internal/DeviceSubTypeMgtServiceComponent.java @@ -0,0 +1,137 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.internal; + +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.impl.DeviceSubTypeServiceImpl; +import io.entgra.device.mgt.subtype.mgt.spi.DeviceSubTypeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.device.mgt.core.config.DeviceConfigurationManager; +import org.wso2.carbon.device.mgt.core.config.DeviceManagementConfig; +import org.wso2.carbon.device.mgt.core.config.datasource.DataSourceConfig; +import org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService; +import org.wso2.carbon.ndatasource.core.DataSourceService; +import org.wso2.carbon.registry.core.service.RegistryService; + +/** + * @scr.component name="io.entgra.device.mgt.subtype.mgt.internal.DeviceSubTypeMgtServiceComponent" immediate="true" + * @scr.reference name="org.wso2.carbon.device.manager" + * interface="org.wso2.carbon.device.mgt.core.service.DeviceManagementProviderService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDeviceManagementService" + * unbind="unsetDeviceManagementService" + * @scr.reference name="org.wso2.carbon.ndatasource" + * interface="org.wso2.carbon.ndatasource.core.DataSourceService" + * cardinality="1..1" + * policy="dynamic" + * bind="setDataSourceService" + * unbind="unsetDataSourceService" + * @scr.reference name="registry.service" + * interface="org.wso2.carbon.registry.core.service.RegistryService" + * cardinality="0..1" + * policy="dynamic" + * bind="setRegistryService" + * unbind="unsetRegistryService" + */ +public class DeviceSubTypeMgtServiceComponent { + + private static final Log log = LogFactory.getLog(DeviceSubTypeMgtServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + + if (log.isDebugEnabled()) { + log.debug("Activating Device SubType Management Service Component"); + } + try { + BundleContext bundleContext = componentContext.getBundleContext(); + + DeviceManagementConfig config = DeviceConfigurationManager.getInstance().getDeviceManagementConfig(); + DataSourceConfig dsConfig = config.getDeviceManagementConfigRepository().getDataSourceConfig(); + DeviceSubTypeDAOFactory.init(dsConfig); + + DeviceSubTypeService deviceSubTypeService = new DeviceSubTypeServiceImpl(); + DeviceSubTypeMgtDataHolder.getInstance().setDeviceSubTypeService(deviceSubTypeService); + bundleContext.registerService(DeviceSubTypeService.class, deviceSubTypeService, null); + + if (log.isDebugEnabled()) { + log.debug("Device SubType Management Service Component has been successfully activated"); + } + } catch (Throwable e) { + log.error("Error occurred while activating Device SubType Management Service Component", e); + } + } + + protected void deactivate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("De-activating Device SubType Management Service Component"); + } + } + + @SuppressWarnings("unused") + protected void setDeviceManagementService(DeviceManagementProviderService deviceManagementProviderService) { + if (log.isDebugEnabled()) { + log.debug("Setting Device Management Service to Device SubType Mgt SC"); + } + DeviceSubTypeMgtDataHolder.getInstance().setDeviceManagementProviderService(deviceManagementProviderService); + } + + @SuppressWarnings("unused") + protected void unsetDeviceManagementService(DeviceManagementProviderService deviceManagementService) { + if (log.isDebugEnabled()) { + log.debug("Removing Device Management Service from Device SubType Mgt SC"); + } + DeviceSubTypeMgtDataHolder.getInstance().setDeviceManagementProviderService(null); + } + + protected void setDataSourceService(DataSourceService dataSourceService) { + /* This is to avoid mobile device management component getting initialized before the underlying datasources + are registered */ + if (log.isDebugEnabled()) { + log.debug("Data source service set to Device SubType Mgt component"); + } + } + + protected void unsetDataSourceService(DataSourceService dataSourceService) { + //do nothing + if (log.isDebugEnabled()) { + log.debug("Removing Data Source service from Device SubType Mgt component"); + } + } + + + protected void setRegistryService(RegistryService registryService) { + if (log.isDebugEnabled()) { + log.debug("RegistryService set to Device SubType Mgt component"); + } + DeviceSubTypeMgtDataHolder.getInstance().setRegistryService(registryService); + } + + protected void unsetRegistryService(RegistryService registryService) { + if (log.isDebugEnabled()) { + log.debug("Removing RegistryService from Device SubType Mgt component"); + } + DeviceSubTypeMgtDataHolder.getInstance().setRegistryService(null); + } + + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/spi/DeviceSubTypeService.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/spi/DeviceSubTypeService.java new file mode 100644 index 00000000000..24aa2fd431c --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/spi/DeviceSubTypeService.java @@ -0,0 +1,46 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.spi; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtPluginException; + +import java.util.List; + +public interface DeviceSubTypeService { + + boolean addDeviceSubType(DeviceSubType deviceSubType) throws SubTypeMgtPluginException; + + boolean updateDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType, String subTypeName, + String typeDefinition) throws SubTypeMgtPluginException; + + DeviceSubType getDeviceSubType(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException; + + List getAllDeviceSubTypes(int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException; + + int getDeviceSubTypeCount(DeviceSubType.DeviceType deviceType) throws SubTypeMgtPluginException; + + DeviceSubType getDeviceSubTypeByProvider(String subTypeName, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException; + + boolean checkDeviceSubTypeExist(String subTypeId, int tenantId, DeviceSubType.DeviceType deviceType) + throws SubTypeMgtPluginException; +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/util/DeviceSubTypeMgtUtil.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/util/DeviceSubTypeMgtUtil.java new file mode 100644 index 00000000000..171d621945b --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/main/java/io/entgra/device/mgt/subtype/mgt/util/DeviceSubTypeMgtUtil.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.util; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubTypeCacheKey; + +public class DeviceSubTypeMgtUtil { + public static String setDeviceSubTypeCacheKey(int tenantId, String subTypeId, DeviceSubType.DeviceType deviceType) { + return tenantId + "|" + subTypeId + "|" + deviceType.toString(); + } + + public static DeviceSubTypeCacheKey getDeviceSubTypeCacheKey(String key) { + String[] keys = key.split("\\|"); + int tenantId = Integer.parseInt(keys[0]); + String subTypeId = keys[1]; + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.valueOf(keys[2]); + + DeviceSubTypeCacheKey deviceSubTypesCacheKey = new DeviceSubTypeCacheKey(); + deviceSubTypesCacheKey.setTenantId(tenantId); + deviceSubTypesCacheKey.setSubTypeId(subTypeId); + deviceSubTypesCacheKey.setDeviceType(deviceType); + return deviceSubTypesCacheKey; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAONegativeTest.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAONegativeTest.java new file mode 100644 index 00000000000..fd0b659fda6 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAONegativeTest.java @@ -0,0 +1,162 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAO; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; +import io.entgra.device.mgt.subtype.mgt.mock.BaseDeviceSubTypePluginTest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +public class DAONegativeTest extends BaseDeviceSubTypePluginTest { + private static final Log log = LogFactory.getLog(DAONegativeTest.class); + + private DeviceSubTypeDAO deviceSubTypeDAO; + + @BeforeClass + public void init() { + deviceSubTypeDAO = DeviceSubTypeDAOFactory.getDeviceSubTypeDAO(); + log.info("DAO Negative test initialized"); + } + + @Test(description = "This method tests the add device subtype method under negative circumstances with null data", + expectedExceptions = {NullPointerException.class} + ) + public void testAddDeviceSubType() throws SubTypeMgtDAOException { + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + try { + ConnectionManagerUtil.beginDBTransaction(); + deviceSubTypeDAO.addDeviceSubType(deviceSubType); + ConnectionManagerUtil.commitDBTransaction(); + } catch (SubTypeMgtDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while processing SQL to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Test(description = "This method tests the add device subtype method under negative circumstances while missing " + + "required fields", + expectedExceptions = {SubTypeMgtDAOException.class}, + expectedExceptionsMessageRegExp = "Error occurred while processing SQL to insert device subtype" + ) + public void testAddDeviceSubTypes() throws SubTypeMgtDAOException { + String subTypeId = "1"; + String subTypeName = "TestSubType"; + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubType.setSubTypeId(subTypeId); + deviceSubType.setSubTypeName(subTypeName); + deviceSubType.setDeviceType(DeviceSubType.DeviceType.COM); + try { + ConnectionManagerUtil.beginDBTransaction(); + deviceSubTypeDAO.addDeviceSubType(deviceSubType); + ConnectionManagerUtil.commitDBTransaction(); + } catch (SubTypeMgtDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while processing SQL to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + + @Test(description = "This method tests the add device subtype method under negative circumstances while passing " + + "same subtype id & device type", + expectedExceptions = {SubTypeMgtDAOException.class}, + expectedExceptionsMessageRegExp = "Error occurred while processing SQL to insert device subtype" + ) + public void testAddDeviceSubtypes() throws SubTypeMgtDAOException { + String subTypeId = "1"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String subTypeName = "TestSubType"; + String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId); + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubType.setSubTypeName(subTypeName); + deviceSubType.setDeviceType(DeviceSubType.DeviceType.COM); + deviceSubType.setTenantId(tenantId); + deviceSubType.setTypeDefinition(typeDefinition); + try { + ConnectionManagerUtil.beginDBTransaction(); + deviceSubTypeDAO.addDeviceSubType(deviceSubType); + deviceSubTypeDAO.addDeviceSubType(deviceSubType); + ConnectionManagerUtil.commitDBTransaction(); + } catch (SubTypeMgtDAOException e) { + ConnectionManagerUtil.rollbackDBTransaction(); + String msg = "Error occurred while processing SQL to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } catch (DBConnectionException e) { + String msg = "Error occurred while obtaining DB connection to insert device subtype"; + log.error(msg); + throw new SubTypeMgtDAOException(msg, e); + } finally { + ConnectionManagerUtil.closeDBConnection(); + } + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAOTest.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAOTest.java new file mode 100644 index 00000000000..5592326962c --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DAOTest.java @@ -0,0 +1,142 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAO; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.DBConnectionException; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtDAOException; +import io.entgra.device.mgt.subtype.mgt.mock.BaseDeviceSubTypePluginTest; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +import java.util.List; + +public class DAOTest extends BaseDeviceSubTypePluginTest { + private static final Log log = LogFactory.getLog(DAOTest.class); + + private DeviceSubTypeDAO deviceSubTypeDAO; + + @BeforeClass + public void init() { + deviceSubTypeDAO = DeviceSubTypeDAOFactory.getDeviceSubTypeDAO(); + log.info("DAO test initialized"); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceSubType() throws DBConnectionException, SubTypeMgtDAOException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + ConnectionManagerUtil.openDBConnection(); + DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubType("1", tenantId, + DeviceSubType.DeviceType.COM); + ConnectionManagerUtil.closeDBConnection(); + Assert.assertNotNull(subTypeActual, "Should not be null"); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetAllDeviceSubTypes() throws DBConnectionException, SubTypeMgtDAOException { + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + ConnectionManagerUtil.openDBConnection(); + List subTypesActual = deviceSubTypeDAO.getAllDeviceSubTypes(tenantId, deviceType); + ConnectionManagerUtil.closeDBConnection(); + log.info(deviceType + " sub types count should be " + subTypesActual.size()); + Assert.assertNotNull(subTypesActual, "Should not be null"); + } + + @Test + public void testAddDeviceSubType() throws DBConnectionException, SubTypeMgtDAOException { + String subTypeId = "1"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String subTypeName = "TestSubType"; + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM; + String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId); + + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubType.setSubTypeId(subTypeId); + deviceSubType.setSubTypeName(subTypeName); + deviceSubType.setDeviceType(deviceType); + deviceSubType.setTenantId(tenantId); + deviceSubType.setTypeDefinition(typeDefinition); + + ConnectionManagerUtil.beginDBTransaction(); + deviceSubTypeDAO.addDeviceSubType(deviceSubType); + ConnectionManagerUtil.commitDBTransaction(); + DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubType(subTypeId, tenantId, deviceType); + ConnectionManagerUtil.closeDBConnection(); + Assert.assertNotNull(subTypeActual, "Cannot be null"); + TestUtils.verifyDeviceSubTypeDAO(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testUpdateDeviceSubType() throws DBConnectionException, SubTypeMgtDAOException { + String subTypeId = "1"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM; + String subTypeName = "TestSubType"; + String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId); + + ConnectionManagerUtil.beginDBTransaction(); + deviceSubTypeDAO.updateDeviceSubType(subTypeId, tenantId, deviceType, subTypeName, subTypeExpected); + ConnectionManagerUtil.commitDBTransaction(); + DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubType(subTypeId, tenantId, deviceType); + ConnectionManagerUtil.closeDBConnection(); + + Assert.assertNotNull(subTypeActual, "Cannot be null"); + TestUtils.verifyUpdatedDeviceSubTypeDAO(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceTypeByProvider() throws DBConnectionException, SubTypeMgtDAOException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM; + String subTypeName = "TestSubType"; + ConnectionManagerUtil.openDBConnection(); + DeviceSubType subTypeActual = deviceSubTypeDAO.getDeviceSubTypeByProvider(subTypeName, tenantId, deviceType); + ConnectionManagerUtil.closeDBConnection(); + Assert.assertNotNull(subTypeActual, "Should not be null"); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceTypeCount() throws DBConnectionException, SubTypeMgtDAOException { + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.COM; + ConnectionManagerUtil.openDBConnection(); + int subTypeCount = deviceSubTypeDAO.getDeviceSubTypeCount(deviceType); + ConnectionManagerUtil.closeDBConnection(); + log.info(deviceType + " Device subtypes count: " + subTypeCount); + Assert.assertEquals(subTypeCount, 1); + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DataSourceConfig.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DataSourceConfig.java new file mode 100644 index 00000000000..1bb8afee842 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/DataSourceConfig.java @@ -0,0 +1,78 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import javax.xml.bind.annotation.XmlElement; +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement(name = "DataSourceConfig") +public class DataSourceConfig { + + private String url; + private String driverClassName; + private String user; + private String password; + + @Override + public String toString() { + return "DataSourceConfig[" + + " Url ='" + url + '\'' + + ", DriverClassName ='" + driverClassName + '\'' + + ", UserName ='" + user + '\'' + + ", Password ='" + password + '\'' + + "]"; + } + + @XmlElement(name = "Url", nillable = false) + public String getUrl() { + return url; + } + + public void setUrl(String url) { + this.url = url; + } + + @XmlElement(name = "DriverClassName", nillable = false) + public String getDriverClassName() { + return driverClassName; + } + + public void setDriverClassName(String driverClassName) { + this.driverClassName = driverClassName; + } + + @XmlElement(name = "User", nillable = false) + public String getUser() { + return user; + } + + public void setUser(String user) { + this.user = user; + } + + @XmlElement(name = "Password", nillable = false) + public String getPassword() { + return password; + } + + public void setPassword(String password) { + this.password = password; + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceNegativeTest.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceNegativeTest.java new file mode 100644 index 00000000000..3562525adef --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceNegativeTest.java @@ -0,0 +1,102 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtPluginException; +import io.entgra.device.mgt.subtype.mgt.impl.DeviceSubTypeServiceImpl; +import io.entgra.device.mgt.subtype.mgt.mock.BaseDeviceSubTypePluginTest; +import io.entgra.device.mgt.subtype.mgt.spi.DeviceSubTypeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +public class ServiceNegativeTest extends BaseDeviceSubTypePluginTest { + + private static final Log log = LogFactory.getLog(ServiceNegativeTest.class); + private DeviceSubTypeService deviceSubTypeService; + + @BeforeClass + public void init() { + deviceSubTypeService = new DeviceSubTypeServiceImpl(); + log.info("Service test initialized"); + } + + @Test(description = "This method tests Add Device Subtype method under negative circumstances with null data", + expectedExceptions = {NullPointerException.class}) + public void testAddDeviceSubType() throws SubTypeMgtPluginException { + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubTypeService.addDeviceSubType(deviceSubType); + } + + @Test(description = "This method tests Add Device Subtype method under negative circumstances while missing " + + "required fields", + expectedExceptions = {SubTypeMgtPluginException.class}, + expectedExceptionsMessageRegExp = "Error occurred in the database level while adding device subtype for " + + "SIM subtype & subtype Id: 1") + public void testAddDeviceSubTypes() throws SubTypeMgtPluginException { + String subTypeId = "1"; + String subTypeName = "TestSubType"; + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.SIM; + + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubType.setSubTypeId(subTypeId); + deviceSubType.setSubTypeName(subTypeName); + deviceSubType.setDeviceType(deviceType); + deviceSubTypeService.addDeviceSubType(deviceSubType); + } + + @Test(description = "This method tests Update Device Subtype method under negative circumstances with invalid " + + "subtype Id", + expectedExceptions = {SubTypeMgtPluginException.class}, + expectedExceptionsMessageRegExp = "Cannot find device subtype for SIM subtype & subtype Id: 15") + public void testUpdateDeviceSubTypes() throws SubTypeMgtPluginException { + String subTypeId = "15"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.SIM; + String subTypeName = "TestSubType"; + String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId); + + deviceSubTypeService.updateDeviceSubType(subTypeId, tenantId, deviceType, subTypeName, subTypeExpected); + } + + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceTest.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceTest.java new file mode 100644 index 00000000000..07694bcce74 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/ServiceTest.java @@ -0,0 +1,127 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import io.entgra.device.mgt.subtype.mgt.exception.SubTypeMgtPluginException; +import io.entgra.device.mgt.subtype.mgt.impl.DeviceSubTypeServiceImpl; +import io.entgra.device.mgt.subtype.mgt.mock.BaseDeviceSubTypePluginTest; +import io.entgra.device.mgt.subtype.mgt.spi.DeviceSubTypeService; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; +import org.wso2.carbon.context.PrivilegedCarbonContext; + +import java.util.List; + + +public class ServiceTest extends BaseDeviceSubTypePluginTest { + + private static final Log log = LogFactory.getLog(ServiceTest.class); + private DeviceSubTypeService deviceSubTypeService; + + @BeforeClass + public void init() { + deviceSubTypeService = new DeviceSubTypeServiceImpl(); + log.info("Service test initialized"); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceType() throws SubTypeMgtPluginException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubType("1", tenantId, + DeviceSubType.DeviceType.METER); + TestUtils.verifyDeviceSubType(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetAllDeviceTypes() throws SubTypeMgtPluginException { + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + List subTypesActual = deviceSubTypeService.getAllDeviceSubTypes(tenantId, deviceType); + log.info(deviceType + " sub types count should be " + subTypesActual.size()); + Assert.assertNotNull(subTypesActual, "Should not be null"); + } + + @Test + public void testAddDeviceSubType() throws SubTypeMgtPluginException { + String subTypeId = "1"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + String subTypeName = "TestSubType"; + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER; + String typeDefinition = TestUtils.createNewDeviceSubType(subTypeId); + + DeviceSubType deviceSubType = new DeviceSubType() { + @Override + public DeviceSubType setDeviceSubType(T objType, String typeDef) { + return null; + } + + @Override + public String parseSubTypeToJson(Object objType) { + return null; + } + }; + deviceSubType.setSubTypeId(subTypeId); + deviceSubType.setSubTypeName(subTypeName); + deviceSubType.setDeviceType(deviceType); + deviceSubType.setTenantId(tenantId); + deviceSubType.setTypeDefinition(typeDefinition); + deviceSubTypeService.addDeviceSubType(deviceSubType); + + DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubType(subTypeId, tenantId, deviceType); + Assert.assertNotNull(subTypeActual, "Cannot be null"); + TestUtils.verifyDeviceSubType(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testUpdateDeviceSubType() throws SubTypeMgtPluginException { + String subTypeId = "1"; + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER; + String subTypeName = "TestSubType"; + String subTypeExpected = TestUtils.createUpdateDeviceSubType(subTypeId); + + deviceSubTypeService.updateDeviceSubType(subTypeId, tenantId, deviceType, subTypeName, subTypeExpected); + + DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubType(subTypeId, tenantId, deviceType); + + Assert.assertNotNull(subTypeActual, "Cannot be null"); + TestUtils.verifyUpdatedDeviceSubType(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceTypeByProvider() throws SubTypeMgtPluginException { + int tenantId = PrivilegedCarbonContext.getThreadLocalCarbonContext().getTenantId(); + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER; + String subTypeName = "TestSubType"; + DeviceSubType subTypeActual = deviceSubTypeService.getDeviceSubTypeByProvider(subTypeName, tenantId, + deviceType); + TestUtils.verifyDeviceSubType(subTypeActual); + } + + @Test(dependsOnMethods = "testAddDeviceSubType") + public void testGetDeviceTypeCount() throws SubTypeMgtPluginException { + DeviceSubType.DeviceType deviceType = DeviceSubType.DeviceType.METER; + int subTypeCount = deviceSubTypeService.getDeviceSubTypeCount(deviceType); + log.info(deviceType + " Device subtypes count: " + subTypeCount); + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/TestUtils.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/TestUtils.java new file mode 100644 index 00000000000..d8e913831c1 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/TestUtils.java @@ -0,0 +1,99 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt; + +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import io.entgra.device.mgt.subtype.mgt.dto.DeviceSubType; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.testng.Assert; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLException; +import java.sql.Statement; + +public class TestUtils { + private static final Log log = LogFactory.getLog(TestUtils.class); + + public static String createNewDeviceSubType(String subtypeId) { + return "{\"make\": \"TestSubType\", \"model\": \"ATx-Mega SIM800\", " + + "\"subTypeId\": " + subtypeId + ", \"hasSMSSupport\": true, \"hasICMPSupport\": true, " + + "\"socketServerPort\": 8071}"; + } + + public static String createUpdateDeviceSubType(String subtypeId) { + return "{\"make\": \"TestSubType\", \"model\": \"ATx-Mega SIM900\", " + + "\"subTypeId\": " + subtypeId + ", \"hasSMSSupport\": false, \"hasICMPSupport\": true, " + + "\"socketServerPort\": 8071}"; + } + + public static void verifyDeviceSubType(DeviceSubType deviceSubType) { + String typeDefExpected = TestUtils.createNewDeviceSubType("1"); + Assert.assertEquals(deviceSubType.getSubTypeId(), "1"); + Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("METER")); + Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType"); + Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); + } + + public static void verifyDeviceSubTypeDAO(DeviceSubType deviceSubType) { + String typeDefExpected = TestUtils.createNewDeviceSubType("1"); + Assert.assertEquals(deviceSubType.getSubTypeId(), "1"); + Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("COM")); + Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType"); + Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); + } + + public static void verifyUpdatedDeviceSubType(DeviceSubType deviceSubType) { + String typeDefExpected = TestUtils.createUpdateDeviceSubType("1"); + Assert.assertEquals(deviceSubType.getSubTypeId(), "1"); + Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("METER")); + Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType"); + Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); + } + + public static void verifyUpdatedDeviceSubTypeDAO(DeviceSubType deviceSubType) { + String typeDefExpected = TestUtils.createUpdateDeviceSubType("1"); + Assert.assertEquals(deviceSubType.getSubTypeId(), "1"); + Assert.assertEquals(deviceSubType.getDeviceType(), DeviceSubType.DeviceType.valueOf("COM")); + Assert.assertEquals(deviceSubType.getSubTypeName(), "TestSubType"); + Assert.assertEquals(deviceSubType.getTypeDefinition(), typeDefExpected); + } + + public static void cleanupResources(Connection conn, Statement stmt, ResultSet rs) { + if (rs != null) { + try { + rs.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing result set", e); + } + } + if (stmt != null) { + try { + stmt.close(); + } catch (SQLException e) { + log.warn("Error occurred while closing prepared statement", e); + } + } + if (conn != null) { + ConnectionManagerUtil.closeDBConnection(); + } + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/BaseDeviceSubTypePluginTest.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/BaseDeviceSubTypePluginTest.java new file mode 100644 index 00000000000..166bafc2810 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/BaseDeviceSubTypePluginTest.java @@ -0,0 +1,157 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import io.entgra.device.mgt.subtype.mgt.TestUtils; +import io.entgra.device.mgt.subtype.mgt.dao.DeviceSubTypeDAOFactory; +import io.entgra.device.mgt.subtype.mgt.DataSourceConfig; +import io.entgra.device.mgt.subtype.mgt.dao.util.ConnectionManagerUtil; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.tomcat.jdbc.pool.PoolProperties; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.BeforeSuite; +import org.testng.annotations.Optional; +import org.testng.annotations.Parameters; +import org.w3c.dom.Document; +import org.wso2.carbon.base.MultitenantConstants; +import org.wso2.carbon.context.PrivilegedCarbonContext; +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; +import org.wso2.carbon.device.mgt.common.exceptions.DeviceManagementException; +import org.wso2.carbon.device.mgt.core.util.DeviceManagerUtil; + +import javax.sql.DataSource; +import javax.xml.bind.JAXBContext; +import javax.xml.bind.JAXBException; +import javax.xml.bind.Unmarshaller; +import java.io.File; +import java.lang.reflect.Field; +import java.sql.Connection; +import java.sql.Statement; + +public abstract class BaseDeviceSubTypePluginTest { + + private static final Log log = LogFactory.getLog(BaseDeviceSubTypePluginTest.class); + + private static final String datasourceLocation = "src/test/resources/carbon-home/repository/conf/" + + "datasources/data-source-config.xml"; + + private static boolean mock; + + @BeforeSuite + @Parameters({"isMock"}) + public void setup(@Optional("false") boolean isMock) throws Exception { + log.info("Setting up test suite"); + this.initDataSource(); + this.initSQLScript(); + this.initializeCarbonContext(); + this.initServices(); + mock = isMock; + log.info("Setting up test suite done!"); + } + + protected void initDataSource() throws Exception { + DataSource dataSource = this.getDataSource(this.readDataSourceConfig()); + Class clazz1 = ConnectionManagerUtil.class; + Field f1 = clazz1.getDeclaredField("dataSource"); + f1.setAccessible(true); + f1.set(clazz1, dataSource); + + Class clazz2 = DeviceSubTypeDAOFactory.class; + Field f2 = clazz2.getDeclaredField("databaseEngine"); + f2.setAccessible(true); + f2.set(clazz2, DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2); + } + + private void initServices() { + + } + + @BeforeClass + public abstract void init() throws Exception; + + protected DataSource getDataSource(DataSourceConfig config) { + if (!isMock()) { + PoolProperties properties = new PoolProperties(); + properties.setUrl(config.getUrl()); + properties.setDriverClassName(config.getDriverClassName()); + properties.setUsername(config.getUser()); + properties.setPassword(config.getPassword()); + return new org.apache.tomcat.jdbc.pool.DataSource(properties); + } else { + return new MockDataSource(config.getUrl()); + } + } + + private void initializeCarbonContext() { + if (System.getProperty("carbon.home") == null) { + File file = new File("src/test/resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + file = new File("../../../resources/carbon-home"); + if (file.exists()) { + System.setProperty("carbon.home", file.getAbsolutePath()); + } + } + + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(MultitenantConstants + .SUPER_TENANT_DOMAIN_NAME); + PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(MultitenantConstants.SUPER_TENANT_ID); + } + + protected DataSourceConfig readDataSourceConfig() throws DeviceManagementException { + try { + File file = new File(BaseDeviceSubTypePluginTest.datasourceLocation); + Document doc = DeviceManagerUtil.convertToDocument(file); + JAXBContext testDBContext = JAXBContext.newInstance(DataSourceConfig.class); + Unmarshaller unmarshaller = testDBContext.createUnmarshaller(); + return (DataSourceConfig) unmarshaller.unmarshal(doc); + } catch (JAXBException e) { + throw new DeviceManagementException("Error occurred while reading data source configuration", e); + } + } + + private void initSQLScript() throws Exception { + Connection conn = null; + Statement stmt = null; + try { + ConnectionManagerUtil.beginDBTransaction(); + conn = ConnectionManagerUtil.getDBConnection(); + stmt = conn.createStatement(); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/dm-db-h2.sql'"); + stmt.executeUpdate("RUNSCRIPT FROM './src/test/resources/carbon-home/dbscripts/h2.sql'"); + } finally { + TestUtils.cleanupResources(conn, stmt, null); + } + } + + protected boolean isMock() { + return mock; + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockConnection.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockConnection.java new file mode 100644 index 00000000000..2ce68a6ded1 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockConnection.java @@ -0,0 +1,343 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import java.sql.CallableStatement; +import java.sql.SQLWarning; +import java.sql.Savepoint; +import java.sql.Connection; +import java.sql.PreparedStatement; +import java.sql.Statement; +import java.sql.Clob; +import java.sql.Blob; +import java.sql.NClob; +import java.sql.SQLXML; +import java.sql.Struct; +import java.sql.Array; +import java.sql.SQLClientInfoException; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; +import java.util.Properties; +import java.util.concurrent.Executor; + +/** + * This is mock class which provides mock database connection. + */ +public class MockConnection implements Connection { + + private final String url; + private final List statements = new ArrayList<>(); + private int statementCounter = 0; + + public MockConnection(String url) { + this.url = url; + } + + @Override + public Statement createStatement() throws SQLException { + return getStatement(); + } + + private MockStatement getStatement() { + if (!statements.isEmpty()) { + MockStatement statement = this.statements.get(this.statementCounter); + statementCounter++; + return statement; + } + return new MockStatement(); + } + + @Override + public PreparedStatement prepareStatement(String sql) throws SQLException { + return getStatement(); + } + + @Override + public CallableStatement prepareCall(String sql) throws SQLException { + return null; + } + + @Override + public String nativeSQL(String sql) throws SQLException { + return null; + } + + @Override + public boolean getAutoCommit() throws SQLException { + return false; + } + + @Override + public void setAutoCommit(boolean autoCommit) throws SQLException { + + } + + @Override + public void commit() throws SQLException { + + } + + @Override + public void rollback() throws SQLException { + + } + + @Override + public void close() throws SQLException { + + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public DatabaseMetaData getMetaData() throws SQLException { + return new MockDatabaseMetaData(this.url); + } + + @Override + public boolean isReadOnly() throws SQLException { + return false; + } + + @Override + public void setReadOnly(boolean readOnly) throws SQLException { + + } + + @Override + public String getCatalog() throws SQLException { + return null; + } + + @Override + public void setCatalog(String catalog) throws SQLException { + + } + + @Override + public int getTransactionIsolation() throws SQLException { + return 0; + } + + @Override + public void setTransactionIsolation(int level) throws SQLException { + + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException { + return null; + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return null; + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency) + throws SQLException { + return null; + } + + @Override + public Map> getTypeMap() throws SQLException { + return null; + } + + @Override + public void setTypeMap(Map> map) throws SQLException { + + } + + @Override + public int getHoldability() throws SQLException { + return 0; + } + + @Override + public void setHoldability(int holdability) throws SQLException { + + } + + @Override + public Savepoint setSavepoint() throws SQLException { + return null; + } + + @Override + public Savepoint setSavepoint(String name) throws SQLException { + return null; + } + + @Override + public void rollback(Savepoint savepoint) throws SQLException { + + } + + @Override + public void releaseSavepoint(Savepoint savepoint) throws SQLException { + + } + + @Override + public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) + throws SQLException { + return null; + } + + @Override + public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return null; + } + + @Override + public CallableStatement prepareCall(String sql, int resultSetType, int resultSetConcurrency, + int resultSetHoldability) throws SQLException { + return null; + } + + @Override + public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException { + return null; + } + + @Override + public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException { + return null; + } + + @Override + public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException { + return new MockStatement(); + } + + @Override + public Clob createClob() throws SQLException { + return null; + } + + @Override + public Blob createBlob() throws SQLException { + return null; + } + + @Override + public NClob createNClob() throws SQLException { + return null; + } + + @Override + public SQLXML createSQLXML() throws SQLException { + return null; + } + + @Override + public boolean isValid(int timeout) throws SQLException { + return false; + } + + @Override + public void setClientInfo(String name, String value) throws SQLClientInfoException { + + } + + @Override + public String getClientInfo(String name) throws SQLException { + return null; + } + + @Override + public Properties getClientInfo() throws SQLException { + return null; + } + + @Override + public void setClientInfo(Properties properties) throws SQLClientInfoException { + + } + + @Override + public Array createArrayOf(String typeName, Object[] elements) throws SQLException { + return null; + } + + @Override + public Struct createStruct(String typeName, Object[] attributes) throws SQLException { + return null; + } + + @Override + public String getSchema() throws SQLException { + return null; + } + + @Override + public void setSchema(String schema) throws SQLException { + + } + + @Override + public void abort(Executor executor) throws SQLException { + + } + + @Override + public void setNetworkTimeout(Executor executor, int milliseconds) throws SQLException { + + } + + @Override + public int getNetworkTimeout() throws SQLException { + return 0; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + public void addMockStatement(MockStatement mockStatement) { + this.statements.add(mockStatement); + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDataSource.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDataSource.java new file mode 100644 index 00000000000..1fd43e0ab33 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDataSource.java @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import javax.sql.DataSource; +import java.io.PrintWriter; +import java.sql.Connection; +import java.sql.SQLException; +import java.sql.SQLFeatureNotSupportedException; +import java.util.ArrayList; +import java.util.List; +import java.util.logging.Logger; + +/** + * This is the mock data source implementation that will be used in the test cases. + */ +public class MockDataSource implements DataSource { + private final List connections = new ArrayList<>(); + private final String url; + private boolean throwException = false; + private int connectionCounter = 0; + + public MockDataSource(String url) { + this.url = url; + } + + @Override + public Connection getConnection() throws SQLException { + if (throwException) { + throw new SQLException("Cannot created test connection."); + } else { + if (!connections.isEmpty()) { + if (this.connectionCounter < this.connections.size()) { + Connection connection = this.connections.get(this.connectionCounter); + this.connectionCounter++; + return connection; + } else { + return new MockConnection(url); + } + } + return new MockConnection(url); + } + } + + public void setConnection(Connection connection) { + this.connections.add(connection); + } + + @Override + public Connection getConnection(String username, String password) throws SQLException { + return null; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + @Override + public PrintWriter getLogWriter() throws SQLException { + return null; + } + + @Override + public void setLogWriter(PrintWriter out) throws SQLException { + + } + + @Override + public int getLoginTimeout() throws SQLException { + return 0; + } + + @Override + public void setLoginTimeout(int seconds) throws SQLException { + + } + + @Override + public Logger getParentLogger() throws SQLFeatureNotSupportedException { + return null; + } + + public void setThrowException(boolean throwException) { + this.throwException = throwException; + } + + public void reset() { + this.throwException = false; + this.connections.clear(); + this.connectionCounter = 0; + } + + public String getUrl() { + return this.url; + } + + public MockConnection getConnection(int id) { + return (MockConnection) this.connections.get(id); + } + +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDatabaseMetaData.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDatabaseMetaData.java new file mode 100644 index 00000000000..0bf75cc2bb7 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockDatabaseMetaData.java @@ -0,0 +1,941 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import org.wso2.carbon.device.mgt.common.DeviceManagementConstants; + +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.RowIdLifetime; +import java.sql.DatabaseMetaData; +import java.sql.SQLException; + +public class MockDatabaseMetaData implements DatabaseMetaData { + private final String url; + + public MockDatabaseMetaData(String url) { + this.url = url; + } + + @Override + public boolean allProceduresAreCallable() throws SQLException { + return false; + } + + @Override + public boolean allTablesAreSelectable() throws SQLException { + return false; + } + + @Override + public String getURL() throws SQLException { + return null; + } + + @Override + public String getUserName() throws SQLException { + return null; + } + + @Override + public boolean isReadOnly() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedHigh() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedLow() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedAtStart() throws SQLException { + return false; + } + + @Override + public boolean nullsAreSortedAtEnd() throws SQLException { + return false; + } + + @Override + public String getDatabaseProductName() throws SQLException { + if (this.url.contains("mysql")) { + return DeviceManagementConstants.DataBaseTypes.DB_TYPE_MYSQL; + } else if (this.url.contains("h2")) { + return DeviceManagementConstants.DataBaseTypes.DB_TYPE_H2; + } else if (this.url.contains("oracle")) { + return DeviceManagementConstants.DataBaseTypes.DB_TYPE_ORACLE; + } else if (this.url.contains("postgresql")) { + return DeviceManagementConstants.DataBaseTypes.DB_TYPE_POSTGRESQL; + } else if (this.url.contains("sqlserver")) { + return DeviceManagementConstants.DataBaseTypes.DB_TYPE_MSSQL; + } else { + return null; + } + } + + @Override + public String getDatabaseProductVersion() throws SQLException { + return null; + } + + @Override + public String getDriverName() throws SQLException { + return null; + } + + @Override + public String getDriverVersion() throws SQLException { + return null; + } + + @Override + public int getDriverMajorVersion() { + return 0; + } + + @Override + public int getDriverMinorVersion() { + return 0; + } + + @Override + public boolean usesLocalFiles() throws SQLException { + return false; + } + + @Override + public boolean usesLocalFilePerTable() throws SQLException { + return false; + } + + @Override + public boolean supportsMixedCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesUpperCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesLowerCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesMixedCaseIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean supportsMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesUpperCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesLowerCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public boolean storesMixedCaseQuotedIdentifiers() throws SQLException { + return false; + } + + @Override + public String getIdentifierQuoteString() throws SQLException { + return null; + } + + @Override + public String getSQLKeywords() throws SQLException { + return null; + } + + @Override + public String getNumericFunctions() throws SQLException { + return null; + } + + @Override + public String getStringFunctions() throws SQLException { + return null; + } + + @Override + public String getSystemFunctions() throws SQLException { + return null; + } + + @Override + public String getTimeDateFunctions() throws SQLException { + return null; + } + + @Override + public String getSearchStringEscape() throws SQLException { + return null; + } + + @Override + public String getExtraNameCharacters() throws SQLException { + return null; + } + + @Override + public boolean supportsAlterTableWithAddColumn() throws SQLException { + return false; + } + + @Override + public boolean supportsAlterTableWithDropColumn() throws SQLException { + return false; + } + + @Override + public boolean supportsColumnAliasing() throws SQLException { + return false; + } + + @Override + public boolean nullPlusNonNullIsNull() throws SQLException { + return false; + } + + @Override + public boolean supportsConvert() throws SQLException { + return false; + } + + @Override + public boolean supportsConvert(int fromType, int toType) throws SQLException { + return false; + } + + @Override + public boolean supportsTableCorrelationNames() throws SQLException { + return false; + } + + @Override + public boolean supportsDifferentTableCorrelationNames() throws SQLException { + return false; + } + + @Override + public boolean supportsExpressionsInOrderBy() throws SQLException { + return false; + } + + @Override + public boolean supportsOrderByUnrelated() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupBy() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupByUnrelated() throws SQLException { + return false; + } + + @Override + public boolean supportsGroupByBeyondSelect() throws SQLException { + return false; + } + + @Override + public boolean supportsLikeEscapeClause() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleResultSets() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsNonNullableColumns() throws SQLException { + return false; + } + + @Override + public boolean supportsMinimumSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsCoreSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsExtendedSQLGrammar() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92EntryLevelSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92IntermediateSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsANSI92FullSQL() throws SQLException { + return false; + } + + @Override + public boolean supportsIntegrityEnhancementFacility() throws SQLException { + return false; + } + + @Override + public boolean supportsOuterJoins() throws SQLException { + return false; + } + + @Override + public boolean supportsFullOuterJoins() throws SQLException { + return false; + } + + @Override + public boolean supportsLimitedOuterJoins() throws SQLException { + return false; + } + + @Override + public String getSchemaTerm() throws SQLException { + return null; + } + + @Override + public String getProcedureTerm() throws SQLException { + return null; + } + + @Override + public String getCatalogTerm() throws SQLException { + return null; + } + + @Override + public boolean isCatalogAtStart() throws SQLException { + return false; + } + + @Override + public String getCatalogSeparator() throws SQLException { + return null; + } + + @Override + public boolean supportsSchemasInDataManipulation() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInProcedureCalls() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInTableDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInIndexDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsSchemasInPrivilegeDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInDataManipulation() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInProcedureCalls() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInTableDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInIndexDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsCatalogsInPrivilegeDefinitions() throws SQLException { + return false; + } + + @Override + public boolean supportsPositionedDelete() throws SQLException { + return false; + } + + @Override + public boolean supportsPositionedUpdate() throws SQLException { + return false; + } + + @Override + public boolean supportsSelectForUpdate() throws SQLException { + return false; + } + + @Override + public boolean supportsStoredProcedures() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInComparisons() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInExists() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInIns() throws SQLException { + return false; + } + + @Override + public boolean supportsSubqueriesInQuantifieds() throws SQLException { + return false; + } + + @Override + public boolean supportsCorrelatedSubqueries() throws SQLException { + return false; + } + + @Override + public boolean supportsUnion() throws SQLException { + return false; + } + + @Override + public boolean supportsUnionAll() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenCursorsAcrossCommit() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenCursorsAcrossRollback() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenStatementsAcrossCommit() throws SQLException { + return false; + } + + @Override + public boolean supportsOpenStatementsAcrossRollback() throws SQLException { + return false; + } + + @Override + public int getMaxBinaryLiteralLength() throws SQLException { + return 0; + } + + @Override + public int getMaxCharLiteralLength() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInGroupBy() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInIndex() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInOrderBy() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInSelect() throws SQLException { + return 0; + } + + @Override + public int getMaxColumnsInTable() throws SQLException { + return 0; + } + + @Override + public int getMaxConnections() throws SQLException { + return 0; + } + + @Override + public int getMaxCursorNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxIndexLength() throws SQLException { + return 0; + } + + @Override + public int getMaxSchemaNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxProcedureNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxCatalogNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxRowSize() throws SQLException { + return 0; + } + + @Override + public boolean doesMaxRowSizeIncludeBlobs() throws SQLException { + return false; + } + + @Override + public int getMaxStatementLength() throws SQLException { + return 0; + } + + @Override + public int getMaxStatements() throws SQLException { + return 0; + } + + @Override + public int getMaxTableNameLength() throws SQLException { + return 0; + } + + @Override + public int getMaxTablesInSelect() throws SQLException { + return 0; + } + + @Override + public int getMaxUserNameLength() throws SQLException { + return 0; + } + + @Override + public int getDefaultTransactionIsolation() throws SQLException { + return 0; + } + + @Override + public boolean supportsTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsTransactionIsolationLevel(int level) throws SQLException { + return false; + } + + @Override + public boolean supportsDataDefinitionAndDataManipulationTransactions() throws SQLException { + return false; + } + + @Override + public boolean supportsDataManipulationTransactionsOnly() throws SQLException { + return false; + } + + @Override + public boolean dataDefinitionCausesTransactionCommit() throws SQLException { + return false; + } + + @Override + public boolean dataDefinitionIgnoredInTransactions() throws SQLException { + return false; + } + + @Override + public ResultSet getProcedures(String catalog, String schemaPattern, String procedureNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getProcedureColumns(String catalog, String schemaPattern, String procedureNamePattern, + String columnNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getTables(String catalog, String schemaPattern, String tableNamePattern, String[] types) + throws SQLException { + return null; + } + + @Override + public ResultSet getSchemas() throws SQLException { + return null; + } + + @Override + public ResultSet getCatalogs() throws SQLException { + return null; + } + + @Override + public ResultSet getTableTypes() throws SQLException { + return null; + } + + @Override + public ResultSet getColumns(String catalog, String schemaPattern, String tableNamePattern, + String columnNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getColumnPrivileges(String catalog, String schema, String table, String columnNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getTablePrivileges(String catalog, String schemaPattern, String tableNamePattern) + throws SQLException { + return null; + } + + @Override + public ResultSet getBestRowIdentifier(String catalog, String schema, String table, int scope, boolean nullable) + throws SQLException { + return null; + } + + @Override + public ResultSet getVersionColumns(String catalog, String schema, String table) throws SQLException { + return null; + } + + @Override + public ResultSet getPrimaryKeys(String catalog, String schema, String table) throws SQLException { + return null; + } + + @Override + public ResultSet getImportedKeys(String catalog, String schema, String table) throws SQLException { + return null; + } + + @Override + public ResultSet getExportedKeys(String catalog, String schema, String table) throws SQLException { + return null; + } + + @Override + public ResultSet getCrossReference(String parentCatalog, String parentSchema, String parentTable, + String foreignCatalog, String foreignSchema, String foreignTable) + throws SQLException { + return null; + } + + @Override + public ResultSet getTypeInfo() throws SQLException { + return null; + } + + @Override + public ResultSet getIndexInfo(String catalog, String schema, String table, boolean unique, boolean approximate) + throws SQLException { + return null; + } + + @Override + public boolean supportsResultSetType(int type) throws SQLException { + return false; + } + + @Override + public boolean supportsResultSetConcurrency(int type, int concurrency) throws SQLException { + return false; + } + + @Override + public boolean ownUpdatesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean ownDeletesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean ownInsertsAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersUpdatesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersDeletesAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean othersInsertsAreVisible(int type) throws SQLException { + return false; + } + + @Override + public boolean updatesAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean deletesAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean insertsAreDetected(int type) throws SQLException { + return false; + } + + @Override + public boolean supportsBatchUpdates() throws SQLException { + return false; + } + + @Override + public ResultSet getUDTs(String catalog, String schemaPattern, String typeNamePattern, int[] types) + throws SQLException { + return null; + } + + @Override + public Connection getConnection() throws SQLException { + return null; + } + + @Override + public boolean supportsSavepoints() throws SQLException { + return false; + } + + @Override + public boolean supportsNamedParameters() throws SQLException { + return false; + } + + @Override + public boolean supportsMultipleOpenResults() throws SQLException { + return false; + } + + @Override + public boolean supportsGetGeneratedKeys() throws SQLException { + return false; + } + + @Override + public ResultSet getSuperTypes(String catalog, String schemaPattern, String typeNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getSuperTables(String catalog, String schemaPattern, String tableNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getAttributes(String catalog, String schemaPattern, String typeNamePattern, + String attributeNamePattern) throws SQLException { + return null; + } + + @Override + public boolean supportsResultSetHoldability(int holdability) throws SQLException { + return false; + } + + @Override + public int getResultSetHoldability() throws SQLException { + return 0; + } + + @Override + public int getDatabaseMajorVersion() throws SQLException { + return 0; + } + + @Override + public int getDatabaseMinorVersion() throws SQLException { + return 0; + } + + @Override + public int getJDBCMajorVersion() throws SQLException { + return 0; + } + + @Override + public int getJDBCMinorVersion() throws SQLException { + return 0; + } + + @Override + public int getSQLStateType() throws SQLException { + return 0; + } + + @Override + public boolean locatorsUpdateCopy() throws SQLException { + return false; + } + + @Override + public boolean supportsStatementPooling() throws SQLException { + return false; + } + + @Override + public RowIdLifetime getRowIdLifetime() throws SQLException { + return null; + } + + @Override + public ResultSet getSchemas(String catalog, String schemaPattern) throws SQLException { + return null; + } + + @Override + public boolean supportsStoredFunctionsUsingCallSyntax() throws SQLException { + return false; + } + + @Override + public boolean autoCommitFailureClosesAllResultSets() throws SQLException { + return false; + } + + @Override + public ResultSet getClientInfoProperties() throws SQLException { + return null; + } + + @Override + public ResultSet getFunctions(String catalog, String schemaPattern, String functionNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getFunctionColumns(String catalog, String schemaPattern, String functionNamePattern, + String columnNamePattern) throws SQLException { + return null; + } + + @Override + public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern, + String columnNamePattern) throws SQLException { + return null; + } + + @Override + public boolean generatedKeyAlwaysReturned() throws SQLException { + return false; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockResultSet.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockResultSet.java new file mode 100644 index 00000000000..0a4208f6340 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockResultSet.java @@ -0,0 +1,1113 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.ResultSet; +import java.sql.SQLWarning; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.Clob; +import java.sql.Blob; +import java.sql.NClob; +import java.sql.SQLXML; +import java.sql.Ref; +import java.sql.Array; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.Statement; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; +import java.util.Map; +import java.util.concurrent.atomic.AtomicInteger; + +public class MockResultSet implements ResultSet { + private final List stringList = new ArrayList<>(); + private final List integerList = new ArrayList<>(); + private final List doubleList = new ArrayList<>(); + private final List booleanList = new ArrayList<>(); + private final List timestamps = new ArrayList<>(); + + private final AtomicInteger stringCounter = new AtomicInteger(0); + private final AtomicInteger integerCounter = new AtomicInteger(0); + private final AtomicInteger doubleCounter = new AtomicInteger(0); + private final AtomicInteger booleanCounter = new AtomicInteger(0); + private final AtomicInteger timestampCounter = new AtomicInteger(0); + + private boolean iterated = false; + private boolean hasData = false; + + @Override + public boolean next() throws SQLException { + if (!this.iterated && this.hasData) { + this.iterated = true; + return true; + } else { + return false; + } + } + + @Override + public void close() throws SQLException { + + } + + @Override + public boolean wasNull() throws SQLException { + return false; + } + + @Override + public String getString(int columnIndex) throws SQLException { + Object item = getItem(this.stringList, this.stringCounter); + if (item != null) { + return (String) item; + } else { + return ""; + } + } + + private Object getItem(List list, AtomicInteger counter) { + if (!list.isEmpty()) { + return list.get(counter.getAndIncrement()); + } + return null; + } + + @Override + public boolean getBoolean(int columnIndex) throws SQLException { + Object item = getItem(this.booleanList, this.booleanCounter); + if (item != null) { + return (Boolean) item; + } else { + return false; + } + } + + @Override + public byte getByte(int columnIndex) throws SQLException { + return 0; + } + + @Override + public short getShort(int columnIndex) throws SQLException { + return 0; + } + + @Override + public int getInt(int columnIndex) throws SQLException { + Object item = getItem(this.integerList, this.integerCounter); + if (item != null) { + return (Integer) item; + } else { + return 0; + } + } + + @Override + public long getLong(int columnIndex) throws SQLException { + return 0; + } + + @Override + public float getFloat(int columnIndex) throws SQLException { + return 0; + } + + @Override + public double getDouble(int columnIndex) throws SQLException { + Object item = getItem(this.doubleList, this.doubleCounter); + if (item != null) { + return (Double) item; + } else { + return 0.0; + } + } + + @Override + public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(int columnIndex) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(int columnIndex) throws SQLException { + return null; + } + + @Override + public Time getTime(int columnIndex) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int columnIndex) throws SQLException { + Object item = getItem(this.timestamps, this.timestampCounter); + if (item != null) { + return (Timestamp) item; + } else { + return new Timestamp(System.currentTimeMillis()); + } + } + + @Override + public InputStream getAsciiStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public String getString(String columnLabel) throws SQLException { + Object item = getItem(this.stringList, this.stringCounter); + if (item != null) { + return (String) item; + } else { + return ""; + } + } + + @Override + public boolean getBoolean(String columnLabel) throws SQLException { + Object item = getItem(this.booleanList, this.booleanCounter); + if (item != null) { + return (Boolean) item; + } else { + return false; + } + } + + @Override + public byte getByte(String columnLabel) throws SQLException { + return 0; + } + + @Override + public short getShort(String columnLabel) throws SQLException { + return 0; + } + + @Override + public int getInt(String columnLabel) throws SQLException { + Object item = getItem(this.integerList, this.integerCounter); + if (item != null) { + return (Integer) item; + } else { + return 0; + } + } + + @Override + public long getLong(String columnLabel) throws SQLException { + return 0; + } + + @Override + public float getFloat(String columnLabel) throws SQLException { + return 0; + } + + @Override + public double getDouble(String columnLabel) throws SQLException { + Object item = getItem(this.doubleList, this.doubleCounter); + if (item != null) { + return (Double) item; + } else { + return 0.0; + } + } + + @Override + public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLException { + return null; + } + + @Override + public byte[] getBytes(String columnLabel) throws SQLException { + return new byte[0]; + } + + @Override + public Date getDate(String columnLabel) throws SQLException { + return null; + } + + @Override + public Time getTime(String columnLabel) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(String columnLabel) throws SQLException { + Object item = getItem(this.timestamps, this.timestampCounter); + if (item != null) { + return (Timestamp) item; + } else { + return new Timestamp(System.currentTimeMillis()); + } + } + + @Override + public InputStream getAsciiStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getUnicodeStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public InputStream getBinaryStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public String getCursorName() throws SQLException { + return null; + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public Object getObject(int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(String columnLabel) throws SQLException { + return null; + } + + @Override + public int findColumn(String columnLabel) throws SQLException { + return 0; + } + + @Override + public Reader getCharacterStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getCharacterStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(int columnIndex) throws SQLException { + return null; + } + + @Override + public BigDecimal getBigDecimal(String columnLabel) throws SQLException { + return null; + } + + @Override + public boolean isBeforeFirst() throws SQLException { + return false; + } + + @Override + public boolean isAfterLast() throws SQLException { + return false; + } + + @Override + public boolean isFirst() throws SQLException { + return false; + } + + @Override + public boolean isLast() throws SQLException { + return false; + } + + @Override + public void beforeFirst() throws SQLException { + + } + + @Override + public void afterLast() throws SQLException { + + } + + @Override + public boolean first() throws SQLException { + return false; + } + + @Override + public boolean last() throws SQLException { + return false; + } + + @Override + public int getRow() throws SQLException { + return 0; + } + + @Override + public boolean absolute(int row) throws SQLException { + return false; + } + + @Override + public boolean relative(int rows) throws SQLException { + return false; + } + + @Override + public boolean previous() throws SQLException { + return false; + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + + } + + @Override + public int getType() throws SQLException { + return 0; + } + + @Override + public int getConcurrency() throws SQLException { + return 0; + } + + @Override + public boolean rowUpdated() throws SQLException { + return false; + } + + @Override + public boolean rowInserted() throws SQLException { + return false; + } + + @Override + public boolean rowDeleted() throws SQLException { + return false; + } + + @Override + public void updateNull(int columnIndex) throws SQLException { + + } + + @Override + public void updateBoolean(int columnIndex, boolean x) throws SQLException { + + } + + @Override + public void updateByte(int columnIndex, byte x) throws SQLException { + + } + + @Override + public void updateShort(int columnIndex, short x) throws SQLException { + + } + + @Override + public void updateInt(int columnIndex, int x) throws SQLException { + + } + + @Override + public void updateLong(int columnIndex, long x) throws SQLException { + + } + + @Override + public void updateFloat(int columnIndex, float x) throws SQLException { + + } + + @Override + public void updateDouble(int columnIndex, double x) throws SQLException { + + } + + @Override + public void updateBigDecimal(int columnIndex, BigDecimal x) throws SQLException { + + } + + @Override + public void updateString(int columnIndex, String x) throws SQLException { + + } + + @Override + public void updateBytes(int columnIndex, byte[] x) throws SQLException { + + } + + @Override + public void updateDate(int columnIndex, Date x) throws SQLException { + + } + + @Override + public void updateTime(int columnIndex, Time x) throws SQLException { + + } + + @Override + public void updateTimestamp(int columnIndex, Timestamp x) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, int length) throws SQLException { + + } + + @Override + public void updateObject(int columnIndex, Object x, int scaleOrLength) throws SQLException { + + } + + @Override + public void updateObject(int columnIndex, Object x) throws SQLException { + + } + + @Override + public void updateNull(String columnLabel) throws SQLException { + + } + + @Override + public void updateBoolean(String columnLabel, boolean x) throws SQLException { + + } + + @Override + public void updateByte(String columnLabel, byte x) throws SQLException { + + } + + @Override + public void updateShort(String columnLabel, short x) throws SQLException { + + } + + @Override + public void updateInt(String columnLabel, int x) throws SQLException { + + } + + @Override + public void updateLong(String columnLabel, long x) throws SQLException { + + } + + @Override + public void updateFloat(String columnLabel, float x) throws SQLException { + + } + + @Override + public void updateDouble(String columnLabel, double x) throws SQLException { + + } + + @Override + public void updateBigDecimal(String columnLabel, BigDecimal x) throws SQLException { + + } + + @Override + public void updateString(String columnLabel, String x) throws SQLException { + + } + + @Override + public void updateBytes(String columnLabel, byte[] x) throws SQLException { + + } + + @Override + public void updateDate(String columnLabel, Date x) throws SQLException { + + } + + @Override + public void updateTime(String columnLabel, Time x) throws SQLException { + + } + + @Override + public void updateTimestamp(String columnLabel, Timestamp x) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, int length) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, int length) throws SQLException { + + } + + @Override + public void updateObject(String columnLabel, Object x, int scaleOrLength) throws SQLException { + + } + + @Override + public void updateObject(String columnLabel, Object x) throws SQLException { + + } + + @Override + public void insertRow() throws SQLException { + + } + + @Override + public void updateRow() throws SQLException { + + } + + @Override + public void deleteRow() throws SQLException { + + } + + @Override + public void refreshRow() throws SQLException { + + } + + @Override + public void cancelRowUpdates() throws SQLException { + + } + + @Override + public void moveToInsertRow() throws SQLException { + + } + + @Override + public void moveToCurrentRow() throws SQLException { + + } + + @Override + public Statement getStatement() throws SQLException { + return null; + } + + @Override + public Object getObject(int columnIndex, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(int columnIndex) throws SQLException { + return null; + } + + @Override + public Blob getBlob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Clob getClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public Array getArray(int columnIndex) throws SQLException { + return null; + } + + @Override + public Object getObject(String columnLabel, Map> map) throws SQLException { + return null; + } + + @Override + public Ref getRef(String columnLabel) throws SQLException { + return null; + } + + @Override + public Blob getBlob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Clob getClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public Array getArray(String columnLabel) throws SQLException { + return null; + } + + @Override + public Date getDate(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Date getDate(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(int columnIndex, Calendar cal) throws SQLException { + return null; + } + + @Override + public Time getTime(String columnLabel, Calendar cal) throws SQLException { + return null; + } + + @Override + public Timestamp getTimestamp(int columnIndex, Calendar cal) throws SQLException { + Object item = getItem(this.timestamps, this.timestampCounter); + if (item != null) { + return (Timestamp) item; + } else { + return new Timestamp(System.currentTimeMillis()); + } + } + + @Override + public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLException { + Object item = getItem(this.timestamps, this.timestampCounter); + if (item != null) { + return (Timestamp) item; + } else { + return new Timestamp(System.currentTimeMillis()); + } + } + + @Override + public URL getURL(int columnIndex) throws SQLException { + return null; + } + + @Override + public URL getURL(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRef(int columnIndex, Ref x) throws SQLException { + + } + + @Override + public void updateRef(String columnLabel, Ref x) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, Blob x) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, Blob x) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Clob x) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Clob x) throws SQLException { + + } + + @Override + public void updateArray(int columnIndex, Array x) throws SQLException { + + } + + @Override + public void updateArray(String columnLabel, Array x) throws SQLException { + + } + + @Override + public RowId getRowId(int columnIndex) throws SQLException { + return null; + } + + @Override + public RowId getRowId(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateRowId(int columnIndex, RowId x) throws SQLException { + + } + + @Override + public void updateRowId(String columnLabel, RowId x) throws SQLException { + + } + + @Override + public int getHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public void updateNString(int columnIndex, String nString) throws SQLException { + + } + + @Override + public void updateNString(String columnLabel, String nString) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, NClob nClob) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, NClob nClob) throws SQLException { + + } + + @Override + public NClob getNClob(int columnIndex) throws SQLException { + return null; + } + + @Override + public NClob getNClob(String columnLabel) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(int columnIndex) throws SQLException { + return null; + } + + @Override + public SQLXML getSQLXML(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateSQLXML(int columnIndex, SQLXML xmlObject) throws SQLException { + + } + + @Override + public void updateSQLXML(String columnLabel, SQLXML xmlObject) throws SQLException { + + } + + @Override + public String getNString(int columnIndex) throws SQLException { + return null; + } + + @Override + public String getNString(String columnLabel) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(int columnIndex) throws SQLException { + return null; + } + + @Override + public Reader getNCharacterStream(String columnLabel) throws SQLException { + return null; + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x, long length) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x, long length) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader, long length) throws SQLException { + + } + + @Override + public void updateNCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateNCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateAsciiStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(int columnIndex, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(int columnIndex, Reader x) throws SQLException { + + } + + @Override + public void updateAsciiStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateBinaryStream(String columnLabel, InputStream x) throws SQLException { + + } + + @Override + public void updateCharacterStream(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateBlob(int columnIndex, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateBlob(String columnLabel, InputStream inputStream) throws SQLException { + + } + + @Override + public void updateClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(int columnIndex, Reader reader) throws SQLException { + + } + + @Override + public void updateNClob(String columnLabel, Reader reader) throws SQLException { + + } + + @Override + public T getObject(int columnIndex, Class type) throws SQLException { + return null; + } + + @Override + public T getObject(String columnLabel, Class type) throws SQLException { + return null; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + public void addString(String string) { + this.stringList.add(string); + this.hasData = true; + } + + public void addInteger(Integer integer) { + this.integerList.add(integer); + this.hasData = true; + } + + public void addBoolean(Boolean bool) { + this.booleanList.add(bool); + this.hasData = true; + } + + public void addDouble(Double doubleVal) { + this.doubleList.add(doubleVal); + this.hasData = true; + } + + public void addTimestamp(Timestamp timestamp) { + this.timestamps.add(timestamp); + this.hasData = true; + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockStatement.java b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockStatement.java new file mode 100644 index 00000000000..44483abe1e7 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/java/io/entgra/device/mgt/subtype/mgt/mock/MockStatement.java @@ -0,0 +1,561 @@ +/* + * Copyright (c) 2023, Entgra Pvt Ltd. (http://www.wso2.org) 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.subtype.mgt.mock; + +import java.io.InputStream; +import java.io.Reader; +import java.math.BigDecimal; +import java.net.URL; +import java.sql.Connection; +import java.sql.ResultSet; +import java.sql.SQLWarning; +import java.sql.Date; +import java.sql.Time; +import java.sql.Timestamp; +import java.sql.PreparedStatement; +import java.sql.ParameterMetaData; +import java.sql.Clob; +import java.sql.Blob; +import java.sql.NClob; +import java.sql.SQLXML; +import java.sql.Ref; +import java.sql.Array; +import java.sql.ResultSetMetaData; +import java.sql.RowId; +import java.sql.SQLException; +import java.util.ArrayList; +import java.util.Calendar; +import java.util.List; + +/** + * This is the mock statement for the test cases. + */ +public class MockStatement implements PreparedStatement { + private final List resultSets = new ArrayList<>(); + private int resultSetCounter; + + @Override + public ResultSet executeQuery(String sql) throws SQLException { + return this.getMockResultSet(); + } + + private ResultSet getMockResultSet() { + if (!this.resultSets.isEmpty()) { + ResultSet resultSet = this.resultSets.get(this.resultSetCounter); + this.resultSetCounter++; + return resultSet; + } else { + return new MockResultSet(); + } + } + + @Override + public int executeUpdate(String sql) throws SQLException { + return 0; + } + + @Override + public void close() throws SQLException { + + } + + @Override + public int getMaxFieldSize() throws SQLException { + return 0; + } + + @Override + public void setMaxFieldSize(int max) throws SQLException { + + } + + @Override + public int getMaxRows() throws SQLException { + return 0; + } + + @Override + public void setMaxRows(int max) throws SQLException { + + } + + @Override + public void setEscapeProcessing(boolean enable) throws SQLException { + + } + + @Override + public int getQueryTimeout() throws SQLException { + return 0; + } + + @Override + public void setQueryTimeout(int seconds) throws SQLException { + + } + + @Override + public void cancel() throws SQLException { + + } + + @Override + public SQLWarning getWarnings() throws SQLException { + return null; + } + + @Override + public void clearWarnings() throws SQLException { + + } + + @Override + public void setCursorName(String name) throws SQLException { + + } + + @Override + public boolean execute(String sql) throws SQLException { + return false; + } + + @Override + public ResultSet getResultSet() throws SQLException { + return getMockResultSet(); + } + + @Override + public int getUpdateCount() throws SQLException { + return 0; + } + + @Override + public boolean getMoreResults() throws SQLException { + return false; + } + + @Override + public int getFetchDirection() throws SQLException { + return 0; + } + + @Override + public void setFetchDirection(int direction) throws SQLException { + + } + + @Override + public int getFetchSize() throws SQLException { + return 0; + } + + @Override + public void setFetchSize(int rows) throws SQLException { + + } + + @Override + public int getResultSetConcurrency() throws SQLException { + return 0; + } + + @Override + public int getResultSetType() throws SQLException { + return 0; + } + + @Override + public void addBatch(String sql) throws SQLException { + + } + + @Override + public void clearBatch() throws SQLException { + + } + + @Override + public int[] executeBatch() throws SQLException { + return new int[0]; + } + + @Override + public Connection getConnection() throws SQLException { + return null; + } + + @Override + public boolean getMoreResults(int current) throws SQLException { + return false; + } + + @Override + public ResultSet getGeneratedKeys() throws SQLException { + return getMockResultSet(); + } + + @Override + public int executeUpdate(String sql, int autoGeneratedKeys) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, int[] columnIndexes) throws SQLException { + return 0; + } + + @Override + public int executeUpdate(String sql, String[] columnNames) throws SQLException { + return 0; + } + + @Override + public boolean execute(String sql, int autoGeneratedKeys) throws SQLException { + return false; + } + + @Override + public boolean execute(String sql, int[] columnIndexes) throws SQLException { + return false; + } + + @Override + public boolean execute(String sql, String[] columnNames) throws SQLException { + return false; + } + + @Override + public int getResultSetHoldability() throws SQLException { + return 0; + } + + @Override + public boolean isClosed() throws SQLException { + return false; + } + + @Override + public boolean isPoolable() throws SQLException { + return false; + } + + @Override + public void setPoolable(boolean poolable) throws SQLException { + + } + + @Override + public void closeOnCompletion() throws SQLException { + + } + + @Override + public boolean isCloseOnCompletion() throws SQLException { + return false; + } + + @Override + public T unwrap(Class iface) throws SQLException { + return null; + } + + @Override + public boolean isWrapperFor(Class iface) throws SQLException { + return false; + } + + @Override + public ResultSet executeQuery() throws SQLException { + return getMockResultSet(); + } + + @Override + public int executeUpdate() throws SQLException { + return 0; + } + + @Override + public void setNull(int parameterIndex, int sqlType) throws SQLException { + + } + + @Override + public void setBoolean(int parameterIndex, boolean x) throws SQLException { + + } + + @Override + public void setByte(int parameterIndex, byte x) throws SQLException { + + } + + @Override + public void setShort(int parameterIndex, short x) throws SQLException { + + } + + @Override + public void setInt(int parameterIndex, int x) throws SQLException { + + } + + @Override + public void setLong(int parameterIndex, long x) throws SQLException { + + } + + @Override + public void setFloat(int parameterIndex, float x) throws SQLException { + + } + + @Override + public void setDouble(int parameterIndex, double x) throws SQLException { + + } + + @Override + public void setBigDecimal(int parameterIndex, BigDecimal x) throws SQLException { + + } + + @Override + public void setString(int parameterIndex, String x) throws SQLException { + + } + + @Override + public void setBytes(int parameterIndex, byte[] x) throws SQLException { + + } + + @Override + public void setDate(int parameterIndex, Date x) throws SQLException { + + } + + @Override + public void setTime(int parameterIndex, Time x) throws SQLException { + + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void setUnicodeStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, int length) throws SQLException { + + } + + @Override + public void clearParameters() throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType) throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x) throws SQLException { + + } + + @Override + public boolean execute() throws SQLException { + return false; + } + + @Override + public void addBatch() throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, int length) throws SQLException { + + } + + @Override + public void setRef(int parameterIndex, Ref x) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, Blob x) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Clob x) throws SQLException { + + } + + @Override + public void setArray(int parameterIndex, Array x) throws SQLException { + + } + + @Override + public ResultSetMetaData getMetaData() throws SQLException { + return null; + } + + @Override + public void setDate(int parameterIndex, Date x, Calendar cal) throws SQLException { + + } + + @Override + public void setTime(int parameterIndex, Time x, Calendar cal) throws SQLException { + + } + + @Override + public void setTimestamp(int parameterIndex, Timestamp x, Calendar cal) throws SQLException { + + } + + @Override + public void setNull(int parameterIndex, int sqlType, String typeName) throws SQLException { + + } + + @Override + public void setURL(int parameterIndex, URL x) throws SQLException { + + } + + @Override + public ParameterMetaData getParameterMetaData() throws SQLException { + return null; + } + + @Override + public void setRowId(int parameterIndex, RowId x) throws SQLException { + + } + + @Override + public void setNString(int parameterIndex, String value) throws SQLException { + + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value, long length) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, NClob value) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream, long length) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setSQLXML(int parameterIndex, SQLXML xmlObject) throws SQLException { + + } + + @Override + public void setObject(int parameterIndex, Object x, int targetSqlType, int scaleOrLength) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x, long length) throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader, long length) throws SQLException { + + } + + @Override + public void setAsciiStream(int parameterIndex, InputStream x) throws SQLException { + + } + + @Override + public void setBinaryStream(int parameterIndex, InputStream x) throws SQLException { + + } + + @Override + public void setCharacterStream(int parameterIndex, Reader reader) throws SQLException { + + } + + @Override + public void setNCharacterStream(int parameterIndex, Reader value) throws SQLException { + + } + + @Override + public void setClob(int parameterIndex, Reader reader) throws SQLException { + + } + + @Override + public void setBlob(int parameterIndex, InputStream inputStream) throws SQLException { + + } + + @Override + public void setNClob(int parameterIndex, Reader reader) throws SQLException { + + } + + public void addResultSet(MockResultSet resultSet) { + this.resultSets.add(resultSet); + } +} diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql new file mode 100644 index 00000000000..9737fd3df00 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/dm-db-h2.sql @@ -0,0 +1,789 @@ +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE ( + ID INT AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) NULL DEFAULT NULL, + DEVICE_TYPE_META VARCHAR(20000) NULL DEFAULT NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, + PROVIDER_TENANT_ID INTEGER DEFAULT 0, + SHARED_WITH_ALL_TENANTS BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_CERTIFICATE ( + ID INTEGER auto_increment NOT NULL, + SERIAL_NUMBER VARCHAR(500) DEFAULT NULL, + CERTIFICATE BLOB DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + USERNAME VARCHAR(500) DEFAULT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_GROUP ( + ID INTEGER AUTO_INCREMENT NOT NULL, + GROUP_NAME VARCHAR(100) DEFAULT NULL, + STATUS VARCHAR(50) DEFAULT NULL, + DESCRIPTION TEXT DEFAULT NULL, + OWNER VARCHAR(255) DEFAULT NULL, + PARENT_PATH VARCHAR(255) DEFAULT '/', + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_ROLE_GROUP_MAP ( + ID INTEGER AUTO_INCREMENT NOT NULL, + GROUP_ID INTEGER DEFAULT NULL, + ROLE VARCHAR(45) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_DM_ROLE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID) + REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE ( + ID INTEGER auto_increment NOT NULL, + DESCRIPTION TEXT DEFAULT NULL, + NAME VARCHAR(100) DEFAULT NULL, + DEVICE_TYPE_ID INT(11) DEFAULT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_DM_DEVICE_DM_DEVICE_TYPE2 FOREIGN KEY (DEVICE_TYPE_ID) + REFERENCES DM_DEVICE_TYPE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uk_DM_DEVICE UNIQUE (NAME, DEVICE_TYPE_ID, DEVICE_IDENTIFICATION, TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_PROPERTIES ( + DEVICE_TYPE_NAME VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DEVICE_TYPE_NAME, DEVICE_IDENTIFICATION, PROPERTY_NAME, TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS GROUP_PROPERTIES ( + GROUP_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (GROUP_ID, PROPERTY_NAME, TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_MAP ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER DEFAULT NULL, + GROUP_ID INTEGER DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_DEVICE2 FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT fk_DM_DEVICE_GROUP_MAP_DM_GROUP2 FOREIGN KEY (GROUP_ID) + REFERENCES DM_GROUP (ID) ON DELETE CASCADE ON UPDATE CASCADE +); + +CREATE TABLE IF NOT EXISTS DM_OPERATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + TYPE VARCHAR(50) NOT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + OPERATION_CODE VARCHAR(1000) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + OPERATION_DETAILS BLOB DEFAULT NULL, + ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_ENROLMENT ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER NOT NULL, + OWNER VARCHAR(255) NOT NULL, + OWNERSHIP VARCHAR(45) DEFAULT NULL, + STATUS VARCHAR(50) NULL, + IS_TRANSFERRED BOOLEAN NOT NULL DEFAULT FALSE, + DATE_OF_ENROLMENT TIMESTAMP DEFAULT NULL, + DATE_OF_LAST_UPDATE TIMESTAMP DEFAULT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_enrolment FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT uk_dm_device_enrolment UNIQUE (DEVICE_ID, OWNER, OWNERSHIP, TENANT_ID) +); + +CREATE TABLE IF NOT EXISTS DM_ENROLMENT_OP_MAPPING ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + STATUS VARCHAR(50) NULL, + PUSH_NOTIFICATION_STATUS VARCHAR(50) NULL, + CREATED_TIMESTAMP INT NOT NULL, + UPDATED_TIMESTAMP INT NOT NULL, + OPERATION_CODE VARCHAR(50) NOT NULL, + INITIATED_BY VARCHAR(100) NULL, + TYPE VARCHAR(20) NOT NULL, + DEVICE_ID INTEGER DEFAULT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, + DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_operation_mapping_device FOREIGN KEY (ENROLMENT_ID) REFERENCES + DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_device_operation_mapping_operation FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_OPERATION_RESPONSE ( + ID INTEGER AUTO_INCREMENT NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NOT NULL, + EN_OP_MAP_ID INTEGER NOT NULL, + OPERATION_RESPONSE VARCHAR(1024) DEFAULT NULL , + IS_LARGE_RESPONSE BOOLEAN NOT NULL DEFAULT FALSE, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device_operation_response_enrollment FOREIGN KEY (ENROLMENT_ID) REFERENCES + DM_ENROLMENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_device_operation_response_operation FOREIGN KEY (OPERATION_ID) REFERENCES + DM_OPERATION (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_en_op_map_response FOREIGN KEY (EN_OP_MAP_ID) REFERENCES + DM_ENROLMENT_OP_MAPPING (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +CREATE TABLE DM_DEVICE_OPERATION_RESPONSE_LARGE ( + ID INTEGER NOT NULL, + OPERATION_RESPONSE LONGBLOB DEFAULT NULL, + OPERATION_ID INTEGER NOT NULL, + EN_OP_MAP_ID INTEGER NOT NULL, + RECEIVED_TIMESTAMP TIMESTAMP NULL, + DEVICE_IDENTIFICATION VARCHAR(300) DEFAULT NULL, + CONSTRAINT fk_dm_device_operation_response_large_mapping FOREIGN KEY (ID) + REFERENCES DM_DEVICE_OPERATION_RESPONSE (ID) + ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_en_op_map_response_large FOREIGN KEY (EN_OP_MAP_ID) + REFERENCES DM_ENROLMENT_OP_MAPPING (ID) + ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- POLICY RELATED TABLES -- + +CREATE TABLE IF NOT EXISTS DM_PROFILE ( + ID INT NOT NULL AUTO_INCREMENT , + PROFILE_NAME VARCHAR(45) NOT NULL , + TENANT_ID INT NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , + CREATED_TIME DATETIME NOT NULL , + UPDATED_TIME DATETIME NOT NULL , + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + NAME VARCHAR(45) DEFAULT NULL , + DESCRIPTION VARCHAR(1000) NULL, + PAYLOAD_VERSION VARCHAR (45) NULL, + TENANT_ID INT(11) NOT NULL , + PROFILE_ID INT(11) NOT NULL , + OWNERSHIP_TYPE VARCHAR(45) NULL, + COMPLIANCE VARCHAR(100) NULL, + PRIORITY INT NOT NULL, + ACTIVE INT(2) NOT NULL, + UPDATED INT(1) NULL, + POLICY_TYPE VARCHAR(45) NULL, + PRIMARY KEY (ID) , + CONSTRAINT FK_DM_PROFILE_DM_POLICY + FOREIGN KEY (PROFILE_ID ) + REFERENCES DM_PROFILE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + DEVICE_ID INT(11) NOT NULL , + ENROLMENT_ID INT(11) NOT NULL, + DEVICE BLOB NOT NULL, + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_POLICY_DEVICE_POLICY + FOREIGN KEY (POLICY_ID ) + REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DEVICE_DEVICE_POLICY + FOREIGN KEY (DEVICE_ID ) + REFERENCES DM_DEVICE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_POLICY ( + ID INT(11) NOT NULL , + DEVICE_TYPE VARCHAR(300) NOT NULL , + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_DEVICE_TYPE_POLICY + FOREIGN KEY (POLICY_ID ) + REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_PROFILE_FEATURES ( + ID INT(11) NOT NULL AUTO_INCREMENT, + PROFILE_ID INT(11) NOT NULL, + FEATURE_CODE VARCHAR(100) NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL, + TENANT_ID INT(11) NOT NULL , + CONTENT BLOB NULL DEFAULT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_PROFILE_DM_POLICY_FEATURES + FOREIGN KEY (PROFILE_ID) + REFERENCES DM_PROFILE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_CORRECTIVE_ACTION ( + ID INT(11) NOT NULL AUTO_INCREMENT, + ACTION_TYPE VARCHAR(45) NOT NULL, + CORRECTIVE_POLICY_ID INT(11) DEFAULT NULL, + POLICY_ID INT(11) NOT NULL, + FEATURE_ID INT(11) DEFAULT NULL, + IS_REACTIVE BOOLEAN NOT NULL DEFAULT FALSE, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_POLICY_DM_POLICY_CORRECTIVE_ACTION + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_ROLE_POLICY ( + ID INT(11) NOT NULL AUTO_INCREMENT , + ROLE_NAME VARCHAR(45) NOT NULL , + POLICY_ID INT(11) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_ROLE_POLICY_POLICY + FOREIGN KEY (POLICY_ID ) + REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_USER_POLICY ( + ID INT NOT NULL AUTO_INCREMENT , + POLICY_ID INT NOT NULL , + USERNAME VARCHAR(45) NOT NULL , + PRIMARY KEY (ID) , + CONSTRAINT DM_POLICY_USER_POLICY + FOREIGN KEY (POLICY_ID ) + REFERENCES DM_POLICY (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_POLICY_APPLIED ( + ID INT NOT NULL AUTO_INCREMENT , + DEVICE_ID INT NOT NULL , + ENROLMENT_ID INT(11) NOT NULL, + POLICY_ID INT NOT NULL , + POLICY_CONTENT BLOB NULL , + TENANT_ID INT NOT NULL, + APPLIED TINYINT(1) NULL , + CREATED_TIME TIMESTAMP NULL , + UPDATED_TIME TIMESTAMP NULL , + APPLIED_TIME TIMESTAMP NULL , + PRIMARY KEY (ID) , + CONSTRAINT FK_DM_POLICY_DEVCIE_APPLIED + FOREIGN KEY (DEVICE_ID ) + REFERENCES DM_DEVICE (ID ) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_CRITERIA ( + ID INT NOT NULL AUTO_INCREMENT, + TENANT_ID INT NOT NULL, + NAME VARCHAR(50) NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA ( + ID INT NOT NULL AUTO_INCREMENT, + CRITERIA_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_CRITERIA_POLICY_CRITERIA + FOREIGN KEY (CRITERIA_ID) + REFERENCES DM_CRITERIA (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_POLICY_POLICY_CRITERIA + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_CRITERIA_PROPERTIES ( + ID INT NOT NULL AUTO_INCREMENT, + POLICY_CRITERION_ID INT NOT NULL, + PROP_KEY VARCHAR(45) NULL, + PROP_VALUE VARCHAR(100) NULL, + CONTENT BLOB NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_POLICY_CRITERIA_PROPERTIES + FOREIGN KEY (POLICY_CRITERION_ID) + REFERENCES DM_POLICY_CRITERIA (ID) + ON DELETE CASCADE + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_STATUS ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_ID INT NOT NULL, + ENROLMENT_ID INT(11) NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + STATUS INT NULL, + LAST_SUCCESS_TIME TIMESTAMP NULL, + LAST_REQUESTED_TIME TIMESTAMP NULL, + LAST_FAILED_TIME TIMESTAMP NULL, + ATTEMPTS INT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_CHANGE_MGT ( + ID INT NOT NULL AUTO_INCREMENT, + POLICY_ID INT NOT NULL, + DEVICE_TYPE VARCHAR(300) NOT NULL , + TENANT_ID INT(11) NOT NULL, + PRIMARY KEY (ID) +); + +CREATE TABLE IF NOT EXISTS DM_POLICY_COMPLIANCE_FEATURES ( + ID INT NOT NULL AUTO_INCREMENT, + COMPLIANCE_STATUS_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + FEATURE_CODE VARCHAR(100) NOT NULL, + STATUS INT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_COMPLIANCE_FEATURES_STATUS + FOREIGN KEY (COMPLIANCE_STATUS_ID) + REFERENCES DM_POLICY_COMPLIANCE_STATUS (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE TABLE IF NOT EXISTS DM_APPLICATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(150) NOT NULL, + APP_IDENTIFIER VARCHAR(150) NOT NULL, + PLATFORM VARCHAR(50) DEFAULT NULL, + CATEGORY VARCHAR(50) NULL, + VERSION VARCHAR(50) NULL, + TYPE VARCHAR(50) NULL, + LOCATION_URL VARCHAR(100) DEFAULT NULL, + IMAGE_URL VARCHAR(100) DEFAULT NULL, + APP_PROPERTIES BLOB NULL, + MEMORY_USAGE INTEGER(10) NULL, + IS_ACTIVE BOOLEAN NOT NULL DEFAULT FALSE, + DEVICE_ID INTEGER NOT NULL, + ENROLMENT_ID INTEGER NOT NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_device + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT fk_dm_enrolement + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +-- POLICY RELATED TABLES FINISHED -- + +-- NOTIFICATION TABLE -- +CREATE TABLE IF NOT EXISTS DM_NOTIFICATION ( + NOTIFICATION_ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INTEGER NOT NULL, + OPERATION_ID INTEGER NULL, + TENANT_ID INTEGER NOT NULL, + STATUS VARCHAR(10) NULL, + DESCRIPTION VARCHAR(1000) NULL, + LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL, + PRIMARY KEY (NOTIFICATION_ID), + CONSTRAINT fk_dm_device_notification FOREIGN KEY (DEVICE_ID) REFERENCES + DM_DEVICE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); +-- NOTIFICATION TABLE END -- + +CREATE TABLE IF NOT EXISTS DM_DEVICE_INFO ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INT NULL, + ENROLMENT_ID INT NOT NULL, + KEY_FIELD VARCHAR(45) NULL, + VALUE_FIELD VARCHAR(1000) NULL, + PRIMARY KEY (ID), + CONSTRAINT DM_DEVICE_INFO_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT DM_DEVICE_INFO_DEVICE_ENROLLMENT + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE INDEX IDX_DM_DEVICE_INFO_DID_EID_KFIELD ON DM_DEVICE_INFO(DEVICE_ID, ENROLMENT_ID, KEY_FIELD); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_LOCATION ( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INT NULL, + ENROLMENT_ID INT NOT NULL, + LATITUDE DOUBLE NULL, + LONGITUDE DOUBLE NULL, + STREET1 VARCHAR(255) NULL, + STREET2 VARCHAR(45) NULL, + CITY VARCHAR(45) NULL, + ZIP VARCHAR(10) NULL, + STATE VARCHAR(45) NULL, + COUNTRY VARCHAR(45) NULL, + GEO_HASH VARCHAR(45) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + ALTITUDE DOUBLE NULL, + SPEED FLOAT NULL, + BEARING FLOAT NULL, + DISTANCE DOUBLE NULL, + PRIMARY KEY (ID), + CONSTRAINT DM_DEVICE_LOCATION_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT DM_DEVICE_LOCATION_DM_ENROLLMENT + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); +CREATE INDEX DM_DEVICE_LOCATION_GEO_hashx ON DM_DEVICE_LOCATION(GEO_HASH ASC); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_DETAIL ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_ID INT NOT NULL, + ENROLMENT_ID INT NOT NULL, + DEVICE_MODEL VARCHAR(45) NULL, + VENDOR VARCHAR(45) NULL, + OS_VERSION VARCHAR(45) NULL, + OS_BUILD_DATE VARCHAR(100) NULL, + BATTERY_LEVEL DECIMAL(4) NULL, + INTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + INTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_TOTAL_MEMORY DECIMAL(30,3) NULL, + EXTERNAL_AVAILABLE_MEMORY DECIMAL(30,3) NULL, + CONNECTION_TYPE VARCHAR(50) NULL, + SSID VARCHAR(45) NULL, + CPU_USAGE DECIMAL(5) NULL, + TOTAL_RAM_MEMORY DECIMAL(30,3) NULL, + AVAILABLE_RAM_MEMORY DECIMAL(30,3) NULL, + PLUGGED_IN INT(1) NULL, + UPDATE_TIMESTAMP BIGINT(15) NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_DETAILS_DEVICE + FOREIGN KEY (DEVICE_ID) + REFERENCES DM_DEVICE (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION, + CONSTRAINT FK_DM_ENROLMENT_DEVICE_DETAILS + FOREIGN KEY (ENROLMENT_ID) + REFERENCES DM_ENROLMENT (ID) + ON DELETE NO ACTION + ON UPDATE NO ACTION +); + +CREATE INDEX IDX_DM_DEVICE_DETAIL_DID_EID ON DM_DEVICE_DETAIL(DEVICE_ID, ENROLMENT_ID); + +CREATE TABLE IF NOT EXISTS DM_DEVICE_HISTORY_LAST_SEVEN_DAYS +( + ID INTEGER AUTO_INCREMENT NOT NULL, + DEVICE_ID INT NOT NULL, + DEVICE_ID_NAME VARCHAR(255) NOT NULL, + TENANT_ID INT NOT NULL, + DEVICE_TYPE_NAME VARCHAR(45) NOT NULL, + LATITUDE DOUBLE NULL, + LONGITUDE DOUBLE NULL, + SPEED FLOAT NULL, + HEADING FLOAT NULL, + TIMESTAMP BIGINT(15) NOT NULL, + GEO_HASH VARCHAR(45) NULL, + DEVICE_OWNER VARCHAR(45) NULL, + DEVICE_ALTITUDE DOUBLE NULL, + DISTANCE DOUBLE NULL, + PRIMARY KEY (ID) +); + +-- POLICY AND DEVICE GROUP MAPPING -- +CREATE TABLE IF NOT EXISTS DM_DEVICE_GROUP_POLICY ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_GROUP_ID INT NOT NULL, + POLICY_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT FK_DM_DEVICE_GROUP_POLICY + FOREIGN KEY (DEVICE_GROUP_ID) + REFERENCES DM_GROUP (ID) + ON DELETE CASCADE + ON UPDATE CASCADE , + CONSTRAINT FK_DM_DEVICE_GROUP_DM_POLICY + FOREIGN KEY (POLICY_ID) + REFERENCES DM_POLICY (ID) + ON DELETE CASCADE + ON UPDATE CASCADE +); +-- END OF POLICY AND DEVICE GROUP MAPPING -- + + +CREATE TABLE IF NOT EXISTS DM_DEVICE_TYPE_PLATFORM ( + ID INT NOT NULL AUTO_INCREMENT, + DEVICE_TYPE_ID INT NULL DEFAULT 0, + VERSION_NAME VARCHAR(100) NULL, + VERSION_STATUS VARCHAR(100) NULL DEFAULT 'ACTIVE', + PRIMARY KEY (ID), + CONSTRAINT DM_DEVICE_TYPE_DM_DEVICE_TYPE_PLATFORM_MAPPING + FOREIGN KEY (DEVICE_TYPE_ID) + REFERENCES DM_DEVICE_TYPE (ID) ON DELETE CASCADE ON UPDATE CASCADE, + CONSTRAINT device_type_version_uk + UNIQUE ( + DEVICE_TYPE_ID, + VERSION_NAME + ) +); + +-- METADATA TABLE -- +CREATE TABLE IF NOT EXISTS DM_METADATA ( + METADATA_ID INT AUTO_INCREMENT NOT NULL, + DATA_TYPE VARCHAR(16) NOT NULL, + METADATA_KEY VARCHAR(128) NOT NULL, + METADATA_VALUE VARCHAR(8000) NOT NULL, + TENANT_ID INTEGER NOT NULL, + PRIMARY KEY (METADATA_ID), + CONSTRAINT METADATA_KEY_TENANT_ID UNIQUE (METADATA_KEY, TENANT_ID) +); +-- END OF METADATA TABLE -- + +-- DM_OTP_DATA TABLE -- +CREATE TABLE IF NOT EXISTS DM_OTP_DATA ( + ID INT AUTO_INCREMENT NOT NULL, + OTP_TOKEN VARCHAR(100) NOT NULL, + TENANT_ID INT NOT NULL, + USERNAME VARCHAR(500) DEFAULT NOT NULL, + EMAIL VARCHAR(100) NOT NULL, + EMAIL_TYPE VARCHAR(20) NOT NULL, + META_INFO VARCHAR(20000) NOT NULL, + CREATED_AT TIMESTAMP NOT NULL, + EXPIRY_TIME INT NOT NULL DEFAULT 3600, + IS_EXPIRED BOOLEAN DEFAULT false, + PRIMARY KEY (ID), + CONSTRAINT email_type_uk UNIQUE (EMAIL, EMAIL_TYPE) +); +-- END OF DM_OTP_DATA TABLE -- + +-- DASHBOARD RELATED VIEWS -- +CREATE VIEW POLICY_COMPLIANCE_INFO AS +SELECT +DEVICE_INFO.DEVICE_ID, +DEVICE_INFO.DEVICE_IDENTIFICATION, +DEVICE_INFO.PLATFORM, +DEVICE_INFO.OWNERSHIP, +DEVICE_INFO.CONNECTIVITY_STATUS, +IFNULL(DEVICE_WITH_POLICY_INFO.POLICY_ID, -1) AS POLICY_ID, +IFNULL(DEVICE_WITH_POLICY_INFO.IS_COMPLIANT, -1) AS IS_COMPLIANT, +DEVICE_INFO.TENANT_ID +FROM +(SELECT +DM_DEVICE.ID AS DEVICE_ID, +DM_DEVICE.DEVICE_IDENTIFICATION, +DM_DEVICE_TYPE.NAME AS PLATFORM, +DM_ENROLMENT.OWNERSHIP, +DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS, +DM_DEVICE.TENANT_ID +FROM DM_DEVICE, DM_DEVICE_TYPE, DM_ENROLMENT +WHERE DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND DM_DEVICE.ID = DM_ENROLMENT.DEVICE_ID) DEVICE_INFO +LEFT JOIN +(SELECT +DEVICE_ID, +POLICY_ID, +STATUS AS IS_COMPLIANT +FROM DM_POLICY_COMPLIANCE_STATUS) DEVICE_WITH_POLICY_INFO +ON DEVICE_INFO.DEVICE_ID = DEVICE_WITH_POLICY_INFO.DEVICE_ID +ORDER BY DEVICE_INFO.DEVICE_ID; + +CREATE VIEW FEATURE_NON_COMPLIANCE_INFO AS +SELECT +DM_DEVICE.ID AS DEVICE_ID, +DM_DEVICE.DEVICE_IDENTIFICATION, +DM_DEVICE_DETAIL.DEVICE_MODEL, +DM_DEVICE_DETAIL.VENDOR, +DM_DEVICE_DETAIL.OS_VERSION, +DM_ENROLMENT.OWNERSHIP, +DM_ENROLMENT.OWNER, +DM_ENROLMENT.STATUS AS CONNECTIVITY_STATUS, +DM_POLICY_COMPLIANCE_STATUS.POLICY_ID, +DM_DEVICE_TYPE.NAME AS PLATFORM, +DM_POLICY_COMPLIANCE_FEATURES.FEATURE_CODE, +DM_POLICY_COMPLIANCE_FEATURES.STATUS AS IS_COMPLAINT, +DM_DEVICE.TENANT_ID +FROM +DM_POLICY_COMPLIANCE_FEATURES, DM_POLICY_COMPLIANCE_STATUS, DM_ENROLMENT, DM_DEVICE, DM_DEVICE_TYPE, DM_DEVICE_DETAIL +WHERE +DM_POLICY_COMPLIANCE_FEATURES.COMPLIANCE_STATUS_ID = DM_POLICY_COMPLIANCE_STATUS.ID AND +DM_POLICY_COMPLIANCE_STATUS.ENROLMENT_ID = DM_ENROLMENT.ID AND +DM_POLICY_COMPLIANCE_STATUS.DEVICE_ID = DM_DEVICE.ID AND +DM_DEVICE.DEVICE_TYPE_ID = DM_DEVICE_TYPE.ID AND +DM_DEVICE.ID = DM_DEVICE_DETAIL.DEVICE_ID +ORDER BY TENANT_ID, DEVICE_ID; + +-- END OF DASHBOARD RELATED VIEWS -- + +-- DM_GEOFENCE TABLE-- + +CREATE TABLE IF NOT EXISTS DM_GEOFENCE ( + ID INT NOT NULL AUTO_INCREMENT, + FENCE_NAME VARCHAR(255) NOT NULL, + DESCRIPTION TEXT DEFAULT NULL, + LATITUDE DOUBLE DEFAULT NULL, + LONGITUDE DOUBLE DEFAULT NULL, + RADIUS DOUBLE DEFAULT NULL, + GEO_JSON TEXT DEFAULT NULL, + FENCE_SHAPE VARCHAR(100) DEFAULT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + OWNER VARCHAR(255) NOT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); + +-- END OF DM_GEOFENCE TABLE-- + +-- DM_GEOFENCE_GROUP_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_GEOFENCE_GROUP_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + FENCE_ID INT NOT NULL, + GROUP_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_geofence_group_mapping_geofence FOREIGN KEY (FENCE_ID) REFERENCES + DM_GEOFENCE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_geofence_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES + DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- END OF DM_GEOFENCE_GROUP_MAPPING TABLE-- + +-- DM_DEVICE_EVENT TABLE -- + +CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT ( + ID INT NOT NULL AUTO_INCREMENT, + EVENT_SOURCE VARCHAR(100) NOT NULL, + EVENT_LOGIC VARCHAR(100) NOT NULL, + ACTIONS TEXT DEFAULT NULL, + CREATED_TIMESTAMP TIMESTAMP NOT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (ID) +); + +-- END OF DM_DEVICE_EVENT TABLE -- + +-- DM_DEVICE_EVENT_GROUP_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_EVENT_GROUP_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + EVENT_ID INT NOT NULL, + GROUP_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_event_group_mapping_event FOREIGN KEY (EVENT_ID) REFERENCES + DM_DEVICE_EVENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_event_group_mapping_group FOREIGN KEY (GROUP_ID) REFERENCES + DM_GROUP (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- END OF DM_DEVICE_EVENT_GROUP_MAPPING TABLE-- + +-- DM_GEOFENCE_GROUP_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_GEOFENCE_EVENT_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + FENCE_ID INT NOT NULL, + EVENT_ID INT NOT NULL, + PRIMARY KEY (ID), + CONSTRAINT fk_dm_geofence_event_mapping_geofence FOREIGN KEY (FENCE_ID) REFERENCES + DM_GEOFENCE (ID) ON DELETE NO ACTION ON UPDATE NO ACTION, + CONSTRAINT fk_dm_geofence_event_mapping_event FOREIGN KEY (EVENT_ID) REFERENCES + DM_DEVICE_EVENT (ID) ON DELETE NO ACTION ON UPDATE NO ACTION +); + +-- END OF DM_GEOFENCE_GROUP_MAPPING TABLE-- + +-- DM_EXT_GROUP_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_GROUP_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + TRACCAR_GROUP_ID INT DEFAULT 0, + GROUP_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + STATUS INT DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_EXT_GROUP_MAPPING TABLE-- + +-- END OF DM_EXT_DEVICE_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_DEVICE_MAPPING ( + ID INT NOT NULL AUTO_INCREMENT, + TRACCAR_DEVICE_ID INT DEFAULT 0, + DEVICE_ID INT NOT NULL, + TENANT_ID INT NOT NULL, + STATUS INT DEFAULT 0, + PRIMARY KEY (ID) +); +-- END OF DM_EXT_DEVICE_MAPPING TABLE-- + +-- END OF DM_EXT_PERMISSION_MAPPING TABLE-- +CREATE TABLE IF NOT EXISTS DM_EXT_PERMISSION_MAPPING ( + TRACCAR_DEVICE_ID INT DEFAULT 0, + TRACCAR_USER_ID INT DEFAULT 0 +); +-- END OF DM_EXT_PERMISSION_MAPPING TABLE-- + +-- DYNAMIC TASK TABLES-- +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK ( + DYNAMIC_TASK_ID INTEGER AUTO_INCREMENT NOT NULL, + NAME VARCHAR(300) DEFAULT NULL , + CRON VARCHAR(8000) DEFAULT NULL, + IS_ENABLED BOOLEAN NOT NULL DEFAULT FALSE, + TASK_CLASS_NAME VARCHAR(8000) DEFAULT NULL, + TENANT_ID INTEGER DEFAULT 0, + PRIMARY KEY (DYNAMIC_TASK_ID) +); + +CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( + DYNAMIC_TASK_ID INTEGER NOT NULL, + PROPERTY_NAME VARCHAR(100) DEFAULT 0, + PROPERTY_VALUE VARCHAR(100) DEFAULT NULL, + TENANT_ID VARCHAR(100), + PRIMARY KEY (DYNAMIC_TASK_ID, PROPERTY_NAME, TENANT_ID), + CONSTRAINT FK_DYNAMIC_TASK_TASK_PROPERTIES FOREIGN KEY (DYNAMIC_TASK_ID) REFERENCES + DYNAMIC_TASK (DYNAMIC_TASK_ID) ON DELETE CASCADE ON UPDATE CASCADE +); +-- END OF DYNAMIC TASK TABLE-- + +-- DM_DEVICE_SUB_TYPE TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +); + +-- END OF DM_DEVICE_SUB_TYPE TABLE-- \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql new file mode 100644 index 00000000000..cd3d81c5664 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/dbscripts/h2.sql @@ -0,0 +1,21 @@ + -- ----------------------------------------------------- + -- Table `DM_DEVICE_SUB_TYPE` + -- ----------------------------------------------------- + + CREATE TABLE IF NOT EXISTS `DM_DEVICE_SUB_TYPE` ( + `TENANT_ID` INT DEFAULT 0, + `SUB_TYPE_ID` VARCHAR(45) NOT NULL, + `DEVICE_TYPE` VARCHAR(25) NOT NULL, + `SUB_TYPE_NAME` VARCHAR(45) NOT NULL, + `TYPE_DEFINITION` TEXT NOT NULL, + PRIMARY KEY (`SUB_TYPE_ID`,`DEVICE_TYPE`) + ); + +-- ----------------------------------------------------- +-- Sample data for test cases +-- ----------------------------------------------------- + +INSERT INTO DM_DEVICE_SUB_TYPE (SUB_TYPE_ID, TENANT_ID, DEVICE_TYPE, SUB_TYPE_NAME, TYPE_DEFINITION) VALUES +(3,-1234,'Meter','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 3, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'), +(4,-1234,'Meter','TestSubType','{"make": "TestSubType", "model": "ATx-Mega SIM800", "subTypeId": 4, "hasSMSSupport": true, "hasICMPSupport": true, "socketServerPort": 8071}'); + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml new file mode 100644 index 00000000000..a30b6dac01f --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2.xml @@ -0,0 +1,726 @@ + + + + + + + + + + + + + ${hotdeployment} + ${hotupdate} + optional + true + work/mtom + 4000 + + ${childfirstCL} + + + true + + + true + + + + false + + inmemory + + + + + + + services + + + axis2services + + + axis2modules + + + @product.name@-@product.version@ + + + @product.name@-@product.version@ + + + + + + + false + + + + + + false + + + true + + + repository/deployment/server/synapse-configs + + + + . + + + . + + + WSO2 Carbon Server + + + + + + + ${jaxwsparam} + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 9763 + + + + + + + + + + + + 9443 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + HTTP/1.1 + chunked + + true + + + HTTP/1.1 + chunked + + true + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + true + + + multicast + + + + + wso2.carbon.domain + + + + + + 45564 + + 100 + + 60 + + + + + + 127.0.0.1 + + + + + + 4000 + + + + + + + + + + + + + + + + + + 127.0.0.1 + 4000 + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml new file mode 100644 index 00000000000..4dc7e2cbfd9 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/axis2_client.xml @@ -0,0 +1,302 @@ + + + + + + + true + false + false + + + 500 + + 15000 + + + false + + + + true + + + + + + false + + + admin + axis2 + + + + + + + + + + + + + + + + + + + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 6071 + + + + + + + + + + + + + + + + + + + + + + HTTP/1.1 + chunked + 60000 + 60000 + + + HTTP/1.1 + chunked + 60000 + 60000 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml new file mode 100644 index 00000000000..a1e4a378f47 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/axis2/tenant-axis2.xml @@ -0,0 +1,287 @@ + + + + + + + + + true + true + optional + + + true + + + false + + + + true + + + + + + false + + + false + + + axis2services + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/carbon.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/carbon.xml new file mode 100644 index 00000000000..7a6bf0858b7 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/carbon.xml @@ -0,0 +1,659 @@ + + + + + + + + + ${product.name} + + + ${product.key} + + + ${product.version} + + + + + + + + + local:/${carbon.context}/services/ + + + + + + + ${default.server.role} + + + + + + + org.wso2.carbon + + + / + + + + + + + + + 15 + + + + + + + + + 0 + + + + + 9999 + + 11111 + + + + + + 10389 + + 8000 + + + + + + 10500 + + + + + + + org.wso2.carbon.tomcat.jndi.CarbonJavaURLContextFactory + + + + + + + + + + java + + + + + + + + + + false + + + false + + + 600 + + + + false + + + + + + + + 30 + + + + + + + + + 15 + + + + + + ${carbon.home}/repository/deployment/server/ + + + 15 + + + ${carbon.home}/repository/conf/axis2/axis2.xml + + + 30000 + + + ${carbon.home}/repository/deployment/client/ + + ${carbon.home}/repository/conf/axis2/axis2_client.xml + + true + + + + + + + + + + admin + Default Administrator Role + + + user + Default User Role + + + + + + + + + + + + ${carbon.home}/repository/resources/security/wso2carbon.jks + + JKS + + wso2carbon + + wso2carbon + + wso2carbon + + + + + + ${carbon.home}/repository/resources/security/client-truststore.jks + + JKS + + wso2carbon + + + + + + + + + + + + + + + + + + + UserManager + + + false + + + + + + + ${carbon.home}/tmp/work + + + + + + true + + + 10 + + + 30 + + + + + + 100 + + + + keystore + certificate + * + + org.wso2.carbon.ui.transports.fileupload.AnyFileUploadExecutor + + + + + jarZip + + org.wso2.carbon.ui.transports.fileupload.JarZipUploadExecutor + + + + dbs + + org.wso2.carbon.ui.transports.fileupload.DBSFileUploadExecutor + + + + tools + + org.wso2.carbon.ui.transports.fileupload.ToolsFileUploadExecutor + + + + toolsAny + + org.wso2.carbon.ui.transports.fileupload.ToolsAnyFileUploadExecutor + + + + + + + info + org.wso2.carbon.core.transports.util.InfoProcessor + + + wsdl + org.wso2.carbon.core.transports.util.Wsdl11Processor + + + wsdl2 + org.wso2.carbon.core.transports.util.Wsdl20Processor + + + xsd + org.wso2.carbon.core.transports.util.XsdProcessor + + + + + + false + false + true + svn + http://svnrepo.example.com/repos/ + username + password + true + + + + + + + + + + + + + + + ${require.carbon.servlet} + + + + + true + + + + + + + default repository + ${p2.repo.url} + + + + + + + + true + + + + + + true + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/cdm-config.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/cdm-config.xml new file mode 100644 index 00000000000..4abba457691 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/cdm-config.xml @@ -0,0 +1,171 @@ + + + + + + + + jdbc/DM_DS + + + + + 1000 + 60000 + 60000 + true + + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.FCMBasedPushNotificationProvider + + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.MQTTBasedPushNotificationProvider + + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.HTTPBasedPushNotificationProvider + + + org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.XMPPBasedPushNotificationProvider + + + + + false + + + https://localhost:9443 + admin + admin + + + https://localhost:9443 + admin + admin + + + org.wso2.carbon.policy.mgt + true + 60000 + 5 + 8 + 20 + + + + Simple + true + + + + 20 + 20 + 20 + 20 + 20 + 20 + 20 + + + + true + + + + false + 600 + + 10000 + + + false + 600 + + 10000 + + + true + + + false + 86400 + + + + + jdbc/DM_ARCHIVAL_DS + + + + false + org.wso2.carbon.device.mgt.core.task.impl.ArchivalTask + + 0 0 0 1/1 * ? * + + 30 + 1000 + + false + org.wso2.carbon.device.mgt.core.task.impl.ArchivedDataDeletionTask + + 0 0 3 1/1 * ? * + + 365 + + + + + false + + + false + false + + false + + + + + * + + + + + + true + wss://localhost:9443 + 2 + 100 + 20 + 15 + 640 + + BYOD,COPE + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml new file mode 100644 index 00000000000..e3b9d0ae6bf --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/datasources/data-source-config.xml @@ -0,0 +1,25 @@ + + + + + jdbc:h2:mem:smart-meter-test-db;DB_CLOSE_ON_EXIT=FALSE;MVCC=true + org.h2.Driver + wso2carbon + wso2carbon + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt new file mode 100644 index 00000000000..ffa7c79264a --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/bundle-config/README.txt @@ -0,0 +1,12 @@ +This directory supports adding third-pary config files to specific bundles during runtime. + +Explanation: Each OSGi bundle has its own classLoader. Some thirdpary libs read configs from classPath. This scenario fails in OSGi runtime, since OSGi runtime does not share a common classPath for individual bundles. Bundling config files during the bundle creation process itself will solve the issue. However it limits the ability to edit the configs during restarts. + +Here we are providing a workaround for such scenarios. The given config file will get resolved to a fragment bundle and will get attached to the specified host bundle. The host bundle name(symbolic name) is resolved by looking at the directory structure. Hence host bundle name should be directory name of the config file directory. + + +Example: The bundle with symbolic name, 'org.foo.bar' expects a config file named 'foobar.properties' from its classPath. + +create a directory named 'org.foo.bar' inside 'repository/conf/etc/bundle-config' - (this directory) and place the foobar.properties file. + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties new file mode 100644 index 00000000000..305bda8f825 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/carboncontext-osgi-services.properties @@ -0,0 +1,19 @@ +# +# Copyright 2023 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +#osgi.service.1 = org.wso2.carbon.client.configcontext.provider.Axis2ClientConfigContextProvider +#osgi.service.2 = org.wso2.carbon.user.core.UserManager +#osgi.service.3 = org.wso2.carbon.user.api.UserRealmService \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml new file mode 100644 index 00000000000..ed37b59ec93 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/config-validation.xml @@ -0,0 +1,55 @@ + + + + + + + + 800 + 2047 + 2047 + 1024 + 4096 + 02:FB:AA:5F:20:64:49:4A:27:29:55:71:83:F7:46:CD + + + 256 + 512 + 256 + + + carbon.home + carbon.config.dir.path + axis2.home + + + Linux + Unix + Mac OS + Windows Server 2003 + Windows XP + Windows Vista + Windows 7 + Mac OS X + Windows Server 2008 + Windows Server 2008 R2 + AIX + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/jmx.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/jmx.xml new file mode 100644 index 00000000000..0e012b5d2e1 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/jmx.xml @@ -0,0 +1,34 @@ + + + + + true + + + localhost + + + ${Ports.JMX.RMIRegistryPort} + + + ${Ports.JMX.RMIServerPort} + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/launch.ini b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/launch.ini new file mode 100644 index 00000000000..8b9f5ad1905 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/launch.ini @@ -0,0 +1,258 @@ +# Eclipse Runtime Configuration Overrides +# These properties are loaded prior to starting the framework and can also be used to override System Properties +# @null is a special value used to override and clear the framework's copy of a System Property prior to starting the framework +# "*" can be used together with @null to clear System Properties that match a prefix name. + +osgi.*=@null +org.osgi.*=@null +eclipse.*=@null + +osgi.parentClassloader=app +osgi.contextClassLoaderParent=app + +# When osgi.clean is set to "true", any cached data used by the OSGi framework +# will be wiped clean. This will clean the caches used to store bundle +# dependency resolution and eclipse extension registry data. Using this +# option will force OSGi framework to reinitialize these caches. +# The following setting is put in place to get rid of the problems +# faced when re-starting the system. Please note that, when this setting is +# true, if you manually start a bundle, it would not be available when +# you re-start the system. To avid this, copy the bundle jar to the plugins +# folder, before you re-start the system. +osgi.clean=true + +# Uncomment the following line to turn on Eclipse Equinox debugging. +# You may also edit the osgi-debug.options file and fine tune the debugging +# options to suite your needs. +#osgi.debug=./repository/conf/osgi-debug.options + +# Following system property allows us to control the public JDK packages exported through the system bundle. +org.osgi.framework.system.packages=javax.accessibility,\ +javax.activity,\ +javax.crypto,\ +javax.crypto.interfaces,\ +javax.crypto.spec,\ +javax.imageio,\ +javax.imageio.event,\ +javax.imageio.metadata,\ +javax.imageio.plugins.bmp,\ +javax.imageio.plugins.jpeg,\ +javax.imageio.spi,\ +javax.imageio.stream,\ +javax.jms,\ +javax.management,\ +javax.management.loading,\ +javax.management.modelmbean,\ +javax.management.monitor,\ +javax.management.openmbean,\ +javax.management.relation,\ +javax.management.remote,\ +javax.management.remote.rmi,\ +javax.management.timer,\ +javax.naming,\ +javax.naming.directory,\ +javax.naming.event,\ +javax.naming.ldap,\ +javax.naming.spi,\ +javax.net,\ +javax.net.ssl,\ +javax.print,\ +javax.print.attribute,\ +javax.print.attribute.standard,\ +javax.print.event,\ +javax.rmi,\ +javax.rmi.CORBA,\ +javax.rmi.ssl,\ +javax.script,\ +javax.security.auth,\ +javax.security.auth.callback,\ +javax.security.auth.kerberos,\ +javax.security.auth.login,\ +javax.security.auth.spi,\ +javax.security.auth.x500,\ +javax.security.cert,\ +javax.security.sasl,\ +javax.sound.midi,\ +javax.sound.midi.spi,\ +javax.sound.sampled,\ +javax.sound.sampled.spi,\ +javax.sql,\ +javax.sql.rowset,\ +javax.sql.rowset.serial,\ +javax.sql.rowset.spi,\ +javax.swing,\ +javax.swing.border,\ +javax.swing.colorchooser,\ +javax.swing.event,\ +javax.swing.filechooser,\ +javax.swing.plaf,\ +javax.swing.plaf.basic,\ +javax.swing.plaf.metal,\ +javax.swing.plaf.multi,\ +javax.swing.plaf.synth,\ +javax.swing.table,\ +javax.swing.text,\ +javax.swing.text.html,\ +javax.swing.text.html.parser,\ +javax.swing.text.rtf,\ +javax.swing.tree,\ +javax.swing.undo,\ +javax.transaction,\ +javax.transaction.xa,\ +javax.xml.namespace,\ +javax.xml.parsers,\ +javax.xml.stream,\ +javax.xml.stream.events,\ +javax.xml.stream.util,\ +javax.xml.transform,\ +javax.xml.transform.stream,\ +javax.xml.transform.dom,\ +javax.xml.transform.sax,\ +javax.xml,\ +javax.xml.validation,\ +javax.xml.datatype,\ +javax.xml.xpath,\ +javax.activation,\ +com.sun.activation.registries,\ +com.sun.activation.viewers,\ +org.ietf.jgss,\ +org.omg.CORBA,\ +org.omg.CORBA_2_3,\ +org.omg.CORBA_2_3.portable,\ +org.omg.CORBA.DynAnyPackage,\ +org.omg.CORBA.ORBPackage,\ +org.omg.CORBA.portable,\ +org.omg.CORBA.TypeCodePackage,\ +org.omg.CosNaming,\ +org.omg.CosNaming.NamingContextExtPackage,\ +org.omg.CosNaming.NamingContextPackage,\ +org.omg.Dynamic,\ +org.omg.DynamicAny,\ +org.omg.DynamicAny.DynAnyFactoryPackage,\ +org.omg.DynamicAny.DynAnyPackage,\ +org.omg.IOP,\ +org.omg.IOP.CodecFactoryPackage,\ +org.omg.IOP.CodecPackage,\ +org.omg.Messaging,\ +org.omg.PortableInterceptor,\ +org.omg.PortableInterceptor.ORBInitInfoPackage,\ +org.omg.PortableServer,\ +org.omg.PortableServer.CurrentPackage,\ +org.omg.PortableServer.POAManagerPackage,\ +org.omg.PortableServer.POAPackage,\ +org.omg.PortableServer.portable,\ +org.omg.PortableServer.ServantLocatorPackage,\ +org.omg.SendingContext,\ +org.omg.stub.java.rmi,\ +org.w3c.dom,\ +org.w3c.dom.bootstrap,\ +org.w3c.dom.css,\ +org.w3c.dom.events,\ +org.w3c.dom.html,\ +org.w3c.dom.ls,\ +org.w3c.dom.ranges,\ +org.w3c.dom.stylesheets,\ +org.w3c.dom.traversal,\ +org.w3c.dom.views ,\ +org.xml.sax,\ +org.xml.sax.ext,\ +org.xml.sax.helpers,\ +org.apache.xerces.xpointer,\ +org.apache.xerces.xni.grammars,\ +org.apache.xerces.impl.xs.util,\ +org.apache.xerces.jaxp.validation,\ +org.apache.xerces.impl.dtd.models,\ +org.apache.xerces.impl.xpath,\ +org.apache.xerces.dom3.as,\ +org.apache.xerces.impl.dv.xs,\ +org.apache.xerces.util,\ +org.apache.xerces.impl.xs.identity,\ +org.apache.xerces.impl.xs.opti,\ +org.apache.xerces.jaxp,\ +org.apache.xerces.impl.dv,\ +org.apache.xerces.xs.datatypes,\ +org.apache.xerces.dom.events,\ +org.apache.xerces.impl.msg,\ +org.apache.xerces.xni,\ +org.apache.xerces.impl.xs,\ +org.apache.xerces.impl,\ +org.apache.xerces.impl.io,\ +org.apache.xerces.xinclude,\ +org.apache.xerces.jaxp.datatype,\ +org.apache.xerces.parsers,\ +org.apache.xerces.impl.dv.util,\ +org.apache.xerces.xni.parser,\ +org.apache.xerces.impl.xs.traversers,\ +org.apache.xerces.impl.dv.dtd,\ +org.apache.xerces.xs,\ +org.apache.xerces.impl.dtd,\ +org.apache.xerces.impl.validation,\ +org.apache.xerces.impl.xs.models,\ +org.apache.xerces.impl.xpath.regex,\ +org.apache.xml.serialize,\ +org.apache.xerces.dom,\ +org.apache.xalan,\ +org.apache.xalan.xslt,\ +org.apache.xalan.templates,\ +org.apache.xalan.xsltc,\ +org.apache.xalan.xsltc.cmdline,\ +org.apache.xalan.xsltc.cmdline.getopt,\ +org.apache.xalan.xsltc.trax,\ +org.apache.xalan.xsltc.dom,\ +org.apache.xalan.xsltc.runtime,\ +org.apache.xalan.xsltc.runtime.output,\ +org.apache.xalan.xsltc.util,\ +org.apache.xalan.xsltc.compiler,\ +org.apache.xalan.xsltc.compiler.util,\ +org.apache.xalan.serialize,\ +org.apache.xalan.client,\ +org.apache.xalan.res,\ +org.apache.xalan.transformer,\ +org.apache.xalan.extensions,\ +org.apache.xalan.lib,\ +org.apache.xalan.lib.sql,\ +org.apache.xalan.processor,\ +org.apache.xalan.trace,\ +org.apache.xml.dtm,\ +org.apache.xml.dtm.ref,\ +org.apache.xml.dtm.ref.sax2dtm,\ +org.apache.xml.dtm.ref.dom2dtm,\ +org.apache.xml.utils,\ +org.apache.xml.utils.res,\ +org.apache.xml.res,\ +org.apache.xml.serializer,\ +org.apache.xml.serializer.utils,\ +org.apache.xpath,\ +org.apache.xpath.domapi,\ +org.apache.xpath.objects,\ +org.apache.xpath.patterns,\ +org.apache.xpath.jaxp,\ +org.apache.xpath.res,\ +org.apache.xpath.operations,\ +org.apache.xpath.functions,\ +org.apache.xpath.axes,\ +org.apache.xpath.compiler,\ +org.apache.xml.resolver,\ +org.apache.xml.resolver.tools,\ +org.apache.xml.resolver.helpers,\ +org.apache.xml.resolver.readers,\ +org.apache.xml.resolver.etc,\ +org.apache.xml.resolver.apps,\ +javax.xml.ws,\ +javax.xml.ws.handler,\ +javax.xml.ws.handler.soap,\ +javax.xml.ws.http,\ +javax.xml.ws.soap,\ +javax.xml.ws.spi,\ +javax.xml.ws.spi.http,\ +javax.xml.ws.wsaddressing,\ +javax.xml.bind,\ +javax.xml.bind.annotation,\ +javax.xml.bind.annotation.adapters,\ +javax.annotation,\ +javax.jws,\ +javax.jws.soap,\ +com.sun.xml.internal.messaging.saaj.soap.ver1_1,\ +com.sun.xml.internal.messaging.saaj.soap,\ +com.sun.tools.internal.ws.spi,\ +org.wso2.carbon.bootstrap diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties new file mode 100644 index 00000000000..5fd86209df3 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/logging-bridge.properties @@ -0,0 +1,70 @@ +# +# Copyright 2023 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +############################################################ +# Default Logging Configuration File +# +# You can use a different file by specifying a filename +# with the java.util.logging.config.file system property. +# For example java -Djava.util.logging.config.file=myfile +############################################################ +############################################################ +# Global properties +# NOTE: this configuration file use to get the handler list, +# Properties(except level property) define for each handler +# may be not available because LogRecords handover to log4j +# appenders in runtime. +############################################################ +# "handlers" specifies a comma separated list of log Handler +# classes. These handlers will be installed during VM startup. +# Note that these classes must be on the system classpath. +# By default we only configure a ConsoleHandler, which will only +# show messages at the INFO and above levels. +#handlers= java.util.logging.ConsoleHandler +# To also add the FileHandler, use the following line instead. +#handlers= java.util.logging.FileHandler, java.util.logging.ConsoleHandler +# Add org.wso2.carbon.bootstrap.logging.handlers.LogEventHandler to handlers if you need to push java logs to LOGEVENT appender +handlers=org.wso2.carbon.bootstrap.logging.handlers.LoggingConsoleHandler, org.wso2.carbon.bootstrap.logging.handlers.LoggingFileHandler +# Default global logging level. +# This specifies which kinds of events are logged across +# all loggers. For any given facility this global level +# can be overriden by a facility specific level +# Note that the ConsoleHandler also has a separate level +# setting to limit messages printed to the console. +.level=INFO +############################################################ +# Handler specific properties. +# Describes specific configuration info for Handlers. +# +############################################################ +# This FileHandler pushed LogRecords to a log4j FileAppander in runtime +org.wso2.carbon.bootstrap.logging.handlers.LoggingFileHandler.level=INFO +#org.wso2.carbon.bootstrap.logging.handlers.LoggingFileHandler.formatter = java.util.logging.SimpleFormatter +# This ConsoleHandler pushed LogRecords to q log4j ConsoleAppander in runtime +org.wso2.carbon.bootstrap.logging.handlers.LoggingConsoleHandler.level=INFO +#org.wso2.carbon.bootstrap.logging.handlers.LoggingConsoleHandler.formatter = java.util.logging.SimpleFormatter +############################################################ +# Facility specific properties. +# Provides extra control for each logger. +############################################################ +# For example, set the com.xyz.foo logger to only log SEVERE +# messages: +#com.xyz.foo.level = SEVERE +org.apache.coyote.level=SEVERE +org.apache.catalina.level=SEVERE +com.hazelcast.level=SEVERE + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.mappings b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.mappings new file mode 100644 index 00000000000..97a5c5a5fc0 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.mappings @@ -0,0 +1,27 @@ +# +# Copyright 2005-2011 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +# This file is to define the human readable media type for a mime type. +# Eg:- +# text/plain txt text +application/wsdl+xml WSDL +application/x-xsd+xml Schema +application/policy+xml Policy +application/vnd.wso2-service+xml Service +application/vnd.wso2-hyperlink Hyperlink +application/vnd.wso2.endpoint Endpoint +application/vnd.wso2-api+xml API +application/vnd.wso2-uri+xml URI diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.types b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.types new file mode 100644 index 00000000000..21c386da005 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/mime.types @@ -0,0 +1,734 @@ +# +# Copyright 2005-2009 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# + +# Media type for wsdl files. This is not defined in the original mime.types file. +chemical/x-alchemy alc +application/andrew-inset ez +application/wsdl+xml wsdl +application/vnd.sun.wadl+xml wadl +application/activemessage +application/applefile +application/atomicmail +application/batch-SMTP +application/beep+xml +application/cals-1840 +application/commonground +application/cu-seeme cu +application/cybercash +application/dca-rft +application/dec-dx +application/docbook+xml +application/dsptype tsp +application/dvcs +application/edi-consent +application/edi-x12 +application/edifact +application/eshop +application/font-tdpfr +application/futuresplash spl +application/ghostview +application/hta hta +application/http +application/hyperstudio +application/iges +application/index +application/index.cmd +application/index.obj +application/index.response +application/index.vnd +application/iotp +application/ipp +application/isup +application/java-archive jar +application/java-serialized-object ser +application/java-vm class +application/mac-binhex40 hqx +application/mac-compactpro cpt +application/macwriteii +application/marc +application/mathematica nb +application/mathematica-old +application/msaccess mdb +application/msword doc dot +application/news-message-id +application/news-transmission +application/ocsp-request +application/ocsp-response +application/octet-stream bin +application/oda oda +application/ogg ogg +application/parityfec +application/pdf pdf +application/pgp-encrypted +application/pgp-keys key +application/pgp-signature pgp +application/pics-rules prf +application/pkcs10 +application/pkcs7-mime +application/pkcs7-signature +application/pkix-cert +application/pkix-crl +application/pkixcmp +application/policy+xml +application/postscript ps ai eps +application/prs.alvestrand.titrax-sheet +application/prs.cww +application/prs.nprend +application/qsig +application/rar rar +application/rdf+xml rdf +application/remote-printing +application/riscos +application/rss+xml rss +application/rtf +application/sdp +application/set-payment +application/set-payment-initiation +application/set-registration +application/set-registration-initiation +application/sgml +application/sgml-open-catalog +application/sieve +application/slate +application/smil smi smil +application/timestamp-query +application/timestamp-reply +application/vemmi +application/whoispp-query +application/whoispp-response +application/wita +application/wordperfect wpd +application/wordperfect5.1 wp5 +application/x400-bp +application/xhtml+xml xhtml xht +application/xml xml xsl xslt jrxml +application/xml-dtd +application/xml-external-parsed-entity +application/zip zip +application/vnd.3M.Post-it-Notes +application/vnd.accpac.simply.aso +application/vnd.accpac.simply.imp +application/vnd.acucobol +application/vnd.aether.imp +application/vnd.anser-web-certificate-issue-initiation +application/vnd.anser-web-funds-transfer-initiation +application/vnd.audiograph +application/vnd.bmi +application/vnd.businessobjects +application/vnd.canon-cpdl +application/vnd.canon-lips +application/vnd.cinderella cdy +application/vnd.claymore +application/vnd.commerce-battelle +application/vnd.commonspace +application/vnd.comsocaller +application/vnd.contact.cmsg +application/vnd.cosmocaller +application/vnd.ctc-posml +application/vnd.cups-postscript +application/vnd.cups-raster +application/vnd.cups-raw +application/vnd.cybank +application/vnd.dna +application/vnd.dpgraph +application/vnd.dxr +application/vnd.ecdis-update +application/vnd.ecowin.chart +application/vnd.ecowin.filerequest +application/vnd.ecowin.fileupdate +application/vnd.ecowin.series +application/vnd.ecowin.seriesrequest +application/vnd.ecowin.seriesupdate +application/vnd.enliven +application/vnd.epson.esf +application/vnd.epson.msf +application/vnd.epson.quickanime +application/vnd.epson.salt +application/vnd.epson.ssf +application/vnd.ericsson.quickcall +application/vnd.eudora.data +application/vnd.fdf +application/vnd.ffsns +application/vnd.flographit +application/vnd.framemaker +application/vnd.fsc.weblaunch +application/vnd.fujitsu.oasys +application/vnd.fujitsu.oasys2 +application/vnd.fujitsu.oasys3 +application/vnd.fujitsu.oasysgp +application/vnd.fujitsu.oasysprs +application/vnd.fujixerox.ddd +application/vnd.fujixerox.docuworks +application/vnd.fujixerox.docuworks.binder +application/vnd.fut-misnet +application/vnd.grafeq +application/vnd.groove-account +application/vnd.groove-identity-message +application/vnd.groove-injector +application/vnd.groove-tool-message +application/vnd.groove-tool-template +application/vnd.groove-vcard +application/vnd.hhe.lesson-player +application/vnd.hp-HPGL +application/vnd.hp-PCL +application/vnd.hp-PCLXL +application/vnd.hp-hpid +application/vnd.hp-hps +application/vnd.httphone +application/vnd.hzn-3d-crossword +application/vnd.ibm.MiniPay +application/vnd.ibm.afplinedata +application/vnd.ibm.modcap +application/vnd.informix-visionary +application/vnd.intercon.formnet +application/vnd.intertrust.digibox +application/vnd.intertrust.nncp +application/vnd.intu.qbo +application/vnd.intu.qfx +application/vnd.irepository.package+xml +application/vnd.is-xpr +application/vnd.japannet-directory-service +application/vnd.japannet-jpnstore-wakeup +application/vnd.japannet-payment-wakeup +application/vnd.japannet-registration +application/vnd.japannet-registration-wakeup +application/vnd.japannet-setstore-wakeup +application/vnd.japannet-verification +application/vnd.japannet-verification-wakeup +application/vnd.koan +application/vnd.lotus-1-2-3 +application/vnd.lotus-approach +application/vnd.lotus-freelance +application/vnd.lotus-notes +application/vnd.lotus-organizer +application/vnd.lotus-screencam +application/vnd.lotus-wordpro +application/vnd.mcd +application/vnd.mediastation.cdkey +application/vnd.meridian-slingshot +application/vnd.mif +application/vnd.minisoft-hp3000-save +application/vnd.mitsubishi.misty-guard.trustweb +application/vnd.mobius.daf +application/vnd.mobius.dis +application/vnd.mobius.msl +application/vnd.mobius.plc +application/vnd.mobius.txf +application/vnd.motorola.flexsuite +application/vnd.motorola.flexsuite.adsi +application/vnd.motorola.flexsuite.fis +application/vnd.motorola.flexsuite.gotap +application/vnd.motorola.flexsuite.kmr +application/vnd.motorola.flexsuite.ttc +application/vnd.motorola.flexsuite.wem +application/vnd.mozilla.xul+xml xul +application/vnd.ms-artgalry +application/vnd.ms-asf +application/vnd.ms-excel xls xlb xlt +application/vnd.ms-lrm +application/vnd.ms-pki.seccat cat +application/vnd.ms-pki.stl stl +application/vnd.ms-powerpoint ppt pps +application/vnd.ms-project +application/vnd.ms-tnef +application/vnd.ms-works +application/vnd.mseq +application/vnd.msign +application/vnd.music-niff +application/vnd.musician +application/vnd.netfpx +application/vnd.noblenet-directory +application/vnd.noblenet-sealer +application/vnd.noblenet-web +application/vnd.novadigm.EDM +application/vnd.novadigm.EDX +application/vnd.novadigm.EXT +application/vnd.oasis.opendocument.chart odc +application/vnd.oasis.opendocument.database odb +application/vnd.oasis.opendocument.formula odf +application/vnd.oasis.opendocument.graphics odg +application/vnd.oasis.opendocument.graphics-template otg +application/vnd.oasis.opendocument.image odi +application/vnd.oasis.opendocument.presentation odp +application/vnd.oasis.opendocument.presentation-template otp +application/vnd.oasis.opendocument.spreadsheet ods +application/vnd.oasis.opendocument.spreadsheet-template ots +application/vnd.oasis.opendocument.text odt +application/vnd.oasis.opendocument.text-master odm +application/vnd.oasis.opendocument.text-template ott +application/vnd.oasis.opendocument.text-web oth +application/vnd.osa.netdeploy +application/vnd.palm +application/vnd.pg.format +application/vnd.pg.osasli +application/vnd.powerbuilder6 +application/vnd.powerbuilder6-s +application/vnd.powerbuilder7 +application/vnd.powerbuilder7-s +application/vnd.powerbuilder75 +application/vnd.powerbuilder75-s +application/vnd.previewsystems.box +application/vnd.publishare-delta-tree +application/vnd.pvi.ptid1 +application/vnd.pwg-xhtml-print+xml +application/vnd.rapid +application/vnd.rim.cod cod +application/vnd.s3sms +application/vnd.seemail +application/vnd.shana.informed.formdata +application/vnd.shana.informed.formtemplate +application/vnd.shana.informed.interchange +application/vnd.shana.informed.package +application/vnd.smaf mmf +application/vnd.sss-cod +application/vnd.sss-dtf +application/vnd.sss-ntf +application/vnd.stardivision.calc sdc +application/vnd.stardivision.draw sda +application/vnd.stardivision.impress sdd sdp +application/vnd.stardivision.math smf +application/vnd.stardivision.writer sdw vor +application/vnd.stardivision.writer-global sgl +application/vnd.street-stream +application/vnd.sun.xml.calc sxc +application/vnd.sun.xml.calc.template stc +application/vnd.sun.xml.draw sxd +application/vnd.sun.xml.draw.template std +application/vnd.sun.xml.impress sxi +application/vnd.sun.xml.impress.template sti +application/vnd.sun.xml.math sxm +application/vnd.sun.xml.writer sxw +application/vnd.sun.xml.writer.global sxg +application/vnd.sun.xml.writer.template stw +application/vnd.svd +application/vnd.swiftview-ics +application/vnd.symbian.install sis +application/vnd.triscape.mxs +application/vnd.trueapp +application/vnd.truedoc +application/vnd.tve-trigger +application/vnd.ufdl +application/vnd.uplanet.alert +application/vnd.uplanet.alert-wbxml +application/vnd.uplanet.bearer-choice +application/vnd.uplanet.bearer-choice-wbxml +application/vnd.uplanet.cacheop +application/vnd.uplanet.cacheop-wbxml +application/vnd.uplanet.channel +application/vnd.uplanet.channel-wbxml +application/vnd.uplanet.list +application/vnd.uplanet.list-wbxml +application/vnd.uplanet.listcmd +application/vnd.uplanet.listcmd-wbxml +application/vnd.uplanet.signal +application/vnd.vcx +application/vnd.vectorworks +application/vnd.vidsoft.vidconference +application/vnd.visio vsd +application/vnd.vividence.scriptfile +application/vnd.wap.sic +application/vnd.wap.slc +application/vnd.wap.wbxml wbxml +application/vnd.wap.wmlc wmlc +application/vnd.wap.wmlscriptc wmlsc +application/vnd.webturbo +application/vnd.wrq-hp3000-labelled +application/vnd.wso2.bpel+xml bpel +application/vnd.wso2.bpmn+xml bpmn +application/vnd.wso2.endpoint +application/vnd.wso2.governance-archive gar +application/vnd.wso2-hyperlink +application/vnd.wso2.registry-ext-type+xml rxt +application/vnd.wso2-service+xml +application/vnd.wso2.xpdl+xml xpdl +application/vnd.wt.stf +application/vnd.xara +application/vnd.xfdl +application/vnd.yellowriver-custom-menu +application/x-123 wk +application/x-abiword abw +application/x-apple-diskimage dmg +application/x-bcpio bcpio +application/x-bittorrent torrent +application/x-cdf cdf +application/x-cdlink vcd +application/x-chess-pgn pgn +application/x-core +application/x-cpio cpio +application/x-csh csh +application/x-debian-package deb udeb +application/x-director dcr dir dxr +application/x-dms dms +application/x-doom wad +application/x-dvi dvi +application/x-executable +application/x-flac flac +application/x-font pfa pfb gsf pcf pcf.Z +application/x-freemind mm +application/x-futuresplash spl +application/x-gnumeric gnumeric +application/x-go-sgf sgf +application/x-graphing-calculator gcf +application/x-gtar gtar tgz taz +application/x-hdf hdf +application/x-httpd-php phtml pht php +application/x-httpd-php-source phps +application/x-httpd-php3 php3 +application/x-httpd-php3-preprocessed php3p +application/x-httpd-php4 php4 +application/x-httpd-eruby rhtml +application/x-ica ica +application/x-internet-signup ins isp +application/x-iphone iii +application/x-iso9660-image iso +application/x-java-applet +application/x-java-bean +application/x-java-jnlp-file jnlp +application/x-javascript js +application/x-jmol jmz +application/x-kchart chrt +application/x-kdelnk +application/x-killustrator kil +application/x-koan skp skd skt skm +application/x-kpresenter kpr kpt +application/x-kspread ksp +application/x-kword kwd kwt +application/x-latex latex +application/x-lha lha +application/x-lzh lzh +application/x-lzx lzx +application/x-maker frm maker frame fm fb book fbdoc +application/x-mif mif +application/x-ms-wmd wmd +application/x-ms-wmz wmz +application/x-msdos-program com exe bat dll +application/x-msi msi +application/x-netcdf nc +application/x-ns-proxy-autoconfig pac +application/x-nwc nwc +application/x-object o +application/x-oz-application oza +application/x-pkcs7-certreqresp p7r +application/x-pkcs7-crl crl +application/x-python-code pyc pyo +application/x-quicktimeplayer qtl +application/x-redhat-package-manager rpm +application/x-rx +application/x-sh sh +application/x-shar shar +application/x-shellscript +application/x-shockwave-flash swf swfl +application/x-stuffit sit +application/x-sv4cpio sv4cpio +application/x-sv4crc sv4crc +application/x-tar tar +application/x-tcl tcl +application/x-tex-gf gf +application/x-tex-pk pk +application/x-texinfo texinfo texi +application/x-trash ~ % bak old sik +application/x-troff t tr roff +application/x-troff-man man +application/x-troff-me me +application/x-troff-ms ms +application/x-ustar ustar +application/x-videolan +application/x-wais-source src +application/x-wingz wz +application/x-x509-ca-cert crt +application/x-xcf xcf +application/x-xfig fig +application/x-xpinstall xpi +application/x-xsd+xml xsd + +audio/32kadpcm +audio/basic au snd +audio/g.722.1 +audio/l16 +audio/midi mid midi kar +audio/mp4a-latm +audio/mpa-robust +audio/mpeg mpga mpega mp2 mp3 m4a +audio/mpegurl m3u +audio/parityfec +audio/prs.sid sid +audio/telephone-event +audio/tone +audio/vnd.cisco.nse +audio/vnd.cns.anp1 +audio/vnd.cns.inf1 +audio/vnd.digital-winds +audio/vnd.everad.plj +audio/vnd.lucent.voice +audio/vnd.nortel.vbk +audio/vnd.nuera.ecelp4800 +audio/vnd.nuera.ecelp7470 +audio/vnd.nuera.ecelp9600 +audio/vnd.octel.sbc +audio/vnd.qcelp +audio/vnd.rhetorex.32kadpcm +audio/vnd.vmx.cvsd +audio/x-aiff aif aiff aifc +audio/x-gsm gsm +audio/x-mpegurl m3u +audio/x-ms-wma wma +audio/x-ms-wax wax +audio/x-pn-realaudio-plugin +audio/x-pn-realaudio ra rm ram +audio/x-realaudio ra +audio/x-scpls pls +audio/x-sd2 sd2 +audio/x-wav wav + +chemical/x-alchemy alc +chemical/x-cache cac cache +chemical/x-cache-csf csf +chemical/x-cactvs-binary cbin cascii ctab +chemical/x-cdx cdx +chemical/x-cerius cer +chemical/x-chem3d c3d +chemical/x-chemdraw chm +chemical/x-cif cif +chemical/x-cmdf cmdf +chemical/x-cml cml +chemical/x-compass cpa +chemical/x-crossfire bsd +chemical/x-csml csml csm +chemical/x-ctx ctx +chemical/x-cxf cxf cef +#chemical/x-daylight-smiles smi +chemical/x-embl-dl-nucleotide emb embl +chemical/x-galactic-spc spc +chemical/x-gamess-input inp gam gamin +chemical/x-gaussian-checkpoint fch fchk +chemical/x-gaussian-cube cub +chemical/x-gaussian-input gau gjc gjf +chemical/x-gaussian-log gal +chemical/x-gcg8-sequence gcg +chemical/x-genbank gen +chemical/x-hin hin +chemical/x-isostar istr ist +chemical/x-jcamp-dx jdx dx +chemical/x-kinemage kin +chemical/x-macmolecule mcm +chemical/x-macromodel-input mmd mmod +chemical/x-mdl-molfile mol +chemical/x-mdl-rdfile rd +chemical/x-mdl-rxnfile rxn +chemical/x-mdl-sdfile sd sdf +chemical/x-mdl-tgf tgf +#chemical/x-mif mif +chemical/x-mmcif mcif +chemical/x-mol2 mol2 +chemical/x-molconn-Z b +chemical/x-mopac-graph gpt +chemical/x-mopac-input mop mopcrt mpc dat zmt +chemical/x-mopac-out moo +chemical/x-mopac-vib mvb +chemical/x-ncbi-asn1 asn +chemical/x-ncbi-asn1-ascii prt ent +chemical/x-ncbi-asn1-binary val aso +chemical/x-ncbi-asn1-spec asn +chemical/x-pdb pdb ent +chemical/x-rosdal ros +chemical/x-swissprot sw +chemical/x-vamas-iso14976 vms +chemical/x-vmd vmd +chemical/x-xtel xtel +chemical/x-xyz xyz + +image/cgm +image/g3fax +image/gif gif +image/ief ief +image/jpeg jpeg jpg jpe +image/naplps +image/pcx pcx +image/png png +image/prs.btif +image/prs.pti +image/svg+xml svg svgz +image/tiff tiff tif +image/vnd.cns.inf2 +image/vnd.djvu djvu djv +image/vnd.dwg +image/vnd.dxf +image/vnd.fastbidsheet +image/vnd.fpx +image/vnd.fst +image/vnd.fujixerox.edmics-mmr +image/vnd.fujixerox.edmics-rlc +image/vnd.mix +image/vnd.net-fpx +image/vnd.svf +image/vnd.wap.wbmp wbmp +image/vnd.xiff +image/x-cmu-raster ras +image/x-coreldraw cdr +image/x-coreldrawpattern pat +image/x-coreldrawtemplate cdt +image/x-corelphotopaint cpt +image/x-icon ico +image/x-jg art +image/x-jng jng +image/x-ms-bmp bmp +image/x-photoshop psd +image/x-portable-anymap pnm +image/x-portable-bitmap pbm +image/x-portable-graymap pgm +image/x-portable-pixmap ppm +image/x-rgb rgb +image/x-xbitmap xbm +image/x-xpixmap xpm +image/x-xwindowdump xwd + +inode/chardevice +inode/blockdevice +inode/directory-locked +inode/directory +inode/fifo +inode/socket + +message/delivery-status +message/disposition-notification +message/external-body +message/http +message/s-http +message/news +message/partial +message/rfc822 + +model/iges igs iges +model/mesh msh mesh silo +model/vnd.dwf +model/vnd.flatland.3dml +model/vnd.gdl +model/vnd.gs-gdl +model/vnd.gtw +model/vnd.mts +model/vnd.vtu +model/vrml wrl vrml + +multipart/alternative +multipart/appledouble +multipart/byteranges +multipart/digest +multipart/encrypted +multipart/form-data +multipart/header-set +multipart/mixed +multipart/parallel +multipart/related +multipart/report +multipart/signed +multipart/voice-message + +text/calendar ics icz +text/comma-separated-values csv +text/css css +text/directory +text/english +text/enriched +text/h323 323 +text/html html htm shtml +text/iuls uls +text/mathml mml +text/parityfec +text/plain asc txt text diff pot sql +text/prs.lines.tag +text/rfc822-headers +text/richtext rtx +text/rtf rtf +text/scriptlet sct wsc +text/t140 +text/texmacs tm ts +text/tab-separated-values tsv +text/uri-list +text/vnd.abc +text/vnd.curl +text/vnd.DMClientScript +text/vnd.flatland.3dml +text/vnd.fly +text/vnd.fmi.flexstor +text/vnd.in3d.3dml +text/vnd.in3d.spot +text/vnd.IPTC.NewsML +text/vnd.IPTC.NITF +text/vnd.latex-z +text/vnd.motorola.reflex +text/vnd.ms-mediapackage +text/vnd.sun.j2me.app-descriptor jad +text/vnd.wap.si +text/vnd.wap.sl +text/vnd.wap.wml wml +text/vnd.wap.wmlscript wmls +text/x-bibtex bib +text/x-boo boo +text/x-c++hdr h++ hpp hxx hh +text/x-c++src c++ cpp cxx cc +text/x-chdr h +text/x-component htc +text/x-crontab +text/x-csh csh +text/x-csrc c +text/x-dsrc d +text/x-haskell hs +text/x-java java +text/x-literate-haskell lhs +text/x-makefile +text/x-moc moc +text/x-pascal p pas +text/x-pcs-gcd gcd +text/x-perl pl pm +text/x-python py +text/x-server-parsed-html +text/x-setext etx +text/x-sh sh +text/x-tcl tcl tk +text/x-tex tex ltx sty cls +text/x-vcalendar vcs +text/x-vcard vcf + +video/dl dl +video/dv dif dv +video/fli fli +video/gl gl +video/mpeg mpeg mpg mpe +video/mp4 mp4 +video/quicktime qt mov +video/mp4v-es +video/parityfec +video/pointer +video/vnd.fvt +video/vnd.motorola.video +video/vnd.motorola.videop +video/vnd.mpegurl mxu +video/vnd.mts +video/vnd.nokia.interleaved-multimedia +video/vnd.vivo +video/x-la-asf lsf lsx +video/x-mng mng +video/x-ms-asf asf asx +video/x-ms-wm wm +video/x-ms-wmv wmv +video/x-ms-wmx wmx +video/x-ms-wvx wvx +video/x-msvideo avi +video/x-sgi-movie movie + +x-conference/x-cooltalk ice + +x-world/x-vrml vrm vrml wrl diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options new file mode 100644 index 00000000000..32ffd873937 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/osgi-debug.options @@ -0,0 +1,95 @@ +#### Debugging options for org.eclipse.osgi + +# Turn on general debugging for org.eclipse.osgi +org.eclipse.osgi/debug=true +# Prints out class loading debug information +org.eclipse.osgi/debug/loader=false +# Prints out event (FrameworkEvent/BundleEvent/ServiceEvent) and listener debug information +org.eclipse.osgi/debug/events=false +# Prints out OSGi service debug information (registration/getting/ungetting etc.) +org.eclipse.osgi/debug/services=false +# Prints out bundle manifest parsing debug information +org.eclipse.osgi/debug/manifest=false +# Prints out LDAP filter debug information +org.eclipse.osgi/debug/filter=false +# Prints out security (PermissionAdmin service) debug information +org.eclipse.osgi/debug/security=false +# Prints out start level service debug information +org.eclipse.osgi/debug/startlevel=true +# Prints out package admin service debug information +org.eclipse.osgi/debug/packageadmin=false +# Prints out timing information for bundle activation +org.eclipse.osgi/debug/bundleTime=false +# Debug the loading of message bundles +org.eclipse.osgi/debug/messageBundles=false + +# Eclipse adaptor options +org.eclipse.osgi/eclipseadaptor/debug = false +org.eclipse.osgi/eclipseadaptor/debug/location = false +org.eclipse.osgi/eclipseadaptor/debug/platformadmin=false +org.eclipse.osgi/eclipseadaptor/debug/platformadmin/resolver=false +org.eclipse.osgi/eclipseadaptor/converter/debug = false + +### OSGi resolver options +# Turns on debugging for the resolver +org.eclipse.osgi/resolver/debug = false +# Prints out wiring information after the resolver has completed the resolve process +org.eclipse.osgi/resolver/wiring = false +# Prints out Import-Package information +org.eclipse.osgi/resolver/imports = false +# Prints out Require-Bundle information +org.eclipse.osgi/resolver/requires = false +# Prints out package grouping information form the "uses" clause +org.eclipse.osgi/resolver/grouping = false +# Prints out cycle information +org.eclipse.osgi/resolver/cycles = false +# Prints out Eclipse-GenericRequire information +org.eclipse.osgi/resolver/generics = false + +#### Profile settings +org.eclipse.osgi/profile/startup = false +org.eclipse.osgi/profile/benchmark = false +org.eclipse.osgi/profile/debug = true + +# Override the default implemenation +org.eclipse.osgi/profile/impl = org.eclipse.osgi.internal.profile.DefaultProfileLogger + +# Append all profile messages to the filename specified +org.eclipse.osgi/defaultprofile/logfilename = + +# Output all profile log messages synchronously to the jvm console. +# By default, all log messages are cached until the log buffer is +# requested. +org.eclipse.osgi/defaultprofile/logsynchronously = false + +# Specify the size of the default profile implementation log buffer. +org.eclipse.osgi/defaultprofile/buffersize = 256 + +#### Monitoring settings +# monitor class loading +org.eclipse.osgi/monitor/classes=false + +# monitor bundle activation +org.eclipse.osgi/monitor/activation=false + +# monitor resource bundle (*.properties) loading +org.eclipse.osgi/monitor/resources=false + + +#### Trace settings +# trace class loading - snapshot the execution stack when a class is loaded +org.eclipse.osgi/trace/classLoading=false + +# trace location - file in which execution traces are written +org.eclipse.osgi/trace/filename=runtime.traces + +# trace filters - Java properties file defining which classes should +# be traced (if trace/classLoading is true) +# File format: +# plugins= +# packages= +# Note that there may be many 'plugins' and 'packages' lines in one file. +org.eclipse.osgi/trace/filters=trace.properties + +# trace bundle activation - snapshot the execution stack when a bundle is activated +org.eclipse.osgi/trace/activation=false diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/tasks-config.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/tasks-config.xml new file mode 100644 index 00000000000..d5a392ca82a --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/etc/tasks-config.xml @@ -0,0 +1,69 @@ + + + + + + STANDALONE + + + 2 + + + + org.wso2.carbon.ntask.core.impl.RoundRobinTaskLocationResolver + + + + + + + https://localhost:9448 + + + https://localhost:9443 + + + admin + + + admin + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/log4j.properties b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/log4j.properties new file mode 100644 index 00000000000..32f8b97483c --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/log4j.properties @@ -0,0 +1,30 @@ +# +# Copyright 2023 WSO2, Inc. (http://wso2.com) +# +# Licensed 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. +# +log4j.rootLogger=DEBUG, console, Default +#Automation file appender +log4j.appender.Default=org.apache.log4j.RollingFileAppender +log4j.appender.Default.File=target/logs/automation.log +log4j.appender.Default.Append=true +log4j.appender.Default.MaxFileSize=10MB +log4j.appender.Default.MaxBackupIndex=10 +log4j.appender.Default.layout=org.apache.log4j.PatternLayout +log4j.appender.Default.layout.ConversionPattern=%d{ISO8601} %-5p [%c] [%t] - %m%n +#Automation console appender +log4j.appender.console=org.apache.log4j.ConsoleAppender +log4j.appender.console.Target=System.out +log4j.appender.console.layout=org.apache.log4j.PatternLayout +log4j.appender.console.layout.ConversionPattern=%d{ISO8601} %-5p [%c] [%t] - %m%n +log4j.logger.io.entgra=TRACE \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/registry.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/registry.xml new file mode 100644 index 00000000000..944d391ea78 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/registry.xml @@ -0,0 +1,108 @@ + + + + + + + + wso2registry + false + true + / + + + jdbc:h2:./target/databasetest/CARBON_TEST + + org.h2.Driver + 80 + 60000 + 5 + + + + + + + + + + + + false + + + + true + true + true + true + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/security/authenticators.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/security/authenticators.xml new file mode 100644 index 00000000000..674e8149fcd --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/security/authenticators.xml @@ -0,0 +1,75 @@ + + + + + + + + + + 5 + + + + + 10 + + /carbon/admin/login.jsp + carbonServer + https://localhost:9443/samlsso + urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml new file mode 100644 index 00000000000..ac237a2b3ad --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/META-INF/context.xml @@ -0,0 +1,36 @@ + + + + + + + WEB-INF/web.xml + + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml new file mode 100644 index 00000000000..3288cfb01c5 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/carbon/WEB-INF/web.xml @@ -0,0 +1,62 @@ + + + + + + + bridgeservlet + Carbon Bridge Servlet + Carbon Bridge Servlet + org.wso2.carbon.tomcat.ext.servlet.DelegationServlet + + 1 + + + bridgeservlet + /* + + + + bridgeservlet + *.jsp + + + + + CharsetFilter + org.wso2.carbon.tomcat.ext.filter.CharacterSetFilter + + requestEncoding + UTF-8 + + + + + CharsetFilter + /* + + + + 15 + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml new file mode 100644 index 00000000000..5ba201f26d3 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/catalina-server.xml @@ -0,0 +1,99 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml new file mode 100644 index 00000000000..1df2d7e53a7 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/tomcat-users.xml @@ -0,0 +1,35 @@ + + + + + + + + + + + + + + \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/web.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/web.xml new file mode 100644 index 00000000000..765febb1add --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/tomcat/web.xml @@ -0,0 +1,1223 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + default + org.apache.catalina.servlets.DefaultServlet + + debug + 0 + + + sendfileSize + -1 + + + listings + false + + 1 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jsp + org.apache.jasper.servlet.JspServlet + + fork + false + + + xpoweredBy + false + + 3 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + jsp + *.jsp + + + + jsp + *.jspx + + + + default + / + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 30 + + + + + + + + + + + + abs + audio/x-mpeg + + + ai + application/postscript + + + aif + audio/x-aiff + + + aifc + audio/x-aiff + + + aiff + audio/x-aiff + + + aim + application/x-aim + + + art + image/x-jg + + + asf + video/x-ms-asf + + + asx + video/x-ms-asf + + + au + audio/basic + + + avi + video/x-msvideo + + + avx + video/x-rad-screenplay + + + bcpio + application/x-bcpio + + + bin + application/octet-stream + + + bmp + image/bmp + + + body + text/html + + + cdf + application/x-cdf + + + cer + application/x-x509-ca-cert + + + class + application/java + + + cpio + application/x-cpio + + + csh + application/x-csh + + + css + text/css + + + dib + image/bmp + + + doc + application/msword + + + dtd + application/xml-dtd + + + dv + video/x-dv + + + dvi + application/x-dvi + + + eps + application/postscript + + + etx + text/x-setext + + + exe + application/octet-stream + + + gif + image/gif + + + gtar + application/x-gtar + + + gz + application/x-gzip + + + hdf + application/x-hdf + + + hqx + application/mac-binhex40 + + + htc + text/x-component + + + htm + text/html + + + html + text/html + + + ief + image/ief + + + jad + text/vnd.sun.j2me.app-descriptor + + + jar + application/java-archive + + + java + text/plain + + + jnlp + application/x-java-jnlp-file + + + jpe + image/jpeg + + + jpeg + image/jpeg + + + jpg + image/jpeg + + + js + application/javascript + + + jsf + text/plain + + + jspf + text/plain + + + kar + audio/x-midi + + + latex + application/x-latex + + + m3u + audio/x-mpegurl + + + mac + image/x-macpaint + + + man + application/x-troff-man + + + mathml + application/mathml+xml + + + me + application/x-troff-me + + + mid + audio/x-midi + + + midi + audio/x-midi + + + mif + application/x-mif + + + mov + video/quicktime + + + movie + video/x-sgi-movie + + + mp1 + audio/x-mpeg + + + mp2 + audio/x-mpeg + + + mp3 + audio/x-mpeg + + + mp4 + video/mp4 + + + mpa + audio/x-mpeg + + + mpe + video/mpeg + + + mpeg + video/mpeg + + + mpega + audio/x-mpeg + + + mpg + video/mpeg + + + mpv2 + video/mpeg2 + + + ms + application/x-wais-source + + + nc + application/x-netcdf + + + oda + application/oda + + + + odb + application/vnd.oasis.opendocument.database + + + + odc + application/vnd.oasis.opendocument.chart + + + + odf + application/vnd.oasis.opendocument.formula + + + + odg + application/vnd.oasis.opendocument.graphics + + + + odi + application/vnd.oasis.opendocument.image + + + + odm + application/vnd.oasis.opendocument.text-master + + + + odp + application/vnd.oasis.opendocument.presentation + + + + ods + application/vnd.oasis.opendocument.spreadsheet + + + + odt + application/vnd.oasis.opendocument.text + + + + otg + application/vnd.oasis.opendocument.graphics-template + + + + oth + application/vnd.oasis.opendocument.text-web + + + + otp + application/vnd.oasis.opendocument.presentation-template + + + + ots + application/vnd.oasis.opendocument.spreadsheet-template + + + + ott + application/vnd.oasis.opendocument.text-template + + + + ogx + application/ogg + + + ogv + video/ogg + + + oga + audio/ogg + + + ogg + audio/ogg + + + spx + audio/ogg + + + flac + audio/flac + + + anx + application/annodex + + + axa + audio/annodex + + + axv + video/annodex + + + xspf + application/xspf+xml + + + pbm + image/x-portable-bitmap + + + pct + image/pict + + + pdf + application/pdf + + + pgm + image/x-portable-graymap + + + pic + image/pict + + + pict + image/pict + + + pls + audio/x-scpls + + + png + image/png + + + pnm + image/x-portable-anymap + + + pnt + image/x-macpaint + + + ppm + image/x-portable-pixmap + + + ppt + application/vnd.ms-powerpoint + + + pps + application/vnd.ms-powerpoint + + + ps + application/postscript + + + psd + image/x-photoshop + + + qt + video/quicktime + + + qti + image/x-quicktime + + + qtif + image/x-quicktime + + + ras + image/x-cmu-raster + + + rdf + application/rdf+xml + + + rgb + image/x-rgb + + + rm + application/vnd.rn-realmedia + + + roff + application/x-troff + + + rtf + application/rtf + + + rtx + text/richtext + + + sh + application/x-sh + + + shar + application/x-shar + + + + smf + audio/x-midi + + + sit + application/x-stuffit + + + snd + audio/basic + + + src + application/x-wais-source + + + sv4cpio + application/x-sv4cpio + + + sv4crc + application/x-sv4crc + + + svg + image/svg+xml + + + svgz + image/svg+xml + + + swf + application/x-shockwave-flash + + + t + application/x-troff + + + tar + application/x-tar + + + tcl + application/x-tcl + + + tex + application/x-tex + + + texi + application/x-texinfo + + + texinfo + application/x-texinfo + + + tif + image/tiff + + + tiff + image/tiff + + + tr + application/x-troff + + + tsv + text/tab-separated-values + + + txt + text/plain + + + ulw + audio/basic + + + ustar + application/x-ustar + + + vxml + application/voicexml+xml + + + xbm + image/x-xbitmap + + + xht + application/xhtml+xml + + + xhtml + application/xhtml+xml + + + xls + application/vnd.ms-excel + + + xml + application/xml + + + xpm + image/x-xpixmap + + + xsl + application/xml + + + xslt + application/xslt+xml + + + xul + application/vnd.mozilla.xul+xml + + + xwd + image/x-xwindowdump + + + vsd + application/x-visio + + + wav + audio/x-wav + + + + wbmp + image/vnd.wap.wbmp + + + + wml + text/vnd.wap.wml + + + + wmlc + application/vnd.wap.wmlc + + + + wmls + text/vnd.wap.wmlscript + + + + wmlscriptc + application/vnd.wap.wmlscriptc + + + wmv + video/x-ms-wmv + + + wrl + x-world/x-vrml + + + wspolicy + application/wspolicy+xml + + + Z + application/x-compress + + + z + application/x-compress + + + zip + application/zip + + + + + + + + + + + + + + + + + + index.html + index.htm + index.jsp + + + \ No newline at end of file diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/user-mgt.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/user-mgt.xml new file mode 100644 index 00000000000..d54f7bbbf66 --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/carbon-home/repository/conf/user-mgt.xml @@ -0,0 +1,382 @@ + + + + + + true + admin + + admin + admin + + everyone + jdbc/WSO2CarbonDB + + + + + + + org.wso2.carbon.user.core.tenant.JDBCTenantManager + false + 100 + false + default + SHA-256 + true + true + true + false + ^[\S]{5,30}$ + Password length should be between 5 to 30 characters + + ^[\S]{5,30}$ + [a-zA-Z0-9._-|//]{3,30}$ + ^[\S]{3,30}$ + ^[^~!#$;%^*+={}\\|\\\\<>,\'\"]{3,30}$ + ^[\S]{3,30}$ + true + 100 + 100 + false + false + true + , + true + + + + + + + + + + + + + + + + + + + /permission + true + true + + + + + diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/testng.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/testng.xml new file mode 100644 index 00000000000..c245837db6f --- /dev/null +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/src/test/resources/testng.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/components/subtype-mgt/pom.xml b/components/subtype-mgt/pom.xml new file mode 100644 index 00000000000..063cd9e7674 --- /dev/null +++ b/components/subtype-mgt/pom.xml @@ -0,0 +1,38 @@ + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.25-SNAPSHOT + ../../pom.xml + + + 4.0.0 + subtype-mgt + pom + Entgra IoT - Subtype Mgt + http://entgra.io + + + io.entgra.device.mgt.subtype.mgt + + + \ No newline at end of file diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql index 960fedcc20a..30ef1d7d79b 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/h2.sql @@ -788,6 +788,17 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( ); -- END OF DYNAMIC TASK TABLE-- +-- DM_DEVICE_SUB_TYPE TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +); +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + -- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( ID INT NOT NULL AUTO_INCREMENT, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql index c8b809ae48b..af29b96e1aa 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mssql.sql @@ -772,6 +772,18 @@ CREATE TABLE DYNAMIC_TASK_PROPERTIES ( ); -- END OF DYNAMIC TASK TABLE-- +-- DM_DEVICE_SUB_TYPE TABLE-- +IF NOT EXISTS (SELECT * FROM SYS.OBJECTS WHERE OBJECT_ID = OBJECT_ID(N'[DBO].[DM_DEVICE_SUB_TYPE]') AND TYPE IN (N'U')) +CREATE TABLE DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +); +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + -- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( ID INT NOT NULL IDENTITY(1,1), diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql index 4981e158705..afebcf6150c 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/mysql.sql @@ -852,6 +852,17 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- +-- DM_DEVICE_SUB_TYPE TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +) ENGINE=InnoDB; +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + -- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( ID INT NOT NULL AUTO_INCREMENT, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql index 10554077ab6..73dcb320b4a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/oracle.sql @@ -1120,6 +1120,17 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- +-- DM_DEVICE_SUB_TYPE TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +) ENGINE=InnoDB; +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + -- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- CREATE TABLE DM_TRACCAR_UNSYNCED_DEVICES ( ID NUMBER(10) NOT NULL, diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql index dca570ebf05..530083d967a 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/src/main/resources/dbscripts/cdm/postgresql.sql @@ -773,6 +773,18 @@ CREATE TABLE IF NOT EXISTS DYNAMIC_TASK_PROPERTIES ( ) ENGINE=InnoDB; -- END OF DYNAMIC TASK TABLE-- + +-- DM_DEVICE_SUB_TYPE TABLE-- +CREATE TABLE IF NOT EXISTS DM_DEVICE_SUB_TYPE ( + TENANT_ID INT DEFAULT 0, + SUB_TYPE_ID VARCHAR(45) NOT NULL, + DEVICE_TYPE VARCHAR(25) NOT NULL, + SUB_TYPE_NAME VARCHAR(45) NOT NULL, + TYPE_DEFINITION TEXT NOT NULL, + PRIMARY KEY (SUB_TYPE_ID,DEVICE_TYPE) +) ENGINE=InnoDB; +-- END OF DM_DEVICE_SUB_TYPE TABLE-- + -- DM_TRACCAR_UNSYNCED_DEVICES TABLE -- CREATE TABLE IF NOT EXISTS DM_TRACCAR_UNSYNCED_DEVICES ( ID SERIAL NOT NULL, diff --git a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml new file mode 100644 index 00000000000..e6d23c6d088 --- /dev/null +++ b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml @@ -0,0 +1,106 @@ + + + + + + + org.wso2.carbon.devicemgt + carbon-devicemgt + 5.0.25-SNAPSHOT + ../../../pom.xml + + + 4.0.0 + io.entgra.device.mgt.subtype.mgt.feature + pom + Entgra IoT - Subtype Management Feature Impl + http://entgra.io + + This feature contains the core bundles required for Subtype management functionality + + + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.subtype.mgt + + + + + + + maven-resources-plugin + 2.6 + + + copy-resources + generate-resources + + copy-resources + + + src/main/resources + + + resources + + build.properties + p2.inf + + + + + + + + + org.wso2.maven + carbon-p2-plugin + ${carbon.p2.plugin.version} + + + p2-feature-generation + package + + p2-feature-gen + + + io.entgra.device.mgt.subtype.mgt + ../../etc/feature.properties + + + org.wso2.carbon.p2.category.type:server + + org.eclipse.equinox.p2.type.group:true + + + + + + org.wso2.carbon.devicemgt:io.entgra.device.mgt.subtype.mgt:${carbon.device.mgt.version} + + + + + + + + + diff --git a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/build.properties b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/build.properties new file mode 100644 index 00000000000..9c86577d768 --- /dev/null +++ b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/build.properties @@ -0,0 +1 @@ +custom = true diff --git a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/p2.inf b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/p2.inf new file mode 100644 index 00000000000..7ab37b9d7d7 --- /dev/null +++ b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/src/main/resources/p2.inf @@ -0,0 +1 @@ +instructions.configure = \ \ No newline at end of file diff --git a/features/subtype-mgt/pom.xml b/features/subtype-mgt/pom.xml new file mode 100644 index 00000000000..96f3ae4aadc --- /dev/null +++ b/features/subtype-mgt/pom.xml @@ -0,0 +1,40 @@ + + + + + + + carbon-devicemgt + org.wso2.carbon.devicemgt + 5.0.25-SNAPSHOT + ../../pom.xml + + + 4.0.0 + subtype-mgt-feature + pom + Entgra IoT - Subtype Management Feature + http://entgra.io + + + io.entgra.device.mgt.subtype.mgt.feature + + + diff --git a/pom.xml b/pom.xml index 7eee718846b..b7c402aeb83 100644 --- a/pom.xml +++ b/pom.xml @@ -48,6 +48,7 @@ components/webapp-authenticator-framework components/logger components/task-mgt + components/subtype-mgt components/tenant-mgt features/device-mgt features/apimgt-extensions @@ -63,6 +64,7 @@ features/webapp-authenticator-framework features/logger features/task-mgt + features/subtype-mgt features/tenant-mgt @@ -406,6 +408,20 @@ ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.subtype.mgt + ${carbon.device.mgt.version} + + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.subtype.mgt.feature + zip + ${carbon.device.mgt.version} + + + org.wso2.carbon @@ -2146,6 +2162,10 @@ 1.1.wso2v1 1.9.0 + + 20220924 + 2.4.5 + 1.60.0.wso2v1 1.60.0.wso2v1 From 71007cc03ceb470e6efb3e636afb243b1d5090bb Mon Sep 17 00:00:00 2001 From: builder Date: Wed, 26 Apr 2023 09:20:33 +0530 Subject: [PATCH 04/22] [maven-release-plugin] prepare release v5.0.25 --- .../io.entgra.analytics.mgt.grafana.proxy.api/pom.xml | 2 +- .../io.entgra.analytics.mgt.grafana.proxy.common/pom.xml | 2 +- .../io.entgra.analytics.mgt.grafana.proxy.core/pom.xml | 2 +- components/analytics-mgt/grafana-mgt/pom.xml | 2 +- components/analytics-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.annotations/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.application.extension/pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension/pom.xml | 2 +- .../org.wso2.carbon.apimgt.webapp.publisher/pom.xml | 2 +- components/apimgt-extensions/pom.xml | 2 +- .../io.entgra.application.mgt.addons/pom.xml | 2 +- .../application-mgt/io.entgra.application.mgt.api/pom.xml | 2 +- .../io.entgra.application.mgt.common/pom.xml | 2 +- .../application-mgt/io.entgra.application.mgt.core/pom.xml | 2 +- .../io.entgra.application.mgt.publisher.api/pom.xml | 2 +- .../io.entgra.application.mgt.store.api/pom.xml | 2 +- components/application-mgt/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.api/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.core/pom.xml | 2 +- components/certificate-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../io.entgra.device.mgt.extensions.logger/pom.xml | 2 +- .../io.entgra.device.mgt.extensions.stateengine/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- components/device-mgt-extensions/pom.xml | 2 +- .../io.entgra.carbon.device.mgt.config.api/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.api/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.common/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.extensions/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.url.printer/pom.xml | 2 +- components/device-mgt/pom.xml | 2 +- .../io.entgra.server.bootup.heartbeat.beacon/pom.xml | 2 +- components/heartbeat-management/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.oauth.extensions/pom.xml | 2 +- .../org.wso2.carbon.identity.jwt.client.extension/pom.xml | 2 +- components/identity-extensions/pom.xml | 2 +- components/logger/io.entgra.notification.logger/pom.xml | 2 +- components/logger/pom.xml | 2 +- .../org.wso2.carbon.policy.decision.point/pom.xml | 2 +- .../org.wso2.carbon.policy.information.point/pom.xml | 2 +- .../policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml | 2 +- .../policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml | 2 +- components/policy-mgt/pom.xml | 2 +- .../subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml | 5 ++--- components/subtype-mgt/pom.xml | 5 ++--- components/task-mgt/pom.xml | 2 +- .../task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml | 2 +- .../task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml | 2 +- components/task-mgt/task-manager/pom.xml | 2 +- .../task-watcher/io.entgra.task.mgt.watcher/pom.xml | 2 +- components/task-mgt/task-watcher/pom.xml | 2 +- components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml | 6 ++---- components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml | 6 ++---- components/tenant-mgt/pom.xml | 6 ++---- .../email-sender/org.wso2.carbon.email.sender.core/pom.xml | 2 +- components/transport-mgt/email-sender/pom.xml | 2 +- components/transport-mgt/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.api/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.common/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.core/pom.xml | 2 +- components/transport-mgt/sms-handler/pom.xml | 2 +- .../io.entgra.ui.request.interceptor/pom.xml | 2 +- components/ui-request-interceptor/pom.xml | 2 +- .../org.wso2.carbon.webapp.authenticator.framework/pom.xml | 2 +- components/webapp-authenticator-framework/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- features/analytics-mgt/grafana-mgt/pom.xml | 2 +- features/analytics-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml | 2 +- .../org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml | 2 +- features/apimgt-extensions/pom.xml | 2 +- .../io.entgra.application.mgt.api.feature/pom.xml | 2 +- .../io.entgra.application.mgt.server.feature/pom.xml | 2 +- features/application-mgt/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.api.feature/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.server.feature/pom.xml | 2 +- features/certificate-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../io.entgra.device.mgt.extensions.logger.feature/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- features/device-mgt-extensions/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.api.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.basics.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.extensions.feature/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.server.feature/pom.xml | 2 +- features/device-mgt/pom.xml | 2 +- .../io.entgra.server.heart.beat.feature/pom.xml | 2 +- features/heartbeat-management/pom.xml | 2 +- .../pom.xml | 2 +- features/jwt-client/pom.xml | 2 +- .../logger/io.entgra.notification.logger.feature/pom.xml | 2 +- features/logger/pom.xml | 2 +- .../org.wso2.carbon.policy.mgt.server.feature/pom.xml | 2 +- features/policy-mgt/pom.xml | 2 +- .../io.entgra.device.mgt.subtype.mgt.feature/pom.xml | 5 ++--- features/subtype-mgt/pom.xml | 5 ++--- features/task-mgt/io.entgra.task.mgt.feature/pom.xml | 2 +- features/task-mgt/pom.xml | 2 +- .../tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml | 6 ++---- features/tenant-mgt/pom.xml | 2 +- .../org.wso2.carbon.email.sender.feature/pom.xml | 2 +- features/transport-mgt/email-sender/pom.xml | 2 +- features/transport-mgt/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.api.feature/pom.xml | 2 +- .../pom.xml | 2 +- features/transport-mgt/sms-handler/pom.xml | 2 +- .../io.entgra.ui.request.interceptor.feature/pom.xml | 2 +- features/ui-request-interceptor/pom.xml | 2 +- .../pom.xml | 2 +- features/webapp-authenticator-framework/pom.xml | 2 +- pom.xml | 6 +++--- 131 files changed, 141 insertions(+), 153 deletions(-) diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml index b0bb0b1788c..f74a1d08801 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml index b48dfaad138..d2610de9fb3 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml index dc7de957147..e84d5ee565e 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index dec81b3aa51..3c858ad42fd 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index 7722cd48682..3b385ccefb0 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml index c4dbc2d8342..1e943eb93c3 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml @@ -20,7 +20,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 147df32e6a3..603d58d9c15 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index eae69d7327b..d38fe0e8492 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 9634e1ffe00..7612b6a2e6b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml index 2716ef61dee..c715d1dbb15 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml index c5db4f8668b..3480848e1e5 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 3289983dd2e..53fe085988a 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 5d84e68023e..2885a51721a 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml index 95d6aaeeffc..f5660866bff 100644 --- a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml @@ -20,7 +20,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.api/pom.xml index 0b4be779e1d..71c12b9c7ce 100644 --- a/components/application-mgt/io.entgra.application.mgt.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.application.mgt.common/pom.xml index 35e4696bda4..c6ac2003423 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.application.mgt.core/pom.xml index 43ea757d71d..e2e54a8ac8f 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml index b10691e62cb..f129a61277c 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml index 1ca97cfc0ea..073a4360c5f 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index ef99d4dbf9f..a36ff45b4b1 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 3794a693414..6ac41a449e2 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index 05fd5a7ae62..e012c947253 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index daa86010f3f..9c2c252c6ce 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.devicemgt certificate-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index 577a4ff1f40..b305c96b599 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml index 5311acc66c1..8c93ceef4d1 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml index 53ec6cf0e66..c4d827240fc 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml index 224941c71d3..747f4fc70a4 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 2cc77447ed5..34bc10a2091 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index cd95a6fe391..ce84a89a126 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index fe857c4bcfa..eab9ddf49cb 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index a5c33e4a3a1..bfd1500e287 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 3e9bf65388a..1a0d77c144b 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index d07439f4f4b..7b48c6fb540 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 2f906d4fcdc..95472f963ca 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml index 356ab22c755..6d43ffd85e5 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index 7077d976727..be0ab829d73 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index a93ef7f3ad0..c5d026d27df 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index 1265503f186..ece6b4cc02e 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 2a420a91ef4..10b8e9997a5 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index a110b174ac0..833d4779181 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index 251617c2372..f1abf7f0613 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index 08e44848251..4dc1a3ca4a4 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heartbeat-management - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index a35a88f848f..68e8b9bd21c 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index 699a82cc62c..f87517fb0c8 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index 190eabc7851..f2f9c80019c 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index a217060c943..15563645993 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index 4cafda1771f..e8a589a226a 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger - 5.0.25-SNAPSHOT + 5.0.25 io.entgra.notification.logger diff --git a/components/logger/pom.xml b/components/logger/pom.xml index 6ca86be582e..f00b30ef0ea 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index 82dc852bed7..aa24a96a297 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index 290b78bee65..28c82cdad1f 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index 06d4ec3256c..240c6526858 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 715349438d0..73569a10cc8 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index 6cdec66ca3a..ba3256b8cb8 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml index 905ed65f0f8..8a83dade4fd 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml @@ -16,12 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + org.wso2.carbon.devicemgt subtype-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/subtype-mgt/pom.xml b/components/subtype-mgt/pom.xml index 063cd9e7674..685d8a70924 100644 --- a/components/subtype-mgt/pom.xml +++ b/components/subtype-mgt/pom.xml @@ -16,12 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml index 1d7fc8d2efe..52c12193a9a 100755 --- a/components/task-mgt/pom.xml +++ b/components/task-mgt/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml index cc8bd843401..034a212353b 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml @@ -20,7 +20,7 @@ task-manager org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml index 897f9a612b2..e37eac0ac88 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-manager - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/task-mgt/task-manager/pom.xml b/components/task-mgt/task-manager/pom.xml index 6edd1e33dcd..df1f091f331 100755 --- a/components/task-mgt/task-manager/pom.xml +++ b/components/task-mgt/task-manager/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml index 21fea0cd512..3a0d7ae10b5 100755 --- a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-watcher - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/task-mgt/task-watcher/pom.xml b/components/task-mgt/task-watcher/pom.xml index 005dbeed265..f915dc579b1 100755 --- a/components/task-mgt/task-watcher/pom.xml +++ b/components/task-mgt/task-watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml index b69c2bb112d..0ca08ff3658 100644 --- a/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml +++ b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml @@ -16,13 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + tenant-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml index a91e831ed5e..fb207fd72ad 100644 --- a/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml @@ -16,13 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + tenant-mgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/tenant-mgt/pom.xml b/components/tenant-mgt/pom.xml index 7d13f340c8b..21a623e39e4 100644 --- a/components/tenant-mgt/pom.xml +++ b/components/tenant-mgt/pom.xml @@ -16,13 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 7bdf9922499..3b5f0c58fc4 100644 --- a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index 35c8d36c064..2deb9dec3a8 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index 69f1f2b02f1..5d101e542c2 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml index 1bc860ed3d5..3b6a9a15bdd 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml index 908957c988b..96686e5fbbd 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml index 0a64c24297b..f79e0e1304d 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index 60742becc62..d2889df91f3 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index b4c89c0eaa9..c5a4f55d1da 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 4.0.0 diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 692ea269775..49a1a7398b4 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 8f23a1cb63a..4394d61d4a4 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index 266aa06eb64..f253e90eea1 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml index 0f8eef62926..d9b5b0d2a11 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml index f63f0dab760..d5cb525a8f4 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index 198de84f7a7..28795bddc11 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index 0782957fd11..398cdcbff7a 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml index 6703c23a7db..4075d99e35d 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index ab7dad3cd44..a55b894cb59 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml index 5f7c41c612a..eefb3d4fd33 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index 2fbefd84571..2040e5154d3 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 950a6bb76d8..9be30cfb0c4 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml index b65017bbdbe..5b5e66d9b01 100644 --- a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml index f1d0f4ae1c6..c5b32a54acd 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index a8c8e7d1f00..807f6ed9a31 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index dd5b7736bc7..a92cbe4fe9a 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index 10bccb16ceb..e55e753c7c4 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index d9cc05af65e..fada447f19a 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index e8ab115dd78..826e51ee93e 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml index c5a49e83967..ea9cf23db6b 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml index 213f436a611..5bc42eae1de 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml index ce45313eda1..5f43d24ce16 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index e236aa89143..acdf8c282d0 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 0f6a8c9df95..888a863a272 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index 6cfddf491cf..39bf6577fb2 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index 6ba02faac50..35fdff48a3b 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index 1a9beb136e8..422e23195fd 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index bdfa204a195..db161cd47e0 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index c16be537ad4..bdfcf93d891 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 7e4c7203c60..51e9c25fb83 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index 2128ddce783..d36d2f187d6 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,7 +4,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index 463215e1734..c56b01442a4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index 63b3a3229c8..dbbeabe660e 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index 11f50bc7d7f..82798be5b4c 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 31a16abe9ce..3b3992aa7e6 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heart-beat-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index 38eb878036d..701c7837eaf 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index 2425ea317f1..c180f6a68cd 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt jwt-client-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index 7dafdc71354..8de990c3e93 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml index d897352777a..49396a6eaa3 100644 --- a/features/logger/io.entgra.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/logger/pom.xml b/features/logger/pom.xml index fbfdbc7656a..a887f1b624e 100644 --- a/features/logger/pom.xml +++ b/features/logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index c08fc4052be..77cda40df15 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index c36d7e00249..4826354966e 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml index e6d23c6d088..e3cc7fb122a 100644 --- a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml +++ b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml @@ -17,13 +17,12 @@ ~ under the License. --> - + org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../../pom.xml diff --git a/features/subtype-mgt/pom.xml b/features/subtype-mgt/pom.xml index 96f3ae4aadc..dbc40f06dc0 100644 --- a/features/subtype-mgt/pom.xml +++ b/features/subtype-mgt/pom.xml @@ -17,13 +17,12 @@ ~ under the License. --> - + carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml index 16bc2d57232..fd50e447d62 100755 --- a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml +++ b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../../pom.xml diff --git a/features/task-mgt/pom.xml b/features/task-mgt/pom.xml index 3678b617ad0..7229a4983f5 100755 --- a/features/task-mgt/pom.xml +++ b/features/task-mgt/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml index 87e3214a433..9c2b69a1f5a 100644 --- a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml +++ b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml @@ -16,13 +16,11 @@ ~ specific language governing permissions and limitations ~ under the License. --> - + tenant-mgt-feature org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/tenant-mgt/pom.xml b/features/tenant-mgt/pom.xml index 44befb42404..ef1ec06c846 100644 --- a/features/tenant-mgt/pom.xml +++ b/features/tenant-mgt/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index b05bb2be06a..9a5a000af72 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index 8e790a71228..573147280c9 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index c80b5988944..e5cad84b922 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml index 512ca7a4c33..47253acbca4 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml index 8d6c87d7362..435fb08aa54 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index e9039888d31..642b3fd0fbb 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml index 1bd46be14b6..91cf1cf9687 100644 --- a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index 8a01acd528b..2f32271b659 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index 218e08e58ea..db58ecd12e1 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 5.0.25-SNAPSHOT + 5.0.25 ../pom.xml diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index bade36ba10c..af16f346370 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25-SNAPSHOT + 5.0.25 ../../pom.xml diff --git a/pom.xml b/pom.xml index b7c402aeb83..662effdbe24 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 5.0.25-SNAPSHOT + 5.0.25 WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -1918,7 +1918,7 @@ https://repository.entgra.net/community/device-mgt-core.git scm:git:https://repository.entgra.net/community/device-mgt-core.git scm:git:https://repository.entgra.net/community/device-mgt-core.git - HEAD + v5.0.25 @@ -2130,7 +2130,7 @@ 1.2.11.wso2v10 - 5.0.25-SNAPSHOT + 5.0.25 4.7.35 From fa7ee67aed18ac915083b235f4ed2ad4c08c08ac Mon Sep 17 00:00:00 2001 From: builder Date: Wed, 26 Apr 2023 09:20:38 +0530 Subject: [PATCH 05/22] [maven-release-plugin] prepare for next development iteration --- .../io.entgra.analytics.mgt.grafana.proxy.api/pom.xml | 2 +- .../io.entgra.analytics.mgt.grafana.proxy.common/pom.xml | 2 +- .../io.entgra.analytics.mgt.grafana.proxy.core/pom.xml | 2 +- components/analytics-mgt/grafana-mgt/pom.xml | 2 +- components/analytics-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.annotations/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.application.extension/pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension/pom.xml | 2 +- .../org.wso2.carbon.apimgt.webapp.publisher/pom.xml | 2 +- components/apimgt-extensions/pom.xml | 2 +- .../io.entgra.application.mgt.addons/pom.xml | 2 +- .../application-mgt/io.entgra.application.mgt.api/pom.xml | 2 +- .../io.entgra.application.mgt.common/pom.xml | 2 +- .../application-mgt/io.entgra.application.mgt.core/pom.xml | 2 +- .../io.entgra.application.mgt.publisher.api/pom.xml | 2 +- .../io.entgra.application.mgt.store.api/pom.xml | 2 +- components/application-mgt/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.api/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.core/pom.xml | 2 +- components/certificate-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../io.entgra.device.mgt.extensions.logger/pom.xml | 2 +- .../io.entgra.device.mgt.extensions.stateengine/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- components/device-mgt-extensions/pom.xml | 2 +- .../io.entgra.carbon.device.mgt.config.api/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.api/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.common/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.core/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.extensions/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.url.printer/pom.xml | 2 +- components/device-mgt/pom.xml | 2 +- .../io.entgra.server.bootup.heartbeat.beacon/pom.xml | 2 +- components/heartbeat-management/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.oauth.extensions/pom.xml | 2 +- .../org.wso2.carbon.identity.jwt.client.extension/pom.xml | 2 +- components/identity-extensions/pom.xml | 2 +- components/logger/io.entgra.notification.logger/pom.xml | 2 +- components/logger/pom.xml | 2 +- .../org.wso2.carbon.policy.decision.point/pom.xml | 2 +- .../org.wso2.carbon.policy.information.point/pom.xml | 2 +- .../policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml | 2 +- .../policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml | 2 +- components/policy-mgt/pom.xml | 2 +- .../subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml | 2 +- components/subtype-mgt/pom.xml | 2 +- components/task-mgt/pom.xml | 2 +- .../task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml | 2 +- .../task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml | 2 +- components/task-mgt/task-manager/pom.xml | 2 +- .../task-watcher/io.entgra.task.mgt.watcher/pom.xml | 2 +- components/task-mgt/task-watcher/pom.xml | 2 +- components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml | 2 +- components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml | 2 +- components/tenant-mgt/pom.xml | 2 +- .../email-sender/org.wso2.carbon.email.sender.core/pom.xml | 2 +- components/transport-mgt/email-sender/pom.xml | 2 +- components/transport-mgt/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.api/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.common/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.core/pom.xml | 2 +- components/transport-mgt/sms-handler/pom.xml | 2 +- .../io.entgra.ui.request.interceptor/pom.xml | 2 +- components/ui-request-interceptor/pom.xml | 2 +- .../org.wso2.carbon.webapp.authenticator.framework/pom.xml | 2 +- components/webapp-authenticator-framework/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- features/analytics-mgt/grafana-mgt/pom.xml | 2 +- features/analytics-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml | 2 +- .../org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml | 2 +- features/apimgt-extensions/pom.xml | 2 +- .../io.entgra.application.mgt.api.feature/pom.xml | 2 +- .../io.entgra.application.mgt.server.feature/pom.xml | 2 +- features/application-mgt/pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.api.feature/pom.xml | 2 +- .../pom.xml | 2 +- .../org.wso2.carbon.certificate.mgt.server.feature/pom.xml | 2 +- features/certificate-mgt/pom.xml | 2 +- .../pom.xml | 2 +- .../io.entgra.device.mgt.extensions.logger.feature/pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- .../pom.xml | 2 +- features/device-mgt-extensions/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.api.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.basics.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.extensions.feature/pom.xml | 2 +- .../device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml | 2 +- .../org.wso2.carbon.device.mgt.server.feature/pom.xml | 2 +- features/device-mgt/pom.xml | 2 +- .../io.entgra.server.heart.beat.feature/pom.xml | 2 +- features/heartbeat-management/pom.xml | 2 +- .../pom.xml | 2 +- features/jwt-client/pom.xml | 2 +- .../logger/io.entgra.notification.logger.feature/pom.xml | 2 +- features/logger/pom.xml | 2 +- .../org.wso2.carbon.policy.mgt.server.feature/pom.xml | 2 +- features/policy-mgt/pom.xml | 2 +- .../io.entgra.device.mgt.subtype.mgt.feature/pom.xml | 2 +- features/subtype-mgt/pom.xml | 2 +- features/task-mgt/io.entgra.task.mgt.feature/pom.xml | 2 +- features/task-mgt/pom.xml | 2 +- .../tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml | 2 +- features/tenant-mgt/pom.xml | 2 +- .../org.wso2.carbon.email.sender.feature/pom.xml | 2 +- features/transport-mgt/email-sender/pom.xml | 2 +- features/transport-mgt/pom.xml | 2 +- .../io.entgra.transport.mgt.sms.handler.api.feature/pom.xml | 2 +- .../pom.xml | 2 +- features/transport-mgt/sms-handler/pom.xml | 2 +- .../io.entgra.ui.request.interceptor.feature/pom.xml | 2 +- features/ui-request-interceptor/pom.xml | 2 +- .../pom.xml | 2 +- features/webapp-authenticator-framework/pom.xml | 2 +- pom.xml | 6 +++--- 131 files changed, 133 insertions(+), 133 deletions(-) diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml index f74a1d08801..bbd9fb5d69b 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml index d2610de9fb3..7093ac33497 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml index e84d5ee565e..0a59c96a805 100644 --- a/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml +++ b/components/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/grafana-mgt/pom.xml b/components/analytics-mgt/grafana-mgt/pom.xml index 3c858ad42fd..0c607aa09cc 100644 --- a/components/analytics-mgt/grafana-mgt/pom.xml +++ b/components/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/analytics-mgt/pom.xml b/components/analytics-mgt/pom.xml index 3b385ccefb0..9c6a1492cdd 100644 --- a/components/analytics-mgt/pom.xml +++ b/components/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml index 1e943eb93c3..06542fee80d 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension/pom.xml @@ -20,7 +20,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml index 603d58d9c15..cf494874fdc 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.annotations/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml index d38fe0e8492..14350fa0c93 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.api/pom.xml @@ -21,7 +21,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml index 7612b6a2e6b..701bfc666a7 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.application.extension/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml index c715d1dbb15..752366b4c1f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.api/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT 4.0.0 diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml index 3480848e1e5..3c065db073f 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension/pom.xml @@ -3,7 +3,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 53fe085988a..25fa414b151 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 2885a51721a..c877688505d 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml index f5660866bff..e871bd31790 100644 --- a/components/application-mgt/io.entgra.application.mgt.addons/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.addons/pom.xml @@ -20,7 +20,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.api/pom.xml index 71c12b9c7ce..c330a1f02d1 100644 --- a/components/application-mgt/io.entgra.application.mgt.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.common/pom.xml b/components/application-mgt/io.entgra.application.mgt.common/pom.xml index c6ac2003423..e64d926b80c 100644 --- a/components/application-mgt/io.entgra.application.mgt.common/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.common/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.core/pom.xml b/components/application-mgt/io.entgra.application.mgt.core/pom.xml index e2e54a8ac8f..f97e04615bf 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt application-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml index f129a61277c..d9cd4fa9c20 100644 --- a/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.publisher.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml index 073a4360c5f..ad89c630dbb 100644 --- a/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml +++ b/components/application-mgt/io.entgra.application.mgt.store.api/pom.xml @@ -22,7 +22,7 @@ application-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/application-mgt/pom.xml b/components/application-mgt/pom.xml index a36ff45b4b1..7d023cae477 100644 --- a/components/application-mgt/pom.xml +++ b/components/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml index 6ac41a449e2..c1b8ff77810 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml index e012c947253..f4b7ae80de1 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api/pom.xml @@ -22,7 +22,7 @@ certificate-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml index 9c2c252c6ce..26b8367795c 100644 --- a/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml +++ b/components/certificate-mgt/org.wso2.carbon.certificate.mgt.core/pom.xml @@ -38,7 +38,7 @@ org.wso2.carbon.devicemgt certificate-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/certificate-mgt/pom.xml b/components/certificate-mgt/pom.xml index b305c96b599..c04f8724db4 100644 --- a/components/certificate-mgt/pom.xml +++ b/components/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml index 8c93ceef4d1..309fe873040 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml index c4d827240fc..3d16f2498d6 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.logger/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml index 747f4fc70a4..4ff04b6f98e 100644 --- a/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml +++ b/components/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine/pom.xml @@ -23,7 +23,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml index 34bc10a2091..ea3c6b5c5bf 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml index ce84a89a126..62b123f3a24 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.pull.notification/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml index eab9ddf49cb..d9db07fdcde 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml index bfd1500e287..4329d100144 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml index 1a0d77c144b..c7ca107625b 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml index 7b48c6fb540..2762460d3eb 100644 --- a/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml +++ b/components/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp/pom.xml @@ -22,7 +22,7 @@ device-mgt-extensions org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt-extensions/pom.xml b/components/device-mgt-extensions/pom.xml index 95472f963ca..04d6ae4544e 100644 --- a/components/device-mgt-extensions/pom.xml +++ b/components/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml index 6d43ffd85e5..067b3916973 100644 --- a/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml +++ b/components/device-mgt/io.entgra.carbon.device.mgt.config.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml index be0ab829d73..8c126c159ee 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.api/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml index c5d026d27df..d66968ac060 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.common/pom.xml @@ -21,7 +21,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml index ece6b4cc02e..28c260d13d7 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml index 10b8e9997a5..dd3c62ff6da 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.extensions/pom.xml @@ -22,7 +22,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml index 833d4779181..c3befb02211 100644 --- a/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml +++ b/components/device-mgt/org.wso2.carbon.device.mgt.url.printer/pom.xml @@ -23,7 +23,7 @@ device-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/device-mgt/pom.xml b/components/device-mgt/pom.xml index f1abf7f0613..c3b618cb276 100644 --- a/components/device-mgt/pom.xml +++ b/components/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml index 4dc1a3ca4a4..9a60509c646 100644 --- a/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml +++ b/components/heartbeat-management/io.entgra.server.bootup.heartbeat.beacon/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heartbeat-management - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/heartbeat-management/pom.xml b/components/heartbeat-management/pom.xml index 68e8b9bd21c..1bd5534a057 100644 --- a/components/heartbeat-management/pom.xml +++ b/components/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml index f87517fb0c8..aa248aceec9 100644 --- a/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.device.mgt.oauth.extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml index f2f9c80019c..ba1e95d9c88 100644 --- a/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml +++ b/components/identity-extensions/org.wso2.carbon.identity.jwt.client.extension/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt identity-extensions - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/identity-extensions/pom.xml b/components/identity-extensions/pom.xml index 15563645993..d71a186726c 100644 --- a/components/identity-extensions/pom.xml +++ b/components/identity-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/logger/io.entgra.notification.logger/pom.xml b/components/logger/io.entgra.notification.logger/pom.xml index e8a589a226a..c9e66cd9407 100644 --- a/components/logger/io.entgra.notification.logger/pom.xml +++ b/components/logger/io.entgra.notification.logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger - 5.0.25 + 5.0.26-SNAPSHOT io.entgra.notification.logger diff --git a/components/logger/pom.xml b/components/logger/pom.xml index f00b30ef0ea..a2ade26cd91 100644 --- a/components/logger/pom.xml +++ b/components/logger/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml index aa24a96a297..c02ae657b64 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.decision.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml index 28c82cdad1f..a6da4012855 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.information.point/pom.xml @@ -3,7 +3,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml index 240c6526858..8b9f7dfb4bc 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml index 73569a10cc8..35e02559540 100644 --- a/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml +++ b/components/policy-mgt/org.wso2.carbon.policy.mgt.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt policy-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/policy-mgt/pom.xml b/components/policy-mgt/pom.xml index ba3256b8cb8..42604365471 100644 --- a/components/policy-mgt/pom.xml +++ b/components/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml index 8a83dade4fd..3e0f0081fc6 100644 --- a/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml +++ b/components/subtype-mgt/io.entgra.device.mgt.subtype.mgt/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt subtype-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/subtype-mgt/pom.xml b/components/subtype-mgt/pom.xml index 685d8a70924..d0d17deb971 100644 --- a/components/subtype-mgt/pom.xml +++ b/components/subtype-mgt/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/pom.xml b/components/task-mgt/pom.xml index 52c12193a9a..4fccbc4256d 100755 --- a/components/task-mgt/pom.xml +++ b/components/task-mgt/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml index 034a212353b..774fec0dffe 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.common/pom.xml @@ -20,7 +20,7 @@ task-manager org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml index e37eac0ac88..e7968bec5b2 100755 --- a/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml +++ b/components/task-mgt/task-manager/io.entgra.task.mgt.core/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-manager - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-manager/pom.xml b/components/task-mgt/task-manager/pom.xml index df1f091f331..7589285d15a 100755 --- a/components/task-mgt/task-manager/pom.xml +++ b/components/task-mgt/task-manager/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml index 3a0d7ae10b5..0011d8d6907 100755 --- a/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml +++ b/components/task-mgt/task-watcher/io.entgra.task.mgt.watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-watcher - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/task-mgt/task-watcher/pom.xml b/components/task-mgt/task-watcher/pom.xml index f915dc579b1..96d2a1bc594 100755 --- a/components/task-mgt/task-watcher/pom.xml +++ b/components/task-mgt/task-watcher/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt task-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml index 0ca08ff3658..31fcb58a0aa 100644 --- a/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml +++ b/components/tenant-mgt/io.entgra.tenant.mgt.common/pom.xml @@ -20,7 +20,7 @@ tenant-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml index fb207fd72ad..698ddbf9420 100644 --- a/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml +++ b/components/tenant-mgt/io.entgra.tenant.mgt.core/pom.xml @@ -20,7 +20,7 @@ tenant-mgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/tenant-mgt/pom.xml b/components/tenant-mgt/pom.xml index 21a623e39e4..537cac339a5 100644 --- a/components/tenant-mgt/pom.xml +++ b/components/tenant-mgt/pom.xml @@ -20,7 +20,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml index 3b5f0c58fc4..9a86790e8e7 100644 --- a/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml +++ b/components/transport-mgt/email-sender/org.wso2.carbon.email.sender.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/email-sender/pom.xml b/components/transport-mgt/email-sender/pom.xml index 2deb9dec3a8..57327359a09 100644 --- a/components/transport-mgt/email-sender/pom.xml +++ b/components/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/pom.xml b/components/transport-mgt/pom.xml index 5d101e542c2..90a4b01e41e 100644 --- a/components/transport-mgt/pom.xml +++ b/components/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml index 3b6a9a15bdd..4da59a95c73 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml index 96686e5fbbd..6e1b971f02b 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.common/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml index f79e0e1304d..5d35139a65c 100644 --- a/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml +++ b/components/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.core/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/transport-mgt/sms-handler/pom.xml b/components/transport-mgt/sms-handler/pom.xml index d2889df91f3..a8f3a7deaac 100644 --- a/components/transport-mgt/sms-handler/pom.xml +++ b/components/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml index c5a4f55d1da..ae20780b3a0 100644 --- a/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml +++ b/components/ui-request-interceptor/io.entgra.ui.request.interceptor/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor io.entgra.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT 4.0.0 diff --git a/components/ui-request-interceptor/pom.xml b/components/ui-request-interceptor/pom.xml index 49a1a7398b4..bbd57a74df2 100644 --- a/components/ui-request-interceptor/pom.xml +++ b/components/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml index 4394d61d4a4..4d53524fe2f 100644 --- a/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml +++ b/components/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/components/webapp-authenticator-framework/pom.xml b/components/webapp-authenticator-framework/pom.xml index f253e90eea1..adca7c3fad0 100644 --- a/components/webapp-authenticator-framework/pom.xml +++ b/components/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml index d9b5b0d2a11..5acf349d6a3 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml index d5cb525a8f4..044bb1fed59 100644 --- a/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml +++ b/features/analytics-mgt/grafana-mgt/io.entgra.analytics.mgt.grafana.proxy.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt grafana-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/grafana-mgt/pom.xml b/features/analytics-mgt/grafana-mgt/pom.xml index 28795bddc11..1c081eeb9dd 100644 --- a/features/analytics-mgt/grafana-mgt/pom.xml +++ b/features/analytics-mgt/grafana-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt analytics-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/analytics-mgt/pom.xml b/features/analytics-mgt/pom.xml index 398cdcbff7a..475da067ab6 100644 --- a/features/analytics-mgt/pom.xml +++ b/features/analytics-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml index 4075d99e35d..0c98267809f 100644 --- a/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml +++ b/features/apimgt-extensions/io.entgra.device.mgt.core.apimgt.analytics.extension.feature/pom.xml @@ -20,7 +20,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml index a55b894cb59..0854142aeba 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.application.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml index eefb3d4fd33..e0ce7c83a5b 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.keymgt.extension.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index 2040e5154d3..b6344f6e454 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt apimgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/apimgt-extensions/pom.xml b/features/apimgt-extensions/pom.xml index 9be30cfb0c4..73a5be82ca4 100644 --- a/features/apimgt-extensions/pom.xml +++ b/features/apimgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml index 5b5e66d9b01..a67320fd0c1 100644 --- a/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml index c5b32a54acd..3622decb742 100644 --- a/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml +++ b/features/application-mgt/io.entgra.application.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt application-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/application-mgt/pom.xml b/features/application-mgt/pom.xml index 807f6ed9a31..6fd0c18f813 100644 --- a/features/application-mgt/pom.xml +++ b/features/application-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml index a92cbe4fe9a..cb1ed90b327 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml index e55e753c7c4..87f9245fc9d 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.cert.admin.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml index fada447f19a..a2aff59a523 100644 --- a/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml +++ b/features/certificate-mgt/org.wso2.carbon.certificate.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt certificate-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/certificate-mgt/pom.xml b/features/certificate-mgt/pom.xml index 826e51ee93e..ed646bb4294 100644 --- a/features/certificate-mgt/pom.xml +++ b/features/certificate-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml index ea9cf23db6b..3e2ca090017 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.defaultrole.manager.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml index 5bc42eae1de..40bc14ec049 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml index 5f43d24ce16..dbf4c755cfa 100644 --- a/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml +++ b/features/device-mgt-extensions/io.entgra.device.mgt.extensions.stateengine.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml index acdf8c282d0..6b8d03fef1d 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.device.type.deployer.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml index 888a863a272..579ac3c50a8 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.fcm.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml index 39bf6577fb2..e461f8bf50f 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.http.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml index 35fdff48a3b..38206938c68 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.mqtt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml index 422e23195fd..6c974cff3c1 100644 --- a/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml +++ b/features/device-mgt-extensions/org.wso2.carbon.device.mgt.extensions.push.notification.provider.xmpp.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-extensions-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt-extensions/pom.xml b/features/device-mgt-extensions/pom.xml index db161cd47e0..366594b5606 100644 --- a/features/device-mgt-extensions/pom.xml +++ b/features/device-mgt-extensions/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml index bdfcf93d891..cb58c5fdccf 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml index 51e9c25fb83..5685d175dd0 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.basics.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml index d36d2f187d6..c49b1e826a2 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.extensions.feature/pom.xml @@ -4,7 +4,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml index c56b01442a4..273ec000ada 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml index dbbeabe660e..5d70664b2e4 100644 --- a/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml +++ b/features/device-mgt/org.wso2.carbon.device.mgt.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt device-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/device-mgt/pom.xml b/features/device-mgt/pom.xml index 82798be5b4c..2fc92261d43 100644 --- a/features/device-mgt/pom.xml +++ b/features/device-mgt/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml index 3b3992aa7e6..b131d4bf391 100644 --- a/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml +++ b/features/heartbeat-management/io.entgra.server.heart.beat.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt heart-beat-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/heartbeat-management/pom.xml b/features/heartbeat-management/pom.xml index 701c7837eaf..4131bc296b2 100644 --- a/features/heartbeat-management/pom.xml +++ b/features/heartbeat-management/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml index c180f6a68cd..03e9edae8fb 100644 --- a/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml +++ b/features/jwt-client/org.wso2.carbon.identity.jwt.client.extension.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt jwt-client-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/jwt-client/pom.xml b/features/jwt-client/pom.xml index 8de990c3e93..3b0d86025fc 100644 --- a/features/jwt-client/pom.xml +++ b/features/jwt-client/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/logger/io.entgra.notification.logger.feature/pom.xml b/features/logger/io.entgra.notification.logger.feature/pom.xml index 49396a6eaa3..ece79e753db 100644 --- a/features/logger/io.entgra.notification.logger.feature/pom.xml +++ b/features/logger/io.entgra.notification.logger.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt logger-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/logger/pom.xml b/features/logger/pom.xml index a887f1b624e..a1d28091bdc 100644 --- a/features/logger/pom.xml +++ b/features/logger/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml index 77cda40df15..8b610a5398b 100644 --- a/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml +++ b/features/policy-mgt/org.wso2.carbon.policy.mgt.server.feature/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt policy-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/policy-mgt/pom.xml b/features/policy-mgt/pom.xml index 4826354966e..d6ec921b4d4 100644 --- a/features/policy-mgt/pom.xml +++ b/features/policy-mgt/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml index e3cc7fb122a..fdf990a2be1 100644 --- a/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml +++ b/features/subtype-mgt/io.entgra.device.mgt.subtype.mgt.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../../pom.xml diff --git a/features/subtype-mgt/pom.xml b/features/subtype-mgt/pom.xml index dbc40f06dc0..5a909a00500 100644 --- a/features/subtype-mgt/pom.xml +++ b/features/subtype-mgt/pom.xml @@ -22,7 +22,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml index fd50e447d62..939aa5f28d0 100755 --- a/features/task-mgt/io.entgra.task.mgt.feature/pom.xml +++ b/features/task-mgt/io.entgra.task.mgt.feature/pom.xml @@ -21,7 +21,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../../pom.xml diff --git a/features/task-mgt/pom.xml b/features/task-mgt/pom.xml index 7229a4983f5..896842812af 100755 --- a/features/task-mgt/pom.xml +++ b/features/task-mgt/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml index 9c2b69a1f5a..d1d8f7adf9e 100644 --- a/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml +++ b/features/tenant-mgt/io.entgra.tenant.mgt.server.feature/pom.xml @@ -20,7 +20,7 @@ tenant-mgt-feature org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/tenant-mgt/pom.xml b/features/tenant-mgt/pom.xml index ef1ec06c846..085da8ad9cb 100644 --- a/features/tenant-mgt/pom.xml +++ b/features/tenant-mgt/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml index 9a5a000af72..12d37b8f93a 100644 --- a/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml +++ b/features/transport-mgt/email-sender/org.wso2.carbon.email.sender.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt email-sender-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/email-sender/pom.xml b/features/transport-mgt/email-sender/pom.xml index 573147280c9..833e4777d41 100644 --- a/features/transport-mgt/email-sender/pom.xml +++ b/features/transport-mgt/email-sender/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/pom.xml b/features/transport-mgt/pom.xml index e5cad84b922..764f136e61b 100644 --- a/features/transport-mgt/pom.xml +++ b/features/transport-mgt/pom.xml @@ -3,7 +3,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml index 47253acbca4..64b7b57cea1 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.api.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml index 435fb08aa54..34f6d270e53 100644 --- a/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml +++ b/features/transport-mgt/sms-handler/io.entgra.transport.mgt.sms.handler.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt sms-handler-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/transport-mgt/sms-handler/pom.xml b/features/transport-mgt/sms-handler/pom.xml index 642b3fd0fbb..7d9c2d9281d 100644 --- a/features/transport-mgt/sms-handler/pom.xml +++ b/features/transport-mgt/sms-handler/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt transport-mgt-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml index 91cf1cf9687..5c77cd533aa 100644 --- a/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml +++ b/features/ui-request-interceptor/io.entgra.ui.request.interceptor.feature/pom.xml @@ -21,7 +21,7 @@ ui-request-interceptor-feature io.entgra.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT 4.0.0 diff --git a/features/ui-request-interceptor/pom.xml b/features/ui-request-interceptor/pom.xml index 2f32271b659..e8b191e153c 100644 --- a/features/ui-request-interceptor/pom.xml +++ b/features/ui-request-interceptor/pom.xml @@ -21,7 +21,7 @@ carbon-devicemgt org.wso2.carbon.devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml index db58ecd12e1..c9dc9f02a7b 100644 --- a/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml +++ b/features/webapp-authenticator-framework/org.wso2.carbon.webapp.authenticator.framework.server.feature/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt webapp-authenticator-framework-feature - 5.0.25 + 5.0.26-SNAPSHOT ../pom.xml diff --git a/features/webapp-authenticator-framework/pom.xml b/features/webapp-authenticator-framework/pom.xml index af16f346370..beeae3ee831 100644 --- a/features/webapp-authenticator-framework/pom.xml +++ b/features/webapp-authenticator-framework/pom.xml @@ -22,7 +22,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt - 5.0.25 + 5.0.26-SNAPSHOT ../../pom.xml diff --git a/pom.xml b/pom.xml index 662effdbe24..b61ce5221b3 100644 --- a/pom.xml +++ b/pom.xml @@ -23,7 +23,7 @@ org.wso2.carbon.devicemgt carbon-devicemgt pom - 5.0.25 + 5.0.26-SNAPSHOT WSO2 Carbon - Device Management - Parent http://wso2.org WSO2 Connected Device Manager Components @@ -1918,7 +1918,7 @@ https://repository.entgra.net/community/device-mgt-core.git scm:git:https://repository.entgra.net/community/device-mgt-core.git scm:git:https://repository.entgra.net/community/device-mgt-core.git - v5.0.25 + HEAD @@ -2130,7 +2130,7 @@ 1.2.11.wso2v10 - 5.0.25 + 5.0.26-SNAPSHOT 4.7.35 From ac834d03595fc59132e55a67a2d1ec866a03bdd8 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 27 Mar 2023 21:42:25 +0530 Subject: [PATCH 06/22] Automated api calls with http client --- .../pom.xml | 148 ++++++++++++++++++ .../PublisherAPIService.java | 6 + .../PublisherAPIServiceImpl.java | 72 +++++++++ .../dto/AccessTokenInfo.java | 50 ++++++ .../PublisherAPIServiceComponent.java | 33 ++++ .../util/PublisherAPIUtil.java | 72 +++++++++ .../pom.xml | 5 + .../publisher/APIPublisherStartupHandler.java | 8 + components/apimgt-extensions/pom.xml | 19 +++ pom.xml | 5 + 10 files changed, 418 insertions(+) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml new file mode 100644 index 00000000000..adb72670cfa --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -0,0 +1,148 @@ + + + + + + + apimgt-extensions + org.wso2.carbon.devicemgt + 5.0.21-SNAPSHOT + ../pom.xml + + + 4.0.0 + io.entgra.devicemgt.apimgt.extension.publisher.api + bundle + Entgra - Device API Management Extension Publisher API + Entgra - Device API Management Extension Publisher API + https://entgra.io + + + + org.apache.httpcomponents.wso2 + httpcore + + + org.wso2.orbit.org.apache.httpcomponents + httpclient + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.utils + + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + + + + + org.apache.felix + maven-scr-plugin + + + org.apache.felix + maven-bundle-plugin + 1.4.0 + true + + + ${project.artifactId} + ${project.artifactId} + ${carbon.device.mgt.version} + Publisher API Management Bundle + + io.entgra.devicemgt.apimgt.extension.publisher.api.* + + + javax.net.ssl, + javax.xml.bind, + org.apache.commons.logging, + org.apache.http;version="${httpclient.version.range}", + org.apache.http.client;version="${httpclient.version.range}", + org.apache.http.client.methods;version="${httpclient.version.range}", + org.apache.http.conn.socket, + org.apache.http.conn.ssl, + org.apache.http.entity, + org.apache.http.impl.client, + org.apache.http.util;version="${httpclient.version.range}", + + org.osgi.framework.*;version="${imp.package.version.osgi.framework}", + org.osgi.service.*;version="${imp.package.version.osgi.service}", + com.sun.jndi.toolkit.ctx, + org.wso2.carbon.utils + + + + + + org.jacoco + jacoco-maven-plugin + + ${basedir}/target/coverage-reports/jacoco-unit.exec + + + + jacoco-initialize + + prepare-agent + + + + jacoco-site + test + + report + + + ${basedir}/target/coverage-reports/jacoco-unit.exec + ${basedir}/target/coverage-reports/site + + + + + + + + + + + + + + + + + + + + true + + + \ No newline at end of file diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java new file mode 100644 index 00000000000..2a377623630 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java @@ -0,0 +1,6 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +public interface PublisherAPIService { + + void registerApplication(); +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java new file mode 100644 index 00000000000..9b33fe4ab18 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java @@ -0,0 +1,72 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.entity.StringEntity; + +import javax.xml.bind.DatatypeConverter; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +public class PublisherAPIServiceImpl implements PublisherAPIService { + private static final Log log = LogFactory.getLog(PublisherAPIServiceImpl.class); + + @Override + public void registerApplication() { + try { + HttpClient httpclient; + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); + httpclient = org.apache.http.impl.client.HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build(); + + URL url =new URL("https://localhost:9443/client-registration/v0.17/register"); + HttpPost request = new HttpPost(url.toString()); + + String payload = "{\n" + + " \"callbackUrl\":\"www.google.lk\",\n" + + " \"clientName\":\"rest_api_publisher_code\",\n" + + " \"owner\":\"admin\",\n" + + " \"grantType\":\"client_credentials password refresh_token\",\n" + + " \"saasApp\":true\n" + + " }"; + + StringEntity entity = new StringEntity(payload); + request.setEntity(entity); + String encoding = DatatypeConverter.printBase64Binary("admin:admin".getBytes("UTF-8")); + + request.setHeader("Authorization", "Basic " + encoding); + request.setHeader("Content-Type", "application/json"); + + HttpResponse httpResponse = httpclient.execute(request); + + if (httpResponse != null) { + BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); + String readLine; + String response = ""; + while (((readLine = br.readLine()) != null)) { + response += readLine; + } + System.out.println(response); + } + + System.out.println(httpResponse.getStatusLine().getStatusCode()); + + } catch (IOException | NoSuchAlgorithmException | KeyStoreException | + KeyManagementException e) { + log.error("failed to call http client.", e); + } + + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java new file mode 100644 index 00000000000..5c1487451ed --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java @@ -0,0 +1,50 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; + +public class AccessTokenInfo { + + private String tokenType; + private long expiresIn; + private String refreshToken; + private String accessToken; + private String scope; + + public String getTokenType() { + return tokenType; + } + + public void setTokenType(String tokenType) { + this.tokenType = tokenType; + } + + public long getExpiresIn() { + return expiresIn; + } + + public void setExpiresIn(long expiresIn) { + this.expiresIn = expiresIn; + } + + public String getRefreshToken() { + return refreshToken; + } + + public void setRefreshToken(String refreshToken) { + this.refreshToken = refreshToken; + } + + public String getAccessToken() { + return accessToken; + } + + public void setAccessToken(String accessToken) { + this.accessToken = accessToken; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java new file mode 100644 index 00000000000..f7059ac20c7 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java @@ -0,0 +1,33 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; + + +import com.sun.jndi.toolkit.ctx.ComponentContext; +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIService; +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIServiceImpl; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; + +import java.io.IOException; + +/** + * @scr.component name="io.entgra.devicemgt.apimgt.extension.publisher.api.internal.PublisherAPIServiceComponent" + * immediate="true" + */ +public class PublisherAPIServiceComponent { + + private static Log log = LogFactory.getLog(PublisherAPIServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Initializing publisher API extension bundle"); + } + + PublisherAPIService publisherAPIService = new PublisherAPIServiceImpl(); + + } + + protected void deactivate(ComponentContext componentContext) { + //do nothing + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java new file mode 100644 index 00000000000..028d40f1900 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java @@ -0,0 +1,72 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.util; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.conn.ssl.SSLConnectionSocketFactory; +import org.apache.http.conn.ssl.SSLContextBuilder; +import org.apache.http.conn.ssl.TrustSelfSignedStrategy; +import org.apache.http.impl.client.HttpClients; +import org.apache.http.util.EntityUtils; +import org.wso2.carbon.utils.CarbonUtils; + +import java.io.BufferedReader; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +public class PublisherAPIUtil { + + private static final Log log = LogFactory.getLog(PublisherAPIUtil.class); + private static final String HTTPS_PROTOCOL = "https"; + private static final String TENANT_JWT_CONFIG_LOCATION = File.separator + "jwt-config" + File.separator + "jwt.properties"; + private static final String JWT_CONFIG_FILE_NAME = "jwt.properties"; + private static final String SUPERTENANT_JWT_CONFIG_LOCATION = + CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + JWT_CONFIG_FILE_NAME; + + /** + * Return a http client instance + * + * @param protocol- service endpoint protocol http/https + * @return + */ + public static HttpClient getHttpClient(String protocol) + throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { + HttpClient httpclient; + if (HTTPS_PROTOCOL.equals(protocol)) { + SSLContextBuilder builder = new SSLContextBuilder(); + builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); + SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); + httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build(); + } else { + httpclient = HttpClients.createDefault(); + } + return httpclient; + } + + public static String getResponseString(HttpResponse httpResponse) throws IOException { + BufferedReader br = null; + try { + br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); + String readLine; + String response = ""; + while (((readLine = br.readLine()) != null)) { + response += readLine; + } + return response; + } finally { + EntityUtils.consumeQuietly(httpResponse.getEntity()); + if (br != null) { + try { + br.close(); + } catch (IOException e) { + log.warn("Error while closing the connection! " + e.getMessage()); + } + } + } + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 25fa414b151..fce4b944960 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -122,6 +122,10 @@ h2-database-engine test + + org.wso2.carbon.devicemgt + io.entgra.devicemgt.apimgt.extension.publisher.api + @@ -165,6 +169,7 @@ org.scannotation;version="1.0", org.scannotation.archiveiterator;version="1.0", org.w3c.dom, + io.entgra.devicemgt.apimgt.extension.publisher.api, org.wso2.carbon.apimgt.annotations.api, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index 949f16c3e9e..e491d35d6ec 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -19,6 +19,7 @@ package org.wso2.carbon.apimgt.webapp.publisher; +import io.entgra.devicemgt.apimgt.extension.publisher.api.ScopeServices; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; @@ -37,6 +38,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { private static Stack currentAPIsStack; private APIPublisherService publisher; + private ScopeServices scopeServices; @Override public void completingServerStartup() { @@ -55,6 +57,12 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { log.debug("Total number of unpublished APIs: " + APIPublisherDataHolder.getInstance().getUnpublishedApis().size()); } + + try { + scopeServices.registerApplication(); + } catch (Exception e) { + throw new RuntimeException(e); + } publisher = APIPublisherDataHolder.getInstance().getApiPublisherService(); int retryCount = 0; while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) { diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index c877688505d..968c5bb3d1f 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -25,6 +25,24 @@ 5.0.26-SNAPSHOT ../../pom.xml + + + org.apache.httpcomponents.wso2 + httpcore + + + org.wso2.orbit.org.apache.httpcomponents + httpclient + + + org.wso2.carbon + org.wso2.carbon.logging + + + org.wso2.carbon + org.wso2.carbon.utils + + 4.0.0 apimgt-extensions @@ -40,6 +58,7 @@ org.wso2.carbon.apimgt.keymgt.extension org.wso2.carbon.apimgt.keymgt.extension.api io.entgra.device.mgt.core.apimgt.analytics.extension + io.entgra.devicemgt.apimgt.extension.publisher.api diff --git a/pom.xml b/pom.xml index b61ce5221b3..b5435d623d5 100644 --- a/pom.xml +++ b/pom.xml @@ -238,6 +238,11 @@ org.wso2.carbon.apimgt.annotations ${carbon.device.mgt.version} + + org.wso2.carbon.devicemgt + io.entgra.devicemgt.apimgt.extension.publisher.api + ${carbon.device.mgt.version} + org.wso2.carbon.devicemgt org.wso2.carbon.device.mgt.oauth.extensions From a9bb2fcb93be48ac27870b74cabc15a8f18ab4d7 Mon Sep 17 00:00:00 2001 From: pasindu Date: Sun, 9 Apr 2023 14:32:17 +0530 Subject: [PATCH 07/22] Use apache http client --- .../pom.xml | 33 ++- .../APIApplicationServices.java | 13 ++ .../APIApplicationServicesImpl.java | 151 ++++++++++++++ .../PublisherAPIService.java | 6 - .../PublisherAPIServiceImpl.java | 72 ------- .../PublisherAPIServiceStartupHandler.java | 159 ++++++++++++++ .../PublisherRESTAPIServices.java | 197 ++++++++++++++++++ .../bean/RegistrationProfile.java | 82 ++++++++ .../constants/Constants.java | 52 +++++ .../dto/APIApplicationKey.java | 26 +++ .../dto/AccessTokenInfo.java | 3 + .../PublisherAPIServiceComponent.java | 33 --- .../PublisherRESTAPIServiceComponent.java | 44 ++++ ...APIUtil.java => PublisherRESTAPIUtil.java} | 9 +- .../util/ScopeUtils.java | 59 ++++++ .../pom.xml | 1 + .../publisher/APIPublisherServiceImpl.java | 45 ++-- .../publisher/APIPublisherStartupHandler.java | 7 - .../lifecycle/util/AnnotationProcessor.java | 4 +- components/apimgt-extensions/pom.xml | 28 +++ 20 files changed, 880 insertions(+), 144 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java rename components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/{PublisherAPIUtil.java => PublisherRESTAPIUtil.java} (83%) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml index adb72670cfa..6601a501126 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -58,6 +58,22 @@ org.eclipse.osgi org.eclipse.osgi.services + + org.wso2.carbon + org.wso2.carbon.core + + + com.googlecode.json-simple.wso2 + json-simple + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + com.squareup.okhttp3 + okhttp + @@ -77,7 +93,11 @@ ${project.artifactId} ${carbon.device.mgt.version} Publisher API Management Bundle + + io.entgra.devicemgt.apimgt.extension.publisher.api.internal + + !io.entgra.devicemgt.apimgt.extension.publisher.api.internal, io.entgra.devicemgt.apimgt.extension.publisher.api.* @@ -95,8 +115,17 @@ org.osgi.framework.*;version="${imp.package.version.osgi.framework}", org.osgi.service.*;version="${imp.package.version.osgi.service}", - com.sun.jndi.toolkit.ctx, - org.wso2.carbon.utils + org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", + org.wso2.carbon.utils, + org.wso2.carbon.core, + org.apache.commons.ssl, + org.json.simple, + org.json.simple.parser, + org.apache.http.client.entity, + org.apache.http.message, + org.apache.commons.httpclient, + org.wso2.carbon.apimgt.api.model, + okhttp3.* diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java new file mode 100644 index 00000000000..342f5aa9549 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java @@ -0,0 +1,13 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; + +public interface APIApplicationServices { + + APIApplicationKey createAndRetrieveApplicationCredentials(); + + AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret); + AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret); + +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java new file mode 100644 index 00000000000..06c1fe97bff --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java @@ -0,0 +1,151 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.bean.RegistrationProfile; +import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; +import okhttp3.OkHttpClient; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.ssl.Base64; +import org.apache.http.HttpHeaders; +import org.apache.http.HttpResponse; +import org.apache.http.NameValuePair; +import org.apache.http.client.HttpClient; +import org.apache.http.client.entity.UrlEncodedFormEntity; +import org.apache.http.client.methods.HttpPost; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.apache.http.message.BasicNameValuePair; +import org.json.simple.JSONObject; +import org.json.simple.parser.JSONParser; +import org.json.simple.parser.ParseException; + +import java.io.IOException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.util.ArrayList; +import java.util.List; + +public class APIApplicationServicesImpl implements APIApplicationServices { + + private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); + private final OkHttpClient client; + + public APIApplicationServicesImpl() { + this.client = new OkHttpClient(); + } + + @Override + public APIApplicationKey createAndRetrieveApplicationCredentials() { + + try { + URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); + HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); + HttpPost request = new HttpPost(url.toString()); + + RegistrationProfile registrationProfile = new RegistrationProfile(); + registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); + registrationProfile.setClientName(Constants.CLIENT_NAME); + registrationProfile.setGrantType(Constants.GRANT_TYPE); + registrationProfile.setOwner(Constants.OWNER); + registrationProfile.setIsSaasApp(true); + + String jsonString = registrationProfile.toJSON(); + StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); + request.setEntity(entity); + + //ToDo: Remove hardcoded value + String basicAuth = getBase64Encode("admin", "admin"); + request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); + request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); + + HttpResponse httpResponse = httpclient.execute(request); + + if (httpResponse != null) { + String response = PublisherRESTAPIUtil.getResponseString(httpResponse); + try { + if(response != null){ + JSONParser jsonParser = new JSONParser(); + JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); + APIApplicationKey apiApplicationKey = new APIApplicationKey(); + apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); + apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); + return apiApplicationKey; + } else { + return null; + } + } catch (ParseException e) { + throw new RuntimeException(e); + } + } + + } catch (IOException | NoSuchAlgorithmException | KeyStoreException | + KeyManagementException e) { + log.error("failed to call http client.", e); + } + return null; + } + + @Override + public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) { + List params = new ArrayList<>(); + params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); + //ToDo: Remove hardcoded value + params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); + params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); + params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); + return getToken(params, consumerKey, consumerSecret); + } + + @Override + public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) { + List params = new ArrayList<>(); + params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE)); + params.add(new BasicNameValuePair(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken)); + params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); + return getToken(params, consumerKey, consumerSecret); + } + + public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) { + + try { + URL url = new URL("https://localhost:9443/oauth2/token"); + HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); + HttpPost request = new HttpPost(url.toString()); + + request.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64Encode(clientId, clientSecret)); + request.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); + request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); + + HttpResponse httpResponse = httpclient.execute(request); + String response = PublisherRESTAPIUtil.getResponseString(httpResponse); + if (log.isDebugEnabled()) { + log.debug(response); + } + JSONParser jsonParser = new JSONParser(); + JSONObject jsonObject = (JSONObject) jsonParser.parse(response); + AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); + String accessToken = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); + if (accessToken != null && !accessToken.isEmpty()){ + accessTokenInfo.setAccessToken(accessToken); + accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); + accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); + accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); + accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); + } + return accessTokenInfo; + + } catch (IOException | KeyStoreException | NoSuchAlgorithmException | + KeyManagementException| ParseException e) { + throw new RuntimeException(e); + } + } + + static String getBase64Encode(String key, String value) { + return new String(Base64.encodeBase64((key + ":" + value).getBytes())); + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java deleted file mode 100644 index 2a377623630..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIService.java +++ /dev/null @@ -1,6 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; - -public interface PublisherAPIService { - - void registerApplication(); -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java deleted file mode 100644 index 9b33fe4ab18..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceImpl.java +++ /dev/null @@ -1,72 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.entity.StringEntity; - -import javax.xml.bind.DatatypeConverter; -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.net.URL; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; - -public class PublisherAPIServiceImpl implements PublisherAPIService { - private static final Log log = LogFactory.getLog(PublisherAPIServiceImpl.class); - - @Override - public void registerApplication() { - try { - HttpClient httpclient; - SSLContextBuilder builder = new SSLContextBuilder(); - builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); - httpclient = org.apache.http.impl.client.HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build(); - - URL url =new URL("https://localhost:9443/client-registration/v0.17/register"); - HttpPost request = new HttpPost(url.toString()); - - String payload = "{\n" + - " \"callbackUrl\":\"www.google.lk\",\n" + - " \"clientName\":\"rest_api_publisher_code\",\n" + - " \"owner\":\"admin\",\n" + - " \"grantType\":\"client_credentials password refresh_token\",\n" + - " \"saasApp\":true\n" + - " }"; - - StringEntity entity = new StringEntity(payload); - request.setEntity(entity); - String encoding = DatatypeConverter.printBase64Binary("admin:admin".getBytes("UTF-8")); - - request.setHeader("Authorization", "Basic " + encoding); - request.setHeader("Content-Type", "application/json"); - - HttpResponse httpResponse = httpclient.execute(request); - - if (httpResponse != null) { - BufferedReader br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); - String readLine; - String response = ""; - while (((readLine = br.readLine()) != null)) { - response += readLine; - } - System.out.println(response); - } - - System.out.println(httpResponse.getStatusLine().getStatusCode()); - - } catch (IOException | NoSuchAlgorithmException | KeyStoreException | - KeyManagementException e) { - log.error("failed to call http client.", e); - } - - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java new file mode 100644 index 00000000000..2b005b0cc0d --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java @@ -0,0 +1,159 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.core.ServerStartupObserver; + +public class PublisherAPIServiceStartupHandler implements ServerStartupObserver { + + private static final Log log = LogFactory.getLog(PublisherAPIServiceStartupHandler.class); + private PublisherRESTAPIServices publisherRESTAPIServices; + private AccessTokenInfo accessTokenInfo; + + @Override + public void completingServerStartup() { + + } + + @Override + public void completedServerStartup() { + +// String cid = null; +// String cS = null; +// String token = null; +// AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); +// +// try { +// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPost request = new HttpPost(url.toString()); +// +// RegistrationProfile registrationProfile = new RegistrationProfile(); +// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); +// registrationProfile.setClientName(Constants.CLIENT_NAME); +// registrationProfile.setOwner(Constants.OWNER); +// registrationProfile.setGrantType(Constants.GRANT_TYPE); +// registrationProfile.setIsSaasApp(true); +// +// String jsonString = registrationProfile.toJSON(); +// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); +// request.setEntity(entity); +// +// String basicAuth = PublisherRESTAPIServices.getBase64Encode("admin", "admin"); +// +// request.setHeader("Authorization", "Basic " + basicAuth); +// request.setHeader("Content-Type", "application/json"); +// +// HttpResponse httpResponse = httpclient.execute(request); +// +// if (httpResponse != null) { +// +// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); +// try { +// if(response != null){ +// JSONParser jsonParser = new JSONParser(); +// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); +// String clientId = (String) jsonPayload.get(Constants.CLIENT_ID); +// String clientSecret = (String) jsonPayload.get(Constants.CLIENT_SECRET); +// cid = clientId; +// cS = clientSecret; +// } +// } catch (ParseException e) { +// throw new RuntimeException(e); +// } +// +// System.out.println(response); +// } +// System.out.println(httpResponse.getStatusLine().getStatusCode()); +// +// +// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | +// KeyManagementException e) { +// log.error("failed to call http client.", e); +// } +// +// +// String response = null; +// +// List params = new ArrayList<>(); +// params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); +// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); +// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); +// params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); +// try { +// URL url = new URL("https://localhost:9443/oauth2/token"); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPost request = new HttpPost(url.toString()); +// +// request.addHeader("Authorization", "Basic " + PublisherRESTAPIServices.getBase64Encode(cid, cS)); +// request.addHeader("Content-Type", "application/x-www-form-urlencoded"); +// request.setEntity(new UrlEncodedFormEntity(params)); +// HttpResponse httpResponse = httpclient.execute(request); +// response = PublisherRESTAPIUtil.getResponseString(httpResponse); +// JSONParser jsonParser = new JSONParser(); +// JSONObject jsonObject = (JSONObject) jsonParser.parse(response); +// token = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); +// if (token != null && !token.isEmpty()){ +// accessTokenInfo.setRefreshToken(token); +// accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); +// accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); +// accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); +// accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); +// } +// System.out.println(accessTokenInfo); +// +// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | +// KeyManagementException| ParseException e) { +// throw new RuntimeException(e); +// } +// +// String key = "perm:sms-handler:view-configuration"; +// String value = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); +// +// +// String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + value; +// try { +// URL url = new URL(getScopeUrl); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpHead request = new HttpHead(url.toString()); +// +// request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token); +// HttpResponse httpResponse = httpclient.execute(request); +// +// String code = String.valueOf(httpResponse.getStatusLine().getStatusCode()); +// System.out.println(code); +// +// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { +// throw new RuntimeException(e); +// } +// +// String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + "27fce6f1-6741-4ad5-b700-a56427fd3dbb"; +// try { +// URL url = new URL(updateScopeUrl); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPut request = new HttpPut(url.toString()); +// +// request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token); +// request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); +// +// +// String jsonString = "{\"name\": \"" + "name" + "\",\"displayName\": \"" + "displayname" + +// "\", \"description\": \"" + "description" + "\"," + "\"bindings\": [" + +// "\"Internal/devicemgt-user\"]}"; +// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); +// request.setEntity(entity); +// +// HttpResponse httpResponse = httpclient.execute(request); +// int code = httpResponse.getStatusLine().getStatusCode(); +// System.out.println(code); +// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { +// throw new RuntimeException(e); +// } + + +// publisherRESTAPIServices = new PublisherRESTAPIServices(); +// publisherRESTAPIServices.isSharedScopeNameExists("perm:sms-handler:view-configuration"); + + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java new file mode 100644 index 00000000000..335680a84dd --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java @@ -0,0 +1,197 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; +import io.entgra.devicemgt.apimgt.extension.publisher.api.util.ScopeUtils; +import org.apache.axis2.databinding.types.xsd._boolean; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.http.HttpHeaders; +import org.apache.http.client.methods.HttpHead; +import org.apache.http.client.methods.HttpPut; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.ssl.Base64; +import org.apache.http.HttpResponse; +import org.apache.http.client.HttpClient; +import org.apache.http.entity.ContentType; +import org.apache.http.entity.StringEntity; +import org.wso2.carbon.apimgt.api.model.Scope; + +import java.io.IOException; +import java.net.URL; +import java.security.KeyManagementException; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; + +public class PublisherRESTAPIServices { + private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); + +// private String clientId; +// private String clientSecret; +// private String accessToken; +// +// public AccessTokenInfo registerApplication() { +// +// try { +// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPost request = new HttpPost(url.toString()); +// +// RegistrationProfile registrationProfile = new RegistrationProfile(); +// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); +// registrationProfile.setClientName(Constants.CLIENT_NAME); +// registrationProfile.setGrantType(Constants.GRANT_TYPE); +// registrationProfile.setOwner(Constants.OWNER); +// registrationProfile.setIsSaasApp(true); +// +// String jsonString = registrationProfile.toJSON(); +// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); +// request.setEntity(entity); +// +// String basicAuth = getBase64Encode("admin", "admin"); +// +// request.setHeader("Authorization", "Basic " + basicAuth); +// request.setHeader("Content-Type", "application/json"); +// +// HttpResponse httpResponse = httpclient.execute(request); +// +// if (httpResponse != null) { +// +// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); +// try { +// if(response != null){ +// JSONParser jsonParser = new JSONParser(); +// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); +// clientId = (String) jsonPayload.get(Constants.CLIENT_ID); +// clientSecret = (String) jsonPayload.get(Constants.CLIENT_SECRET); +// } +// } catch (ParseException e) { +// throw new RuntimeException(e); +// } +// System.out.println(response); +// } +// System.out.println(httpResponse.getStatusLine().getStatusCode()); +// +// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | +// KeyManagementException e) { +// log.error("failed to call http client.", e); +// } +// return getAccessTokenFromRegisteredApplication(clientId, clientSecret); +// +// } +// +// public AccessTokenInfo getAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) { +// List params = new ArrayList<>(); +// params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); +// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); +// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); +// params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); +// return getToken(params, consumerKey, consumerSecret); +// } +// +// public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) { +// +// String token = null; +// String response = null; +// try { +// URL url = new URL("https://localhost:9443/oauth2/token"); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPost request = new HttpPost(url.toString()); +// +// request.addHeader("Authorization", "Basic " + getBase64Encode(clientId, clientSecret)); +// request.addHeader("Content-Type", "application/x-www-form-urlencoded"); +// request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); +// HttpResponse httpResponse = httpclient.execute(request); +// response = PublisherRESTAPIUtil.getResponseString(httpResponse); +// JSONParser jsonParser = new JSONParser(); +// JSONObject jsonObject = (JSONObject) jsonParser.parse(response); +// AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); +// token = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); +// if (token != null && !token.isEmpty()){ +// accessTokenInfo.setRefreshToken(token); +// accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); +// accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); +// accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); +// accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); +// } +// accessToken = token; +// return accessTokenInfo; +// +// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | +// KeyManagementException| ParseException e) { +// throw new RuntimeException(e); +// } +// } + + public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key){ + + String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); + String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; + try { + URL url = new URL(getScopeUrl); + HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); + HttpHead request = new HttpHead(url.toString()); + + request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessTokenInfo.getAccessToken()); + HttpResponse httpResponse = httpclient.execute(request); + + if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()){ + return true; + } else if(HttpStatus.SC_UNAUTHORIZED == httpResponse.getStatusLine().getStatusCode()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); + return isSharedScopeNameExists(apiApplicationKey,refreshedAccessToken, key); + } else{ + return false; + } + + } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { + throw new RuntimeException(e); + } + } + + public void updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope){ + +// String keyValue = new String(Base64.encodeBase64((scope.getKey()).getBytes())).replace("=", ""); +// String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; + String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); + try { + URL url = new URL(updateScopeUrl); + HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); + HttpPut request = new HttpPut(url.toString()); + + request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccessToken()); + request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); + + ScopeUtils setScope = new ScopeUtils(); + setScope.setKey(scope.getKey()); + setScope.setName(scope.getName()); + setScope.setDescription(scope.getDescription()); + setScope.setRoles(scope.getRoles()); + String jsonString = setScope.toJSON(); + StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); + request.setEntity(entity); + + HttpResponse httpResponse = httpclient.execute(request); + if (HttpStatus.SC_OK != httpResponse.getStatusLine().getStatusCode() && HttpStatus.SC_UNAUTHORIZED == httpResponse.getStatusLine().getStatusCode()){ + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo accessTokenInfo1 = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); + updateSharedScope(apiApplicationKey, accessTokenInfo1, scope); + } else { + String response = httpResponse.toString(); + log.info(response); + } + + } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { + throw new RuntimeException(e); + } + } +// static String getBase64Encode(String key, String value) { +// return new String(Base64.encodeBase64((key + ":" + value).getBytes())); +// } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java new file mode 100644 index 00000000000..242788ed26e --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java @@ -0,0 +1,82 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.bean; + +/** + * This class represents the data that are required to register + * the oauth application. + */ +public class RegistrationProfile { + + private String callbackUrl; + private String clientName; + private String tokenScope; + private String owner; + private String grantType; + private String applicationType; + private boolean isSaasApp; + + private static final String TAG = RegistrationProfile.class.getSimpleName(); + + public String getCallbackUrl() { + return callbackUrl; + } + + public void setCallbackUrl(String callBackUrl) { + this.callbackUrl = callBackUrl; + } + + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + public String getTokenScope() { + return tokenScope; + } + + public void setTokenScope(String tokenScope) { + this.tokenScope = tokenScope; + } + + public String getOwner() { + return owner; + } + + public void setOwner(String owner) { + this.owner = owner; + } + + public String getGrantType() { + return grantType; + } + + public void setGrantType(String grantType) { + this.grantType = grantType; + } + + public String getApplicationType() { + return applicationType; + } + + public void setApplicationType(String applicationType) { + this.applicationType = applicationType; + } + + public boolean isSaasApp() { + return isSaasApp; + } + + public void setIsSaasApp(boolean isSaasApp) { + this.isSaasApp = isSaasApp; + } + + public String toJSON() { + String jsonString = + "{\"callbackUrl\": \"" + callbackUrl + "\",\"clientName\": \"" + clientName + + "\", \"owner\": \"" + owner + "\"," + "\"grantType\": \"" + grantType + + "\", \"saasApp\" : " + isSaasApp + " }\n"; + return jsonString; + } +} \ No newline at end of file diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java new file mode 100644 index 00000000000..0144e129f10 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java @@ -0,0 +1,52 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.constants; + +public final class Constants { + + private Constants() { + } + + public static final String EMPTY_STRING = ""; + public static final String CLIENT_NAME = "rest_api_publisher_code"; + public static final String OWNER = "admin"; + public static final String GRANT_TYPE = "client_credentials password refresh_token"; + public static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token"; + public static final String OAUTH_EXPIRES_IN = "expires_in"; + public static final String OAUTH_TOKEN_SCOPE = "scope"; + public static final String OAUTH_TOKEN_TYPE = "token_type"; + public static final String REFRESH_TOKEN_GRANT_TYPE = "refresh_token"; + public static final String SCOPE_PARAM_NAME = "scope"; + public static final String SCOPES = "apim:api_create apim:api_view apim:shared_scope_manage"; + + public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; + public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; + + public static final int DEFAULT_MIN_THREAD_POOL_SIZE = 8; + public static final int DEFAULT_MAX_THREAD_POOL_SIZE = 100; + public static final int DEFAULT_EXECUTOR_JOB_QUEUE_SIZE = 2000; + public static final long DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS = 20000; + public static final String ADAPTER_MIN_THREAD_POOL_SIZE_NAME = "minThread"; + public static final String ADAPTER_MAX_THREAD_POOL_SIZE_NAME = "maxThread"; + public static final String ADAPTER_KEEP_ALIVE_TIME_NAME = "keepAliveTimeInMillis"; + public static final String ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME = "jobQueueSize"; + + public static final String DEFAULT_CALLBACK = ""; + public static final String DEFAULT_PASSWORD = ""; + public static final String TOKEN_SCOPE = "production"; + public static final String APPLICATION_NAME_PREFIX = "OutputAdapter_"; + public static final String CLIENT_ID = "clientId"; + public static final String CLIENT_SECRET = "clientSecret"; + + public static final String AUTHORIZATION_HEADER_NAME = "Authorization"; + public static final String AUTHORIZATION_HEADER_VALUE_PREFIX = "Basic "; + public static final String AUTHORIZATION_HEADER_PREFIX_BEARER = "Bearer "; + public static final String HEADER_CONTENT_TYPE = "Content-Type"; + public static final String APPLICATION_JSON = "application/json"; + public static final String PASSWORD_GRANT_TYPE = "password"; + public static final String PASSWORD_GRANT_TYPE_USERNAME = "username"; + public static final String PASSWORD_GRANT_TYPE_PASSWORD = "password"; + public static final String PASSWORD_GRANT_TYPE_SCOPES = "scopes"; + public static final String ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME = "access_token"; + public static final String GRANT_TYPE_PARAM_NAME = "grant_type"; +} + + diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java new file mode 100644 index 00000000000..fdd20f2f221 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java @@ -0,0 +1,26 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; + +/** + * This holds api application consumer id and secret. + */ +public class APIApplicationKey { + + private String clientId; + private String clientSecret; + + public String getClientId() { + return clientId; + } + + public void setClientId(String clientId) { + this.clientId = clientId; + } + + public String getClientSecret() { + return clientSecret; + } + + public void setClientSecret(String clientSecret) { + this.clientSecret = clientSecret; + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java index 5c1487451ed..e738c71f458 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java @@ -1,5 +1,8 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; +/** + * This holds the token information that return from the token endpoint. + */ public class AccessTokenInfo { private String tokenType; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java deleted file mode 100644 index f7059ac20c7..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherAPIServiceComponent.java +++ /dev/null @@ -1,33 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; - - -import com.sun.jndi.toolkit.ctx.ComponentContext; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIService; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIServiceImpl; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.osgi.framework.BundleContext; - -import java.io.IOException; - -/** - * @scr.component name="io.entgra.devicemgt.apimgt.extension.publisher.api.internal.PublisherAPIServiceComponent" - * immediate="true" - */ -public class PublisherAPIServiceComponent { - - private static Log log = LogFactory.getLog(PublisherAPIServiceComponent.class); - - protected void activate(ComponentContext componentContext) { - if (log.isDebugEnabled()) { - log.debug("Initializing publisher API extension bundle"); - } - - PublisherAPIService publisherAPIService = new PublisherAPIServiceImpl(); - - } - - protected void deactivate(ComponentContext componentContext) { - //do nothing - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java new file mode 100644 index 00000000000..612f77a8d96 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java @@ -0,0 +1,44 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIServiceStartupHandler; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.osgi.framework.BundleContext; +import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.core.ServerShutdownHandler; +import org.wso2.carbon.core.ServerStartupObserver; + +/** + * @scr.component name="io.entgra.devicemgt.apimgt.extension.publisher.api.internal.PublisherRESTAPIServiceComponent" + * immediate="true" + */ +public class PublisherRESTAPIServiceComponent { + + private static Log log = LogFactory.getLog(PublisherRESTAPIServiceComponent.class); + + protected void activate(ComponentContext componentContext) { + if (log.isDebugEnabled()) { + log.debug("Initializing publisher API extension bundle"); + } + try { + BundleContext bundleContext = componentContext.getBundleContext(); + + PublisherAPIServiceStartupHandler publisherAPIServiceStartupHandler = new PublisherAPIServiceStartupHandler(); + bundleContext.registerService(PublisherAPIServiceStartupHandler.class.getName(), publisherAPIServiceStartupHandler, null); + bundleContext.registerService(ServerStartupObserver.class.getName(), publisherAPIServiceStartupHandler, null); + bundleContext.registerService(ServerShutdownHandler.class.getName(), publisherAPIServiceStartupHandler, null); + + PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); + bundleContext.registerService(PublisherRESTAPIServices.class.getName(), publisherRESTAPIServices, null); + + + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + protected void deactivate(ComponentContext componentContext) { + //do nothing + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java similarity index 83% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java index 028d40f1900..1d532d17a7c 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherAPIUtil.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java @@ -19,14 +19,9 @@ import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -public class PublisherAPIUtil { - - private static final Log log = LogFactory.getLog(PublisherAPIUtil.class); +public class PublisherRESTAPIUtil { + private static final Log log = LogFactory.getLog(PublisherRESTAPIUtil.class); private static final String HTTPS_PROTOCOL = "https"; - private static final String TENANT_JWT_CONFIG_LOCATION = File.separator + "jwt-config" + File.separator + "jwt.properties"; - private static final String JWT_CONFIG_FILE_NAME = "jwt.properties"; - private static final String SUPERTENANT_JWT_CONFIG_LOCATION = - CarbonUtils.getEtcCarbonConfigDirPath() + File.separator + JWT_CONFIG_FILE_NAME; /** * Return a http client instance diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java new file mode 100644 index 00000000000..db8011521dd --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java @@ -0,0 +1,59 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.util; + +/** + * This class represents the data that are required to register + * the oauth application. + */ +public class ScopeUtils { + + private String key; + private String name; + private String roles; + private String description; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRoles() { + return roles; + } + + public void setRoles(String roles) { + this.roles = roles; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String toJSON() { + String jsonString = + "{\"name\": \"" + key + "\",\"displayName\": \"" + name + + "\", \"description\": \"" + description + "\"," + "\"bindings\": [" + + roles + "]" + " }"; + +// String jsonString = +// "{\"name\": \"" + name + "\",\"displayName\": \"" + name + +// "\", \"description\": \"" + description + "\"," + "\"bindings\": [" + +// "\"Internal/devicemgt-user\"" + +// "]" + " }"; + return jsonString; + } +} \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index fce4b944960..0ca58492f50 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -170,6 +170,7 @@ org.scannotation.archiveiterator;version="1.0", org.w3c.dom, io.entgra.devicemgt.apimgt.extension.publisher.api, + io.entgra.devicemgt.apimgt.extension.publisher.api.dto, org.wso2.carbon.apimgt.annotations.api, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 0dcc92e6381..ea7f2e11089 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -18,6 +18,11 @@ */ package org.wso2.carbon.apimgt.webapp.publisher; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -50,7 +55,6 @@ import org.wso2.carbon.user.core.tenant.Tenant; import org.wso2.carbon.user.core.tenant.TenantSearchResult; import org.wso2.carbon.utils.CarbonUtils; import org.wso2.carbon.utils.multitenancy.MultitenantConstants; -import org.wso2.carbon.utils.multitenancy.MultitenantUtils; import java.io.BufferedReader; import java.io.File; @@ -357,13 +361,19 @@ public class APIPublisherServiceImpl implements APIPublisherService { WebappPublisherConfig config = WebappPublisherConfig.getInstance(); List tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN)); tenants.addAll(config.getTenants().getTenant()); + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + APIApplicationKey apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); + AccessTokenInfo accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + try { for (String tenantDomain : tenants) { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); - APIProvider apiProvider = API_MANAGER_FACTORY.getAPIProvider(MultitenantUtils.getTenantAwareUsername( - PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() - .getAdminUserName())); + PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); +// APIProvider apiProvider = API_MANAGER_FACTORY.getAPIProvider(MultitenantUtils.getTenantAwareUsername( +// PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() +// .getAdminUserName())); try { String fileName = @@ -409,8 +419,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { } scope.setRoles(roleString); - if (apiProvider.isSharedScopeNameExists(scope.getKey(), tenantDomain)) { - apiProvider.updateSharedScope(scope, tenantDomain); +// if (apiProvider.isSharedScopeNameExists(scope.getKey(), tenantDomain)) { +// apiProvider.updateSharedScope(scope, tenantDomain); + if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { + 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 if (log.isDebugEnabled()) { @@ -424,15 +436,18 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } - } catch (UserStoreException e) { - String msg = "Error occurred while reading tenant admin username"; - log.error(msg, e); - throw new APIManagerPublisherException(e); - } catch (APIManagementException e) { - String msg = "Error occurred while loading api provider"; - log.error(msg, e); - throw new APIManagerPublisherException(e); - } finally { + } +// catch (UserStoreException e) { +// String msg = "Error occurred while reading tenant admin username"; +// log.error(msg, e); +// throw new APIManagerPublisherException(e); +// } +// catch (APIManagementException e) { +// String msg = "Error occurred while loading api provider"; +// log.error(msg, e); +// throw new APIManagerPublisherException(e); +// } + finally { PrivilegedCarbonContext.endTenantFlow(); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index e491d35d6ec..bfcafcc2c84 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -19,13 +19,11 @@ package org.wso2.carbon.apimgt.webapp.publisher; -import io.entgra.devicemgt.apimgt.extension.publisher.api.ScopeServices; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import org.wso2.carbon.core.ServerStartupObserver; - import java.util.Stack; public class APIPublisherStartupHandler implements ServerStartupObserver { @@ -36,13 +34,10 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { private static final int MAX_RETRY_COUNT = 5; private static Stack failedAPIsStack = new Stack<>(); private static Stack currentAPIsStack; - private APIPublisherService publisher; - private ScopeServices scopeServices; @Override public void completingServerStartup() { - } @Override @@ -57,9 +52,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { log.debug("Total number of unpublished APIs: " + APIPublisherDataHolder.getInstance().getUnpublishedApis().size()); } - try { - scopeServices.registerApplication(); } catch (Exception e) { throw new RuntimeException(e); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index f41c07967a5..7cdede5bcb6 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -299,7 +299,7 @@ public class AnnotationProcessor { // if (scope != null) { // resource.setScope(scope); // } else { -// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + +// log.warn("ScopeUtils is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); // scope = new ApiScope(); // scope.setName(DEFAULT_SCOPE_NAME); @@ -537,7 +537,7 @@ public class AnnotationProcessor { if (scope != null) { apiResource.setScope(scope); } else { -// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + +// log.warn("ScopeUtils is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); scope = new ApiScope(); scope.setName(DEFAULT_SCOPE_NAME); diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 968c5bb3d1f..747eb843dda 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -42,6 +42,34 @@ org.wso2.carbon org.wso2.carbon.utils + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + + + org.wso2.carbon + org.wso2.carbon.core + + + com.googlecode.json-simple.wso2 + json-simple + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + com.squareup.okhttp3 + okhttp + + + io.github.openfeign + feign-okhttp + 4.0.0 From 8e4998ede8f11a6dfd1ca078a412ae4b9b6aeb61 Mon Sep 17 00:00:00 2001 From: pasindu Date: Sun, 9 Apr 2023 20:37:37 +0530 Subject: [PATCH 08/22] Test okhttp --- .../pom.xml | 20 ++- .../APIApplicationServicesImpl.java | 161 +++++++++++++----- 2 files changed, 128 insertions(+), 53 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml index 6601a501126..e5fec434f06 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -74,6 +74,10 @@ com.squareup.okhttp3 okhttp + + io.github.openfeign + feign-okhttp + @@ -85,7 +89,7 @@ org.apache.felix maven-bundle-plugin - 1.4.0 + 5.1.7 true @@ -102,7 +106,7 @@ javax.net.ssl, - javax.xml.bind, + org.apache.commons.logging, org.apache.http;version="${httpclient.version.range}", org.apache.http.client;version="${httpclient.version.range}", @@ -115,14 +119,14 @@ org.osgi.framework.*;version="${imp.package.version.osgi.framework}", org.osgi.service.*;version="${imp.package.version.osgi.service}", - org.apache.commons.codec.binary;version="${commons-codec.wso2.osgi.version.range}", - org.wso2.carbon.utils, + + org.wso2.carbon.core, org.apache.commons.ssl, - org.json.simple, - org.json.simple.parser, - org.apache.http.client.entity, - org.apache.http.message, + + + + org.apache.commons.httpclient, org.wso2.carbon.apimgt.api.model, okhttp3.* diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java index 06c1fe97bff..8932384f6dc 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java @@ -1,11 +1,12 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api; +import com.google.gson.JsonObject; import io.entgra.devicemgt.apimgt.extension.publisher.api.bean.RegistrationProfile; import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; -import okhttp3.OkHttpClient; +import okhttp3.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.ssl.Base64; @@ -22,71 +23,141 @@ import org.json.simple.JSONObject; import org.json.simple.parser.JSONParser; import org.json.simple.parser.ParseException; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.net.URL; import java.security.KeyManagementException; import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -import java.util.ArrayList; -import java.util.List; +import java.util.*; public class APIApplicationServicesImpl implements APIApplicationServices { private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); - private final OkHttpClient client; + private static final OkHttpClient client = getOkHttpClient(); - public APIApplicationServicesImpl() { - this.client = new OkHttpClient(); + private static OkHttpClient getOkHttpClient() { + X509TrustManager trustAllCerts = new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return new java.security.cert.X509Certificate[0]; + } + + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + }; + return new OkHttpClient.Builder() + .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) + .hostnameVerifier((hostname, sslSession) -> true).build(); } + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { + try { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + } + }; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new java.security.SecureRandom()); + return sc.getSocketFactory(); + } catch (KeyManagementException | NoSuchAlgorithmException e) { + return null; + } + + } @Override public APIApplicationKey createAndRetrieveApplicationCredentials() { - try { - URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); - HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); - HttpPost request = new HttpPost(url.toString()); + JsonObject jsonObject = new JsonObject(); + jsonObject.addProperty("callbackUrl",Constants.EMPTY_STRING); + jsonObject.addProperty("clientName",Constants.CLIENT_NAME); + jsonObject.addProperty("grantType",Constants.EMPTY_STRING); + jsonObject.addProperty("owner",Constants.OWNER); + jsonObject.addProperty("saasApp",true); - RegistrationProfile registrationProfile = new RegistrationProfile(); - registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); - registrationProfile.setClientName(Constants.CLIENT_NAME); - registrationProfile.setGrantType(Constants.GRANT_TYPE); - registrationProfile.setOwner(Constants.OWNER); - registrationProfile.setIsSaasApp(true); + MediaType jsonMediaType = MediaType.parse("application/json; charset=utf-8"); + RequestBody requestBody = RequestBody.create(jsonMediaType, jsonObject.toString()); - String jsonString = registrationProfile.toJSON(); - StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); - request.setEntity(entity); + String keyManagerEndpoint = "https://localhost:9443/client-registration/v0.17/register"; - //ToDo: Remove hardcoded value - String basicAuth = getBase64Encode("admin", "admin"); - request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); - request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); - - HttpResponse httpResponse = httpclient.execute(request); + Request request = new Request.Builder() + .url(keyManagerEndpoint) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) + .post(requestBody) + .build(); + try { + Response response = client.newCall(request).execute(); + System.out.println(request); + System.out.println("---------------------------"); + System.out.println(response); - if (httpResponse != null) { - String response = PublisherRESTAPIUtil.getResponseString(httpResponse); - try { - if(response != null){ - JSONParser jsonParser = new JSONParser(); - JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); - APIApplicationKey apiApplicationKey = new APIApplicationKey(); - apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); - apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); - return apiApplicationKey; - } else { - return null; - } - } catch (ParseException e) { - throw new RuntimeException(e); - } - } +// JSONObject responseObj = new JSONObject(Objects.requireNonNull(response.body()).string()); - } catch (IOException | NoSuchAlgorithmException | KeyStoreException | - KeyManagementException e) { - log.error("failed to call http client.", e); + } catch (IOException e) { + throw new RuntimeException(e); } + +// try { +// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); +// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); +// HttpPost request = new HttpPost(url.toString()); +// +// RegistrationProfile registrationProfile = new RegistrationProfile(); +// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); +// registrationProfile.setClientName(Constants.CLIENT_NAME); +// registrationProfile.setGrantType(Constants.GRANT_TYPE); +// registrationProfile.setOwner(Constants.OWNER); +// registrationProfile.setIsSaasApp(true); +// +// String jsonString = registrationProfile.toJSON(); +// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); +// request.setEntity(entity); +// +// //ToDo: Remove hardcoded value +// String basicAuth = getBase64Encode("admin", "admin"); +// request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); +// request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); +// +// HttpResponse httpResponse = httpclient.execute(request); +// +// if (httpResponse != null) { +// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); +// try { +// if(response != null){ +// JSONParser jsonParser = new JSONParser(); +// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); +// APIApplicationKey apiApplicationKey = new APIApplicationKey(); +// apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); +// apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); +// return apiApplicationKey; +// } else { +// return null; +// } +// } catch (ParseException e) { +// throw new RuntimeException(e); +// } +// } +// +// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | +// KeyManagementException e) { +// log.error("failed to call http client.", e); +// } return null; } From f1120baec3878dbfe5ca5709c8b47fa8cce85a84 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 10 Apr 2023 09:33:51 +0530 Subject: [PATCH 09/22] Implement exception handling --- .../pom.xml | 4 + .../APIApplicationServices.java | 8 +- .../APIApplicationServicesImpl.java | 82 +++++++++- .../PublisherRESTAPIServices.java | 140 ++++-------------- .../APIApplicationServicesException.java | 12 ++ .../exceptions/BadRequestException.java | 34 +++++ .../webapp/publisher/APIPublisherService.java | 1 + .../publisher/APIPublisherServiceImpl.java | 23 ++- .../publisher/APIPublisherStartupHandler.java | 1 + 9 files changed, 180 insertions(+), 125 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml index e5fec434f06..002909f6444 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -78,6 +78,10 @@ io.github.openfeign feign-okhttp + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java index 342f5aa9549..5ca41cf6e2f 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java @@ -2,12 +2,14 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; public interface APIApplicationServices { - APIApplicationKey createAndRetrieveApplicationCredentials(); + APIApplicationKey createAndRetrieveApplicationCredentials() throws BadRequestException, APIApplicationServicesException; - AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret); - AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret); + AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIApplicationServicesException; + AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIApplicationServicesException; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java index 8932384f6dc..55c544d25b2 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java @@ -5,6 +5,8 @@ import io.entgra.devicemgt.apimgt.extension.publisher.api.bean.RegistrationProfi import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; import okhttp3.*; import org.apache.commons.logging.Log; @@ -37,6 +39,7 @@ import java.util.*; public class APIApplicationServicesImpl implements APIApplicationServices { private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); +<<<<<<< HEAD private static final OkHttpClient client = getOkHttpClient(); private static OkHttpClient getOkHttpClient() { @@ -57,6 +60,13 @@ public class APIApplicationServicesImpl implements APIApplicationServices { .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) .hostnameVerifier((hostname, sslSession) -> true).build(); } +======= +// private final OkHttpClient client; + +// public APIApplicationServicesImpl() { +// this.client = new OkHttpClient(); +// } +>>>>>>> e76624c1de (Add exceptions) private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { @@ -82,7 +92,8 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } @Override - public APIApplicationKey createAndRetrieveApplicationCredentials() { + public APIApplicationKey createAndRetrieveApplicationCredentials() + throws APIApplicationServicesException, BadRequestException { JsonObject jsonObject = new JsonObject(); jsonObject.addProperty("callbackUrl",Constants.EMPTY_STRING); @@ -109,6 +120,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { // JSONObject responseObj = new JSONObject(Objects.requireNonNull(response.body()).string()); +<<<<<<< HEAD } catch (IOException e) { throw new RuntimeException(e); } @@ -159,10 +171,54 @@ public class APIApplicationServicesImpl implements APIApplicationServices { // log.error("failed to call http client.", e); // } return null; +======= + String jsonString = registrationProfile.toJSON(); + StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); + request.setEntity(entity); + + //ToDo: Remove hardcoded value + String basicAuth = getBase64Encode("admin", "admin"); + request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); + request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); + + HttpResponse httpResponse = httpclient.execute(request); + + if (httpResponse != null) { + String response = PublisherRESTAPIUtil.getResponseString(httpResponse); + try { + if(response != null){ + JSONParser jsonParser = new JSONParser(); + JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); + APIApplicationKey apiApplicationKey = new APIApplicationKey(); + apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); + apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); + return apiApplicationKey; + } else { + String msg = "Request payload is null. Please verify the request payload."; + log.error(msg); + throw new BadRequestException(msg); + } + } catch (ParseException e) { + throw new APIApplicationServicesException("Error when parsing the response " + response, e); + } + } else { + return null; + } + } catch (IOException e) { + throw new APIApplicationServicesException("Error when reading the response from buffer.", e); + } catch (KeyStoreException e) { + throw new APIApplicationServicesException("Failed loading the keystore.", e); + } catch (NoSuchAlgorithmException e) { + throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); + } catch (KeyManagementException e) { + throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); + } +>>>>>>> e76624c1de (Add exceptions) } @Override - public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) { + public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) + throws APIApplicationServicesException { List params = new ArrayList<>(); params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); //ToDo: Remove hardcoded value @@ -173,7 +229,8 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } @Override - public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) { + public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) + throws APIApplicationServicesException { List params = new ArrayList<>(); params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE)); params.add(new BasicNameValuePair(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken)); @@ -181,8 +238,10 @@ public class APIApplicationServicesImpl implements APIApplicationServices { return getToken(params, consumerKey, consumerSecret); } - public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) { + public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) + throws APIApplicationServicesException{ + String response = null; try { URL url = new URL("https://localhost:9443/oauth2/token"); HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); @@ -193,7 +252,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); HttpResponse httpResponse = httpclient.execute(request); - String response = PublisherRESTAPIUtil.getResponseString(httpResponse); + response = PublisherRESTAPIUtil.getResponseString(httpResponse); if (log.isDebugEnabled()) { log.debug(response); } @@ -210,9 +269,16 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } return accessTokenInfo; - } catch (IOException | KeyStoreException | NoSuchAlgorithmException | - KeyManagementException| ParseException e) { - throw new RuntimeException(e); + } catch (IOException e) { + throw new APIApplicationServicesException("Error when reading the response from buffer.", e); + } catch (KeyStoreException e) { + throw new APIApplicationServicesException("Failed loading the keystore.", e); + } catch (NoSuchAlgorithmException e) { + throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); + } catch (ParseException e) { + throw new APIApplicationServicesException("Error when parsing the response " + response, e); + } catch (KeyManagementException e) { + throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java index 335680a84dd..6e37e019862 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java @@ -3,9 +3,10 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api; import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; import io.entgra.devicemgt.apimgt.extension.publisher.api.util.ScopeUtils; -import org.apache.axis2.databinding.types.xsd._boolean; import org.apache.commons.httpclient.HttpStatus; import org.apache.http.HttpHeaders; import org.apache.http.client.methods.HttpHead; @@ -28,104 +29,8 @@ import java.security.NoSuchAlgorithmException; public class PublisherRESTAPIServices { private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); -// private String clientId; -// private String clientSecret; -// private String accessToken; -// -// public AccessTokenInfo registerApplication() { -// -// try { -// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPost request = new HttpPost(url.toString()); -// -// RegistrationProfile registrationProfile = new RegistrationProfile(); -// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); -// registrationProfile.setClientName(Constants.CLIENT_NAME); -// registrationProfile.setGrantType(Constants.GRANT_TYPE); -// registrationProfile.setOwner(Constants.OWNER); -// registrationProfile.setIsSaasApp(true); -// -// String jsonString = registrationProfile.toJSON(); -// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); -// request.setEntity(entity); -// -// String basicAuth = getBase64Encode("admin", "admin"); -// -// request.setHeader("Authorization", "Basic " + basicAuth); -// request.setHeader("Content-Type", "application/json"); -// -// HttpResponse httpResponse = httpclient.execute(request); -// -// if (httpResponse != null) { -// -// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); -// try { -// if(response != null){ -// JSONParser jsonParser = new JSONParser(); -// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); -// clientId = (String) jsonPayload.get(Constants.CLIENT_ID); -// clientSecret = (String) jsonPayload.get(Constants.CLIENT_SECRET); -// } -// } catch (ParseException e) { -// throw new RuntimeException(e); -// } -// System.out.println(response); -// } -// System.out.println(httpResponse.getStatusLine().getStatusCode()); -// -// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | -// KeyManagementException e) { -// log.error("failed to call http client.", e); -// } -// return getAccessTokenFromRegisteredApplication(clientId, clientSecret); -// -// } -// -// public AccessTokenInfo getAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) { -// List params = new ArrayList<>(); -// params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); -// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); -// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); -// params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); -// return getToken(params, consumerKey, consumerSecret); -// } -// -// public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) { -// -// String token = null; -// String response = null; -// try { -// URL url = new URL("https://localhost:9443/oauth2/token"); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPost request = new HttpPost(url.toString()); -// -// request.addHeader("Authorization", "Basic " + getBase64Encode(clientId, clientSecret)); -// request.addHeader("Content-Type", "application/x-www-form-urlencoded"); -// request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); -// HttpResponse httpResponse = httpclient.execute(request); -// response = PublisherRESTAPIUtil.getResponseString(httpResponse); -// JSONParser jsonParser = new JSONParser(); -// JSONObject jsonObject = (JSONObject) jsonParser.parse(response); -// AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); -// token = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); -// if (token != null && !token.isEmpty()){ -// accessTokenInfo.setRefreshToken(token); -// accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); -// accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); -// accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); -// accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); -// } -// accessToken = token; -// return accessTokenInfo; -// -// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | -// KeyManagementException| ParseException e) { -// throw new RuntimeException(e); -// } -// } - - public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key){ + public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) + throws APIApplicationServicesException, BadRequestException { String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; @@ -144,19 +49,28 @@ public class PublisherRESTAPIServices { AccessTokenInfo refreshedAccessToken = apiApplicationServices. generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); return isSharedScopeNameExists(apiApplicationKey,refreshedAccessToken, key); - } else{ + } else if (HttpStatus.SC_BAD_REQUEST == httpResponse.getStatusLine().getStatusCode()){ + String response = httpResponse.toString(); + log.info(response); + throw new BadRequestException(response); + } else { return false; } - } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { - throw new RuntimeException(e); + } catch (IOException e) { + throw new APIApplicationServicesException("Error when reading the response from buffer.", e); + } catch (KeyStoreException e) { + throw new APIApplicationServicesException("Failed loading the keystore.", e); + } catch (NoSuchAlgorithmException e) { + throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); + } catch (KeyManagementException e) { + throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); } } - public void updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope){ + public void updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) + throws APIApplicationServicesException, BadRequestException { -// String keyValue = new String(Base64.encodeBase64((scope.getKey()).getBytes())).replace("=", ""); -// String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); try { URL url = new URL(updateScopeUrl); @@ -182,16 +96,20 @@ public class PublisherRESTAPIServices { AccessTokenInfo accessTokenInfo1 = apiApplicationServices. generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); updateSharedScope(apiApplicationKey, accessTokenInfo1, scope); - } else { + } else if (HttpStatus.SC_BAD_REQUEST == httpResponse.getStatusLine().getStatusCode()){ String response = httpResponse.toString(); log.info(response); + throw new BadRequestException(response); } - } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { - throw new RuntimeException(e); + } catch (IOException e) { + throw new APIApplicationServicesException("Error when reading the response from buffer.", e); + } catch (KeyStoreException e) { + throw new APIApplicationServicesException("Failed loading the keystore.", e); + } catch (NoSuchAlgorithmException e) { + throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); + } catch (KeyManagementException e) { + throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); } } -// static String getBase64Encode(String key, String value) { -// return new String(Base64.encodeBase64((key + ":" + value).getBytes())); -// } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java new file mode 100644 index 00000000000..bd7aa85cd96 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java @@ -0,0 +1,12 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions; + +public class APIApplicationServicesException extends Exception{ + + public APIApplicationServicesException() {super();} + + public APIApplicationServicesException(String message) {super();} + + public APIApplicationServicesException(String message, Throwable cause){super();} + + public APIApplicationServicesException(Throwable cause){super();} +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java new file mode 100644 index 00000000000..1e58e27d7ba --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java @@ -0,0 +1,34 @@ +/* + * + * * Copyright (c) 2022, 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. + * + * + */ + +/** + * Custom exception class for handling bad request exceptions. + */ +package io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions; + +public class BadRequestException extends Exception { + + private static final long serialVersionUID = -2387103750774855056L; + + public BadRequestException(String errorMessage) { + super(errorMessage); + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java index a7299501bdd..85dcf72d138 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java @@ -19,6 +19,7 @@ package org.wso2.carbon.apimgt.webapp.publisher; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; /** diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index ea7f2e11089..c6f16436a19 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -23,6 +23,8 @@ import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -361,10 +363,21 @@ public class APIPublisherServiceImpl implements APIPublisherService { WebappPublisherConfig config = WebappPublisherConfig.getInstance(); List tenants = new ArrayList<>(Collections.singletonList(APIConstants.SUPER_TENANT_DOMAIN)); tenants.addAll(config.getTenants().getTenant()); + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - APIApplicationKey apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); - AccessTokenInfo accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( - apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + APIApplicationKey apiApplicationKey; + AccessTokenInfo accessTokenInfo; + try { + apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); + accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + } catch (BadRequestException e) { + String errorMsg = "Error while generating application"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(e); + } catch (APIApplicationServicesException e) { + throw new RuntimeException(e); + } try { for (String tenantDomain : tenants) { @@ -433,6 +446,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } catch (IOException | DirectoryIteratorException ex) { log.error("failed to read scopes from file.", ex); + } catch (APIApplicationServicesException | BadRequestException e) { + String errorMsg = "Error while generating an OAuth token"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(e); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index bfcafcc2c84..a530fa5b479 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -19,6 +19,7 @@ package org.wso2.carbon.apimgt.webapp.publisher; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; From 0d7057640110c7ee92f59867fde681a20a124bd7 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 17 Apr 2023 09:49:43 +0530 Subject: [PATCH 10/22] change http client to okhttp --- .../pom.xml | 15 +- .../APIApplicationServices.java | 3 +- .../APIApplicationServicesImpl.java | 104 +++++++++--- .../PublisherAPIServiceStartupHandler.java | 159 ------------------ .../PublisherRESTAPIServices.java | 111 +++++------- .../dto/APIApplicationKey.java | 70 +++++++- .../exceptions/BadRequestException.java | 2 + .../internal/PublisherRESTAPIDataHolder.java | 30 ++++ .../PublisherRESTAPIServiceComponent.java | 23 +-- .../pom.xml | 5 + .../publisher/APIPublisherServiceImpl.java | 9 +- .../publisher/APIPublisherStartupHandler.java | 10 +- components/apimgt-extensions/pom.xml | 46 ----- 13 files changed, 264 insertions(+), 323 deletions(-) delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml index 002909f6444..8e25736b1f9 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -79,8 +79,13 @@ feign-okhttp +<<<<<<< HEAD org.wso2.carbon.apimgt org.wso2.carbon.apimgt.api +======= + org.json.wso2 + json +>>>>>>> 2855ef0a30 (change http client to okhttp) @@ -110,7 +115,6 @@ javax.net.ssl, - org.apache.commons.logging, org.apache.http;version="${httpclient.version.range}", org.apache.http.client;version="${httpclient.version.range}", @@ -123,17 +127,12 @@ org.osgi.framework.*;version="${imp.package.version.osgi.framework}", org.osgi.service.*;version="${imp.package.version.osgi.service}", - - org.wso2.carbon.core, org.apache.commons.ssl, - - - - org.apache.commons.httpclient, org.wso2.carbon.apimgt.api.model, - okhttp3.* + okhttp3.*, + org.json diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java index 5ca41cf6e2f..401f680214f 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java @@ -3,11 +3,10 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; public interface APIApplicationServices { - APIApplicationKey createAndRetrieveApplicationCredentials() throws BadRequestException, APIApplicationServicesException; + APIApplicationKey createAndRetrieveApplicationCredentials() throws APIApplicationServicesException; AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIApplicationServicesException; AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIApplicationServicesException; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java index 55c544d25b2..c2aa63c4329 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java @@ -1,48 +1,109 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api; -import com.google.gson.JsonObject; -import io.entgra.devicemgt.apimgt.extension.publisher.api.bean.RegistrationProfile; +import com.google.gson.Gson; +import org.json.JSONObject; import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; import okhttp3.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.ssl.Base64; -import org.apache.http.HttpHeaders; -import org.apache.http.HttpResponse; -import org.apache.http.NameValuePair; -import org.apache.http.client.HttpClient; -import org.apache.http.client.entity.UrlEncodedFormEntity; -import org.apache.http.client.methods.HttpPost; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; -import org.apache.http.message.BasicNameValuePair; -import org.json.simple.JSONObject; -import org.json.simple.parser.JSONParser; -import org.json.simple.parser.ParseException; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; import javax.net.ssl.TrustManager; import javax.net.ssl.X509TrustManager; import java.io.IOException; -import java.net.URL; import java.security.KeyManagementException; -import java.security.KeyStoreException; import java.security.NoSuchAlgorithmException; -import java.util.*; public class APIApplicationServicesImpl implements APIApplicationServices { private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); <<<<<<< HEAD private static final OkHttpClient client = getOkHttpClient(); + private static final Gson gson = new Gson(); + private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); + String msg = null; + // private ApiApplicationConfigurations ApplicationConfig = null; - private static OkHttpClient getOkHttpClient() { + @Override + public APIApplicationKey createAndRetrieveApplicationCredentials() + throws APIApplicationServicesException { + + JSONObject jsonObject = new JSONObject(); + jsonObject.put("callbackUrl", Constants.EMPTY_STRING); + jsonObject.put("clientName",Constants.CLIENT_NAME); + jsonObject.put("grantType",Constants.GRANT_TYPE); + jsonObject.put("owner",Constants.OWNER); + jsonObject.put("saasApp",true); + + RequestBody requestBody = RequestBody.Companion.create(jsonObject.toString(), JSON); + String keyManagerEndpoint = "https://localhost:9443/client-registration/v0.17/register"; + + Request request = new Request.Builder() + .url(keyManagerEndpoint) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) + .post(requestBody) + .build(); + try { + Response response = client.newCall(request).execute(); + return gson.fromJson(response.body().string(), APIApplicationKey.class); + } catch (IOException e) { + msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); + } + } + + @Override + public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) + throws APIApplicationServicesException { + JSONObject params = new JSONObject(); + params.put(Constants.GRANT_TYPE_PARAM_NAME,Constants.PASSWORD_GRANT_TYPE); + //ToDo: Remove hardcoded value + params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME,"admin"); + params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD,"admin"); + params.put(Constants.SCOPE_PARAM_NAME,Constants.SCOPES); + return getToken(params, consumerKey, consumerSecret); + } + + @Override + public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) + throws APIApplicationServicesException { + + JSONObject params = new JSONObject(); + params.put(Constants.GRANT_TYPE_PARAM_NAME,Constants.REFRESH_TOKEN_GRANT_TYPE); + //ToDo: Remove hardcoded value + params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken); + params.put(Constants.SCOPE_PARAM_NAME,Constants.SCOPES); + return getToken(params, consumerKey, consumerSecret); + } + + public AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret) + throws APIApplicationServicesException{ + + RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON); + //application/x-www-form-urlencoded + String keyManagerEndpoint = "https://localhost:9443/oauth2/token"; + + Request request = new Request.Builder() + .url(keyManagerEndpoint) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic(clientId, clientSecret)) + .post(requestBody) + .build(); + + try { + Response response = client.newCall(request).execute(); + return gson.fromJson(response.body().string(), AccessTokenInfo.class); + } catch (IOException e) { + msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); + } + } + + protected static OkHttpClient getOkHttpClient() { X509TrustManager trustAllCerts = new X509TrustManager() { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return new java.security.cert.X509Certificate[0]; @@ -91,6 +152,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } } +<<<<<<< HEAD @Override public APIApplicationKey createAndRetrieveApplicationCredentials() throws APIApplicationServicesException, BadRequestException { @@ -285,4 +347,6 @@ public class APIApplicationServicesImpl implements APIApplicationServices { static String getBase64Encode(String key, String value) { return new String(Base64.encodeBase64((key + ":" + value).getBytes())); } +======= +>>>>>>> 2855ef0a30 (change http client to okhttp) } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java deleted file mode 100644 index 2b005b0cc0d..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherAPIServiceStartupHandler.java +++ /dev/null @@ -1,159 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; - -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.wso2.carbon.core.ServerStartupObserver; - -public class PublisherAPIServiceStartupHandler implements ServerStartupObserver { - - private static final Log log = LogFactory.getLog(PublisherAPIServiceStartupHandler.class); - private PublisherRESTAPIServices publisherRESTAPIServices; - private AccessTokenInfo accessTokenInfo; - - @Override - public void completingServerStartup() { - - } - - @Override - public void completedServerStartup() { - -// String cid = null; -// String cS = null; -// String token = null; -// AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); -// -// try { -// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPost request = new HttpPost(url.toString()); -// -// RegistrationProfile registrationProfile = new RegistrationProfile(); -// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); -// registrationProfile.setClientName(Constants.CLIENT_NAME); -// registrationProfile.setOwner(Constants.OWNER); -// registrationProfile.setGrantType(Constants.GRANT_TYPE); -// registrationProfile.setIsSaasApp(true); -// -// String jsonString = registrationProfile.toJSON(); -// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); -// request.setEntity(entity); -// -// String basicAuth = PublisherRESTAPIServices.getBase64Encode("admin", "admin"); -// -// request.setHeader("Authorization", "Basic " + basicAuth); -// request.setHeader("Content-Type", "application/json"); -// -// HttpResponse httpResponse = httpclient.execute(request); -// -// if (httpResponse != null) { -// -// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); -// try { -// if(response != null){ -// JSONParser jsonParser = new JSONParser(); -// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); -// String clientId = (String) jsonPayload.get(Constants.CLIENT_ID); -// String clientSecret = (String) jsonPayload.get(Constants.CLIENT_SECRET); -// cid = clientId; -// cS = clientSecret; -// } -// } catch (ParseException e) { -// throw new RuntimeException(e); -// } -// -// System.out.println(response); -// } -// System.out.println(httpResponse.getStatusLine().getStatusCode()); -// -// -// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | -// KeyManagementException e) { -// log.error("failed to call http client.", e); -// } -// -// -// String response = null; -// -// List params = new ArrayList<>(); -// params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); -// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); -// params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); -// params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); -// try { -// URL url = new URL("https://localhost:9443/oauth2/token"); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPost request = new HttpPost(url.toString()); -// -// request.addHeader("Authorization", "Basic " + PublisherRESTAPIServices.getBase64Encode(cid, cS)); -// request.addHeader("Content-Type", "application/x-www-form-urlencoded"); -// request.setEntity(new UrlEncodedFormEntity(params)); -// HttpResponse httpResponse = httpclient.execute(request); -// response = PublisherRESTAPIUtil.getResponseString(httpResponse); -// JSONParser jsonParser = new JSONParser(); -// JSONObject jsonObject = (JSONObject) jsonParser.parse(response); -// token = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); -// if (token != null && !token.isEmpty()){ -// accessTokenInfo.setRefreshToken(token); -// accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); -// accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); -// accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); -// accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); -// } -// System.out.println(accessTokenInfo); -// -// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | -// KeyManagementException| ParseException e) { -// throw new RuntimeException(e); -// } -// -// String key = "perm:sms-handler:view-configuration"; -// String value = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); -// -// -// String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + value; -// try { -// URL url = new URL(getScopeUrl); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpHead request = new HttpHead(url.toString()); -// -// request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token); -// HttpResponse httpResponse = httpclient.execute(request); -// -// String code = String.valueOf(httpResponse.getStatusLine().getStatusCode()); -// System.out.println(code); -// -// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { -// throw new RuntimeException(e); -// } -// -// String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + "27fce6f1-6741-4ad5-b700-a56427fd3dbb"; -// try { -// URL url = new URL(updateScopeUrl); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPut request = new HttpPut(url.toString()); -// -// request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token); -// request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); -// -// -// String jsonString = "{\"name\": \"" + "name" + "\",\"displayName\": \"" + "displayname" + -// "\", \"description\": \"" + "description" + "\"," + "\"bindings\": [" + -// "\"Internal/devicemgt-user\"]}"; -// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); -// request.setEntity(entity); -// -// HttpResponse httpResponse = httpclient.execute(request); -// int code = httpResponse.getStatusLine().getStatusCode(); -// System.out.println(code); -// } catch (IOException | KeyStoreException | NoSuchAlgorithmException | KeyManagementException e) { -// throw new RuntimeException(e); -// } - - -// publisherRESTAPIServices = new PublisherRESTAPIServices(); -// publisherRESTAPIServices.isSharedScopeNameExists("perm:sms-handler:view-configuration"); - - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java index 6e37e019862..a0bb43217d0 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java @@ -5,111 +5,92 @@ import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.util.PublisherRESTAPIUtil; -import io.entgra.devicemgt.apimgt.extension.publisher.api.util.ScopeUtils; +import okhttp3.*; import org.apache.commons.httpclient.HttpStatus; -import org.apache.http.HttpHeaders; -import org.apache.http.client.methods.HttpHead; -import org.apache.http.client.methods.HttpPut; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.commons.ssl.Base64; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.entity.ContentType; -import org.apache.http.entity.StringEntity; +import org.json.JSONObject; import org.wso2.carbon.apimgt.api.model.Scope; import java.io.IOException; -import java.net.URL; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; +import static io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl.getOkHttpClient; public class PublisherRESTAPIServices { private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); + private static final OkHttpClient client = getOkHttpClient(); + private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) throws APIApplicationServicesException, BadRequestException { String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; - try { - URL url = new URL(getScopeUrl); - HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); - HttpHead request = new HttpHead(url.toString()); - - request.setHeader(HttpHeaders.AUTHORIZATION, "Bearer " + accessTokenInfo.getAccessToken()); - HttpResponse httpResponse = httpclient.execute(request); - if (HttpStatus.SC_OK == httpResponse.getStatusLine().getStatusCode()){ + Request request = new Request.Builder() + .url(getScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccessToken()) + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + if (response.code() == HttpStatus.SC_OK){ return true; - } else if(HttpStatus.SC_UNAUTHORIZED == httpResponse.getStatusLine().getStatusCode()) { + }else if(HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); + //max attempt count return isSharedScopeNameExists(apiApplicationKey,refreshedAccessToken, key); - } else if (HttpStatus.SC_BAD_REQUEST == httpResponse.getStatusLine().getStatusCode()){ - String response = httpResponse.toString(); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()){ log.info(response); - throw new BadRequestException(response); + throw new BadRequestException(response.toString()); } else { return false; } - } catch (IOException e) { - throw new APIApplicationServicesException("Error when reading the response from buffer.", e); - } catch (KeyStoreException e) { - throw new APIApplicationServicesException("Failed loading the keystore.", e); - } catch (NoSuchAlgorithmException e) { - throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); - } catch (KeyManagementException e) { - throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); + String msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); } } - public void updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) + public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) throws APIApplicationServicesException, BadRequestException { String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); - try { - URL url = new URL(updateScopeUrl); - HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); - HttpPut request = new HttpPut(url.toString()); - request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + - accessTokenInfo.getAccessToken()); - request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); + JSONObject setScope = new JSONObject(); + setScope.put("name", scope.getKey()); + setScope.put("displayName", scope.getName()); + setScope.put("description", scope.getDescription()); + setScope.put("bindings", scope.getRoles()); + - ScopeUtils setScope = new ScopeUtils(); - setScope.setKey(scope.getKey()); - setScope.setName(scope.getName()); - setScope.setDescription(scope.getDescription()); - setScope.setRoles(scope.getRoles()); - String jsonString = setScope.toJSON(); - StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); - request.setEntity(entity); + RequestBody requestBody = RequestBody.Companion.create(setScope.toString(), JSON); + Request request = new Request.Builder() + .url(updateScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccessToken()) + .put(requestBody) + .build(); - HttpResponse httpResponse = httpclient.execute(request); - if (HttpStatus.SC_OK != httpResponse.getStatusLine().getStatusCode() && HttpStatus.SC_UNAUTHORIZED == httpResponse.getStatusLine().getStatusCode()){ + try { + Response response = client.newCall(request).execute(); + if (response.code() == HttpStatus.SC_OK) { + return true; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo accessTokenInfo1 = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); - updateSharedScope(apiApplicationKey, accessTokenInfo1, scope); - } else if (HttpStatus.SC_BAD_REQUEST == httpResponse.getStatusLine().getStatusCode()){ - String response = httpResponse.toString(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { log.info(response); - throw new BadRequestException(response); + throw new BadRequestException(response.toString()); + } else { + return false; } - } catch (IOException e) { - throw new APIApplicationServicesException("Error when reading the response from buffer.", e); - } catch (KeyStoreException e) { - throw new APIApplicationServicesException("Failed loading the keystore.", e); - } catch (NoSuchAlgorithmException e) { - throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); - } catch (KeyManagementException e) { - throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); + String msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); } } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java index fdd20f2f221..d0fc3b9f68b 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java @@ -4,9 +4,20 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; * This holds api application consumer id and secret. */ public class APIApplicationKey { - + private String clientName; private String clientId; private String clientSecret; + private String callBackURL; + private String isSaasApplication; + private String appOwner; + private String jsonString; + private String jsonAppAttribute; + private String tokenType; + + public APIApplicationKey(String clientId, String clientSecret){ + this.clientId = clientId; + this.clientSecret = clientSecret; + } public String getClientId() { return clientId; @@ -23,4 +34,61 @@ public class APIApplicationKey { public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } + public String getClientName() { + return clientName; + } + + public void setClientName(String clientName) { + this.clientName = clientName; + } + + + public String getCallBackURL() { + return callBackURL; + } + + public void setCallBackURL(String callBackURL) { + this.callBackURL = callBackURL; + } + + public String getIsSaasApplication() { + return isSaasApplication; + } + + public void setIsSaasApplication(String isSaasApplication) { + this.isSaasApplication = isSaasApplication; + } + + public String getAppOwner() { + return appOwner; + } + + public void setAppOwner(String appOwner) { + this.appOwner = appOwner; + } + + public String getJsonString() { + return jsonString; + } + + public void setJsonString(String jsonString) { + this.jsonString = jsonString; + } + + public String getJsonAppAttribute() { + return jsonAppAttribute; + } + + public void setJsonAppAttribute(String jsonAppAttribute) { + this.jsonAppAttribute = jsonAppAttribute; + } + + public String getTokenType() { + return tokenType; + } + + public void setTokenType(String tokenType) { + this.tokenType = tokenType; + } + } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java index 1e58e27d7ba..427c4b5e358 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java @@ -24,6 +24,8 @@ */ package io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions; +import okhttp3.Response; + public class BadRequestException extends Exception { private static final long serialVersionUID = -2387103750774855056L; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java new file mode 100644 index 00000000000..885f3ead7aa --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java @@ -0,0 +1,30 @@ +package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; + +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; + +public class PublisherRESTAPIDataHolder { + + private static final PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); + + private APIApplicationServices apiApplicationServices; +// +// private PublisherRESTAPIServices publisherRESTAPIServices; + + public static PublisherRESTAPIDataHolder getInstance(){ + return thisInstance; + } + public APIApplicationServices getApiApplicationServices() { + return apiApplicationServices; + } + public void setApiApplicationServices(APIApplicationServices apiApplicationServices) { + this.apiApplicationServices = apiApplicationServices; + } +// public PublisherRESTAPIServices getPublisherRESTAPIServices() { +// return publisherRESTAPIServices; +// } +// public void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) { +// this.publisherRESTAPIServices = publisherRESTAPIServices; +// } + +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java index 612f77a8d96..d34012c1f46 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java @@ -1,13 +1,12 @@ package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherAPIServiceStartupHandler; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; -import org.wso2.carbon.core.ServerShutdownHandler; -import org.wso2.carbon.core.ServerStartupObserver; /** * @scr.component name="io.entgra.devicemgt.apimgt.extension.publisher.api.internal.PublisherRESTAPIServiceComponent" @@ -24,17 +23,19 @@ public class PublisherRESTAPIServiceComponent { try { BundleContext bundleContext = componentContext.getBundleContext(); - PublisherAPIServiceStartupHandler publisherAPIServiceStartupHandler = new PublisherAPIServiceStartupHandler(); - bundleContext.registerService(PublisherAPIServiceStartupHandler.class.getName(), publisherAPIServiceStartupHandler, null); - bundleContext.registerService(ServerStartupObserver.class.getName(), publisherAPIServiceStartupHandler, null); - bundleContext.registerService(ServerShutdownHandler.class.getName(), publisherAPIServiceStartupHandler, null); - - PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); - bundleContext.registerService(PublisherRESTAPIServices.class.getName(), publisherRESTAPIServices, null); +// PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); +// bundleContext.registerService(PublisherRESTAPIServices.class.getName(), publisherRESTAPIServices, null); +// PublisherRESTAPIDataHolder.getInstance().setPublisherRESTAPIServices(publisherRESTAPIServices); + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + bundleContext.registerService(APIApplicationServices.class.getName(), apiApplicationServices, null); + PublisherRESTAPIDataHolder.getInstance().setApiApplicationServices(apiApplicationServices); + if (log.isDebugEnabled()) { + log.debug("API Application bundle has been successfully initialized"); + } } catch (Exception e) { - throw new RuntimeException(e); + log.error("Error occurred while initializing API Application bundle", e); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index 0ca58492f50..d9246c253a2 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -126,6 +126,10 @@ org.wso2.carbon.devicemgt io.entgra.devicemgt.apimgt.extension.publisher.api + + org.wso2.carbon.devicemgt + io.entgra.devicemgt.apimgt.extension.publisher.api + @@ -171,6 +175,7 @@ org.w3c.dom, io.entgra.devicemgt.apimgt.extension.publisher.api, io.entgra.devicemgt.apimgt.extension.publisher.api.dto, + io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions, org.wso2.carbon.apimgt.annotations.api, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index c6f16436a19..2fe4883df58 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -371,12 +371,10 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - } catch (BadRequestException e) { + } catch (APIApplicationServicesException e) { String errorMsg = "Error while generating application"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); - } catch (APIApplicationServicesException e) { - throw new RuntimeException(e); } try { @@ -384,9 +382,6 @@ public class APIPublisherServiceImpl implements APIPublisherService { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); -// APIProvider apiProvider = API_MANAGER_FACTORY.getAPIProvider(MultitenantUtils.getTenantAwareUsername( -// PrivilegedCarbonContext.getThreadLocalCarbonContext().getUserRealm().getRealmConfiguration() -// .getAdminUserName())); try { String fileName = @@ -447,7 +442,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { } catch (IOException | DirectoryIteratorException ex) { log.error("failed to read scopes from file.", ex); } catch (APIApplicationServicesException | BadRequestException e) { - String errorMsg = "Error while generating an OAuth token"; + String errorMsg = "Error while Calling APIs"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index a530fa5b479..3933f60716d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -19,6 +19,11 @@ package org.wso2.carbon.apimgt.webapp.publisher; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -53,10 +58,7 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { log.debug("Total number of unpublished APIs: " + APIPublisherDataHolder.getInstance().getUnpublishedApis().size()); } - try { - } catch (Exception e) { - throw new RuntimeException(e); - } + publisher = APIPublisherDataHolder.getInstance().getApiPublisherService(); int retryCount = 0; while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) { diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 747eb843dda..ae822fd4eb6 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -25,52 +25,6 @@ 5.0.26-SNAPSHOT ../../pom.xml - - - org.apache.httpcomponents.wso2 - httpcore - - - org.wso2.orbit.org.apache.httpcomponents - httpclient - - - org.wso2.carbon - org.wso2.carbon.logging - - - org.wso2.carbon - org.wso2.carbon.utils - - - org.eclipse.osgi - org.eclipse.osgi - - - org.eclipse.osgi - org.eclipse.osgi.services - - - org.wso2.carbon - org.wso2.carbon.core - - - com.googlecode.json-simple.wso2 - json-simple - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api - - - com.squareup.okhttp3 - okhttp - - - io.github.openfeign - feign-okhttp - - 4.0.0 apimgt-extensions From e920df6da3ff4a9d8f104e9e8027c3e1e6dacfc4 Mon Sep 17 00:00:00 2001 From: pasindu Date: Mon, 17 Apr 2023 13:31:49 +0530 Subject: [PATCH 11/22] Minor changes --- .../pom.xml | 7 +- .../APIApplicationServicesImpl.java | 212 +----------------- .../pom.xml | 5 +- components/apimgt-extensions/pom.xml | 18 ++ 4 files changed, 26 insertions(+), 216 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml index 8e25736b1f9..0b2d3f034b1 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.21-SNAPSHOT + 5.0.25-SNAPSHOT ../pom.xml @@ -79,13 +79,12 @@ feign-okhttp -<<<<<<< HEAD org.wso2.carbon.apimgt org.wso2.carbon.apimgt.api -======= + + org.json.wso2 json ->>>>>>> 2855ef0a30 (change http client to okhttp) diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java index c2aa63c4329..5e6439edbbd 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java @@ -9,7 +9,6 @@ import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicat import okhttp3.*; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.commons.ssl.Base64; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -22,7 +21,6 @@ import java.security.NoSuchAlgorithmException; public class APIApplicationServicesImpl implements APIApplicationServices { private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); -<<<<<<< HEAD private static final OkHttpClient client = getOkHttpClient(); private static final Gson gson = new Gson(); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); @@ -53,6 +51,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { return gson.fromJson(response.body().string(), APIApplicationKey.class); } catch (IOException e) { msg = "Error occurred while processing the response"; + log.error(msg); throw new APIApplicationServicesException(msg); } } @@ -86,10 +85,10 @@ public class APIApplicationServicesImpl implements APIApplicationServices { RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON); //application/x-www-form-urlencoded - String keyManagerEndpoint = "https://localhost:9443/oauth2/token"; + String tokenEndPoint = "https://localhost:9443/oauth2/token"; Request request = new Request.Builder() - .url(keyManagerEndpoint) + .url(tokenEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic(clientId, clientSecret)) .post(requestBody) .build(); @@ -99,6 +98,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { return gson.fromJson(response.body().string(), AccessTokenInfo.class); } catch (IOException e) { msg = "Error occurred while processing the response"; + log.error(msg); throw new APIApplicationServicesException(msg); } } @@ -121,13 +121,6 @@ public class APIApplicationServicesImpl implements APIApplicationServices { .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) .hostnameVerifier((hostname, sslSession) -> true).build(); } -======= -// private final OkHttpClient client; - -// public APIApplicationServicesImpl() { -// this.client = new OkHttpClient(); -// } ->>>>>>> e76624c1de (Add exceptions) private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { try { @@ -152,201 +145,4 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } } -<<<<<<< HEAD - @Override - public APIApplicationKey createAndRetrieveApplicationCredentials() - throws APIApplicationServicesException, BadRequestException { - - JsonObject jsonObject = new JsonObject(); - jsonObject.addProperty("callbackUrl",Constants.EMPTY_STRING); - jsonObject.addProperty("clientName",Constants.CLIENT_NAME); - jsonObject.addProperty("grantType",Constants.EMPTY_STRING); - jsonObject.addProperty("owner",Constants.OWNER); - jsonObject.addProperty("saasApp",true); - - MediaType jsonMediaType = MediaType.parse("application/json; charset=utf-8"); - RequestBody requestBody = RequestBody.create(jsonMediaType, jsonObject.toString()); - - String keyManagerEndpoint = "https://localhost:9443/client-registration/v0.17/register"; - - Request request = new Request.Builder() - .url(keyManagerEndpoint) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) - .post(requestBody) - .build(); - try { - Response response = client.newCall(request).execute(); - System.out.println(request); - System.out.println("---------------------------"); - System.out.println(response); - -// JSONObject responseObj = new JSONObject(Objects.requireNonNull(response.body()).string()); - -<<<<<<< HEAD - } catch (IOException e) { - throw new RuntimeException(e); - } - -// try { -// URL url = new URL("https://localhost:9443/client-registration/v0.17/register"); -// HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); -// HttpPost request = new HttpPost(url.toString()); -// -// RegistrationProfile registrationProfile = new RegistrationProfile(); -// registrationProfile.setCallbackUrl(Constants.EMPTY_STRING); -// registrationProfile.setClientName(Constants.CLIENT_NAME); -// registrationProfile.setGrantType(Constants.GRANT_TYPE); -// registrationProfile.setOwner(Constants.OWNER); -// registrationProfile.setIsSaasApp(true); -// -// String jsonString = registrationProfile.toJSON(); -// StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); -// request.setEntity(entity); -// -// //ToDo: Remove hardcoded value -// String basicAuth = getBase64Encode("admin", "admin"); -// request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); -// request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); -// -// HttpResponse httpResponse = httpclient.execute(request); -// -// if (httpResponse != null) { -// String response = PublisherRESTAPIUtil.getResponseString(httpResponse); -// try { -// if(response != null){ -// JSONParser jsonParser = new JSONParser(); -// JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); -// APIApplicationKey apiApplicationKey = new APIApplicationKey(); -// apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); -// apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); -// return apiApplicationKey; -// } else { -// return null; -// } -// } catch (ParseException e) { -// throw new RuntimeException(e); -// } -// } -// -// } catch (IOException | NoSuchAlgorithmException | KeyStoreException | -// KeyManagementException e) { -// log.error("failed to call http client.", e); -// } - return null; -======= - String jsonString = registrationProfile.toJSON(); - StringEntity entity = new StringEntity(jsonString, ContentType.APPLICATION_JSON); - request.setEntity(entity); - - //ToDo: Remove hardcoded value - String basicAuth = getBase64Encode("admin", "admin"); - request.setHeader(HttpHeaders.AUTHORIZATION, Constants.AUTHORIZATION_HEADER_VALUE_PREFIX + basicAuth); - request.setHeader(HttpHeaders.CONTENT_TYPE, Constants.APPLICATION_JSON); - - HttpResponse httpResponse = httpclient.execute(request); - - if (httpResponse != null) { - String response = PublisherRESTAPIUtil.getResponseString(httpResponse); - try { - if(response != null){ - JSONParser jsonParser = new JSONParser(); - JSONObject jsonPayload = (JSONObject) jsonParser.parse(response); - APIApplicationKey apiApplicationKey = new APIApplicationKey(); - apiApplicationKey.setClientId((String) jsonPayload.get(Constants.CLIENT_ID)); - apiApplicationKey.setClientSecret((String) jsonPayload.get(Constants.CLIENT_SECRET)); - return apiApplicationKey; - } else { - String msg = "Request payload is null. Please verify the request payload."; - log.error(msg); - throw new BadRequestException(msg); - } - } catch (ParseException e) { - throw new APIApplicationServicesException("Error when parsing the response " + response, e); - } - } else { - return null; - } - } catch (IOException e) { - throw new APIApplicationServicesException("Error when reading the response from buffer.", e); - } catch (KeyStoreException e) { - throw new APIApplicationServicesException("Failed loading the keystore.", e); - } catch (NoSuchAlgorithmException e) { - throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); - } catch (KeyManagementException e) { - throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); - } ->>>>>>> e76624c1de (Add exceptions) - } - - @Override - public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) - throws APIApplicationServicesException { - List params = new ArrayList<>(); - params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE)); - //ToDo: Remove hardcoded value - params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin")); - params.add(new BasicNameValuePair(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin")); - params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); - return getToken(params, consumerKey, consumerSecret); - } - - @Override - public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) - throws APIApplicationServicesException { - List params = new ArrayList<>(); - params.add(new BasicNameValuePair(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE)); - params.add(new BasicNameValuePair(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken)); - params.add(new BasicNameValuePair(Constants.SCOPE_PARAM_NAME, Constants.SCOPES)); - return getToken(params, consumerKey, consumerSecret); - } - - public AccessTokenInfo getToken(List nameValuePairs, String clientId, String clientSecret) - throws APIApplicationServicesException{ - - String response = null; - try { - URL url = new URL("https://localhost:9443/oauth2/token"); - HttpClient httpclient = PublisherRESTAPIUtil.getHttpClient(url.getProtocol()); - HttpPost request = new HttpPost(url.toString()); - - request.addHeader(HttpHeaders.AUTHORIZATION, "Basic " + getBase64Encode(clientId, clientSecret)); - request.addHeader(HttpHeaders.CONTENT_TYPE, "application/x-www-form-urlencoded"); - request.setEntity(new UrlEncodedFormEntity(nameValuePairs)); - - HttpResponse httpResponse = httpclient.execute(request); - response = PublisherRESTAPIUtil.getResponseString(httpResponse); - if (log.isDebugEnabled()) { - log.debug(response); - } - JSONParser jsonParser = new JSONParser(); - JSONObject jsonObject = (JSONObject) jsonParser.parse(response); - AccessTokenInfo accessTokenInfo = new AccessTokenInfo(); - String accessToken = (String) jsonObject.get(Constants.ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME); - if (accessToken != null && !accessToken.isEmpty()){ - accessTokenInfo.setAccessToken(accessToken); - accessTokenInfo.setRefreshToken((String) jsonObject.get(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME)); - accessTokenInfo.setExpiresIn((Long) jsonObject.get(Constants.OAUTH_EXPIRES_IN)); - accessTokenInfo.setTokenType((String) jsonObject.get(Constants.OAUTH_TOKEN_TYPE)); - accessTokenInfo.setScope((String) jsonObject.get(Constants.OAUTH_TOKEN_SCOPE)); - } - return accessTokenInfo; - - } catch (IOException e) { - throw new APIApplicationServicesException("Error when reading the response from buffer.", e); - } catch (KeyStoreException e) { - throw new APIApplicationServicesException("Failed loading the keystore.", e); - } catch (NoSuchAlgorithmException e) { - throw new APIApplicationServicesException("No such algorithm found when loading the ssl socket", e); - } catch (ParseException e) { - throw new APIApplicationServicesException("Error when parsing the response " + response, e); - } catch (KeyManagementException e) { - throw new APIApplicationServicesException("Failed setting up the ssl http client.", e); - } - } - - static String getBase64Encode(String key, String value) { - return new String(Base64.encodeBase64((key + ":" + value).getBytes())); - } -======= ->>>>>>> 2855ef0a30 (change http client to okhttp) } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index d9246c253a2..c08735db3fd 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -125,10 +125,7 @@ org.wso2.carbon.devicemgt io.entgra.devicemgt.apimgt.extension.publisher.api - - - org.wso2.carbon.devicemgt - io.entgra.devicemgt.apimgt.extension.publisher.api + provided diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index ae822fd4eb6..137f35b5724 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -25,6 +25,24 @@ 5.0.26-SNAPSHOT ../../pom.xml + + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.api + + + org.json.wso2 + json + + + io.github.openfeign + feign-okhttp + + + com.google.code.gson + gson + + 4.0.0 apimgt-extensions From aab94d8fdd5263762c90a9ae3978c3b963b5009f Mon Sep 17 00:00:00 2001 From: pasindu Date: Fri, 21 Apr 2023 00:26:16 +0530 Subject: [PATCH 12/22] Implement get scopesID API call and rename the module --- .../PublisherRESTAPIServices.java | 96 ------------ .../dto/AccessTokenInfo.java | 53 ------- .../internal/PublisherRESTAPIDataHolder.java | 30 ---- .../util/PublisherRESTAPIUtil.java | 67 --------- .../util/ScopeUtils.java | 59 -------- .../pom.xml | 12 +- .../rest/api}/APIApplicationServices.java | 8 +- .../rest/api}/APIApplicationServicesImpl.java | 57 +++++--- .../rest/api/PublisherRESTAPIServices.java | 137 ++++++++++++++++++ .../rest/api}/bean/RegistrationProfile.java | 2 +- .../rest/api}/constants/Constants.java | 2 +- .../rest/api}/dto/APIApplicationKey.java | 2 +- .../rest/api/dto/AccessTokenInfo.java | 53 +++++++ .../APIApplicationServicesException.java | 2 +- .../api}/exceptions/BadRequestException.java | 4 +- .../internal/PublisherRESTAPIDataHolder.java | 21 +++ .../PublisherRESTAPIServiceComponent.java | 13 +- .../extension/rest/api/util/ScopeUtils.java | 57 ++++++++ .../pom.xml | 15 +- .../webapp/publisher/APIPublisherService.java | 2 - .../publisher/APIPublisherServiceImpl.java | 49 ++++--- .../publisher/APIPublisherStartupHandler.java | 6 - components/apimgt-extensions/pom.xml | 18 ++- pom.xml | 2 +- 24 files changed, 377 insertions(+), 390 deletions(-) delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java delete mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api}/pom.xml (96%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/APIApplicationServices.java (58%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/APIApplicationServicesImpl.java (73%) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/bean/RegistrationProfile.java (96%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/constants/Constants.java (97%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/dto/APIApplicationKey.java (97%) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/exceptions/APIApplicationServicesException.java (83%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/exceptions/BadRequestException.java (91%) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api => io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api}/internal/PublisherRESTAPIServiceComponent.java (62%) create mode 100644 components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java deleted file mode 100644 index a0bb43217d0..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/PublisherRESTAPIServices.java +++ /dev/null @@ -1,96 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; - -import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; -import okhttp3.*; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.ssl.Base64; -import org.json.JSONObject; -import org.wso2.carbon.apimgt.api.model.Scope; - -import java.io.IOException; -import static io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl.getOkHttpClient; - -public class PublisherRESTAPIServices { - private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); - private static final OkHttpClient client = getOkHttpClient(); - private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); - - public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) - throws APIApplicationServicesException, BadRequestException { - - String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); - String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; - - Request request = new Request.Builder() - .url(getScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccessToken()) - .head() - .build(); - try { - Response response = client.newCall(request).execute(); - if (response.code() == HttpStatus.SC_OK){ - return true; - }else if(HttpStatus.SC_UNAUTHORIZED == response.code()) { - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret() ); - //max attempt count - return isSharedScopeNameExists(apiApplicationKey,refreshedAccessToken, key); - } else if (HttpStatus.SC_BAD_REQUEST == response.code()){ - log.info(response); - throw new BadRequestException(response.toString()); - } else { - return false; - } - } catch (IOException e) { - String msg = "Error occurred while processing the response"; - throw new APIApplicationServicesException(msg); - } - } - - public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) - throws APIApplicationServicesException, BadRequestException { - - String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); - - JSONObject setScope = new JSONObject(); - setScope.put("name", scope.getKey()); - setScope.put("displayName", scope.getName()); - setScope.put("description", scope.getDescription()); - setScope.put("bindings", scope.getRoles()); - - - RequestBody requestBody = RequestBody.Companion.create(setScope.toString(), JSON); - Request request = new Request.Builder() - .url(updateScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccessToken()) - .put(requestBody) - .build(); - - try { - Response response = client.newCall(request).execute(); - if (response.code() == HttpStatus.SC_OK) { - return true; - } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefreshToken(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); - } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - log.info(response); - throw new BadRequestException(response.toString()); - } else { - return false; - } - } catch (IOException e) { - String msg = "Error occurred while processing the response"; - throw new APIApplicationServicesException(msg); - } - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java deleted file mode 100644 index e738c71f458..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/AccessTokenInfo.java +++ /dev/null @@ -1,53 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; - -/** - * This holds the token information that return from the token endpoint. - */ -public class AccessTokenInfo { - - private String tokenType; - private long expiresIn; - private String refreshToken; - private String accessToken; - private String scope; - - public String getTokenType() { - return tokenType; - } - - public void setTokenType(String tokenType) { - this.tokenType = tokenType; - } - - public long getExpiresIn() { - return expiresIn; - } - - public void setExpiresIn(long expiresIn) { - this.expiresIn = expiresIn; - } - - public String getRefreshToken() { - return refreshToken; - } - - public void setRefreshToken(String refreshToken) { - this.refreshToken = refreshToken; - } - - public String getAccessToken() { - return accessToken; - } - - public void setAccessToken(String accessToken) { - this.accessToken = accessToken; - } - - public String getScope() { - return scope; - } - - public void setScope(String scope) { - this.scope = scope; - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java deleted file mode 100644 index 885f3ead7aa..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIDataHolder.java +++ /dev/null @@ -1,30 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; - -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; - -public class PublisherRESTAPIDataHolder { - - private static final PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); - - private APIApplicationServices apiApplicationServices; -// -// private PublisherRESTAPIServices publisherRESTAPIServices; - - public static PublisherRESTAPIDataHolder getInstance(){ - return thisInstance; - } - public APIApplicationServices getApiApplicationServices() { - return apiApplicationServices; - } - public void setApiApplicationServices(APIApplicationServices apiApplicationServices) { - this.apiApplicationServices = apiApplicationServices; - } -// public PublisherRESTAPIServices getPublisherRESTAPIServices() { -// return publisherRESTAPIServices; -// } -// public void setPublisherRESTAPIServices(PublisherRESTAPIServices publisherRESTAPIServices) { -// this.publisherRESTAPIServices = publisherRESTAPIServices; -// } - -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java deleted file mode 100644 index 1d532d17a7c..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/PublisherRESTAPIUtil.java +++ /dev/null @@ -1,67 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.util; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.http.HttpResponse; -import org.apache.http.client.HttpClient; -import org.apache.http.conn.ssl.SSLConnectionSocketFactory; -import org.apache.http.conn.ssl.SSLContextBuilder; -import org.apache.http.conn.ssl.TrustSelfSignedStrategy; -import org.apache.http.impl.client.HttpClients; -import org.apache.http.util.EntityUtils; -import org.wso2.carbon.utils.CarbonUtils; - -import java.io.BufferedReader; -import java.io.File; -import java.io.IOException; -import java.io.InputStreamReader; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; - -public class PublisherRESTAPIUtil { - private static final Log log = LogFactory.getLog(PublisherRESTAPIUtil.class); - private static final String HTTPS_PROTOCOL = "https"; - - /** - * Return a http client instance - * - * @param protocol- service endpoint protocol http/https - * @return - */ - public static HttpClient getHttpClient(String protocol) - throws IOException, KeyStoreException, NoSuchAlgorithmException, KeyManagementException { - HttpClient httpclient; - if (HTTPS_PROTOCOL.equals(protocol)) { - SSLContextBuilder builder = new SSLContextBuilder(); - builder.loadTrustMaterial(null, new TrustSelfSignedStrategy()); - SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(builder.build()); - httpclient = HttpClients.custom().setSSLSocketFactory(sslsf).useSystemProperties().build(); - } else { - httpclient = HttpClients.createDefault(); - } - return httpclient; - } - - public static String getResponseString(HttpResponse httpResponse) throws IOException { - BufferedReader br = null; - try { - br = new BufferedReader(new InputStreamReader(httpResponse.getEntity().getContent())); - String readLine; - String response = ""; - while (((readLine = br.readLine()) != null)) { - response += readLine; - } - return response; - } finally { - EntityUtils.consumeQuietly(httpResponse.getEntity()); - if (br != null) { - try { - br.close(); - } catch (IOException e) { - log.warn("Error while closing the connection! " + e.getMessage()); - } - } - } - } -} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java deleted file mode 100644 index db8011521dd..00000000000 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/util/ScopeUtils.java +++ /dev/null @@ -1,59 +0,0 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.util; - -/** - * This class represents the data that are required to register - * the oauth application. - */ -public class ScopeUtils { - - private String key; - private String name; - private String roles; - private String description; - - public String getKey() { - return key; - } - - public void setKey(String key) { - this.key = key; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getRoles() { - return roles; - } - - public void setRoles(String roles) { - this.roles = roles; - } - - public String getDescription() { - return description; - } - - public void setDescription(String description) { - this.description = description; - } - - public String toJSON() { - String jsonString = - "{\"name\": \"" + key + "\",\"displayName\": \"" + name + - "\", \"description\": \"" + description + "\"," + "\"bindings\": [" + - roles + "]" + " }"; - -// String jsonString = -// "{\"name\": \"" + name + "\",\"displayName\": \"" + name + -// "\", \"description\": \"" + description + "\"," + "\"bindings\": [" + -// "\"Internal/devicemgt-user\"" + -// "]" + " }"; - return jsonString; - } -} \ No newline at end of file diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml similarity index 96% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml index 0b2d3f034b1..2471b48fed9 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml @@ -27,7 +27,7 @@ 4.0.0 - io.entgra.devicemgt.apimgt.extension.publisher.api + io.entgra.devicemgt.apimgt.extension.rest.api bundle Entgra - Device API Management Extension Publisher API Entgra - Device API Management Extension Publisher API @@ -86,6 +86,10 @@ org.json.wso2 json + + com.google.code.gson + gson + @@ -106,11 +110,11 @@ ${carbon.device.mgt.version} Publisher API Management Bundle - io.entgra.devicemgt.apimgt.extension.publisher.api.internal + io.entgra.devicemgt.apimgt.extension.rest.api.internal - !io.entgra.devicemgt.apimgt.extension.publisher.api.internal, - io.entgra.devicemgt.apimgt.extension.publisher.api.* + !io.entgra.devicemgt.apimgt.extension.rest.api.internal, + io.entgra.devicemgt.apimgt.extension.rest.api.* javax.net.ssl, diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java similarity index 58% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java index 401f680214f..1816df83d8a 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java @@ -1,8 +1,8 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; +package io.entgra.devicemgt.apimgt.extension.rest.api; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; public interface APIApplicationServices { diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java similarity index 73% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 5e6439edbbd..50c6c7d4d45 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -1,12 +1,18 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api; +package io.entgra.devicemgt.apimgt.extension.rest.api; import com.google.gson.Gson; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; import org.json.JSONObject; -import io.entgra.devicemgt.apimgt.extension.publisher.api.constants.Constants; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import okhttp3.*; +import io.entgra.devicemgt.apimgt.extension.rest.api.constants.Constants; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.RequestBody; +import okhttp3.Credentials; +import okhttp3.ConnectionPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -17,6 +23,7 @@ import javax.net.ssl.X509TrustManager; import java.io.IOException; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; +import java.util.concurrent.TimeUnit; public class APIApplicationServicesImpl implements APIApplicationServices { @@ -33,16 +40,16 @@ public class APIApplicationServicesImpl implements APIApplicationServices { JSONObject jsonObject = new JSONObject(); jsonObject.put("callbackUrl", Constants.EMPTY_STRING); - jsonObject.put("clientName",Constants.CLIENT_NAME); - jsonObject.put("grantType",Constants.GRANT_TYPE); - jsonObject.put("owner",Constants.OWNER); - jsonObject.put("saasApp",true); + jsonObject.put("clientName", Constants.CLIENT_NAME); + jsonObject.put("grantType", Constants.GRANT_TYPE); + jsonObject.put("owner", Constants.OWNER); + jsonObject.put("saasApp", true); RequestBody requestBody = RequestBody.Companion.create(jsonObject.toString(), JSON); - String keyManagerEndpoint = "https://localhost:9443/client-registration/v0.17/register"; + String applicationEndpoint = "https://localhost:9443/client-registration/v0.17/register"; Request request = new Request.Builder() - .url(keyManagerEndpoint) + .url(applicationEndpoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) .post(requestBody) .build(); @@ -58,13 +65,13 @@ public class APIApplicationServicesImpl implements APIApplicationServices { @Override public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) - throws APIApplicationServicesException { + throws APIApplicationServicesException { JSONObject params = new JSONObject(); - params.put(Constants.GRANT_TYPE_PARAM_NAME,Constants.PASSWORD_GRANT_TYPE); + params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE); //ToDo: Remove hardcoded value - params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME,"admin"); - params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD,"admin"); - params.put(Constants.SCOPE_PARAM_NAME,Constants.SCOPES); + params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin"); + params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin"); + params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES); return getToken(params, consumerKey, consumerSecret); } @@ -73,18 +80,17 @@ public class APIApplicationServicesImpl implements APIApplicationServices { throws APIApplicationServicesException { JSONObject params = new JSONObject(); - params.put(Constants.GRANT_TYPE_PARAM_NAME,Constants.REFRESH_TOKEN_GRANT_TYPE); + params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE); //ToDo: Remove hardcoded value params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken); - params.put(Constants.SCOPE_PARAM_NAME,Constants.SCOPES); + params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES); return getToken(params, consumerKey, consumerSecret); } public AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret) - throws APIApplicationServicesException{ + throws APIApplicationServicesException { RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON); - //application/x-www-form-urlencoded String tokenEndPoint = "https://localhost:9443/oauth2/token"; Request request = new Request.Builder() @@ -117,9 +123,14 @@ public class APIApplicationServicesImpl implements APIApplicationServices { java.security.cert.X509Certificate[] certs, String authType) { } }; - return new OkHttpClient.Builder() + OkHttpClient okHttpClient = new OkHttpClient.Builder() + .connectTimeout(300, TimeUnit.SECONDS) + .writeTimeout(300, TimeUnit.SECONDS) + .readTimeout(300, TimeUnit.SECONDS) + .connectionPool(new ConnectionPool(500, 500, TimeUnit.SECONDS)) .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) .hostnameVerifier((hostname, sslSession) -> true).build(); + return okHttpClient; } private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { @@ -129,9 +140,11 @@ public class APIApplicationServicesImpl implements APIApplicationServices { public java.security.cert.X509Certificate[] getAcceptedIssuers() { return null; } + public void checkClientTrusted( java.security.cert.X509Certificate[] certs, String authType) { } + public void checkServerTrusted( java.security.cert.X509Certificate[] certs, String authType) { } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java new file mode 100644 index 00000000000..c2c0202c8a7 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -0,0 +1,137 @@ +package io.entgra.devicemgt.apimgt.extension.rest.api; + +import io.entgra.devicemgt.apimgt.extension.rest.api.constants.Constants; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.BadRequestException; +import io.entgra.devicemgt.apimgt.extension.rest.api.util.ScopeUtils; + +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.RequestBody; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.ssl.Base64; +import org.json.JSONObject; +import org.wso2.carbon.apimgt.api.model.Scope; + +import java.io.IOException; + +import static io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl.getOkHttpClient; + +public class PublisherRESTAPIServices { + private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); + private static final OkHttpClient client = getOkHttpClient(); + private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); + + public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + throws APIApplicationServicesException, BadRequestException { + + String getScopesUrl = "https://localhost:9443/api/am/publisher/v2/scopes?limit=1000"; + Request request = new Request.Builder() + .url(getScopesUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .get() + .build(); + + try { + Response response = client.newCall(request).execute(); + if (response.code() == HttpStatus.SC_OK) { + JSONObject jsonObject = new JSONObject(response.body().string()); + return jsonObject; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return getScopes(apiApplicationKey, refreshedAccessToken); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + log.info(response); + throw new BadRequestException(response.toString()); + } else { + return null; + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); + } + } + + public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) + throws APIApplicationServicesException, BadRequestException { + + String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); + String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; + + Request request = new Request.Builder() + .url(getScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + if (response.code() == HttpStatus.SC_OK) { + return true; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + log.info(response); + throw new BadRequestException(response.toString()); + } else { + return false; + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); + } + } + + public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) + throws APIApplicationServicesException, BadRequestException { + + String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); + + ScopeUtils scopeUtil = new ScopeUtils(); + scopeUtil.setKey(scope.getKey()); + scopeUtil.setName(scope.getName()); + scopeUtil.setDescription(scope.getDescription()); + scopeUtil.setRoles(scope.getRoles()); + String scopeString = scopeUtil.toJSON(); + + RequestBody requestBody = RequestBody.create(JSON, scopeString); + Request request = new Request.Builder() + .url(updateScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .put(requestBody) + .build(); + + try { + Response response = client.newCall(request).execute(); + if (response.code() == HttpStatus.SC_OK) { + return true; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + log.info(response); + throw new BadRequestException(response.toString()); + } else { + return false; + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + throw new APIApplicationServicesException(msg); + } + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java similarity index 96% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java index 242788ed26e..c4544445980 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/bean/RegistrationProfile.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java @@ -1,4 +1,4 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.bean; +package io.entgra.devicemgt.apimgt.extension.rest.api.bean; /** * This class represents the data that are required to register diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java similarity index 97% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java index 0144e129f10..4e92ad6d93e 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java @@ -1,4 +1,4 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.constants; +package io.entgra.devicemgt.apimgt.extension.rest.api.constants; public final class Constants { diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java similarity index 97% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java index d0fc3b9f68b..e18c4b3d90a 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/dto/APIApplicationKey.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java @@ -1,4 +1,4 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.dto; +package io.entgra.devicemgt.apimgt.extension.rest.api.dto; /** * This holds api application consumer id and secret. diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java new file mode 100644 index 00000000000..f9c9a4db673 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java @@ -0,0 +1,53 @@ +package io.entgra.devicemgt.apimgt.extension.rest.api.dto; + +/** + * This holds the token information that return from the token endpoint. + */ +public class AccessTokenInfo { + + private String token_type; + private long expires_in; + private String refresh_token; + private String access_token; + private String scope; + + public String getToken_type() { + return token_type; + } + + public void setToken_type(String token_type) { + this.token_type = token_type; + } + + public long getExpires_in() { + return expires_in; + } + + public void setExpires_in(long expires_in) { + this.expires_in = expires_in; + } + + public String getRefresh_token() { + return refresh_token; + } + + public void setRefresh_token(String refresh_token) { + this.refresh_token = refresh_token; + } + + public String getAccess_token() { + return access_token; + } + + public void setAccess_token(String access_token) { + this.access_token = access_token; + } + + public String getScope() { + return scope; + } + + public void setScope(String scope) { + this.scope = scope; + } +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java similarity index 83% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java index bd7aa85cd96..897146bbcd5 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/APIApplicationServicesException.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java @@ -1,4 +1,4 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions; +package io.entgra.devicemgt.apimgt.extension.rest.api.exceptions; public class APIApplicationServicesException extends Exception{ diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java similarity index 91% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java index 427c4b5e358..00d4b423fa2 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/exceptions/BadRequestException.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java @@ -22,9 +22,7 @@ /** * Custom exception class for handling bad request exceptions. */ -package io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions; - -import okhttp3.Response; +package io.entgra.devicemgt.apimgt.extension.rest.api.exceptions; public class BadRequestException extends Exception { diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java new file mode 100644 index 00000000000..ce651eeb368 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java @@ -0,0 +1,21 @@ +package io.entgra.devicemgt.apimgt.extension.rest.api.internal; + +import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; + +public class PublisherRESTAPIDataHolder { + + private static final PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); + + private APIApplicationServices apiApplicationServices; + + public static PublisherRESTAPIDataHolder getInstance(){ + return thisInstance; + } + public APIApplicationServices getApiApplicationServices() { + return apiApplicationServices; + } + public void setApiApplicationServices(APIApplicationServices apiApplicationServices) { + this.apiApplicationServices = apiApplicationServices; + } + +} diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java similarity index 62% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java rename to components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java index d34012c1f46..3817e365a4f 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.publisher.api/src/main/java/io.entgra.devicemgt.apimgt.extension.publisher.api/internal/PublisherRESTAPIServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java @@ -1,15 +1,14 @@ -package io.entgra.devicemgt.apimgt.extension.publisher.api.internal; +package io.entgra.devicemgt.apimgt.extension.rest.api.internal; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; +import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; /** - * @scr.component name="io.entgra.devicemgt.apimgt.extension.publisher.api.internal.PublisherRESTAPIServiceComponent" + * @scr.component name="io.entgra.devicemgt.apimgt.extension.rest.api.internal.PublisherRESTAPIServiceComponent" * immediate="true" */ public class PublisherRESTAPIServiceComponent { @@ -23,10 +22,6 @@ public class PublisherRESTAPIServiceComponent { try { BundleContext bundleContext = componentContext.getBundleContext(); -// PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); -// bundleContext.registerService(PublisherRESTAPIServices.class.getName(), publisherRESTAPIServices, null); -// PublisherRESTAPIDataHolder.getInstance().setPublisherRESTAPIServices(publisherRESTAPIServices); - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); bundleContext.registerService(APIApplicationServices.class.getName(), apiApplicationServices, null); PublisherRESTAPIDataHolder.getInstance().setApiApplicationServices(apiApplicationServices); diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java new file mode 100644 index 00000000000..8a7e6d2fbbb --- /dev/null +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java @@ -0,0 +1,57 @@ +package io.entgra.devicemgt.apimgt.extension.rest.api.util; + +/** + * This class represents the data that are required to register + * the oauth application. + */ +public class ScopeUtils { + + private String key; + private String name; + private String roles; + private String description; + + public String getKey() { + return key; + } + + public void setKey(String key) { + this.key = key; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getRoles() { + return roles; + } + + public void setRoles(String roles) { + this.roles = roles; + } + + public String getDescription() { + return description; + } + + public void setDescription(String description) { + this.description = description; + } + + public String toJSON() { + String jsonString = "{\n" + + " \"name\":\" " + key + "\",\n" + + " \"displayName\":\" " + name + "\",\n" + + " \"description\":\" " + description + " \",\n" + + " \"bindings\":[\n" + + " \" " + roles + " \"\n" + + " ]\n" + + "}"; + return jsonString; + } +} \ No newline at end of file diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index c08735db3fd..d1bc922c545 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -124,9 +124,13 @@ org.wso2.carbon.devicemgt - io.entgra.devicemgt.apimgt.extension.publisher.api + io.entgra.devicemgt.apimgt.extension.rest.api provided + + org.json.wso2 + json + @@ -170,9 +174,9 @@ org.scannotation;version="1.0", org.scannotation.archiveiterator;version="1.0", org.w3c.dom, - io.entgra.devicemgt.apimgt.extension.publisher.api, - io.entgra.devicemgt.apimgt.extension.publisher.api.dto, - io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions, + io.entgra.devicemgt.apimgt.extension.rest.api, + io.entgra.devicemgt.apimgt.extension.rest.api.dto, + io.entgra.devicemgt.apimgt.extension.rest.api.exceptions, org.wso2.carbon.apimgt.annotations.api, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, @@ -195,7 +199,8 @@ org.wso2.carbon.utils;version="4.6", org.wso2.carbon.utils.multitenancy;version="4.6", org.wso2.carbon.apimgt.impl.definitions, - org.apache.commons.lang + org.apache.commons.lang, + org.json jsr311-api;scope=compile|runtime;inline=false diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java index 85dcf72d138..fd111a46de9 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java @@ -18,8 +18,6 @@ */ package org.wso2.carbon.apimgt.webapp.publisher; - -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; /** diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 2fe4883df58..0aebefbaa49 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -18,18 +18,20 @@ */ package org.wso2.carbon.apimgt.webapp.publisher; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; -import io.entgra.devicemgt.apimgt.extension.publisher.api.PublisherRESTAPIServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; +import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl; +import io.entgra.devicemgt.apimgt.extension.rest.api.PublisherRESTAPIServices; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; +import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.BadRequestException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.api.model.Documentation; import org.wso2.carbon.apimgt.api.model.DocumentationType; +import org.json.JSONArray; +import org.json.JSONObject; import org.wso2.carbon.apimgt.api.APIManagementException; import org.wso2.carbon.apimgt.api.APIProvider; import org.wso2.carbon.apimgt.api.FaultGatewaysException; @@ -382,6 +384,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); + JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); try { String fileName = @@ -427,8 +430,18 @@ public class APIPublisherServiceImpl implements APIPublisherService { } scope.setRoles(roleString); -// if (apiProvider.isSharedScopeNameExists(scope.getKey(), tenantDomain)) { -// apiProvider.updateSharedScope(scope, tenantDomain); + //Set scope id which related to the scope key + JSONArray scopeList = (JSONArray) scopeObject.get("list"); + JSONObject object = null; + for (int i = 0; i < scopeList.length(); i++) { + JSONObject obj = null; + obj = scopeList.getJSONObject(i); + if (obj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { + object = obj; + } + } + scope.setId(object.getString("id")); + if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); } else { @@ -449,17 +462,13 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } -// catch (UserStoreException e) { -// String msg = "Error occurred while reading tenant admin username"; -// log.error(msg, e); -// throw new APIManagerPublisherException(e); -// } -// catch (APIManagementException e) { -// String msg = "Error occurred while loading api provider"; -// log.error(msg, e); -// throw new APIManagerPublisherException(e); -// } - finally { + catch (APIApplicationServicesException e) { + log.error(e); + throw new RuntimeException(e); + } catch (BadRequestException e) { + log.error(e); + throw new RuntimeException(e); + } finally { PrivilegedCarbonContext.endTenantFlow(); } } diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index 3933f60716d..01b1cd810cf 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -19,12 +19,6 @@ package org.wso2.carbon.apimgt.webapp.publisher; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.publisher.api.APIApplicationServicesImpl; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.publisher.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.publisher.api.exceptions.BadRequestException; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 137f35b5724..2c175c1ea1e 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -31,17 +31,25 @@ org.wso2.carbon.apimgt.api - org.json.wso2 - json + com.squareup.okhttp3 + okhttp - io.github.openfeign - feign-okhttp + org.json.wso2 + json com.google.code.gson gson + + org.eclipse.osgi + org.eclipse.osgi + + + org.eclipse.osgi + org.eclipse.osgi.services + 4.0.0 @@ -58,7 +66,7 @@ org.wso2.carbon.apimgt.keymgt.extension org.wso2.carbon.apimgt.keymgt.extension.api io.entgra.device.mgt.core.apimgt.analytics.extension - io.entgra.devicemgt.apimgt.extension.publisher.api + io.entgra.devicemgt.apimgt.extension.rest.api diff --git a/pom.xml b/pom.xml index b5435d623d5..e52350555b1 100644 --- a/pom.xml +++ b/pom.xml @@ -240,7 +240,7 @@ org.wso2.carbon.devicemgt - io.entgra.devicemgt.apimgt.extension.publisher.api + io.entgra.devicemgt.apimgt.extension.rest.api ${carbon.device.mgt.version} From 34ae40e233885417b9f432460841b9c68101db5d Mon Sep 17 00:00:00 2001 From: pasindu Date: Fri, 21 Apr 2023 00:53:50 +0530 Subject: [PATCH 13/22] Code format fixes --- .../rest/api/APIApplicationServices.java | 19 +++ .../rest/api/APIApplicationServicesImpl.java | 19 ++- .../rest/api/PublisherRESTAPIServices.java | 18 +++ .../rest/api/bean/RegistrationProfile.java | 116 ++++++++++-------- .../rest/api/constants/Constants.java | 9 -- .../rest/api/dto/APIApplicationKey.java | 23 +++- .../rest/api/dto/AccessTokenInfo.java | 18 +++ .../APIApplicationServicesException.java | 36 +++++- .../api/exceptions/BadRequestException.java | 27 ++-- .../internal/PublisherRESTAPIDataHolder.java | 22 +++- .../PublisherRESTAPIServiceComponent.java | 18 +++ .../extension/rest/api/util/ScopeUtils.java | 21 +++- .../publisher/APIPublisherServiceImpl.java | 12 +- .../publisher/APIPublisherStartupHandler.java | 4 +- .../lifecycle/util/AnnotationProcessor.java | 4 +- components/apimgt-extensions/pom.xml | 26 ---- 16 files changed, 273 insertions(+), 119 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java index 1816df83d8a..d420bbc6222 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api; import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; @@ -9,6 +27,7 @@ public interface APIApplicationServices { APIApplicationKey createAndRetrieveApplicationCredentials() throws APIApplicationServicesException; AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIApplicationServicesException; + AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIApplicationServicesException; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 50c6c7d4d45..d1613f3d74f 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api; import com.google.gson.Gson; @@ -81,7 +99,6 @@ public class APIApplicationServicesImpl implements APIApplicationServices { JSONObject params = new JSONObject(); params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE); - //ToDo: Remove hardcoded value params.put(Constants.REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME, refreshToken); params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES); return getToken(params, consumerKey, consumerSecret); diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java index c2c0202c8a7..7148286aa31 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api; import io.entgra.devicemgt.apimgt.extension.rest.api.constants.Constants; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java index c4544445980..97033b6d5cb 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.bean; /** @@ -6,63 +24,63 @@ package io.entgra.devicemgt.apimgt.extension.rest.api.bean; */ public class RegistrationProfile { - private String callbackUrl; - private String clientName; - private String tokenScope; - private String owner; - private String grantType; - private String applicationType; + private String callbackUrl; + private String clientName; + private String tokenScope; + private String owner; + private String grantType; + private String applicationType; private boolean isSaasApp; - private static final String TAG = RegistrationProfile.class.getSimpleName(); + private static final String TAG = RegistrationProfile.class.getSimpleName(); - public String getCallbackUrl() { - return callbackUrl; - } + public String getCallbackUrl() { + return callbackUrl; + } - public void setCallbackUrl(String callBackUrl) { - this.callbackUrl = callBackUrl; - } + public void setCallbackUrl(String callBackUrl) { + this.callbackUrl = callBackUrl; + } - public String getClientName() { - return clientName; - } + public String getClientName() { + return clientName; + } - public void setClientName(String clientName) { - this.clientName = clientName; - } + public void setClientName(String clientName) { + this.clientName = clientName; + } - public String getTokenScope() { - return tokenScope; - } + public String getTokenScope() { + return tokenScope; + } - public void setTokenScope(String tokenScope) { - this.tokenScope = tokenScope; - } + public void setTokenScope(String tokenScope) { + this.tokenScope = tokenScope; + } - public String getOwner() { - return owner; - } + public String getOwner() { + return owner; + } - public void setOwner(String owner) { - this.owner = owner; - } + public void setOwner(String owner) { + this.owner = owner; + } - public String getGrantType() { - return grantType; - } + public String getGrantType() { + return grantType; + } - public void setGrantType(String grantType) { - this.grantType = grantType; - } + public void setGrantType(String grantType) { + this.grantType = grantType; + } - public String getApplicationType() { - return applicationType; - } + public String getApplicationType() { + return applicationType; + } - public void setApplicationType(String applicationType) { - this.applicationType = applicationType; - } + public void setApplicationType(String applicationType) { + this.applicationType = applicationType; + } public boolean isSaasApp() { return isSaasApp; @@ -73,10 +91,10 @@ public class RegistrationProfile { } public String toJSON() { - String jsonString = - "{\"callbackUrl\": \"" + callbackUrl + "\",\"clientName\": \"" + clientName + - "\", \"owner\": \"" + owner + "\"," + "\"grantType\": \"" + grantType + - "\", \"saasApp\" : " + isSaasApp + " }\n"; - return jsonString; - } + String jsonString = + "{\"callbackUrl\": \"" + callbackUrl + "\",\"clientName\": \"" + clientName + + "\", \"owner\": \"" + owner + "\"," + "\"grantType\": \"" + grantType + + "\", \"saasApp\" : " + isSaasApp + " }\n"; + return jsonString; + } } \ No newline at end of file diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java index 4e92ad6d93e..73b4a3a842d 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java @@ -20,15 +20,6 @@ public final class Constants { public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; - public static final int DEFAULT_MIN_THREAD_POOL_SIZE = 8; - public static final int DEFAULT_MAX_THREAD_POOL_SIZE = 100; - public static final int DEFAULT_EXECUTOR_JOB_QUEUE_SIZE = 2000; - public static final long DEFAULT_KEEP_ALIVE_TIME_IN_MILLIS = 20000; - public static final String ADAPTER_MIN_THREAD_POOL_SIZE_NAME = "minThread"; - public static final String ADAPTER_MAX_THREAD_POOL_SIZE_NAME = "maxThread"; - public static final String ADAPTER_KEEP_ALIVE_TIME_NAME = "keepAliveTimeInMillis"; - public static final String ADAPTER_EXECUTOR_JOB_QUEUE_SIZE_NAME = "jobQueueSize"; - public static final String DEFAULT_CALLBACK = ""; public static final String DEFAULT_PASSWORD = ""; public static final String TOKEN_SCOPE = "production"; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java index e18c4b3d90a..cbadf626b26 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java @@ -1,7 +1,25 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.dto; /** - * This holds api application consumer id and secret. + * This holds the consumer application information that return from the register application endpoint */ public class APIApplicationKey { private String clientName; @@ -14,7 +32,7 @@ public class APIApplicationKey { private String jsonAppAttribute; private String tokenType; - public APIApplicationKey(String clientId, String clientSecret){ + public APIApplicationKey(String clientId, String clientSecret) { this.clientId = clientId; this.clientSecret = clientSecret; } @@ -34,6 +52,7 @@ public class APIApplicationKey { public void setClientSecret(String clientSecret) { this.clientSecret = clientSecret; } + public String getClientName() { return clientName; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java index f9c9a4db673..061e7e898d1 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.dto; /** diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java index 897146bbcd5..35a247a190b 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java @@ -1,12 +1,38 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.exceptions; -public class APIApplicationServicesException extends Exception{ +public class APIApplicationServicesException extends Exception { - public APIApplicationServicesException() {super();} + public APIApplicationServicesException() { + super(); + } - public APIApplicationServicesException(String message) {super();} + public APIApplicationServicesException(String message) { + super(); + } - public APIApplicationServicesException(String message, Throwable cause){super();} + public APIApplicationServicesException(String message, Throwable cause) { + super(); + } - public APIApplicationServicesException(Throwable cause){super();} + public APIApplicationServicesException(Throwable cause) { + super(); + } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java index 00d4b423fa2..25cebe82fc5 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java @@ -1,22 +1,19 @@ /* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. * - * * Copyright (c) 2022, 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. + * 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. */ /** diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java index ce651eeb368..9545a94fb40 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.internal; import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; @@ -8,12 +26,14 @@ public class PublisherRESTAPIDataHolder { private APIApplicationServices apiApplicationServices; - public static PublisherRESTAPIDataHolder getInstance(){ + public static PublisherRESTAPIDataHolder getInstance() { return thisInstance; } + public APIApplicationServices getApiApplicationServices() { return apiApplicationServices; } + public void setApiApplicationServices(APIApplicationServices apiApplicationServices) { this.apiApplicationServices = apiApplicationServices; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java index 3817e365a4f..fdf74638c60 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java @@ -1,3 +1,21 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.internal; import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java index 8a7e6d2fbbb..5716ebfcb1b 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java +++ b/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java @@ -1,8 +1,25 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + package io.entgra.devicemgt.apimgt.extension.rest.api.util; /** - * This class represents the data that are required to register - * the oauth application. + * This class represents the scope data. */ public class ScopeUtils { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 0aebefbaa49..5452a4f8bd5 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -432,15 +432,15 @@ public class APIPublisherServiceImpl implements APIPublisherService { //Set scope id which related to the scope key JSONArray scopeList = (JSONArray) scopeObject.get("list"); - JSONObject object = null; + JSONObject jsonObject = null; for (int i = 0; i < scopeList.length(); i++) { - JSONObject obj = null; - obj = scopeList.getJSONObject(i); - if (obj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { - object = obj; + JSONObject scopeObj = null; + scopeObj = scopeList.getJSONObject(i); + if (scopeObj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { + jsonObject = scopeObj; } } - scope.setId(object.getString("id")); + scope.setId(jsonObject.getString("id")); if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java index 01b1cd810cf..949f16c3e9e 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherStartupHandler.java @@ -24,6 +24,7 @@ import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; import org.wso2.carbon.apimgt.webapp.publisher.internal.APIPublisherDataHolder; import org.wso2.carbon.core.ServerStartupObserver; + import java.util.Stack; public class APIPublisherStartupHandler implements ServerStartupObserver { @@ -34,10 +35,12 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { private static final int MAX_RETRY_COUNT = 5; private static Stack failedAPIsStack = new Stack<>(); private static Stack currentAPIsStack; + private APIPublisherService publisher; @Override public void completingServerStartup() { + } @Override @@ -52,7 +55,6 @@ public class APIPublisherStartupHandler implements ServerStartupObserver { log.debug("Total number of unpublished APIs: " + APIPublisherDataHolder.getInstance().getUnpublishedApis().size()); } - publisher = APIPublisherDataHolder.getInstance().getApiPublisherService(); int retryCount = 0; while (retryCount < MAX_RETRY_COUNT && (!failedAPIsStack.isEmpty() || !currentAPIsStack.isEmpty())) { diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java index 7cdede5bcb6..f41c07967a5 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/lifecycle/util/AnnotationProcessor.java @@ -299,7 +299,7 @@ public class AnnotationProcessor { // if (scope != null) { // resource.setScope(scope); // } else { -// log.warn("ScopeUtils is not defined for '" + makeContextURLReady(resourceRootContext) + +// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); // scope = new ApiScope(); // scope.setName(DEFAULT_SCOPE_NAME); @@ -537,7 +537,7 @@ public class AnnotationProcessor { if (scope != null) { apiResource.setScope(scope); } else { -// log.warn("ScopeUtils is not defined for '" + makeContextURLReady(resourceRootContext) + +// log.warn("Scope is not defined for '" + makeContextURLReady(resourceRootContext) + // makeContextURLReady(subCtx) + "' endpoint, hence assigning the default scope"); scope = new ApiScope(); scope.setName(DEFAULT_SCOPE_NAME); diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index 2c175c1ea1e..c4bfc0d36d5 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -25,32 +25,6 @@ 5.0.26-SNAPSHOT ../../pom.xml - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api - - - com.squareup.okhttp3 - okhttp - - - org.json.wso2 - json - - - com.google.code.gson - gson - - - org.eclipse.osgi - org.eclipse.osgi - - - org.eclipse.osgi - org.eclipse.osgi.services - - 4.0.0 apimgt-extensions From 07c157e9d6985e989e2dcdd6e8bd44e1b6511678 Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 25 Apr 2023 14:02:19 +0530 Subject: [PATCH 14/22] Fix URL Generation, Make feature, Refactor the module --- .../pom.xml | 58 +++++------------ .../rest/api/APIApplicationServices.java | 14 ++--- .../rest/api/APIApplicationServicesImpl.java | 51 ++++++++------- .../rest/api/PublisherRESTAPIServices.java | 63 +++++++++++-------- .../rest/api/bean/RegistrationProfile.java | 2 +- .../rest/api/constants/Constants.java | 35 ++++++++--- .../rest/api/dto/APIApplicationKey.java | 2 +- .../rest/api/dto/AccessTokenInfo.java | 2 +- .../api/exceptions/APIServicesException.java} | 18 +++--- .../api/exceptions/BadRequestException.java | 2 +- .../internal/PublisherRESTAPIDataHolder.java | 26 ++++++-- .../PublisherRESTAPIServiceComponent.java | 29 +++++++-- .../extension/rest/api/util/ScopeUtils.java | 2 +- .../pom.xml | 8 +-- .../webapp/publisher/APIPublisherService.java | 1 + .../publisher/APIPublisherServiceImpl.java | 35 ++++++----- components/apimgt-extensions/pom.xml | 2 +- .../pom.xml | 7 +++ pom.xml | 2 +- 19 files changed, 209 insertions(+), 150 deletions(-) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api => io.entgra.device.mgt.core.apimgt.extension.rest.api}/pom.xml (71%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/APIApplicationServices.java (64%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/APIApplicationServicesImpl.java (80%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/PublisherRESTAPIServices.java (72%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/bean/RegistrationProfile.java (97%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/constants/Constants.java (57%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/dto/APIApplicationKey.java (97%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/dto/AccessTokenInfo.java (96%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/APIServicesException.java} (63%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/exceptions/BadRequestException.java (93%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java (52%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java (59%) rename components/apimgt-extensions/{io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt => io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core}/apimgt/extension/rest/api/util/ScopeUtils.java (96%) diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml similarity index 71% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 2471b48fed9..7fb3f1726ff 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -27,21 +27,13 @@ 4.0.0 - io.entgra.devicemgt.apimgt.extension.rest.api + io.entgra.device.mgt.core.apimgt.extension.rest.api bundle - Entgra - Device API Management Extension Publisher API - Entgra - Device API Management Extension Publisher API + Entgra - Device Management Extension for APIM REST API + Entgra - Device Management Extension for APIM REST API https://entgra.io - - org.apache.httpcomponents.wso2 - httpcore - - - org.wso2.orbit.org.apache.httpcomponents - httpclient - org.wso2.carbon org.wso2.carbon.logging @@ -90,6 +82,11 @@ com.google.code.gson gson + + org.wso2.carbon.apimgt + org.wso2.carbon.apimgt.impl + provided + @@ -110,31 +107,23 @@ ${carbon.device.mgt.version} Publisher API Management Bundle - io.entgra.devicemgt.apimgt.extension.rest.api.internal + io.entgra.device.mgt.core.apimgt.extension.rest.api.internal - !io.entgra.devicemgt.apimgt.extension.rest.api.internal, - io.entgra.devicemgt.apimgt.extension.rest.api.* + !io.entgra.device.mgt.core.apimgt.extension.rest.api.internal, + io.entgra.device.mgt.core.apimgt.extension.rest.api.* javax.net.ssl, - org.apache.commons.logging, - org.apache.http;version="${httpclient.version.range}", - org.apache.http.client;version="${httpclient.version.range}", - org.apache.http.client.methods;version="${httpclient.version.range}", - org.apache.http.conn.socket, - org.apache.http.conn.ssl, - org.apache.http.entity, - org.apache.http.impl.client, - org.apache.http.util;version="${httpclient.version.range}", - org.osgi.framework.*;version="${imp.package.version.osgi.framework}", org.osgi.service.*;version="${imp.package.version.osgi.service}", - org.wso2.carbon.core, - org.apache.commons.ssl, - org.apache.commons.httpclient, + org.wso2.carbon.core;version="4.6", + org.wso2.carbon.core.util;version="4.6", org.wso2.carbon.apimgt.api.model, okhttp3.*, + org.wso2.carbon.apimgt.impl;version="${carbon.api.mgt.version.range}", + org.wso2.carbon.apimgt.impl.utils;version="${carbon.api.mgt.version.range}", + org.wso2.carbon.apimgt.impl.internal;version="${carbon.api.mgt.version.range}", org.json @@ -166,22 +155,7 @@ - - - - - - - - - - - - - - true - \ No newline at end of file diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java similarity index 64% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java index d420bbc6222..51d7d20b17f 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServices.java @@ -16,18 +16,18 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api; +package io.entgra.device.mgt.core.apimgt.extension.rest.api; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; public interface APIApplicationServices { - APIApplicationKey createAndRetrieveApplicationCredentials() throws APIApplicationServicesException; + APIApplicationKey createAndRetrieveApplicationCredentials() throws APIServicesException; - AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIApplicationServicesException; + AccessTokenInfo generateAccessTokenFromRegisteredApplication(String clientId, String clientSecret) throws APIServicesException; - AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIApplicationServicesException; + AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String clientId, String clientSecret) throws APIServicesException; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java similarity index 80% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index d1613f3d74f..bffb97893a6 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -16,14 +16,14 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api; +package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import org.json.JSONObject; -import io.entgra.devicemgt.apimgt.extension.rest.api.constants.Constants; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -33,6 +33,8 @@ import okhttp3.Credentials; import okhttp3.ConnectionPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; +import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder; import javax.net.ssl.SSLContext; import javax.net.ssl.SSLSocketFactory; @@ -50,22 +52,24 @@ public class APIApplicationServicesImpl implements APIApplicationServices { private static final Gson gson = new Gson(); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); String msg = null; - // private ApiApplicationConfigurations ApplicationConfig = null; + APIManagerConfiguration config = ServiceReferenceHolder.getInstance(). + getAPIManagerConfigurationService().getAPIManagerConfiguration(); @Override public APIApplicationKey createAndRetrieveApplicationCredentials() - throws APIApplicationServicesException { + throws APIServicesException { + + String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT); + String owner = config.getFirstProperty(Constants.SERVER_USER); JSONObject jsonObject = new JSONObject(); jsonObject.put("callbackUrl", Constants.EMPTY_STRING); jsonObject.put("clientName", Constants.CLIENT_NAME); jsonObject.put("grantType", Constants.GRANT_TYPE); - jsonObject.put("owner", Constants.OWNER); + jsonObject.put("owner", owner); jsonObject.put("saasApp", true); RequestBody requestBody = RequestBody.Companion.create(jsonObject.toString(), JSON); - String applicationEndpoint = "https://localhost:9443/client-registration/v0.17/register"; - Request request = new Request.Builder() .url(applicationEndpoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) @@ -76,26 +80,29 @@ public class APIApplicationServicesImpl implements APIApplicationServices { return gson.fromJson(response.body().string(), APIApplicationKey.class); } catch (IOException e) { msg = "Error occurred while processing the response"; - log.error(msg); - throw new APIApplicationServicesException(msg); + log.error(msg, e); + throw new APIServicesException(e); } } @Override public AccessTokenInfo generateAccessTokenFromRegisteredApplication(String consumerKey, String consumerSecret) - throws APIApplicationServicesException { + throws APIServicesException { + + String userName = config.getFirstProperty(Constants.SERVER_USER); + String userPassword = config.getFirstProperty(Constants.SERVER_PASSWORD); + JSONObject params = new JSONObject(); params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.PASSWORD_GRANT_TYPE); - //ToDo: Remove hardcoded value - params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME, "admin"); - params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD, "admin"); + params.put(Constants.PASSWORD_GRANT_TYPE_USERNAME, userName); + params.put(Constants.PASSWORD_GRANT_TYPE_PASSWORD, userPassword); params.put(Constants.SCOPE_PARAM_NAME, Constants.SCOPES); return getToken(params, consumerKey, consumerSecret); } @Override public AccessTokenInfo generateAccessTokenFromRefreshToken(String refreshToken, String consumerKey, String consumerSecret) - throws APIApplicationServicesException { + throws APIServicesException { JSONObject params = new JSONObject(); params.put(Constants.GRANT_TYPE_PARAM_NAME, Constants.REFRESH_TOKEN_GRANT_TYPE); @@ -105,11 +112,11 @@ public class APIApplicationServicesImpl implements APIApplicationServices { } public AccessTokenInfo getToken(JSONObject nameValuePairs, String clientId, String clientSecret) - throws APIApplicationServicesException { + throws APIServicesException { - RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON); - String tokenEndPoint = "https://localhost:9443/oauth2/token"; + String tokenEndPoint = config.getFirstProperty(Constants.TOKE_END_POINT); + RequestBody requestBody = RequestBody.Companion.create(nameValuePairs.toString(), JSON); Request request = new Request.Builder() .url(tokenEndPoint) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic(clientId, clientSecret)) @@ -121,8 +128,8 @@ public class APIApplicationServicesImpl implements APIApplicationServices { return gson.fromJson(response.body().string(), AccessTokenInfo.class); } catch (IOException e) { msg = "Error occurred while processing the response"; - log.error(msg); - throw new APIApplicationServicesException(msg); + log.error(msg, e); + throw new APIServicesException(e); } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java similarity index 72% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 7148286aa31..5fedcca952d 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -16,14 +16,14 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api; +package io.entgra.device.mgt.core.apimgt.extension.rest.api; -import io.entgra.devicemgt.apimgt.extension.rest.api.constants.Constants; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.BadRequestException; -import io.entgra.devicemgt.apimgt.extension.rest.api.util.ScopeUtils; +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.AccessTokenInfo; +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.util.ScopeUtils; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -39,26 +39,31 @@ import org.wso2.carbon.apimgt.api.model.Scope; import java.io.IOException; -import static io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl.getOkHttpClient; +import static io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl.getOkHttpClient; public class PublisherRESTAPIServices { private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); private static final OkHttpClient client = getOkHttpClient(); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); + private static final String host = System.getProperty(Constants.IOT_CORE_HOST); + private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT); + public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) - throws APIApplicationServicesException, BadRequestException { + throws APIServicesException, BadRequestException { + - String getScopesUrl = "https://localhost:9443/api/am/publisher/v2/scopes?limit=1000"; + String getAllScopesUrl = "https://" + "://" + host + ":" + port + Constants.GET_ALL_SCOPES; Request request = new Request.Builder() - .url(getScopesUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .url(getAllScopesUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) .get() .build(); try { Response response = client.newCall(request).execute(); - if (response.code() == HttpStatus.SC_OK) { + if (HttpStatus.SC_OK == response.code()) { JSONObject jsonObject = new JSONObject(response.body().string()); return jsonObject; } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { @@ -68,22 +73,24 @@ public class PublisherRESTAPIServices { //TODO: max attempt count return getScopes(apiApplicationKey, refreshedAccessToken); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - log.info(response); - throw new BadRequestException(response.toString()); + String msg = "Bad Request, Invalid request"; + log.error(msg); + throw new BadRequestException(msg); } else { return null; } } catch (IOException e) { String msg = "Error occurred while processing the response"; - throw new APIApplicationServicesException(msg); + log.error(msg, e); + throw new APIServicesException(e); } } public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) - throws APIApplicationServicesException, BadRequestException { + throws APIServicesException, BadRequestException { String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); - String getScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + keyValue; + String getScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + keyValue; Request request = new Request.Builder() .url(getScopeUrl) @@ -101,21 +108,23 @@ public class PublisherRESTAPIServices { //TODO: max attempt count return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - log.info(response); - throw new BadRequestException(response.toString()); + String msg = "Bad Request, Invalid request"; + log.error(msg); + throw new BadRequestException(msg); } else { return false; } } catch (IOException e) { String msg = "Error occurred while processing the response"; - throw new APIApplicationServicesException(msg); + log.error(msg, e); + throw new APIServicesException(e); } } public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) - throws APIApplicationServicesException, BadRequestException { + throws APIServicesException, BadRequestException { - String updateScopeUrl = "https://localhost:9443/api/am/publisher/v2/scopes/" + scope.getId(); + String updateScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + scope.getId(); ScopeUtils scopeUtil = new ScopeUtils(); scopeUtil.setKey(scope.getKey()); @@ -142,14 +151,16 @@ public class PublisherRESTAPIServices { //TODO: max attempt count return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - log.info(response); - throw new BadRequestException(response.toString()); + String msg = "Bad Request, Invalid scope object"; + log.error(msg); + throw new BadRequestException(msg); } else { return false; } } catch (IOException e) { String msg = "Error occurred while processing the response"; - throw new APIApplicationServicesException(msg); + log.error(msg, e); + throw new APIServicesException(e); } } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/RegistrationProfile.java similarity index 97% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/RegistrationProfile.java index 97033b6d5cb..455c4704d1a 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/bean/RegistrationProfile.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/bean/RegistrationProfile.java @@ -16,7 +16,7 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.bean; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.bean; /** * This class represents the data that are required to register diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java similarity index 57% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java index 73b4a3a842d..11b056298af 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java @@ -1,4 +1,22 @@ -package io.entgra.devicemgt.apimgt.extension.rest.api.constants; +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.apimgt.extension.rest.api.constants; public final class Constants { @@ -7,7 +25,8 @@ public final class Constants { public static final String EMPTY_STRING = ""; public static final String CLIENT_NAME = "rest_api_publisher_code"; - public static final String OWNER = "admin"; + public static final String SERVER_USER = "WorkflowConfigurations.ServerUser"; + public static final String SERVER_PASSWORD = "ServerPassword"; public static final String GRANT_TYPE = "client_credentials password refresh_token"; public static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token"; public static final String OAUTH_EXPIRES_IN = "expires_in"; @@ -16,14 +35,10 @@ public final class Constants { public static final String REFRESH_TOKEN_GRANT_TYPE = "refresh_token"; public static final String SCOPE_PARAM_NAME = "scope"; public static final String SCOPES = "apim:api_create apim:api_view apim:shared_scope_manage"; - + public static final String DCR_END_POINT = "WorkflowConfigurations.DCREndPoint"; + public static final String TOKE_END_POINT = "WorkflowConfigurations.TokenEndPoint"; public static final String ADAPTER_CONF_KEEP_ALIVE = "keepAlive"; public static final int ADAPTER_CONF_DEFAULT_KEEP_ALIVE = 60000; - - public static final String DEFAULT_CALLBACK = ""; - public static final String DEFAULT_PASSWORD = ""; - public static final String TOKEN_SCOPE = "production"; - public static final String APPLICATION_NAME_PREFIX = "OutputAdapter_"; public static final String CLIENT_ID = "clientId"; public static final String CLIENT_SECRET = "clientSecret"; @@ -38,6 +53,10 @@ public final class Constants { public static final String PASSWORD_GRANT_TYPE_SCOPES = "scopes"; public static final String ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME = "access_token"; public static final String GRANT_TYPE_PARAM_NAME = "grant_type"; + public static final String IOT_CORE_HOST = "iot.core.host"; + public static final String IOT_CORE_HTTPS_PORT = "iot.core.https.port"; + public static final String GET_ALL_SCOPES = "/api/am/publisher/v2/scopes?limit=1000"; + public static final String GET_SCOPE = "/api/am/publisher/v2/scopes/"; } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIApplicationKey.java similarity index 97% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIApplicationKey.java index cbadf626b26..a4b4660bb8c 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/APIApplicationKey.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/APIApplicationKey.java @@ -16,7 +16,7 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.dto; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto; /** * This holds the consumer application information that return from the register application endpoint diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/AccessTokenInfo.java similarity index 96% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/AccessTokenInfo.java index 061e7e898d1..95bc2b34ba4 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/dto/AccessTokenInfo.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/dto/AccessTokenInfo.java @@ -16,7 +16,7 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.dto; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.dto; /** * This holds the token information that return from the token endpoint. diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/APIServicesException.java similarity index 63% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/APIServicesException.java index 35a247a190b..3b9c4cfc7d2 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/APIApplicationServicesException.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/APIServicesException.java @@ -16,23 +16,23 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.exceptions; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions; -public class APIApplicationServicesException extends Exception { +public class APIServicesException extends Exception { - public APIApplicationServicesException() { + public APIServicesException() { super(); } - public APIApplicationServicesException(String message) { - super(); + public APIServicesException(String message) { + super(message); } - public APIApplicationServicesException(String message, Throwable cause) { - super(); + public APIServicesException(String message, Throwable cause) { + super(message); } - public APIApplicationServicesException(Throwable cause) { - super(); + public APIServicesException(Throwable cause) { + super(cause); } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/BadRequestException.java similarity index 93% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/BadRequestException.java index 25cebe82fc5..6aa9be1130c 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/exceptions/BadRequestException.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/BadRequestException.java @@ -19,7 +19,7 @@ /** * Custom exception class for handling bad request exceptions. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.exceptions; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions; public class BadRequestException extends Exception { diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java similarity index 52% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java index 9545a94fb40..18398af9d54 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIDataHolder.java @@ -16,17 +16,22 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.internal; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.internal; -import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; +import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; public class PublisherRESTAPIDataHolder { - private static final PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); - private APIApplicationServices apiApplicationServices; + private APIManagerConfigurationService apiManagerConfigurationService; + + private static PublisherRESTAPIDataHolder thisInstance = new PublisherRESTAPIDataHolder(); + + private PublisherRESTAPIDataHolder() { + } - public static PublisherRESTAPIDataHolder getInstance() { + static PublisherRESTAPIDataHolder getInstance() { return thisInstance; } @@ -38,4 +43,15 @@ public class PublisherRESTAPIDataHolder { this.apiApplicationServices = apiApplicationServices; } + public void setAPIManagerConfiguration(APIManagerConfigurationService apiManagerConfigurationService) { + this.apiManagerConfigurationService = apiManagerConfigurationService; + } + + public APIManagerConfigurationService getAPIManagerConfigurationService() { + if (apiManagerConfigurationService == null) { + throw new IllegalStateException("API Manager Configuration service is not initialized properly"); + } + return apiManagerConfigurationService; + } + } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java similarity index 59% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java index fdf74638c60..989a5477299 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/internal/PublisherRESTAPIServiceComponent.java @@ -16,18 +16,25 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.internal; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.internal; -import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.osgi.framework.BundleContext; import org.osgi.service.component.ComponentContext; +import org.wso2.carbon.apimgt.impl.APIManagerConfigurationService; /** - * @scr.component name="io.entgra.devicemgt.apimgt.extension.rest.api.internal.PublisherRESTAPIServiceComponent" + * @scr.component name="internal.io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServiceComponent" * immediate="true" + * @scr.reference name="user.apimanagerconfigurationservice.default" + * interface="org.wso2.carbon.apimgt.impl.APIManagerConfigurationService" + * cardinality="1..1" + * policy="dynamic" + * bind="setAPIManagerConfigurationService" + * unbind="unsetAPIManagerConfigurationService" */ public class PublisherRESTAPIServiceComponent { @@ -55,4 +62,18 @@ public class PublisherRESTAPIServiceComponent { protected void deactivate(ComponentContext componentContext) { //do nothing } + + protected void setAPIManagerConfigurationService(APIManagerConfigurationService apiManagerConfigurationService) { + if (log.isDebugEnabled()) { + log.debug("Setting API Manager Configuration Service"); + } + PublisherRESTAPIDataHolder.getInstance().setAPIManagerConfiguration(apiManagerConfigurationService); + } + + protected void unsetAPIManagerConfigurationService(APIManagerConfigurationService apiManagerConfigurationService) { + if (log.isDebugEnabled()) { + log.debug("Unsetting API Manager Configuration Service"); + } + PublisherRESTAPIDataHolder.getInstance().setAPIManagerConfiguration(null); + } } diff --git a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java similarity index 96% rename from components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java rename to components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java index 5716ebfcb1b..18944c945c6 100644 --- a/components/apimgt-extensions/io.entgra.devicemgt.apimgt.extension.rest.api/src/main/java/io/entgra/devicemgt/apimgt/extension/rest/api/util/ScopeUtils.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/ScopeUtils.java @@ -16,7 +16,7 @@ * under the License. */ -package io.entgra.devicemgt.apimgt.extension.rest.api.util; +package io.entgra.device.mgt.core.apimgt.extension.rest.api.util; /** * This class represents the scope data. diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml index d1bc922c545..21c7df3235b 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/pom.xml @@ -124,7 +124,7 @@ org.wso2.carbon.devicemgt - io.entgra.devicemgt.apimgt.extension.rest.api + io.entgra.device.mgt.core.apimgt.extension.rest.api provided @@ -174,9 +174,9 @@ org.scannotation;version="1.0", org.scannotation.archiveiterator;version="1.0", org.w3c.dom, - io.entgra.devicemgt.apimgt.extension.rest.api, - io.entgra.devicemgt.apimgt.extension.rest.api.dto, - io.entgra.devicemgt.apimgt.extension.rest.api.exceptions, + io.entgra.device.mgt.core.apimgt.extension.rest.api, + io.entgra.device.mgt.core.apimgt.extension.rest.api.dto, + io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions, org.wso2.carbon.apimgt.annotations.api, org.wso2.carbon.apimgt.api, org.wso2.carbon.apimgt.api.model, diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java index fd111a46de9..a7299501bdd 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherService.java @@ -18,6 +18,7 @@ */ package org.wso2.carbon.apimgt.webapp.publisher; + import org.wso2.carbon.apimgt.webapp.publisher.exception.APIManagerPublisherException; /** diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index 5452a4f8bd5..ef429bbf508 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -18,13 +18,13 @@ */ package org.wso2.carbon.apimgt.webapp.publisher; -import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServices; -import io.entgra.devicemgt.apimgt.extension.rest.api.APIApplicationServicesImpl; -import io.entgra.devicemgt.apimgt.extension.rest.api.PublisherRESTAPIServices; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.APIApplicationKey; -import io.entgra.devicemgt.apimgt.extension.rest.api.dto.AccessTokenInfo; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.APIApplicationServicesException; -import io.entgra.devicemgt.apimgt.extension.rest.api.exceptions.BadRequestException; +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.PublisherRESTAPIServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; +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.BadRequestException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -373,7 +373,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { apiApplicationKey = apiApplicationServices.createAndRetrieveApplicationCredentials(); accessTokenInfo = apiApplicationServices.generateAccessTokenFromRegisteredApplication( apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - } catch (APIApplicationServicesException e) { + } catch (APIServicesException e) { String errorMsg = "Error while generating application"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); @@ -436,7 +436,8 @@ public class APIPublisherServiceImpl implements APIPublisherService { for (int i = 0; i < scopeList.length(); i++) { JSONObject scopeObj = null; scopeObj = scopeList.getJSONObject(i); - if (scopeObj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { + if (scopeObj.getString("name").equals(scopeMapping[2] != null ? + StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { jsonObject = scopeObj; } } @@ -454,20 +455,22 @@ public class APIPublisherServiceImpl implements APIPublisherService { } } catch (IOException | DirectoryIteratorException ex) { log.error("failed to read scopes from file.", ex); - } catch (APIApplicationServicesException | BadRequestException e) { - String errorMsg = "Error while Calling APIs"; + } catch (APIServicesException | BadRequestException e) { + String errorMsg = "Error while calling APIs"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); } } } - catch (APIApplicationServicesException e) { - log.error(e); - throw new RuntimeException(e); + catch (APIServicesException e) { + String errorMsg = "Error while processing Publisher REST API response"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(e); } catch (BadRequestException e) { - log.error(e); - throw new RuntimeException(e); + String errorMsg = "Error while calling Publisher REST APIs"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(e); } finally { PrivilegedCarbonContext.endTenantFlow(); } diff --git a/components/apimgt-extensions/pom.xml b/components/apimgt-extensions/pom.xml index c4bfc0d36d5..c2586135daf 100644 --- a/components/apimgt-extensions/pom.xml +++ b/components/apimgt-extensions/pom.xml @@ -40,7 +40,7 @@ org.wso2.carbon.apimgt.keymgt.extension org.wso2.carbon.apimgt.keymgt.extension.api io.entgra.device.mgt.core.apimgt.analytics.extension - io.entgra.devicemgt.apimgt.extension.rest.api + io.entgra.device.mgt.core.apimgt.extension.rest.api diff --git a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml index b6344f6e454..de2739b1995 100644 --- a/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml +++ b/features/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher.feature/pom.xml @@ -51,6 +51,10 @@ io.swagger swagger-annotations + + org.wso2.carbon.devicemgt + io.entgra.device.mgt.core.apimgt.extension.rest.api + @@ -143,6 +147,9 @@ io.swagger:swagger-annotations:${swagger.version} + + org.wso2.carbon.devicemgt:io.entgra.device.mgt.core.apimgt.extension.rest.api:${carbon.device.mgt.version} + org.wso2.carbon.core.server:${carbon.kernel.version} diff --git a/pom.xml b/pom.xml index e52350555b1..e9686004167 100644 --- a/pom.xml +++ b/pom.xml @@ -240,7 +240,7 @@ org.wso2.carbon.devicemgt - io.entgra.devicemgt.apimgt.extension.rest.api + io.entgra.device.mgt.core.apimgt.extension.rest.api ${carbon.device.mgt.version} From 50fbb5120a5c17fa4492dac99e6ccc2443652ae2 Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 25 Apr 2023 15:11:10 +0530 Subject: [PATCH 15/22] Minor fixes --- .../pom.xml | 9 +++++++++ .../rest/api/APIApplicationServicesImpl.java | 7 ++++--- .../rest/api/PublisherRESTAPIServices.java | 18 +++++++++--------- .../rest/api/constants/Constants.java | 2 +- 4 files changed, 23 insertions(+), 13 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 7fb3f1726ff..17dbdbf8661 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -34,6 +34,14 @@ https://entgra.io + + org.apache.httpcomponents.wso2 + httpcore + + + org.wso2.orbit.org.apache.httpcomponents + httpclient + org.wso2.carbon org.wso2.carbon.logging @@ -119,6 +127,7 @@ org.osgi.service.*;version="${imp.package.version.osgi.service}", org.wso2.carbon.core;version="4.6", org.wso2.carbon.core.util;version="4.6", + org.apache.commons.ssl, org.wso2.carbon.apimgt.api.model, okhttp3.*, org.wso2.carbon.apimgt.impl;version="${carbon.api.mgt.version.range}", diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index bffb97893a6..d3ffe4b4d41 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -60,19 +60,20 @@ public class APIApplicationServicesImpl implements APIApplicationServices { throws APIServicesException { String applicationEndpoint = config.getFirstProperty(Constants.DCR_END_POINT); - String owner = config.getFirstProperty(Constants.SERVER_USER); + String serverUser = config.getFirstProperty(Constants.SERVER_USER); + String serverPassword = config.getFirstProperty(Constants.SERVER_PASSWORD); JSONObject jsonObject = new JSONObject(); jsonObject.put("callbackUrl", Constants.EMPTY_STRING); jsonObject.put("clientName", Constants.CLIENT_NAME); jsonObject.put("grantType", Constants.GRANT_TYPE); - jsonObject.put("owner", owner); + jsonObject.put("owner", serverUser); jsonObject.put("saasApp", true); RequestBody requestBody = RequestBody.Companion.create(jsonObject.toString(), JSON); Request request = new Request.Builder() .url(applicationEndpoint) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic("admin", "admin")) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Credentials.basic(serverUser, serverPassword)) .post(requestBody) .build(); try { diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 5fedcca952d..8ca7fb61722 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -45,15 +45,13 @@ public class PublisherRESTAPIServices { private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); private static final OkHttpClient client = getOkHttpClient(); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); - private static final String host = System.getProperty(Constants.IOT_CORE_HOST); private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT); public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException { - - String getAllScopesUrl = "https://" + "://" + host + ":" + port + Constants.GET_ALL_SCOPES; + String getAllScopesUrl = "https://" + host + ":" + port + Constants.GET_ALL_SCOPES; Request request = new Request.Builder() .url(getAllScopesUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -90,16 +88,17 @@ public class PublisherRESTAPIServices { throws APIServicesException, BadRequestException { String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); - String getScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + keyValue; + String getScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + keyValue; Request request = new Request.Builder() .url(getScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) .head() .build(); try { Response response = client.newCall(request).execute(); - if (response.code() == HttpStatus.SC_OK) { + if (HttpStatus.SC_OK == response.code()) { return true; } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); @@ -124,7 +123,7 @@ public class PublisherRESTAPIServices { public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) throws APIServicesException, BadRequestException { - String updateScopeUrl = "https://" + "://" + host + ":" + port + Constants.GET_SCOPE + scope.getId(); + String updateScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + scope.getId(); ScopeUtils scopeUtil = new ScopeUtils(); scopeUtil.setKey(scope.getKey()); @@ -136,13 +135,14 @@ public class PublisherRESTAPIServices { RequestBody requestBody = RequestBody.create(JSON, scopeString); Request request = new Request.Builder() .url(updateScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, "Bearer " + accessTokenInfo.getAccess_token()) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) .put(requestBody) .build(); try { Response response = client.newCall(request).execute(); - if (response.code() == HttpStatus.SC_OK) { + if (HttpStatus.SC_OK == response.code()) { return true; } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java index 11b056298af..bdc557d3e46 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java @@ -26,7 +26,7 @@ public final class Constants { public static final String EMPTY_STRING = ""; public static final String CLIENT_NAME = "rest_api_publisher_code"; public static final String SERVER_USER = "WorkflowConfigurations.ServerUser"; - public static final String SERVER_PASSWORD = "ServerPassword"; + public static final String SERVER_PASSWORD = "WorkflowConfigurations.ServerPassword"; public static final String GRANT_TYPE = "client_credentials password refresh_token"; public static final String REFRESH_TOKEN_GRANT_TYPE_PARAM_NAME = "refresh_token"; public static final String OAUTH_EXPIRES_IN = "expires_in"; From 9ced84a2dff7f5fabe84075cbdb1db7857862d6b Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 25 Apr 2023 17:45:06 +0530 Subject: [PATCH 16/22] Fix scope id issue --- .../apimgt/webapp/publisher/APIPublisherServiceImpl.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index ef429bbf508..a38b3cacf8d 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -432,16 +432,14 @@ public class APIPublisherServiceImpl implements APIPublisherService { //Set scope id which related to the scope key JSONArray scopeList = (JSONArray) scopeObject.get("list"); - JSONObject jsonObject = null; for (int i = 0; i < scopeList.length(); i++) { JSONObject scopeObj = null; scopeObj = scopeList.getJSONObject(i); if (scopeObj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { - jsonObject = scopeObj; + scope.setId(scopeObj.getString("id")); } } - scope.setId(jsonObject.getString("id")); if (publisherRESTAPIServices.isSharedScopeNameExists(apiApplicationKey, accessTokenInfo, scope.getKey())) { publisherRESTAPIServices.updateSharedScope(apiApplicationKey, accessTokenInfo, scope); From ba5effbf65303726bfd1b20a0751106403a620d7 Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 25 Apr 2023 18:22:13 +0530 Subject: [PATCH 17/22] Remove unwanted dependencies and minor fixes --- .../pom.xml | 8 -------- .../extension/rest/api/PublisherRESTAPIServices.java | 10 ++++++---- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 17dbdbf8661..7ecbdf7900f 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -34,14 +34,6 @@ https://entgra.io - - org.apache.httpcomponents.wso2 - httpcore - - - org.wso2.orbit.org.apache.httpcomponents - httpclient - org.wso2.carbon org.wso2.carbon.logging diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 8ca7fb61722..f7c4430880a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -24,7 +24,6 @@ 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.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils; - import okhttp3.MediaType; import okhttp3.OkHttpClient; import okhttp3.Request; @@ -67,7 +66,8 @@ public class PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return getScopes(apiApplicationKey, refreshedAccessToken); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { @@ -103,7 +103,8 @@ public class PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { @@ -147,7 +148,8 @@ public class PublisherRESTAPIServices { } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); //TODO: max attempt count return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { From 2ca425819e09851b90df9d7a62e3353682c92d4f Mon Sep 17 00:00:00 2001 From: pasindu Date: Tue, 25 Apr 2023 23:23:29 +0530 Subject: [PATCH 18/22] Get hardcoded values as constats and fix exception error handling --- .../rest/api/APIApplicationServicesImpl.java | 1 + .../extension/rest/api/PublisherRESTAPIServices.java | 12 ++++++++---- .../extension/rest/api/constants/Constants.java | 5 +++++ .../webapp/publisher/APIPublisherServiceImpl.java | 3 +-- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index d3ffe4b4d41..210a7104558 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -179,6 +179,7 @@ public class APIApplicationServicesImpl implements APIApplicationServices { sc.init(null, trustAllCerts, new java.security.SecureRandom()); return sc.getSocketFactory(); } catch (KeyManagementException | NoSuchAlgorithmException e) { + log.error("Error while creating the SSL socket factory due to " + e.getMessage(), e); return null; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index f7c4430880a..60d93890b2e 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -50,7 +50,8 @@ public class PublisherRESTAPIServices { public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) throws APIServicesException, BadRequestException { - String getAllScopesUrl = "https://" + host + ":" + port + Constants.GET_ALL_SCOPES; + String getAllScopesUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + + port + Constants.GET_ALL_SCOPES; Request request = new Request.Builder() .url(getAllScopesUrl) .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER @@ -87,8 +88,10 @@ public class PublisherRESTAPIServices { public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) throws APIServicesException, BadRequestException { - String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace("=", ""); - String getScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + keyValue; + String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR, + Constants.EMPTY_STRING); + String getScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + + port + Constants.GET_SCOPE + keyValue; Request request = new Request.Builder() .url(getScopeUrl) @@ -124,7 +127,8 @@ public class PublisherRESTAPIServices { public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) throws APIServicesException, BadRequestException { - String updateScopeUrl = "https://" + host + ":" + port + Constants.GET_SCOPE + scope.getId(); + String updateScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + + Constants.COLON + port + Constants.GET_SCOPE + scope.getId(); ScopeUtils scopeUtil = new ScopeUtils(); scopeUtil.setKey(scope.getKey()); diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java index bdc557d3e46..e4dd49b3818 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/constants/Constants.java @@ -53,6 +53,11 @@ public final class Constants { public static final String PASSWORD_GRANT_TYPE_SCOPES = "scopes"; public static final String ACCESS_TOKEN_GRANT_TYPE_PARAM_NAME = "access_token"; public static final String GRANT_TYPE_PARAM_NAME = "grant_type"; + public static final String HTTPS_PROTOCOL = "https"; + public static final String HTTP_PROTOCOL = "http"; + public static final String SCHEME_SEPARATOR = "://"; + public static final String COLON = ":"; + public static final String QUERY_KEY_VALUE_SEPARATOR = "="; public static final String IOT_CORE_HOST = "iot.core.host"; public static final String IOT_CORE_HTTPS_PORT = "iot.core.https.port"; public static final String GET_ALL_SCOPES = "/api/am/publisher/v2/scopes?limit=1000"; diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index a38b3cacf8d..fb4509858d2 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -433,8 +433,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { //Set scope id which related to the scope key JSONArray scopeList = (JSONArray) scopeObject.get("list"); for (int i = 0; i < scopeList.length(); i++) { - JSONObject scopeObj = null; - scopeObj = scopeList.getJSONObject(i); + JSONObject scopeObj = scopeList.getJSONObject(i); if (scopeObj.getString("name").equals(scopeMapping[2] != null ? StringUtils.trim(scopeMapping[2]) : StringUtils.EMPTY)) { scope.setId(scopeObj.getString("id")); From eb11036b6ccf7549fd220b03a1579ce64eacb2ee Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 26 Apr 2023 10:02:40 +0530 Subject: [PATCH 19/22] Change version snd remove unwanted dependencies --- .../pom.xml | 43 ++++++++----------- .../rest/api/APIApplicationServicesImpl.java | 2 +- 2 files changed, 18 insertions(+), 27 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml index 7ecbdf7900f..2dca4947dba 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/pom.xml @@ -22,7 +22,7 @@ apimgt-extensions org.wso2.carbon.devicemgt - 5.0.25-SNAPSHOT + 5.0.26-SNAPSHOT ../pom.xml @@ -37,43 +37,29 @@ org.wso2.carbon org.wso2.carbon.logging + provided org.wso2.carbon org.wso2.carbon.utils - - - org.eclipse.osgi - org.eclipse.osgi - - - org.eclipse.osgi - org.eclipse.osgi.services + provided org.wso2.carbon org.wso2.carbon.core + provided - com.googlecode.json-simple.wso2 - json-simple - - - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api - - - com.squareup.okhttp3 - okhttp - - - io.github.openfeign - feign-okhttp + org.eclipse.osgi + org.eclipse.osgi + provided - org.wso2.carbon.apimgt - org.wso2.carbon.apimgt.api + org.eclipse.osgi + org.eclipse.osgi.services + provided + org.json.wso2 json @@ -81,12 +67,18 @@ com.google.code.gson gson + provided org.wso2.carbon.apimgt org.wso2.carbon.apimgt.impl provided + + com.squareup.okhttp3 + okhttp + compile + @@ -114,7 +106,6 @@ io.entgra.device.mgt.core.apimgt.extension.rest.api.* - javax.net.ssl, org.osgi.framework.*;version="${imp.package.version.osgi.framework}", org.osgi.service.*;version="${imp.package.version.osgi.service}", org.wso2.carbon.core;version="4.6", diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 210a7104558..0fc1f4792ea 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -19,8 +19,8 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import org.json.JSONObject; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; From 455917f21e0ea3d73411f7b38b9e14ad3006b662 Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 26 Apr 2023 20:35:56 +0530 Subject: [PATCH 20/22] Implement method for Https ssl trustmanager and improve exception --- .../rest/api/APIApplicationServicesImpl.java | 54 +---- .../rest/api/PublisherRESTAPIServices.java | 21 +- .../UnexpectedResponseException.java | 31 +++ .../rest/api/util/HttpsTrustManagerUtils.java | 229 ++++++++++++++++++ .../publisher/APIPublisherServiceImpl.java | 7 +- 5 files changed, 280 insertions(+), 62 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/UnexpectedResponseException.java create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index 0fc1f4792ea..abf383b501b 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -19,6 +19,7 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import org.json.JSONObject; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; @@ -48,7 +49,7 @@ import java.util.concurrent.TimeUnit; public class APIApplicationServicesImpl implements APIApplicationServices { private static final Log log = LogFactory.getLog(APIApplicationServicesImpl.class); - private static final OkHttpClient client = getOkHttpClient(); + private static final OkHttpClient client = new OkHttpClient(HttpsTrustManagerUtils.getSSLClient().newBuilder()); private static final Gson gson = new Gson(); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); String msg = null; @@ -133,55 +134,4 @@ public class APIApplicationServicesImpl implements APIApplicationServices { throw new APIServicesException(e); } } - - protected static OkHttpClient getOkHttpClient() { - X509TrustManager trustAllCerts = new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return new java.security.cert.X509Certificate[0]; - } - - public void checkClientTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - }; - OkHttpClient okHttpClient = new OkHttpClient.Builder() - .connectTimeout(300, TimeUnit.SECONDS) - .writeTimeout(300, TimeUnit.SECONDS) - .readTimeout(300, TimeUnit.SECONDS) - .connectionPool(new ConnectionPool(500, 500, TimeUnit.SECONDS)) - .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) - .hostnameVerifier((hostname, sslSession) -> true).build(); - return okHttpClient; - } - - private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { - try { - TrustManager[] trustAllCerts = new TrustManager[]{ - new X509TrustManager() { - public java.security.cert.X509Certificate[] getAcceptedIssuers() { - return null; - } - - public void checkClientTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - - public void checkServerTrusted( - java.security.cert.X509Certificate[] certs, String authType) { - } - } - }; - SSLContext sc = SSLContext.getInstance("SSL"); - sc.init(null, trustAllCerts, new java.security.SecureRandom()); - return sc.getSocketFactory(); - } catch (KeyManagementException | NoSuchAlgorithmException e) { - log.error("Error while creating the SSL socket factory due to " + e.getMessage(), e); - return null; - } - - } } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index 60d93890b2e..c74b227289b 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -23,6 +23,8 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey 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.BadRequestException; +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.ScopeUtils; import okhttp3.MediaType; import okhttp3.OkHttpClient; @@ -38,17 +40,15 @@ import org.wso2.carbon.apimgt.api.model.Scope; import java.io.IOException; -import static io.entgra.device.mgt.core.apimgt.extension.rest.api.APIApplicationServicesImpl.getOkHttpClient; - public class PublisherRESTAPIServices { private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); - private static final OkHttpClient client = getOkHttpClient(); + private static final OkHttpClient client = new OkHttpClient(HttpsTrustManagerUtils.getSSLClient().newBuilder()); private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); private static final String host = System.getProperty(Constants.IOT_CORE_HOST); private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT); public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) - throws APIServicesException, BadRequestException { + throws APIServicesException, BadRequestException, UnexpectedResponseException { String getAllScopesUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + port + Constants.GET_ALL_SCOPES; @@ -76,7 +76,8 @@ public class PublisherRESTAPIServices { log.error(msg); throw new BadRequestException(msg); } else { - return null; + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); } } catch (IOException e) { String msg = "Error occurred while processing the response"; @@ -86,7 +87,7 @@ public class PublisherRESTAPIServices { } public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) - throws APIServicesException, BadRequestException { + throws APIServicesException, BadRequestException, UnexpectedResponseException { String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR, Constants.EMPTY_STRING); @@ -115,7 +116,8 @@ public class PublisherRESTAPIServices { log.error(msg); throw new BadRequestException(msg); } else { - return false; + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); } } catch (IOException e) { String msg = "Error occurred while processing the response"; @@ -125,7 +127,7 @@ public class PublisherRESTAPIServices { } public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) - throws APIServicesException, BadRequestException { + throws APIServicesException, BadRequestException, UnexpectedResponseException { String updateScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + port + Constants.GET_SCOPE + scope.getId(); @@ -161,7 +163,8 @@ public class PublisherRESTAPIServices { log.error(msg); throw new BadRequestException(msg); } else { - return false; + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); } } catch (IOException e) { String msg = "Error occurred while processing the response"; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/UnexpectedResponseException.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/UnexpectedResponseException.java new file mode 100644 index 00000000000..898caba26e8 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/exceptions/UnexpectedResponseException.java @@ -0,0 +1,31 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +/** + * Custom exception class for handling unexpected server response exceptions. + */ +package io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions; + +public class UnexpectedResponseException extends Exception { + + private static final long serialVersionUID = -2387103750774855056L; + + public UnexpectedResponseException(String errorMessage) { + super(errorMessage); + } +} diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java new file mode 100644 index 00000000000..8b47d77a343 --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java @@ -0,0 +1,229 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.apimgt.extension.rest.api.util; + +import okhttp3.ConnectionPool; +import okhttp3.OkHttpClient; +import org.apache.commons.lang.StringUtils; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.wso2.carbon.base.ServerConfiguration; + +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLSocketFactory; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; +import javax.net.ssl.SSLSession; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.TrustManagerFactory; +import javax.net.ssl.HostnameVerifier; + +import java.io.FileInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.net.Proxy; +import java.net.ProxySelector; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.net.URI; + +import java.security.*; +import java.security.cert.CertificateException; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.TimeUnit; + +public class HttpsTrustManagerUtils { + + private static final Log log = LogFactory.getLog(HttpsTrustManagerUtils.class); + private static final String KEY_STORE_TYPE = "JKS"; + /** + * Default truststore type of the client + */ + private static final String TRUST_STORE_TYPE = "JKS"; + /** + * Default keymanager type of the client + */ + private static final String KEY_MANAGER_TYPE = "SunX509"; //Default Key Manager Type + /** + * Default trustmanager type of the client + */ + private static final String TRUST_MANAGER_TYPE = "SunX509"; //Default Trust Manager Type + private static final String SSLV3 = "SSLv3"; + private static final String DEFAULT_HOST = "localhost"; + private static final String DEFAULT_HOST_IP = "127.0.0.1"; + private static final int TIMEOUT = 100; + + public static OkHttpClient getSSLClient() { + + boolean isIgnoreHostnameVerification = Boolean.parseBoolean(System.getProperty("org.wso2" + + ".ignoreHostnameVerification")); + OkHttpClient okHttpClient; + final String proxyHost = System.getProperty("http.proxyHost"); + final String proxyPort = System.getProperty("http.proxyPort"); + final String nonProxyHostsValue = System.getProperty("http.nonProxyHosts"); + + final ProxySelector proxySelector = new ProxySelector() { + @Override + public List select(URI uri) { + List proxyList = new ArrayList<>(); + String host = uri.getHost(); + + if (!StringUtils.isEmpty(host)) { + if (host.startsWith(DEFAULT_HOST_IP) || host.startsWith(DEFAULT_HOST) || StringUtils + .isEmpty(nonProxyHostsValue) || StringUtils.contains(nonProxyHostsValue, host) || + StringUtils.isEmpty(proxyHost) || StringUtils.isEmpty(proxyPort)) { + proxyList.add(Proxy.NO_PROXY); + } else { + proxyList.add(new Proxy(Proxy.Type.HTTP, + new InetSocketAddress(proxyHost, Integer.parseInt(proxyPort)))); + } + } else { + log.error("Host is null. Host could not be empty or null"); + } + return proxyList; + } + + @Override + public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { + throw new UnsupportedOperationException("Not supported yet."); + } + }; + + X509TrustManager trustAllCerts = new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return new java.security.cert.X509Certificate[0]; + } + + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + }; + + if (isIgnoreHostnameVerification) { + okHttpClient = new OkHttpClient.Builder() + .connectTimeout(TIMEOUT, TimeUnit.SECONDS) + .writeTimeout(TIMEOUT, TimeUnit.SECONDS) + .readTimeout(TIMEOUT, TimeUnit.SECONDS) + .connectionPool(new ConnectionPool(TIMEOUT, TIMEOUT, TimeUnit.SECONDS)) + .sslSocketFactory(getSimpleTrustedSSLSocketFactory(), trustAllCerts) + .hostnameVerifier(new HostnameVerifier() { + @Override + public boolean verify(String s, SSLSession sslSession) { + return true; + } + }).proxySelector(proxySelector).build(); + return okHttpClient; + } else { + SSLSocketFactory trustedSSLSocketFactory = getTrustedSSLSocketFactory(); + okHttpClient = new OkHttpClient.Builder() + .connectTimeout(TIMEOUT, TimeUnit.SECONDS) + .writeTimeout(TIMEOUT, TimeUnit.SECONDS) + .readTimeout(TIMEOUT, TimeUnit.SECONDS) + .connectionPool(new ConnectionPool(TIMEOUT, TIMEOUT, TimeUnit.SECONDS)) + .sslSocketFactory(trustedSSLSocketFactory) + .proxySelector(proxySelector).build(); + return okHttpClient; + } + } + + private static SSLSocketFactory getSimpleTrustedSSLSocketFactory() { + try { + TrustManager[] trustAllCerts = new TrustManager[]{ + new X509TrustManager() { + public java.security.cert.X509Certificate[] getAcceptedIssuers() { + return null; + } + + public void checkClientTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + + public void checkServerTrusted( + java.security.cert.X509Certificate[] certs, String authType) { + } + } + }; + SSLContext sc = SSLContext.getInstance("SSL"); + sc.init(null, trustAllCerts, new SecureRandom()); + return sc.getSocketFactory(); + } catch (KeyManagementException | NoSuchAlgorithmException e) { + log.error("Error while creating the SSL socket factory due to " + e.getMessage(), e); + return null; + } + } + + private static SSLSocketFactory getTrustedSSLSocketFactory() { + try { + String keyStorePassword = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Password"); + String keyStoreLocation = ServerConfiguration.getInstance().getFirstProperty("Security.KeyStore.Location"); + String trustStorePassword = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Password"); + String trustStoreLocation = ServerConfiguration.getInstance().getFirstProperty( + "Security.TrustStore.Location"); + KeyStore keyStore = loadKeyStore(keyStoreLocation, keyStorePassword, KEY_STORE_TYPE); + KeyStore trustStore = loadTrustStore(trustStoreLocation, trustStorePassword); + + return initSSLConnection(keyStore, keyStorePassword, trustStore); + } catch (KeyManagementException | NoSuchAlgorithmException | KeyStoreException + | CertificateException | IOException | UnrecoverableKeyException e) { + log.error("Error while creating the SSL socket factory due to " + e.getMessage(), e); + return null; + } + } + + private static SSLSocketFactory initSSLConnection(KeyStore keyStore, String keyStorePassword, KeyStore trustStore) + throws NoSuchAlgorithmException, UnrecoverableKeyException, KeyStoreException, KeyManagementException { + KeyManagerFactory keyManagerFactory = KeyManagerFactory.getInstance(KEY_MANAGER_TYPE); + keyManagerFactory.init(keyStore, keyStorePassword.toCharArray()); + TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(TRUST_MANAGER_TYPE); + trustManagerFactory.init(trustStore); + + // Create and initialize SSLContext for HTTPS communication + SSLContext sslContext = SSLContext.getInstance(SSLV3); + sslContext.init(keyManagerFactory.getKeyManagers(), trustManagerFactory.getTrustManagers(), null); + SSLContext.setDefault(sslContext); + return sslContext.getSocketFactory(); + } + + private static KeyStore loadKeyStore(String keyStorePath, String ksPassword, String type) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + InputStream fileInputStream = null; + try { + char[] keypassChar = ksPassword.toCharArray(); + KeyStore keyStore = KeyStore.getInstance(type); + fileInputStream = new FileInputStream(keyStorePath); + keyStore.load(fileInputStream, keypassChar); + return keyStore; + } finally { + if (fileInputStream != null) { + fileInputStream.close(); + } + } + } + + private static KeyStore loadTrustStore(String trustStorePath, String tsPassword) + throws KeyStoreException, IOException, CertificateException, NoSuchAlgorithmException { + return loadKeyStore(trustStorePath, tsPassword, TRUST_STORE_TYPE); + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index fb4509858d2..e4a63f456a0 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -25,6 +25,7 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey 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.BadRequestException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; import org.apache.commons.lang.StringUtils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -468,7 +469,11 @@ public class APIPublisherServiceImpl implements APIPublisherService { String errorMsg = "Error while calling Publisher REST APIs"; log.error(errorMsg, e); throw new APIManagerPublisherException(e); - } finally { + } catch (UnexpectedResponseException e) { + String errorMsg = "Unexpected response from the server"; + log.error(errorMsg, e); + throw new APIManagerPublisherException(e); + }finally { PrivilegedCarbonContext.endTenantFlow(); } } From 6b6b303d87420e3bc4dd1f3ec0d00ea3b9107109 Mon Sep 17 00:00:00 2001 From: pasindu Date: Wed, 26 Apr 2023 23:20:21 +0530 Subject: [PATCH 21/22] Create interface for Publlisher rest api services --- .../rest/api/APIApplicationServicesImpl.java | 11 +- .../rest/api/PublisherRESTAPIServices.java | 150 +-------------- .../api/PublisherRESTAPIServicesImpl.java | 174 ++++++++++++++++++ .../publisher/APIPublisherServiceImpl.java | 3 +- 4 files changed, 184 insertions(+), 154 deletions(-) create mode 100644 components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java index abf383b501b..68faf24b80a 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/APIApplicationServicesImpl.java @@ -19,8 +19,8 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; import com.google.gson.Gson; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import org.json.JSONObject; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.constants.Constants; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; @@ -31,20 +31,11 @@ import okhttp3.Request; import okhttp3.Response; import okhttp3.RequestBody; import okhttp3.Credentials; -import okhttp3.ConnectionPool; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.wso2.carbon.apimgt.impl.APIManagerConfiguration; import org.wso2.carbon.apimgt.impl.internal.ServiceReferenceHolder; - -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLSocketFactory; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; import java.io.IOException; -import java.security.KeyManagementException; -import java.security.NoSuchAlgorithmException; -import java.util.concurrent.TimeUnit; public class APIApplicationServicesImpl implements APIApplicationServices { diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java index c74b227289b..2ea0a51f344 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServices.java @@ -18,158 +18,22 @@ package io.entgra.device.mgt.core.apimgt.extension.rest.api; -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.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; -import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils; -import okhttp3.MediaType; -import okhttp3.OkHttpClient; -import okhttp3.Request; -import okhttp3.Response; -import okhttp3.RequestBody; -import org.apache.commons.httpclient.HttpStatus; -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.apache.commons.ssl.Base64; import org.json.JSONObject; import org.wso2.carbon.apimgt.api.model.Scope; -import java.io.IOException; +public interface PublisherRESTAPIServices { -public class PublisherRESTAPIServices { - private static final Log log = LogFactory.getLog(PublisherRESTAPIServices.class); - private static final OkHttpClient client = new OkHttpClient(HttpsTrustManagerUtils.getSSLClient().newBuilder()); - private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); - private static final String host = System.getProperty(Constants.IOT_CORE_HOST); - private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT); + JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + throws APIServicesException, BadRequestException, UnexpectedResponseException; - public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) - throws APIServicesException, BadRequestException, UnexpectedResponseException { + boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) + throws APIServicesException, BadRequestException, UnexpectedResponseException; - String getAllScopesUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON - + port + Constants.GET_ALL_SCOPES; - Request request = new Request.Builder() - .url(getAllScopesUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) - .get() - .build(); - - try { - Response response = client.newCall(request).execute(); - if (HttpStatus.SC_OK == response.code()) { - JSONObject jsonObject = new JSONObject(response.body().string()); - return jsonObject; - } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), - apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - //TODO: max attempt count - return getScopes(apiApplicationKey, refreshedAccessToken); - } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - String msg = "Bad Request, Invalid request"; - log.error(msg); - throw new BadRequestException(msg); - } else { - String msg = "Response : " + response.code() + response.body(); - throw new UnexpectedResponseException(msg); - } - } catch (IOException e) { - String msg = "Error occurred while processing the response"; - log.error(msg, e); - throw new APIServicesException(e); - } - } - - public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) - throws APIServicesException, BadRequestException, UnexpectedResponseException { - - String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR, - Constants.EMPTY_STRING); - String getScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON - + port + Constants.GET_SCOPE + keyValue; - - Request request = new Request.Builder() - .url(getScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) - .head() - .build(); - try { - Response response = client.newCall(request).execute(); - if (HttpStatus.SC_OK == response.code()) { - return true; - } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), - apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - //TODO: max attempt count - return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); - } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - String msg = "Bad Request, Invalid request"; - log.error(msg); - throw new BadRequestException(msg); - } else { - String msg = "Response : " + response.code() + response.body(); - throw new UnexpectedResponseException(msg); - } - } catch (IOException e) { - String msg = "Error occurred while processing the response"; - log.error(msg, e); - throw new APIServicesException(e); - } - } - - public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) - throws APIServicesException, BadRequestException, UnexpectedResponseException { - - String updateScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host - + Constants.COLON + port + Constants.GET_SCOPE + scope.getId(); - - ScopeUtils scopeUtil = new ScopeUtils(); - scopeUtil.setKey(scope.getKey()); - scopeUtil.setName(scope.getName()); - scopeUtil.setDescription(scope.getDescription()); - scopeUtil.setRoles(scope.getRoles()); - String scopeString = scopeUtil.toJSON(); - - RequestBody requestBody = RequestBody.create(JSON, scopeString); - Request request = new Request.Builder() - .url(updateScopeUrl) - .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER - + accessTokenInfo.getAccess_token()) - .put(requestBody) - .build(); - - try { - Response response = client.newCall(request).execute(); - if (HttpStatus.SC_OK == response.code()) { - return true; - } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { - APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); - AccessTokenInfo refreshedAccessToken = apiApplicationServices. - generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), - apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); - //TODO: max attempt count - return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); - } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { - String msg = "Bad Request, Invalid scope object"; - log.error(msg); - throw new BadRequestException(msg); - } else { - String msg = "Response : " + response.code() + response.body(); - throw new UnexpectedResponseException(msg); - } - } catch (IOException e) { - String msg = "Error occurred while processing the response"; - log.error(msg, e); - throw new APIServicesException(e); - } - } + boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) + throws APIServicesException, BadRequestException, UnexpectedResponseException; } diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java new file mode 100644 index 00000000000..9a5bf73a84b --- /dev/null +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -0,0 +1,174 @@ +/* + * Copyright (c) 2023, Entgra (Pvt) Ltd. (http://www.entgra.io) All Rights Reserved. + * + * Entgra (Pvt) Ltd. licenses this file to you under the Apache License, + * Version 2.0 (the "License"); you may not use this file except + * in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package io.entgra.device.mgt.core.apimgt.extension.rest.api; + +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.AccessTokenInfo; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequestException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.UnexpectedResponseException; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.HttpsTrustManagerUtils; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.util.ScopeUtils; +import okhttp3.*; +import org.apache.commons.httpclient.HttpStatus; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.apache.commons.ssl.Base64; +import org.json.JSONObject; +import org.wso2.carbon.apimgt.api.model.Scope; + +import java.io.IOException; + +public class PublisherRESTAPIServicesImpl implements PublisherRESTAPIServices { + private static final Log log = LogFactory.getLog(PublisherRESTAPIServicesImpl.class); + private static final OkHttpClient client = new OkHttpClient(HttpsTrustManagerUtils.getSSLClient().newBuilder()); + private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8"); + private static final String host = System.getProperty(Constants.IOT_CORE_HOST); + private static final String port = System.getProperty(Constants.IOT_CORE_HTTPS_PORT); + + @Override + public JSONObject getScopes(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo) + throws APIServicesException, BadRequestException, UnexpectedResponseException { + + String getAllScopesUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + + port + Constants.GET_ALL_SCOPES; + Request request = new Request.Builder() + .url(getAllScopesUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) + .get() + .build(); + + try { + Response response = client.newCall(request).execute(); + if (HttpStatus.SC_OK == response.code()) { + JSONObject jsonObject = new JSONObject(response.body().string()); + return jsonObject; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return getScopes(apiApplicationKey, refreshedAccessToken); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + String msg = "Bad Request, Invalid request"; + log.error(msg); + throw new BadRequestException(msg); + } else { + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + log.error(msg, e); + throw new APIServicesException(e); + } + } + + @Override + public boolean isSharedScopeNameExists(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, String key) + throws APIServicesException, BadRequestException, UnexpectedResponseException { + + String keyValue = new String(Base64.encodeBase64((key).getBytes())).replace(Constants.QUERY_KEY_VALUE_SEPARATOR, + Constants.EMPTY_STRING); + String getScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + Constants.COLON + + port + Constants.GET_SCOPE + keyValue; + + Request request = new Request.Builder() + .url(getScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) + .head() + .build(); + try { + Response response = client.newCall(request).execute(); + if (HttpStatus.SC_OK == response.code()) { + return true; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return isSharedScopeNameExists(apiApplicationKey, refreshedAccessToken, key); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + String msg = "Bad Request, Invalid request"; + log.error(msg); + throw new BadRequestException(msg); + } else { + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + log.error(msg, e); + throw new APIServicesException(e); + } + } + + @Override + public boolean updateSharedScope(APIApplicationKey apiApplicationKey, AccessTokenInfo accessTokenInfo, Scope scope) + throws APIServicesException, BadRequestException, UnexpectedResponseException { + + String updateScopeUrl = Constants.HTTPS_PROTOCOL + Constants.SCHEME_SEPARATOR + host + + Constants.COLON + port + Constants.GET_SCOPE + scope.getId(); + + ScopeUtils scopeUtil = new ScopeUtils(); + scopeUtil.setKey(scope.getKey()); + scopeUtil.setName(scope.getName()); + scopeUtil.setDescription(scope.getDescription()); + scopeUtil.setRoles(scope.getRoles()); + String scopeString = scopeUtil.toJSON(); + + RequestBody requestBody = RequestBody.create(JSON, scopeString); + Request request = new Request.Builder() + .url(updateScopeUrl) + .addHeader(Constants.AUTHORIZATION_HEADER_NAME, Constants.AUTHORIZATION_HEADER_PREFIX_BEARER + + accessTokenInfo.getAccess_token()) + .put(requestBody) + .build(); + + try { + Response response = client.newCall(request).execute(); + if (HttpStatus.SC_OK == response.code()) { + return true; + } else if (HttpStatus.SC_UNAUTHORIZED == response.code()) { + APIApplicationServices apiApplicationServices = new APIApplicationServicesImpl(); + AccessTokenInfo refreshedAccessToken = apiApplicationServices. + generateAccessTokenFromRefreshToken(accessTokenInfo.getRefresh_token(), + apiApplicationKey.getClientId(), apiApplicationKey.getClientSecret()); + //TODO: max attempt count + return updateSharedScope(apiApplicationKey, refreshedAccessToken, scope); + } else if (HttpStatus.SC_BAD_REQUEST == response.code()) { + String msg = "Bad Request, Invalid scope object"; + log.error(msg); + throw new BadRequestException(msg); + } else { + String msg = "Response : " + response.code() + response.body(); + throw new UnexpectedResponseException(msg); + } + } catch (IOException e) { + String msg = "Error occurred while processing the response"; + log.error(msg, e); + throw new APIServicesException(e); + } + } +} diff --git a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java index e4a63f456a0..0725998e7f2 100644 --- a/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java +++ b/components/apimgt-extensions/org.wso2.carbon.apimgt.webapp.publisher/src/main/java/org/wso2/carbon/apimgt/webapp/publisher/APIPublisherServiceImpl.java @@ -21,6 +21,7 @@ package org.wso2.carbon.apimgt.webapp.publisher; 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.PublisherRESTAPIServices; +import io.entgra.device.mgt.core.apimgt.extension.rest.api.PublisherRESTAPIServicesImpl; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.APIApplicationKey; import io.entgra.device.mgt.core.apimgt.extension.rest.api.dto.AccessTokenInfo; import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.APIServicesException; @@ -384,7 +385,7 @@ public class APIPublisherServiceImpl implements APIPublisherService { for (String tenantDomain : tenants) { PrivilegedCarbonContext.startTenantFlow(); PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantDomain(tenantDomain, true); - PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServices(); + PublisherRESTAPIServices publisherRESTAPIServices = new PublisherRESTAPIServicesImpl(); JSONObject scopeObject = publisherRESTAPIServices.getScopes(apiApplicationKey, accessTokenInfo); try { From bb325f7c46b2f9076255b916eff5ee451655516e Mon Sep 17 00:00:00 2001 From: pasindu Date: Thu, 27 Apr 2023 09:32:04 +0530 Subject: [PATCH 22/22] Remove wild card imports --- .../extension/rest/api/PublisherRESTAPIServicesImpl.java | 6 +++++- .../extension/rest/api/util/HttpsTrustManagerUtils.java | 7 ++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java index 9a5bf73a84b..819b91210d4 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/PublisherRESTAPIServicesImpl.java @@ -26,7 +26,11 @@ import io.entgra.device.mgt.core.apimgt.extension.rest.api.exceptions.BadRequest 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.ScopeUtils; -import okhttp3.*; +import okhttp3.MediaType; +import okhttp3.OkHttpClient; +import okhttp3.Request; +import okhttp3.Response; +import okhttp3.RequestBody; import org.apache.commons.httpclient.HttpStatus; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; diff --git a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java index 8b47d77a343..b55857af378 100644 --- a/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java +++ b/components/apimgt-extensions/io.entgra.device.mgt.core.apimgt.extension.rest.api/src/main/java/io/entgra/device/mgt/core/apimgt/extension/rest/api/util/HttpsTrustManagerUtils.java @@ -43,7 +43,12 @@ import java.net.InetSocketAddress; import java.net.SocketAddress; import java.net.URI; -import java.security.*; +import java.security.KeyManagementException; +import java.security.KeyStore; +import java.security.KeyStoreException; +import java.security.NoSuchAlgorithmException; +import java.security.UnrecoverableKeyException; +import java.security.SecureRandom; import java.security.cert.CertificateException; import java.util.ArrayList; import java.util.List;