diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/SPApplicationDAO.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/SPApplicationDAO.java index 62f97db9d0..9fe44a72e7 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/SPApplicationDAO.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/SPApplicationDAO.java @@ -26,7 +26,7 @@ import java.util.List; public interface SPApplicationDAO { - int createIdentityServer(IdentityServerDTO identityServer, int tenantId) throws ApplicationManagementDAOException; + int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException; /** * diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/GenericSPApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/GenericSPApplicationDAOImpl.java index 4a586d8af6..ab2ca8cca6 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/GenericSPApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/GenericSPApplicationDAOImpl.java @@ -41,7 +41,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp private static final Log log = LogFactory.getLog(GenericApplicationDAOImpl.class); @Override public List getIdentityServers(int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ?"; try { @@ -68,7 +68,7 @@ public class GenericSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp @Override public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ? AND " + "ID = ?"; diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/OracleSPApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/OracleSPApplicationDAOImpl.java index 3526fe88e2..828ad1acae 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/OracleSPApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/OracleSPApplicationDAOImpl.java @@ -41,7 +41,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp @Override public List getIdentityServers(int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ?"; try { @@ -68,7 +68,7 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp @Override public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ? AND " + "ID = ?"; @@ -99,6 +99,46 @@ public class OracleSPApplicationDAOImpl extends AbstractDAOImpl implements SPAp } } + @Override + public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to create an identity server"); + } + String sql = "INSERT INTO AP_IDENTITY_SERVER " + + "(PROVIDER_NAME, " + + "NAME, " + + "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) " + + "VALUES (?, ?, ?, ?)"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, identityServerDTO.getProviderName()); + stmt.setString(2, identityServerDTO.getName()); + stmt.setString(3, identityServerDTO.getDescription()); + stmt.setString(4, identityServerDTO.getUrl()); + stmt.setString(5, identityServerDTO.getApiUrl()); + stmt.setString(6, identityServerDTO.getUserName()); + stmt.setString(7, identityServerDTO.getPassword()); + stmt.setInt(8, tenantId); + stmt.executeUpdate(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + return rs.getInt(1); + } + return -1; + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while creating identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to create an identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + @Override public List getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/PostgreSQLSPApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/PostgreSQLSPApplicationDAOImpl.java index 88d482bf13..629b0b3df8 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/PostgreSQLSPApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/PostgreSQLSPApplicationDAOImpl.java @@ -41,7 +41,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S @Override public List getIdentityServers(int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ?"; try { @@ -68,7 +68,7 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S @Override public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ? AND " + "ID = ?"; @@ -99,6 +99,46 @@ public class PostgreSQLSPApplicationDAOImpl extends AbstractDAOImpl implements S } } + @Override + public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to create an identity server"); + } + String sql = "INSERT INTO AP_IDENTITY_SERVER " + + "(PROVIDER_NAME, " + + "NAME, " + + "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) " + + "VALUES (?, ?, ?, ?)"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, identityServerDTO.getProviderName()); + stmt.setString(2, identityServerDTO.getName()); + stmt.setString(3, identityServerDTO.getDescription()); + stmt.setString(4, identityServerDTO.getUrl()); + stmt.setString(5, identityServerDTO.getApiUrl()); + stmt.setString(6, identityServerDTO.getUserName()); + stmt.setString(7, identityServerDTO.getPassword()); + stmt.setInt(8, tenantId); + stmt.executeUpdate(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + return rs.getInt(1); + } + return -1; + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while creating identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to create an identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + @Override public List getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) { diff --git a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/SQLServerSPApplicationDAOImpl.java b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/SQLServerSPApplicationDAOImpl.java index acbfe124b5..e943570286 100644 --- a/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/SQLServerSPApplicationDAOImpl.java +++ b/components/application-mgt/io.entgra.application.mgt.core/src/main/java/io/entgra/application/mgt/core/dao/impl/application/spapplication/SQLServerSPApplicationDAOImpl.java @@ -41,7 +41,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S @Override public List getIdentityServers(int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ?"; try { @@ -68,7 +68,7 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S @Override public IdentityServerDTO getIdentityServerById(int id, int tenantId) throws ApplicationManagementDAOException { - String sql = "SELECT ID, NAME, DESCRIPTION, URL, SP_APPS_URI, SP_APPS_API, TENANT_ID, USERNAME, PASSWORD " + String sql = "SELECT ID, PROVIDER_NAME, NAME, DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID " + "FROM AP_IDENTITY_SERVER " + "WHERE TENANT_ID = ? AND " + "ID = ?"; @@ -99,6 +99,46 @@ public class SQLServerSPApplicationDAOImpl extends AbstractDAOImpl implements S } } + @Override + public int createIdentityServer(IdentityServerDTO identityServerDTO, int tenantId) throws ApplicationManagementDAOException { + if (log.isDebugEnabled()) { + log.debug("Request received in DAO Layer to create an identity server"); + } + String sql = "INSERT INTO AP_IDENTITY_SERVER " + + "(PROVIDER_NAME, " + + "NAME, " + + "DESCRIPTION, URL, API_URL, USERNAME, PASSWORD, TENANT_ID) " + + "VALUES (?, ?, ?, ?)"; + try { + Connection conn = this.getDBConnection(); + try (PreparedStatement stmt = conn.prepareStatement(sql, Statement.RETURN_GENERATED_KEYS)) { + stmt.setString(1, identityServerDTO.getProviderName()); + stmt.setString(2, identityServerDTO.getName()); + stmt.setString(3, identityServerDTO.getDescription()); + stmt.setString(4, identityServerDTO.getUrl()); + stmt.setString(5, identityServerDTO.getApiUrl()); + stmt.setString(6, identityServerDTO.getUserName()); + stmt.setString(7, identityServerDTO.getPassword()); + stmt.setInt(8, tenantId); + stmt.executeUpdate(); + try (ResultSet rs = stmt.getGeneratedKeys()) { + if (rs.next()) { + return rs.getInt(1); + } + return -1; + } + } + } catch (DBConnectionException e) { + String msg = "Error occurred while creating identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } catch (SQLException e) { + String msg = "Error occurred while executing SQL to create an identity server "; + log.error(msg, e); + throw new ApplicationManagementDAOException(msg, e); + } + } + @Override public List getSPApplications(int identityServerId, String spUID, int tenantId) throws ApplicationManagementDAOException { if (log.isDebugEnabled()) {