diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementService.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementService.java index 5f469a4ed23a..cc79a3c53b0e 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementService.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementService.java @@ -489,7 +489,21 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te throw new NotImplementedException(); } + /** + * Retrieve application UUID using the application name. + * + * @param name Name of the application + * @param tenantDomain Tenant domain of the application + * @return Application UUID + * @throws IdentityApplicationManagementException + */ + public String getApplicationUUIDByName(String name, String tenantDomain) + throws IdentityApplicationManagementException { + + throw new NotImplementedException(); + } + /** * Get custom inbound authenticator configurations. * * @return custom inbound authenticator configs maps. diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java index 7c26a56ef327..a9e845f64e23 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImpl.java @@ -656,6 +656,19 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te return basicAppInfo; } + @Override + public String getApplicationUUIDByName(String name, String tenantDomain) + throws IdentityApplicationManagementException { + + if (log.isDebugEnabled()) { + log.debug("Getting application UUID for name: " + name + + " in tenantDomain: " + tenantDomain); + } + + ApplicationDAO appDAO = ApplicationMgtSystemConfig.getInstance().getApplicationDAO(); + return appDAO.getApplicationUUIDByName(name, tenantDomain); + } + /** * Get count of all Application Basic Information. * diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/ApplicationDAO.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/ApplicationDAO.java index 00c32b8f1b9b..e94cb5203832 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/ApplicationDAO.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/ApplicationDAO.java @@ -230,6 +230,20 @@ default ApplicationBasicInfo getApplicationBasicInfoByName(String name, String t throw new NotImplementedException(); } + /** + * Retrieve application UUID using the application name. + * + * @param name Name of the application + * @param tenantDomain Tenant domain of the application + * @return Application UUID + * @throws IdentityApplicationManagementException + */ + default String getApplicationUUIDByName(String name, String tenantDomain) + throws IdentityApplicationManagementException { + + throw new NotImplementedException(); + } + default String addApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException { diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java index d1a2b0fa9b5b..063bb4bd6a96 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationDAOImpl.java @@ -5798,6 +5798,37 @@ public ApplicationBasicInfo getApplicationBasicInfoByName(String name, String te return applicationBasicInfo; } + @Override + public String getApplicationUUIDByName(String name, String tenantDomain) + throws IdentityApplicationManagementException { + + if (log.isDebugEnabled()) { + log.debug("Getting application UUID for name: " + name + + " in tenantDomain: " + tenantDomain); + } + + String applicationUuid = null; + try (Connection connection = IdentityDatabaseUtil.getDBConnection(false)) { + try (NamedPreparedStatement statement = + new NamedPreparedStatement(connection, + ApplicationMgtDBQueries.GET_APP_UUID_BY_TENANT_AND_NAME)) { + statement.setInt(ApplicationTableColumns.TENANT_ID, IdentityTenantUtil.getTenantId(tenantDomain)); + statement.setString(ApplicationTableColumns.APP_NAME, name); + + try (ResultSet resultSet = statement.executeQuery()) { + while (resultSet.next()) { + applicationUuid = resultSet.getString(ApplicationTableColumns.UUID); + } + } + } + } catch (SQLException e) { + String message = "Error while getting application uuid for name: %s in " + + "tenantDomain: %s"; + throw new IdentityApplicationManagementException(String.format(message, name, tenantDomain), e); + } + return applicationUuid; + } + public String addApplication(ServiceProvider application, String tenantDomain) throws IdentityApplicationManagementException { diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationMgtDBQueries.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationMgtDBQueries.java index 5cac2cfaffdd..b6ee788f9ccc 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationMgtDBQueries.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/dao/impl/ApplicationMgtDBQueries.java @@ -100,6 +100,9 @@ public class ApplicationMgtDBQueries { "IMAGE_URL, ACCESS_URL, IS_DISCOVERABLE, USERNAME, USER_STORE, TENANT_ID FROM SP_APP WHERE " + "TENANT_ID = :TENANT_ID; AND APP_NAME = :APP_NAME;"; + public static final String GET_APP_UUID_BY_TENANT_AND_NAME = "SELECT UUID FROM SP_APP WHERE " + + "TENANT_ID = :TENANT_ID; AND APP_NAME = :APP_NAME;"; + // Load application basic information for listing with pagination public static final String LOAD_APP_NAMES_BY_TENANT_MYSQL = "SELECT ID, APP_NAME, VERSION, DESCRIPTION, " + "UUID, IMAGE_URL, ACCESS_URL, USERNAME, USER_STORE, TENANT_ID FROM SP_APP WHERE TENANT_ID = ? AND " + diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java index 6b6d14fe6489..ec71ddfe0732 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/test/java/org/wso2/carbon/identity/application/mgt/ApplicationManagementServiceImplTest.java @@ -707,6 +707,25 @@ public void testGetSAMLApplicationBasicInfoWithFilterOffsetLimit(String filter, applicationManagementService.deleteApplications(SUPER_TENANT_ID); } + @Test() + public void testGetApplicationUUIDFromName() + throws IdentityApplicationManagementException { + + ServiceProvider serviceProvider = new ServiceProvider(); + serviceProvider.setApplicationName(APPLICATION_NAME_1); + // Adding new application. + String resourceId = applicationManagementService.createApplication(serviceProvider, + SUPER_TENANT_DOMAIN_NAME, USERNAME_1); + + // Retrieving added application info. + String applicationUUID = applicationManagementService.getApplicationUUIDByName( + serviceProvider.getApplicationName(), SUPER_TENANT_DOMAIN_NAME); + Assert.assertEquals(applicationUUID, resourceId); + + // Deleting added application. + applicationManagementService.deleteApplications(SUPER_TENANT_ID); + } + @Test public void testGetConfiguredAuthenticators() throws IdentityApplicationManagementException {