diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/findbugs-exclude.xml b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/findbugs-exclude.xml
deleted file mode 100644
index cd226386..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/findbugs-exclude.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/pom.xml b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/pom.xml
deleted file mode 100644
index 8003b149..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/pom.xml
+++ /dev/null
@@ -1,212 +0,0 @@
-
-
-
- open-banking-accelerator
- com.wso2.openbanking.accelerator
- 3.2.11-SNAPSHOT
- ../../../pom.xml
-
- 4.0.0
-
- com.wso2.openbanking.accelerator.account.metadata.service
- WSO2 Open Banking - Account Metadata Service Module
- bundle
-
-
-
- org.springframework
- spring-web
- provided
-
-
- org.apache.cxf
- cxf-bundle-jaxrs
- provided
-
-
- org.apache.commons
- commons-lang3
- provided
-
-
- commons-logging
- commons-logging
- provided
-
-
- org.testng
- testng
- test
-
-
- com.h2database
- h2
- test
-
-
- org.mockito
- mockito-all
-
-
- org.powermock
- powermock-module-testng
-
-
- org.powermock
- powermock-api-mockito
-
-
- com.wso2.openbanking.accelerator
- com.wso2.openbanking.accelerator.common
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- src/test/resources/testng.xml
-
-
-
-
- org.jacoco
- jacoco-maven-plugin
- ${jacoco.version}
-
-
-
- **/*Constants.class
- **/*Component.class
- **/*DataHolder.class
-
-
-
-
- default-prepare-agent
-
- prepare-agent
-
-
-
- default-prepare-agent-integration
-
- prepare-agent-integration
-
-
-
- default-report
-
- report
-
-
-
- default-report-integration
-
- report-integration
-
-
-
- default-check
-
- check
-
-
-
-
- BUNDLE
-
-
- INSTRUCTION
- COVEREDRATIO
- 0.73
-
-
-
-
-
-
-
-
-
- com.github.spotbugs
- spotbugs-maven-plugin
-
- Max
- Low
- true
- false
- ${project.build.directory}/spotbugs
- ${project.basedir}/findbugs-exclude.xml
-
-
-
- analyze-compile
- compile
-
- check
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- 1.8
- UTF-8
-
-
-
- org.apache.felix
- maven-bundle-plugin
- true
-
-
-
- ${project.artifactId}
-
-
- com.wso2.openbanking.accelerator.event.notifications.service.internal
-
-
- org.osgi.framework;version="${osgi.framework.imp.pkg.version.range}",
- org.osgi.service.component;version="${osgi.service.component.imp.pkg.version.range}",
- org.apache.commons.lang3;version="${commons-lang.version}"
-
-
- !com.wso2.openbanking.accelerator.account.metadata.service.internal,
- com.wso2.openbanking.accelerator.account.metadata.service.service.*;version="${project.version}",
- com.wso2.openbanking.accelerator.account.metadata.service.dao.*;version="${project.version}",
-\
-
- javax.ws.rs-api;scope=compile;inline=false,
-
- *
- <_dsannotations>*
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAO.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAO.java
deleted file mode 100644
index 3bf5ea3b..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAO.java
+++ /dev/null
@@ -1,128 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.dao;
-
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-
-import java.sql.Connection;
-import java.util.Map;
-
-/**
- * AccountMetadataDAO
- *
- * Contains the methods to store, retrieve and delete account
- * metadata in the database.
- */
-public interface AccountMetadataDAO {
-
- /**
- * Store account metadata.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param metadataKey - Metadata key
- * @param metadataValue - Metadata value
- * @return number of rows affected
- * @throws OpenBankingException - OpenBankingException
- */
- int storeAccountMetadata(Connection dbConnection, String accountId, String userId, String metadataKey,
- String metadataValue) throws OpenBankingException;
-
- /**
- * Store or update account metadata.
- * If the key already exists for the account-id and user-id combination, the value be updated.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param metadataKey - Metadata key
- * @param metadataValue - Metadata value
- * @return number of rows affected
- * @throws OpenBankingException - OpenBankingException
- */
- int updateAccountMetadata(Connection dbConnection, String accountId, String userId, String metadataKey,
- String metadataValue) throws OpenBankingException;
-
- /**
- * Retrieve account metadata for a given user-id and account-id combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @return Map of account metadata
- * @throws OpenBankingException - OpenBankingException
- */
- Map getAccountMetadataMap(Connection dbConnection, String accountId, String userId)
- throws OpenBankingException;
-
- /**
- * Retrieve account metadata for a given account-id and key combination.
- *
- * @param accountId - Account ID
- * @param key - Attribute key
- * @return Map of user-id and attribute value
- * @throws OpenBankingException - OpenBankingException
- */
- Map getMetadataForAccountIdAndKey(Connection dbConnection, String accountId, String key)
- throws OpenBankingException;
-
- /**
- * Retrieve the value for the given account-id, user-id and key combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param key - Key
- * @return Attribute value
- * @throws OpenBankingException - OpenBankingException
- */
- String getAccountMetadataByKey(Connection dbConnection, String accountId, String userId, String key)
- throws OpenBankingException;
-
- /**
- * Delete all account metadata for a given user-id and account-id combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @return number of rows affected
- * @throws OpenBankingException - OpenBankingException
- */
- int deleteAccountMetadata(Connection dbConnection, String accountId, String userId) throws OpenBankingException;
-
- /**
- * Delete account metadata for a given user-id, account-id and key combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param key - Key
- * @return number of rows affected
- * @throws OpenBankingException - OpenBankingException
- */
- int deleteAccountMetadataByKey(Connection dbConnection, String accountId, String userId, String key) throws
- OpenBankingException;
-
- /**
- * Delete all account metadata for a given account-id and key combination.
- *
- * @param accountId - Account ID
- * @param key - Key
- * @return number of rows affected
- * @throws OpenBankingException - OpenBankingException
- */
- int deleteAccountMetadataByKeyForAllUsers(Connection dbConnection, String accountId, String key) throws
- OpenBankingException;
-
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOImpl.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOImpl.java
deleted file mode 100644
index 1fe8c4e8..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOImpl.java
+++ /dev/null
@@ -1,493 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.dao;
-
-import com.wso2.openbanking.accelerator.account.metadata.service.dao.queries.AccountMetadataDBQueries;
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-import com.wso2.openbanking.accelerator.common.util.DatabaseUtil;
-import org.apache.commons.lang3.StringUtils;
-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.sql.Savepoint;
-import java.sql.Timestamp;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Implementation of AccountMetadataDAO.
- */
-public class AccountMetadataDAOImpl implements AccountMetadataDAO {
-
- private static final Log log = LogFactory.getLog(AccountMetadataDAOImpl.class);
- private static final String KEY = "METADATA_KEY";
- private static final String VALUE = "METADATA_VALUE";
- private static final String USER_ID = "USER_ID";
-
- //Error messages
- private static final String DB_CONNECTION_NULL_ERROR = "Database connection is null.";
- private static final String ACCOUNT_ID_USER_ID_MISSING_ERROR = "Account Id or User Id is not provided";
- private static final String ACCOUNT_METADATA_MISSING_ERROR = "Metadata key or Metadata value is not provided";
- private static final String ERROR_WHILE_DELETING_METADATA = "Error occurred while deleting account metadata.";
-
-
- AccountMetadataDBQueries sqlStatements;
-
- public AccountMetadataDAOImpl(AccountMetadataDBQueries sqlStatements) {
- this.sqlStatements = sqlStatements;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int storeAccountMetadata(Connection dbConnection, String accountId, String userId,
- String metadataKey, String metadataValue) throws OpenBankingException {
-
- int noOfRows;
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- }
- if (StringUtils.isBlank(metadataKey) || StringUtils.isBlank(metadataValue)) {
- log.error(ACCOUNT_METADATA_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_METADATA_MISSING_ERROR);
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
-
- try {
- String storeAttributeSqlStatement = sqlStatements.getStoreAccountMetadataPreparedStatement();
- Savepoint savepoint = dbConnection.setSavepoint();
- log.debug("Storing account metadata data in the database for account-id " + accountId + " and " +
- "user-id " + userId);
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(storeAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, userId);
- prepStmt.setString(3, metadataKey);
- prepStmt.setString(4, metadataValue);
- prepStmt.setTimestamp(5, new Timestamp(new Date().getTime()));
-
- if (log.isDebugEnabled()) {
- log.debug("Added data for the key " + metadataKey + " and value " + metadataValue +
- " to be inserted to the database.");
- }
- noOfRows = prepStmt.executeUpdate();
- if (noOfRows > 0) {
- if (log.isDebugEnabled()) {
- log.debug("The query affected " + noOfRows + " rows.");
- log.debug("Stored attributes for account-id" + accountId + " and user-id " + userId +
- " in the database.");
- }
- dbConnection.commit();
- } else {
- dbConnection.rollback(savepoint);
- log.error("Error occurred while inserting account metadata data. Any changes occurred " +
- "during the failed transaction are rolled back.");
- throw new OpenBankingException("Error occurred while inserting account metadata " +
- "data.");
- }
- } catch (SQLException e) {
- dbConnection.rollback(savepoint);
- log.error("Error occurred while inserting account metadata data.", e);
- throw new OpenBankingException("Error occurred while inserting account metadata " +
- "data.", e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while interacting with the database connection.", e);
- throw new OpenBankingException("Error occurred while interacting with the database connection", e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return noOfRows;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int updateAccountMetadata(Connection dbConnection, String accountId, String userId,
- String metadataKey, String metadataValue) throws OpenBankingException {
-
- int noOfRows;
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- }
- if (StringUtils.isBlank(metadataKey) || StringUtils.isBlank(metadataValue)) {
- log.error(ACCOUNT_METADATA_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_METADATA_MISSING_ERROR);
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
-
- try {
- String storeAttributeSqlStatement = sqlStatements.getUpdateAccountMetadataPreparedStatement();
- Savepoint savepoint = dbConnection.setSavepoint();
- log.debug("Storing account metadata data in the database for account-id " + accountId + " and " +
- "user-id " + userId);
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(storeAttributeSqlStatement)) {
- prepStmt.setString(1, metadataValue);
- prepStmt.setTimestamp(2, new Timestamp(new Date().getTime()));
- prepStmt.setString(3, accountId);
- prepStmt.setString(4, userId);
- prepStmt.setString(5, metadataKey);
- prepStmt.executeUpdate();
- if (log.isDebugEnabled()) {
- log.debug("Added data for the key " + metadataKey + " and value" + metadataValue +
- " to be updated in the database.");
- }
- noOfRows = prepStmt.executeUpdate();
- if (noOfRows > 0) {
- if (log.isDebugEnabled()) {
- log.debug("The query affected " + noOfRows + " rows.");
- log.debug("Updated attributes for account-id" + accountId + " and user-id " + userId +
- " in the database.");
- }
- } else {
- log.info("No rows were affected in the transaction. No change was made to existing account " +
- "metadata.");
- }
- dbConnection.commit();
- } catch (SQLException e) {
- dbConnection.rollback(savepoint);
- log.error("Error occurred while updating account metadata.", e);
- throw new OpenBankingException("Error occurred while inserting account metadata.", e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while interacting with the database connection.", e);
- throw new OpenBankingException("Error occurred while interacting with the database connection", e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return noOfRows;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map getAccountMetadataMap(Connection dbConnection, String accountId, String userId) throws
- OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- HashMap attributesMap = new HashMap<>();
- final String retrieveAttributeSqlStatement = sqlStatements.getRetrieveAccountMetadataPreparedStatement();
-
- if (log.isDebugEnabled()) {
- log.debug("Retrieving account metadata for account-id " + accountId + " and user-id " +
- userId);
- }
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(retrieveAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, userId);
- try (ResultSet rs = prepStmt.executeQuery()) {
- while (rs.next()) {
- attributesMap.put(rs.getString(KEY), rs.getString(VALUE));
- if (log.isDebugEnabled()) {
- log.debug("Added attribute with key " + rs.getString(KEY) + " and value " +
- rs.getString(VALUE) + "to the map.");
- }
- }
- } catch (SQLException e) {
- log.error("Error occurred while reading retrieved result set for account-id " + accountId +
- "and user-id " + userId, e);
- throw new OpenBankingException("Error occurred while reading retrieved result set for " +
- "account-id " + accountId + " and user-id " + userId, e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while retrieving account metadata from database for account-id " +
- accountId + " and user-id " + userId, e);
- throw new OpenBankingException("Error occurred while retrieving account metadata " +
- "from database for account-id " + accountId + " and user-id " + userId, e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return attributesMap;
- }
-
- @Override
- public Map getMetadataForAccountIdAndKey(Connection dbConnection, String accountId, String key)
- throws OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(key)) {
- log.error("AccountId or Key not found in the request");
- throw new OpenBankingException("AccountId and Key should be submitted in order to proceed.");
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- HashMap attributesMap = new HashMap<>();
- final String retrieveAttributeSqlStatement = sqlStatements.
- getRetrieveMetadataByAccountIdAndKeyPreparedStatement();
-
- if (log.isDebugEnabled()) {
- log.debug("Retrieving account metadata for account-id " + accountId + " and metadata-key " +
- key);
- }
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(retrieveAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, key);
- try (ResultSet rs = prepStmt.executeQuery()) {
- while (rs.next()) {
- attributesMap.put(rs.getString(USER_ID), rs.getString(VALUE));
- if (log.isDebugEnabled()) {
- log.debug("Added attribute with user-id " + rs.getString(USER_ID) + " and value " +
- rs.getString(VALUE) + "to the map.");
- }
- }
- } catch (SQLException e) {
- log.error("Error occurred while reading retrieved result set for account-id " + accountId +
- "and key " + key, e);
- throw new OpenBankingException("Error occurred while reading retrieved result set for " +
- "account-id " + accountId + " and key " + key, e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while retrieving account metadata from database for account-id " +
- accountId + " and key " + key, e);
- throw new OpenBankingException("Error occurred while retrieving account metadata " +
- "from database for account-id " + accountId + " and key " + key, e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return attributesMap;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getAccountMetadataByKey(Connection dbConnection, String accountId, String userId, String key) throws
- OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId) || StringUtils.isBlank(key)) {
- log.error("AccountId, UserId or Key not found in the request");
- throw new OpenBankingException("AccountId, UserId and Key should be submitted in order to " +
- "proceed.");
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- String attributeValue = null;
- final String retrieveAttributeSqlStatement = sqlStatements.
- getRetrieveAccountMetadataByKeyPreparedStatement();
-
- if (log.isDebugEnabled()) {
- log.debug("Retrieving account metadata for account-id " + accountId + " and user-id " + userId);
- }
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(retrieveAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, userId);
- prepStmt.setString(3, key);
- try (ResultSet rs = prepStmt.executeQuery()) {
- if (rs.next()) {
- attributeValue = rs.getString(VALUE);
- if (log.isDebugEnabled()) {
- log.debug("Retrieved attribute with key " + key + " and value " + attributeValue);
- }
- }
- dbConnection.commit();
- } catch (SQLException e) {
- log.error("Error occurred while reading retrieved result set for account-id " + accountId +
- " and user-id " + userId, e);
- throw new OpenBankingException("Error occurred while reading retrieved result set for " +
- "account-id " + accountId + " and user-id " + userId, e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while retrieving account metadata from database for account-id " +
- accountId + " and user-id " + userId, e);
- throw new OpenBankingException("Error occurred while retrieving account metadata " +
- "from database for account-id " + accountId + " and user-id " + userId, e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return attributeValue;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int deleteAccountMetadata(Connection dbConnection, String accountId, String userId)
- throws OpenBankingException {
-
- int noOfRows;
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- throw new OpenBankingException(ACCOUNT_ID_USER_ID_MISSING_ERROR);
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- try {
- String deleteAttributeSqlStatement = sqlStatements.getDeleteAccountMetadataPreparedStatement();
- dbConnection.setAutoCommit(false);
- Savepoint savepoint = dbConnection.setSavepoint();
-
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(deleteAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, userId);
- noOfRows = prepStmt.executeUpdate();
- if (noOfRows >= 0) {
- dbConnection.commit();
- if (log.isDebugEnabled()) {
- log.debug("Deleted " + noOfRows + " account metadata for account-id " + accountId +
- "and user-id " + userId);
- }
- } else {
- dbConnection.rollback(savepoint);
- log.error(ERROR_WHILE_DELETING_METADATA + "Any changes occurred " +
- "during the failed transaction are rolled back.");
- throw new OpenBankingException(ERROR_WHILE_DELETING_METADATA);
- }
- } catch (SQLException e) {
- dbConnection.rollback(savepoint);
- log.error(ERROR_WHILE_DELETING_METADATA, e);
- throw new OpenBankingException(ERROR_WHILE_DELETING_METADATA, e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while interacting with the database connection.", e);
- throw new OpenBankingException("Error occurred while interacting with the database connection", e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return noOfRows;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int deleteAccountMetadataByKey(Connection dbConnection, String accountId, String userId, String key) throws
- OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId) || StringUtils.isBlank(key)) {
- log.error("AccountId, UserId or Key not found in the request");
- throw new OpenBankingException("AccountId, UserId and Key should be submitted in order to " +
- "proceed.");
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- int noOfRows;
- try {
- String deleteAttributeSqlStatement = sqlStatements.getDeleteAccountMetadataByKeyPreparedStatement();
- Savepoint savepoint = dbConnection.setSavepoint();
-
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(deleteAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, userId);
- prepStmt.setString(3, key);
- noOfRows = prepStmt.executeUpdate();
- if (noOfRows >= 0) {
- dbConnection.commit();
- if (log.isDebugEnabled()) {
- log.debug("Deleted account metadata for account-id " + accountId + "and user-id " +
- userId + "for the key " + key);
- }
- } else {
- dbConnection.rollback(savepoint);
- log.error(ERROR_WHILE_DELETING_METADATA + "Any changes occurred " +
- "during the failed transaction are rolled back.");
- throw new OpenBankingException(ERROR_WHILE_DELETING_METADATA);
- }
- } catch (SQLException e) {
- dbConnection.rollback(savepoint);
- log.error("Error occurred while deleting account metadata data.", e);
- throw new OpenBankingException("Error occurred while deleting account metadata data.", e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while interacting with the database connection.", e);
- throw new OpenBankingException("Error occurred while interacting with the database connection", e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return noOfRows;
- }
-
- @Override
- public int deleteAccountMetadataByKeyForAllUsers(Connection dbConnection, String accountId, String key) throws
- OpenBankingException {
-
- int noOfRows;
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(key)) {
- log.error("AccountId or Key not found in the request");
- throw new OpenBankingException("AccountId and Key should be submitted in order to " +
- "proceed.");
- }
- if (dbConnection == null) {
- log.error(DB_CONNECTION_NULL_ERROR);
- throw new OpenBankingException(DB_CONNECTION_NULL_ERROR);
- }
- try {
- String deleteAttributeSqlStatement = sqlStatements.
- getDeleteAccountMetadataByKeyForAllUsersPreparedStatement();
- Savepoint savepoint = dbConnection.setSavepoint();
-
- try (PreparedStatement prepStmt = dbConnection.prepareStatement(deleteAttributeSqlStatement)) {
- prepStmt.setString(1, accountId);
- prepStmt.setString(2, key);
- noOfRows = prepStmt.executeUpdate();
- if (noOfRows >= 0) {
- dbConnection.commit();
- if (log.isDebugEnabled()) {
- log.debug("Deleted account metadata for account-id " + accountId + "for the key " + key);
- }
- } else {
- dbConnection.rollback(savepoint);
- log.error(ERROR_WHILE_DELETING_METADATA + "Any changes occurred " +
- "during the failed transaction are rolled back.");
- throw new OpenBankingException(ERROR_WHILE_DELETING_METADATA);
- }
- } catch (SQLException e) {
- dbConnection.rollback(savepoint);
- log.error("Error occurred while deleting account metadata data.", e);
- throw new OpenBankingException("Error occurred while deleting account metadata data.", e);
- }
- } catch (SQLException e) {
- log.error("Error occurred while interacting with the database connection.", e);
- throw new OpenBankingException("Error occurred while interacting with the database connection", e);
- } finally {
- DatabaseUtil.closeConnection(dbConnection);
- }
- return noOfRows;
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueries.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueries.java
deleted file mode 100644
index 56cde3ac..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueries.java
+++ /dev/null
@@ -1,83 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.dao.queries;
-
-/**
- * AccountMetadataDBQueries
- * Contains the queries used by the AccountMetadataDAOImpl.
- */
-public interface AccountMetadataDBQueries {
-
- /**
- * Returns the query to store account metadata.
- *
- * @return String
- */
- String getStoreAccountMetadataPreparedStatement();
-
- /**
- * Returns the query to update account metadata.
- *
- * @return String
- */
- String getUpdateAccountMetadataPreparedStatement();
-
- /**
- * Returns the query to retrieve account metadata.
- *
- * @return String
- */
- String getRetrieveAccountMetadataPreparedStatement();
-
- /**
- * Returns the query to retrieve user-ids and metadata values when
- * account-id and metadata-key is given.
- *
- * @return String
- */
- String getRetrieveMetadataByAccountIdAndKeyPreparedStatement();
-
- /**
- * Returns the query to retrieve the account metadata by key.
- *
- * @return String
- */
- String getRetrieveAccountMetadataByKeyPreparedStatement();
-
- /**
- * Returns the query to delete the account metadata.
- *
- * @return String
- */
- String getDeleteAccountMetadataPreparedStatement();
-
- /**
- * Returns the query to delete the account metadata by key.
- *
- * @return String
- */
- String getDeleteAccountMetadataByKeyPreparedStatement();
-
- /**
- * Returns the query to delete the account metadata by key for al users.
- *
- * @return String
- */
- String getDeleteAccountMetadataByKeyForAllUsersPreparedStatement();
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueriesMySQLImpl.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueriesMySQLImpl.java
deleted file mode 100644
index e82bef48..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/queries/AccountMetadataDBQueriesMySQLImpl.java
+++ /dev/null
@@ -1,99 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.dao.queries;
-
-/**
- * AccountMetadataDBQueriesMySQLImpl
- * Contains the MySQL queries used by the AccountMetadataDAOImpl.
- */
-public class AccountMetadataDBQueriesMySQLImpl implements AccountMetadataDBQueries {
-
- /**
- * {@inheritDoc}
- */
- public String getStoreAccountMetadataPreparedStatement() {
-
- return "INSERT INTO OB_ACCOUNT_METADATA (ACCOUNT_ID, USER_ID, METADATA_KEY, METADATA_VALUE, " +
- "LAST_UPDATED_TIMESTAMP) VALUES (?, ?, ?, ?, ?)";
- }
-
- /**
- * {@inheritDoc}
- */
- public String getUpdateAccountMetadataPreparedStatement() {
-
- return "UPDATE OB_ACCOUNT_METADATA SET METADATA_VALUE = ?, LAST_UPDATED_TIMESTAMP = ? WHERE ACCOUNT_ID = ? " +
- "AND USER_ID = ? AND METADATA_KEY = ?";
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRetrieveAccountMetadataPreparedStatement() {
-
- return "SELECT METADATA_KEY, METADATA_VALUE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND USER_ID = ?";
-
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRetrieveMetadataByAccountIdAndKeyPreparedStatement() {
-
- return "SELECT USER_ID, METADATA_VALUE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND METADATA_KEY = ?";
-
- }
-
- /**
- * {@inheritDoc}
- */
- public String getRetrieveAccountMetadataByKeyPreparedStatement() {
-
- return "SELECT METADATA_VALUE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND USER_ID = ? AND " +
- "METADATA_KEY = ?";
-
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDeleteAccountMetadataPreparedStatement() {
-
- return "DELETE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND USER_ID = ?";
-
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDeleteAccountMetadataByKeyPreparedStatement() {
-
- return "DELETE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND USER_ID = ? AND METADATA_KEY = ?";
-
- }
-
- /**
- * {@inheritDoc}
- */
- public String getDeleteAccountMetadataByKeyForAllUsersPreparedStatement() {
-
- return "DELETE FROM OB_ACCOUNT_METADATA WHERE ACCOUNT_ID = ? AND METADATA_KEY = ?";
-
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataDataHolder.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataDataHolder.java
deleted file mode 100644
index 5d25bd7a..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataDataHolder.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.internal;
-
-import org.wso2.carbon.user.core.service.RealmService;
-
-/**
- * AccountMetadata Data Holder.
- */
-public class AccountMetadataDataHolder {
-
- private static AccountMetadataDataHolder instance = new AccountMetadataDataHolder();
-
- private RealmService realmService;
-
- private AccountMetadataDataHolder() {
-
- }
-
- public static AccountMetadataDataHolder getInstance() {
-
- return instance;
- }
-
- public RealmService getRealmService() {
-
- if (realmService == null) {
- throw new RuntimeException("Realm Service is not available. Component did not start correctly.");
- }
- return realmService;
- }
-
- void setRealmService(RealmService realmService) {
-
- this.realmService = realmService;
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataServiceComponent.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataServiceComponent.java
deleted file mode 100644
index 9fe71917..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/internal/AccountMetadataServiceComponent.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.internal;
-
-import com.wso2.openbanking.accelerator.account.metadata.service.service.AccountMetadataService;
-import com.wso2.openbanking.accelerator.account.metadata.service.service.AccountMetadataServiceImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.osgi.service.component.ComponentContext;
-import org.osgi.service.component.annotations.Activate;
-import org.osgi.service.component.annotations.Component;
-import org.osgi.service.component.annotations.Deactivate;
-import org.osgi.service.component.annotations.Reference;
-import org.osgi.service.component.annotations.ReferenceCardinality;
-import org.osgi.service.component.annotations.ReferencePolicy;
-import org.wso2.carbon.context.PrivilegedCarbonContext;
-import org.wso2.carbon.user.core.service.RealmService;
-
-/**
- * AccountMetadataService component.
- */
-@Component(
- name = "open.banking.account.metadata.service.component",
- immediate = true
-)
-public class AccountMetadataServiceComponent {
-
- private static final Log log = LogFactory.getLog(AccountMetadataServiceComponent.class);
-
- public static RealmService getRealmService() {
- return (RealmService) PrivilegedCarbonContext.getThreadLocalCarbonContext()
- .getOSGiService(RealmService.class);
- }
-
- @Reference(
- name = "realm.service",
- service = RealmService.class,
- cardinality = ReferenceCardinality.MANDATORY,
- policy = ReferencePolicy.DYNAMIC,
- unbind = "unsetRealmService"
- )
- protected void setRealmService(RealmService realmService) {
-
- log.debug("Setting the Realm Service");
- AccountMetadataDataHolder.getInstance().setRealmService(realmService);
- }
-
- @Activate
- protected void activate(ComponentContext ctxt) {
-
- try {
- AccountMetadataService accountMetadataService = AccountMetadataServiceImpl.getInstance();
- ctxt.getBundleContext().registerService(AccountMetadataServiceImpl.class.getName(),
- accountMetadataService, null);
- log.debug("AccountMetadataService bundle is activated");
-
- } catch (Throwable e) {
- log.error("AccountMetadataService bundle activation Failed", e);
- }
- }
-
- @Deactivate
- protected void deactivate(ComponentContext ctxt) {
-
- log.debug("AccountMetadataService bundle is deactivated");
- }
-
- protected void unsetRealmService(RealmService realmService) {
-
- log.debug("UnSetting the Realm Service");
- AccountMetadataDataHolder.getInstance().setRealmService(null);
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataService.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataService.java
deleted file mode 100644
index 2350e26b..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataService.java
+++ /dev/null
@@ -1,190 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.service;
-
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-
-import java.util.Map;
-
-/**
- * Account Metadata Service.
- *
- * Handles the calls for persisting and retrieving metadata related to accounts.
- */
-public interface AccountMetadataService {
-
-
- /**
- * Add or update multiple account metadata.
- * If the key already exists for the account-id and user-id combination, the value be updated.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param accountMetadataMap - Map containing metadata key and value pairs
- * @return number of records inserted/updated
- * @throws OpenBankingException - OpenBankingException
- */
- int addOrUpdateAccountMetadata(String accountId, String userId, Map accountMetadataMap) throws
- OpenBankingException;
-
- /**
- * Add or update multiple account metadata for account-id where the user id is N/A.
- * If the key already exists for the account-id, the value be updated.
- *
- * @param accountId - Account ID
- * @param accountMetadataMap - Map containing metadata key and value pairs
- * @return number of records inserted/updated
- * @throws OpenBankingException - OpenBankingException
- */
- int addOrUpdateAccountMetadata(String accountId, Map accountMetadataMap) throws
- OpenBankingException;
-
- /**
- * Add or update account metadata.
- * If the key already exists for the account-id and user-id combination, the value be updated.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param metadataKey - Metadata Key
- * @param metadataValue - Metadata Value
- * @return number of records inserted/updated
- * @throws OpenBankingException - OpenBankingException
- */
- int addOrUpdateAccountMetadata(String accountId, String userId, String metadataKey, String metadataValue) throws
- OpenBankingException;
-
- /**
- * Add or update metadata for account-id where the user id is N/A.
- * If the key already exists for the account-id, the value be updated.
- *
- * @param accountId - Account ID
- * @param metadataKey - Metadata Key
- * @param metadataValue - Metadata Value
- * @return number of records updated
- * @throws OpenBankingException - OpenBankingException
- */
- int addOrUpdateAccountMetadata(String accountId, String metadataKey, String metadataValue) throws
- OpenBankingException;
-
- /**
- * Get all metadata for an account-id user-id combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @return Map of account metadata
- * @throws OpenBankingException - OpenBankingException
- */
- Map getAccountMetadataMap(String accountId, String userId) throws
- OpenBankingException;
-
- /**
- * Get all metadata affecting the account-id regardless of the user-id.
- *
- * @param accountId - Account ID
- * @return Map of account metadata
- * @throws OpenBankingException - OpenBankingException
- */
- Map getAccountMetadataMap(String accountId) throws OpenBankingException;
-
- /**
- * Get users and metadata values for an account-id and key combination.
- *
- * @param accountId - Account ID
- * @param key - Metadata key
- * @return Map of users and metadata values
- * @throws OpenBankingException - OpenBankingException
- */
- Map getUserMetadataForAccountIdAndKey(String accountId, String key) throws
- OpenBankingException;
-
- /**
- * Get metadata value for an account-id user-id and key combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param key - Metadata key
- * @return Metadata value
- * @throws OpenBankingException - OpenBankingException
- */
- String getAccountMetadataByKey(String accountId, String userId, String key) throws
- OpenBankingException;
-
- /**
- * Given the key, get metadata value of the account-id where the user-id is N/A.
- *
- * @param accountId - Account ID
- * @param key - Metadata key
- * @return Metadata value
- * @throws OpenBankingException - OpenBankingException
- */
- String getAccountMetadataByKey(String accountId, String key) throws OpenBankingException;
-
- /**
- * Remove all metadata for an account-id user-id combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @return number of affected rows
- * @throws OpenBankingException - OpenBankingException
- */
- int removeAccountMetadata(String accountId, String userId) throws OpenBankingException;
-
- /**
- * Remove all metadata for an account-id where the user-id is N/A.
- *
- * @param accountId - Account ID
- * @return number of affected rows
- * @throws OpenBankingException - OpenBankingException
- */
- int removeAccountMetadata(String accountId) throws OpenBankingException;
-
- /**
- * Remove metadata for an account-id user-id and key combination.
- *
- * @param accountId - Account ID
- * @param userId - User ID
- * @param key - Metadata key
- * @return number of affected rows
- * @throws OpenBankingException - OpenBankingException
- */
- int removeAccountMetadataByKey(String accountId, String userId, String key) throws
- OpenBankingException;
-
- /**
- * Remove metadata for an account-id and key combination for all user-ids.
- *
- * @param accountId - Account ID
- * @param key - Metadata key
- * @return number of affected rows
- * @throws OpenBankingException - OpenBankingException
- */
- int removeAccountMetadataByKeyForAllUsers(String accountId, String key) throws
- OpenBankingException;
-
- /**
- * Given the key, remove metadata affecting the account-id where the user-id is N/A.
- *
- * @param accountId - Account ID
- * @param key - Metadata key
- * @return number of affected rows
- * @throws OpenBankingException - OpenBankingException
- */
- int removeAccountMetadataByKey(String accountId, String key) throws OpenBankingException;
-
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceImpl.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceImpl.java
deleted file mode 100644
index 72db3fe5..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/main/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceImpl.java
+++ /dev/null
@@ -1,240 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.service;
-
-import com.wso2.openbanking.accelerator.account.metadata.service.dao.AccountMetadataDAO;
-import com.wso2.openbanking.accelerator.account.metadata.service.dao.AccountMetadataDAOImpl;
-import com.wso2.openbanking.accelerator.account.metadata.service.dao.queries.AccountMetadataDBQueriesMySQLImpl;
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-import com.wso2.openbanking.accelerator.common.util.DatabaseUtil;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.sql.Connection;
-import java.util.Map;
-
-/**
- * Implementation of AccountMetadataService.
- */
-public class AccountMetadataServiceImpl implements AccountMetadataService {
-
- private static final Log log = LogFactory.getLog(AccountMetadataServiceImpl.class);
- private static final String NOT_APPLICABLE = "N/A";
- private static AccountMetadataServiceImpl instance = null;
- AccountMetadataDAO accountMetadataDAO = new AccountMetadataDAOImpl(
- new AccountMetadataDBQueriesMySQLImpl());
-
- // private constructor
- private AccountMetadataServiceImpl() {
- }
-
- /**
- * @return AccountMetadataServiceImpl instance
- */
- public static synchronized AccountMetadataServiceImpl getInstance() {
-
- if (instance == null) {
- instance = new AccountMetadataServiceImpl();
- }
- return instance;
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int addOrUpdateAccountMetadata(String accountId, String userId, Map accountMetadataMap)
- throws OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error("Account Id or User Id is not provided.");
- throw new OpenBankingException("Account Id or User Id is not provided.");
- }
- if (accountMetadataMap == null || accountMetadataMap.isEmpty()) {
- log.error("Account metadata is not present.");
- throw new OpenBankingException("Account metadata is not present");
- }
- int noOfRecords = 0;
- // Add all entries in the accountMetadataMap to the database
- for (Map.Entry accountMetadata : accountMetadataMap.entrySet()) {
- addOrUpdateAccountMetadata(accountId, userId, accountMetadata.getKey(), accountMetadata.getValue());
- noOfRecords++;
- }
- return noOfRecords;
- }
-
- @Override
- public int addOrUpdateAccountMetadata(String accountId, Map accountMetadataMap)
- throws OpenBankingException {
- return addOrUpdateAccountMetadata(accountId, NOT_APPLICABLE, accountMetadataMap);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int addOrUpdateAccountMetadata(String accountId, String userId, String metadataKey, String metadataValue)
- throws OpenBankingException {
-
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error("Account Id or User Id is not provided.");
- throw new OpenBankingException("Account Id or User Id is not provided.");
- }
- if (StringUtils.isBlank(metadataKey) || StringUtils.isBlank(metadataValue)) {
- log.error("Account metadata is not present.");
- throw new OpenBankingException("Account metadata is not present");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- // Check if the record is already present in the database.
- if (getAccountMetadataByKey(accountId, userId, metadataKey) == null) {
- // Add the record
- return accountMetadataDAO.storeAccountMetadata(dbConnection, accountId, userId, metadataKey, metadataValue);
- } else {
- // Update the record
- return accountMetadataDAO.updateAccountMetadata(dbConnection, accountId, userId, metadataKey,
- metadataValue);
- }
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int addOrUpdateAccountMetadata(String accountId, String metadataKey, String metadataValue)
- throws OpenBankingException {
- return addOrUpdateAccountMetadata(accountId, NOT_APPLICABLE, metadataKey, metadataValue);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map getAccountMetadataMap(String accountId, String userId)
- throws OpenBankingException {
- if (StringUtils.isBlank(userId) || StringUtils.isBlank(accountId)) {
- log.error("Account Id or User Id is not provided.");
- throw new OpenBankingException("Account Id or User Id is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.getAccountMetadataMap(dbConnection, accountId, userId);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map getAccountMetadataMap(String accountId) throws OpenBankingException {
- return getAccountMetadataMap(accountId, NOT_APPLICABLE);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public Map getUserMetadataForAccountIdAndKey(String accountId, String key)
- throws OpenBankingException {
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(key)) {
- log.error("Account Id or Key is not provided.");
- throw new OpenBankingException("Account Id or Key is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.getMetadataForAccountIdAndKey(dbConnection, accountId, key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getAccountMetadataByKey(String accountId, String userId, String key)
- throws OpenBankingException {
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId) || StringUtils.isBlank(key)) {
- log.error("Account Id, User Id or Key is not provided.");
- throw new OpenBankingException("Account Id, User Id or Key is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.getAccountMetadataByKey(dbConnection, accountId, userId, key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public String getAccountMetadataByKey(String accountId, String key) throws OpenBankingException {
- return getAccountMetadataByKey(accountId, NOT_APPLICABLE, key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int removeAccountMetadata(String accountId, String userId) throws OpenBankingException {
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId)) {
- log.error("Account Id or User Id is not provided.");
- throw new OpenBankingException("Account Id or User Id is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.deleteAccountMetadata(dbConnection, accountId, userId);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int removeAccountMetadata(String accountId) throws OpenBankingException {
- return removeAccountMetadata(accountId, NOT_APPLICABLE);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int removeAccountMetadataByKey(String accountId, String userId, String key) throws
- OpenBankingException {
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(userId) || StringUtils.isBlank(key)) {
- log.error("Account Id, User Id or Key is not provided.");
- throw new OpenBankingException("Account Id, User Id or Key is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.deleteAccountMetadataByKey(dbConnection, accountId, userId, key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int removeAccountMetadataByKeyForAllUsers(String accountId, String key) throws
- OpenBankingException {
- if (StringUtils.isBlank(accountId) || StringUtils.isBlank(key)) {
- log.error("Account Id or Key is not provided.");
- throw new OpenBankingException("Account Id or Key is not provided.");
- }
- Connection dbConnection = DatabaseUtil.getDBConnection();
- return accountMetadataDAO.deleteAccountMetadataByKeyForAllUsers(dbConnection, accountId, key);
- }
-
- /**
- * {@inheritDoc}
- */
- @Override
- public int removeAccountMetadataByKey(String accountId, String key) throws OpenBankingException {
- return removeAccountMetadataByKey(accountId, NOT_APPLICABLE, key);
- }
-
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOTests.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOTests.java
deleted file mode 100644
index a4a0d2e8..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/dao/AccountMetadataDAOTests.java
+++ /dev/null
@@ -1,315 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.dao;
-
-import com.wso2.openbanking.accelerator.account.metadata.service.dao.queries.AccountMetadataDBQueriesMySQLImpl;
-import com.wso2.openbanking.accelerator.account.metadata.service.util.AccountMetadataDAOTestData;
-import com.wso2.openbanking.accelerator.account.metadata.service.util.DAOUtils;
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import java.sql.Connection;
-import java.util.Map;
-
-/**
- * Implementation of AccountMetadataDAOTests class.
- */
-public class AccountMetadataDAOTests {
-
- private static final String DB_NAME = "OPENBANKING_DB";
- private AccountMetadataDAO accountMetadataDAO;
-
- @BeforeClass
- public void initTest() throws Exception {
-
- DAOUtils.initializeDataSource(DB_NAME, DAOUtils.getFilePath("dbScripts/h2.sql"));
- accountMetadataDAO = new AccountMetadataDAOImpl(new AccountMetadataDBQueriesMySQLImpl());
- }
-
- @DataProvider(name = "accountMetadataDataProvider")
- public Object[][] accountMetadataData() {
- return AccountMetadataDAOTestData.DataProviders.METADATA_DATA_HOLDER;
- }
-
- @DataProvider(name = "getAccountMetadataDataProvider")
- public Object[][] getAccountMetadataData() {
- return AccountMetadataDAOTestData.DataProviders.GET_METADATA_DATA_HOLDER;
- }
-
- @Test
- public void testStoreAccountMetadata() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- Map metadataMap = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ATTRIBUTES_MAP;
- int affectedRows = 0;
-
- for (Map.Entry entry : metadataMap.entrySet()) {
- String metadataKey = entry.getKey();
- String metadataValue = entry.getValue();
- Connection dbConnection = DAOUtils.getConnection(DB_NAME);
- affectedRows += accountMetadataDAO.storeAccountMetadata(dbConnection, accountId, userId, metadataKey,
- metadataValue);
-
- }
- Assert.assertEquals(affectedRows, 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testStoreAccountMetadataNullAccountIdAndUserIdError() throws Exception {
-
- String key = AccountMetadataDAOTestData.SAMPLE_KEY;
- String value = AccountMetadataDAOTestData.SAMPLE_VALUE;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.storeAccountMetadata(dbConnection, null, null, key, value);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testStoreAccountMetadataEmptyMetadataMapError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.storeAccountMetadata(dbConnection, accountId, userId, "", "");
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testStoreAccountMetadataNullMetadataMapError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.storeAccountMetadata(dbConnection, accountId, userId, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testStoreAccountMetadataNullDBConnectionError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- String key = AccountMetadataDAOTestData.SAMPLE_KEY;
- String value = AccountMetadataDAOTestData.SAMPLE_VALUE;
- accountMetadataDAO.storeAccountMetadata(null, accountId, userId, key, value);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testUpdateAccountMetadataNullAccountIdAndUserIdError() throws Exception {
-
- String key = AccountMetadataDAOTestData.SAMPLE_KEY;
- String value = AccountMetadataDAOTestData.SAMPLE_VALUE;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.updateAccountMetadata(dbConnection, null, null, key, value);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testUpdateAccountMetadataEmptyMetadataMapError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.updateAccountMetadata(dbConnection, accountId, userId, "", "");
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testUpdateAccountMetadataNullMetadataMapError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.updateAccountMetadata(dbConnection, accountId, userId, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testUpdateAccountMetadataNullDBConnectionError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- String key = AccountMetadataDAOTestData.SAMPLE_KEY;
- String value = AccountMetadataDAOTestData.SAMPLE_VALUE;
- accountMetadataDAO.updateAccountMetadata(null, accountId, userId, key, value);
- }
-
- @Test(dataProvider = "getAccountMetadataDataProvider", dependsOnMethods = {"testStoreAccountMetadata"},
- priority = 1)
- public void testGetAccountMetadata(String accountId, String userId) throws Exception {
-
- Map metadataMap;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- metadataMap = accountMetadataDAO.getAccountMetadataMap(dbConnection, accountId, userId);
- }
- Assert.assertEquals(metadataMap.size(), 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testGetAccountMetadataNullAccountIdAndUserIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.getAccountMetadataMap(dbConnection, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "getAccountMetadataDataProvider",
- dependsOnMethods = {"testStoreAccountMetadata"},
- priority = 1)
- public void testGetAccountMetadataNullDBConnectionError(String accountId, String userId) throws Exception {
- accountMetadataDAO.getAccountMetadataMap(null, accountId, userId);
- }
-
- @Test(dataProvider = "accountMetadataDataProvider", dependsOnMethods = {"testStoreAccountMetadata"},
- priority = 1)
- public void testGetAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- String metadataValue;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- metadataValue = accountMetadataDAO.getAccountMetadataByKey(dbConnection, accountId, userId, key);
- }
- Assert.assertEquals(metadataValue, value);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testGetAccountMetadataByKeyNullAccountIdUserIdAndKeyError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.getAccountMetadataByKey(dbConnection, null, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testGetAccountMetadataByKeyNullDBConnectionError(String accountId, String userId, String key,
- String value) throws Exception {
- accountMetadataDAO.getAccountMetadataByKey(null, accountId, userId, key);
- }
-
- @Test(dataProvider = "accountMetadataDataProvider", dependsOnMethods = {"testStoreAccountMetadata"},
- priority = 2)
- public void testDeleteAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- int affectedRows;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- affectedRows = accountMetadataDAO.deleteAccountMetadataByKey(dbConnection, accountId, userId, key);
- }
- Assert.assertEquals(affectedRows, 1);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataByKeyNullAccountIdUserIdAndKeyError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.deleteAccountMetadataByKey(dbConnection, null, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testDeleteAccountMetadataByKeyNullDBConnectionError(String accountId, String userId, String key,
- String value) throws Exception {
-
- accountMetadataDAO.deleteAccountMetadataByKey(null, accountId, userId, key);
- }
-
- @Test(dependsOnMethods = {"testStoreAccountMetadata", "testDeleteAccountMetadataByKey"}, priority = 2)
- public void testDeleteAccountMetadata() throws Exception {
-
- int affectedRows;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- affectedRows = accountMetadataDAO.deleteAccountMetadata(dbConnection, accountId, userId);
- }
- Assert.assertEquals(affectedRows, 3);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataNullAccountIdAndUserIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.deleteAccountMetadata(dbConnection, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataNullDBConnection() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- accountMetadataDAO.deleteAccountMetadata(null, accountId, userId);
- }
-
- @Test
- public void testStoreAccountMetadataForSameAccount() throws Exception {
- int affectedRows = 0;
- Map userAttributeAMp = AccountMetadataDAOTestData.SAMPLE_USER_ID_ATTRIBUTE_VALUE_MAP;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String attributeKey = AccountMetadataDAOTestData.SAMPLE_KEY;
-
- for (Map.Entry entry : userAttributeAMp.entrySet()) {
- Connection dbConnection = DAOUtils.getConnection(DB_NAME);
- String userId = entry.getKey();
- String attributeValue = entry.getValue();
- affectedRows += accountMetadataDAO.storeAccountMetadata(dbConnection, accountId, userId, attributeKey,
- attributeValue);
- }
- Assert.assertEquals(affectedRows, 4);
- }
-
- @Test(dependsOnMethods = {"testStoreAccountMetadataForSameAccount"}, priority = 2)
- public void testDeleteAccountMetadataByKeyForAllUsers() throws Exception {
-
- int affectedRows;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String key = AccountMetadataDAOTestData.SAMPLE_KEY;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- affectedRows = accountMetadataDAO.deleteAccountMetadataByKeyForAllUsers(dbConnection, accountId, key);
- }
- Assert.assertEquals(affectedRows, 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataByKeyForAllUsersNullAccountIdAndKeyError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- accountMetadataDAO.deleteAccountMetadataByKeyForAllUsers(dbConnection, null, null);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataByKeyForAllUsersNullDBConnection() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- accountMetadataDAO.deleteAccountMetadataByKeyForAllUsers(null, accountId, userId);
- }
-
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceTests.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceTests.java
deleted file mode 100644
index 330664d7..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/service/AccountMetadataServiceTests.java
+++ /dev/null
@@ -1,610 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.service;
-
-import com.wso2.openbanking.accelerator.account.metadata.service.util.AccountMetadataDAOTestData;
-import com.wso2.openbanking.accelerator.account.metadata.service.util.DAOUtils;
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-import com.wso2.openbanking.accelerator.common.util.DatabaseUtil;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.testng.PowerMockTestCase;
-import org.testng.Assert;
-import org.testng.annotations.BeforeClass;
-import org.testng.annotations.DataProvider;
-import org.testng.annotations.Test;
-
-import java.sql.Connection;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Implementation of AccountMetadataServiceTests class.
- */
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({DatabaseUtil.class})
-public class AccountMetadataServiceTests extends PowerMockTestCase {
-
- private static final String DB_NAME = "OPENBANKING_DB";
- private AccountMetadataService accountMetadataService;
-
- @BeforeClass
- public void initTest() throws Exception {
- DAOUtils.initializeDataSource(DB_NAME, DAOUtils.getFilePath("dbScripts/h2.sql"));
- accountMetadataService = AccountMetadataServiceImpl.getInstance();
- }
-
- @DataProvider(name = "accountMetadataDataProvider")
- public Object[][] accountMetadataData() {
- return AccountMetadataDAOTestData.DataProviders.METADATA_DATA_HOLDER;
- }
-
- @DataProvider(name = "globalAccountMetadataDataProvider")
- public Object[][] globalAccountMetadataData() {
- return AccountMetadataDAOTestData.DataProviders.GLOBAL_METADATA_DATA_HOLDER;
- }
-
- @DataProvider(name = "getAccountMetadataDataProvider")
- public Object[][] getAccountMetadataData() {
- return AccountMetadataDAOTestData.DataProviders.GET_METADATA_DATA_HOLDER;
- }
-
- @Test
- public void testAddOrUpdateAccountMetadata() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- Map metadataMap = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ATTRIBUTES_MAP;
- int noOfEntries;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- noOfEntries = accountMetadataService.addOrUpdateAccountMetadata(accountId, userId, metadataMap);
-
- }
- Assert.assertEquals(noOfEntries, 4);
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateAccountMetadata"}, priority = 1)
- public void testUpdateExistingAccountMetadata() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- String updateMetadataKey = "secondary-account-privilege";
- String updateMetadataValue = "active";
- int noOfEntries;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- noOfEntries = accountMetadataService.addOrUpdateAccountMetadata(accountId, userId, updateMetadataKey,
- updateMetadataValue);
-
- }
- Assert.assertEquals(noOfEntries, 1);
- }
-
- @Test
- public void testAddOrUpdateAccountMetadataForSameAccount() throws Exception {
- int noOfEntries = 0;
- Map userAttributeAMp = AccountMetadataDAOTestData.SAMPLE_USER_ID_ATTRIBUTE_VALUE_MAP;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String attributeKey = AccountMetadataDAOTestData.SAMPLE_KEY;
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- for (Map.Entry entry : userAttributeAMp.entrySet()) {
- String userId = entry.getKey();
- String attributeValue = entry.getValue();
- Map metadataMap = Collections.singletonMap(attributeKey, attributeValue);
- noOfEntries += accountMetadataService.addOrUpdateAccountMetadata(accountId, userId,
- metadataMap);
- }
- }
- Assert.assertEquals(noOfEntries, 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateAccountMetadataNullAccountIdError() throws Exception {
-
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- Map metadataMap = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ATTRIBUTES_MAP;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(null, userId, metadataMap);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateAccountMetadataNullMetadataError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(accountId, userId, "");
-
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateAccountMetadataEmptyMetadataError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(accountId, userId, new HashMap<>());
-
- }
- }
-
- @Test
- public void testAddOrUpdateGlobalAccountMetadataMap() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- Map metadataMap = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ATTRIBUTES_MAP;
- int noOfEntries;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- noOfEntries = accountMetadataService.addOrUpdateAccountMetadata(accountId, metadataMap);
-
- }
- Assert.assertEquals(noOfEntries, 4);
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateGlobalAccountMetadataMap"})
- public void testUpdateGlobalAccountMetadata() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String updateMetadataKey = "secondary-account-privilege";
- String updateMetadataValue = "active"; int noOfEntries;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- noOfEntries = accountMetadataService.addOrUpdateAccountMetadata(accountId, updateMetadataKey,
- updateMetadataValue);
-
- }
- Assert.assertEquals(noOfEntries, 1);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateGlobalAccountMetadataNullAccountIdError() throws Exception {
-
- Map metadataMap = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ATTRIBUTES_MAP;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(null, metadataMap);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateGlobalAccountMetadataNullMetadataError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(accountId, null);
-
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testAddOrUpdateGlobalAccountMetadataEmptyMetadataError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.addOrUpdateAccountMetadata(accountId, new HashMap<>());
-
- }
- }
-
- @Test(dataProvider = "getAccountMetadataDataProvider", dependsOnMethods = {"testAddOrUpdateAccountMetadata"},
- priority = 1)
- public void testGetAccountMetadataMap(String accountId, String userId) throws Exception {
-
- Map metadataMap;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- metadataMap = accountMetadataService.getAccountMetadataMap(accountId, userId);
-
- }
- Assert.assertEquals(metadataMap.size(), 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "getAccountMetadataDataProvider")
- public void testGetAccountMetadataMapNullAccountIdError(String accountId, String userId) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataMap(null, userId);
-
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "getAccountMetadataDataProvider")
- public void testGetAccountMetadataMapNullUserIdError(String accountId, String userId) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataMap(accountId, null);
-
- }
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateGlobalAccountMetadataMap"}, priority = 1)
- public void testGetGlobalAccountMetadataMap() throws Exception {
-
- Map metadataMap;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- metadataMap = accountMetadataService.getAccountMetadataMap(accountId);
-
- }
- Assert.assertEquals(metadataMap.size(), 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testGetGlobalAccountMetadataMapNullAccountIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataMap(null);
-
- }
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateAccountMetadataForSameAccount"}, priority = 1)
- public void testGetUserAttributesForAccountIdAndKey() throws Exception {
-
- Map metadataMap;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String attributeKey = AccountMetadataDAOTestData.SAMPLE_KEY;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- metadataMap = accountMetadataService.getUserMetadataForAccountIdAndKey(accountId, attributeKey);
-
- }
- Assert.assertEquals(metadataMap.size(), 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testGetUserAttributesForAccountIdAndKeyNullAccountIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getUserMetadataForAccountIdAndKey(null,
- AccountMetadataDAOTestData.SAMPLE_KEY);
-
- }
- }
-
- @Test(dataProvider = "accountMetadataDataProvider", dependsOnMethods = {"testAddOrUpdateAccountMetadata"},
- priority = 1)
- public void testGetAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- String metadataValue;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- metadataValue = accountMetadataService.getAccountMetadataByKey(accountId, userId, key);
- }
- Assert.assertEquals(metadataValue, value);
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testGetAccountMetadataByKeyNullAccountIdError(String accountId, String userId, String key, String value)
- throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataByKey(null, userId, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testGetAccountMetadataByKeyNullUserIdError(String accountId, String userId, String key, String value)
- throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataByKey(accountId, null, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testGetAccountMetadataByKeyNullKeyError(String accountId, String userId, String key, String value)
- throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataByKey(accountId, userId, null);
- }
- }
-
- @Test(dataProvider = "globalAccountMetadataDataProvider", dependsOnMethods =
- {"testAddOrUpdateGlobalAccountMetadataMap"},
- priority = 1)
- public void testGetGlobalAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- String metadataValue;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- metadataValue = accountMetadataService.getAccountMetadataByKey(accountId, key);
- }
- Assert.assertEquals(metadataValue, value);
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "globalAccountMetadataDataProvider")
- public void testGetGlobalAccountMetadataByKeyNullAccountIdError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataByKey(null, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "globalAccountMetadataDataProvider")
- public void testGetGlobalAccountMetadataByKeyNullKeyError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.getAccountMetadataByKey(accountId, null);
- }
- }
-
- @Test(dataProvider = "accountMetadataDataProvider", dependsOnMethods = {"testAddOrUpdateAccountMetadata"},
- priority = 2)
- public void testDeleteAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- int affectedRows;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- affectedRows = accountMetadataService.removeAccountMetadataByKey(accountId, userId, key);
- }
- Assert.assertEquals(affectedRows, 1);
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testDeleteAccountMetadataByKeyNullAccountIdError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKey(null, userId, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testDeleteAccountMetadataByKeyNullUserIdError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKey(accountId, null, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "accountMetadataDataProvider")
- public void testDeleteAccountMetadataByKeyNullKeyError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKey(accountId, userId, null);
- }
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateAccountMetadata", "testDeleteAccountMetadataByKey"}, priority = 2)
- public void testDeleteAccountMetadata()
- throws Exception {
-
- int affectedRows;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- affectedRows = accountMetadataService.removeAccountMetadata(accountId, userId);
- }
- Assert.assertEquals(affectedRows, 3);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataNullAccountIdError() throws Exception {
-
- String userId = AccountMetadataDAOTestData.SAMPLE_USER_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadata(null, userId);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataNullUserIdError() throws Exception {
-
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadata(accountId, null);
- }
- }
-
- @Test(dataProvider = "globalAccountMetadataDataProvider", dependsOnMethods =
- {"testAddOrUpdateGlobalAccountMetadataMap"},
- priority = 2)
- public void testDeleteGlobalAccountMetadataByKey(String accountId, String userId, String key, String value)
- throws Exception {
-
- int affectedRows;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- affectedRows = accountMetadataService.removeAccountMetadataByKey(accountId, key);
- }
- Assert.assertEquals(affectedRows, 1);
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "globalAccountMetadataDataProvider")
- public void testDeleteGlobalAccountMetadataByKeyNullAccountIdError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKey(null, key);
- }
- }
-
- @Test(expectedExceptions = OpenBankingException.class, dataProvider = "globalAccountMetadataDataProvider")
- public void testDeleteGlobalAccountMetadataByKeyNullKeyError(String accountId, String userId, String key,
- String value) throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKey(accountId, null);
- }
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateGlobalAccountMetadataMap", "testDeleteGlobalAccountMetadataByKey"},
- priority = 2)
- public void testDeleteGlobalAccountMetadata()
- throws Exception {
-
- int affectedRows;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- affectedRows = accountMetadataService.removeAccountMetadata(accountId);
- }
- Assert.assertEquals(affectedRows, 3);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteGlobalAccountMetadataNullAccountIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadata(null);
- }
- }
-
- @Test(dependsOnMethods = {"testAddOrUpdateAccountMetadataForSameAccount"}, priority = 2)
- public void testDeleteAccountMetadataByKeyForAllUsers() throws Exception {
-
- int affectedRows;
- String accountId = AccountMetadataDAOTestData.SAMPLE_ACCOUNT_ID;
- String attributeKey = AccountMetadataDAOTestData.SAMPLE_KEY;
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- affectedRows = accountMetadataService.removeAccountMetadataByKeyForAllUsers(accountId, attributeKey);
- }
- Assert.assertEquals(affectedRows, 4);
- }
-
- @Test(expectedExceptions = OpenBankingException.class)
- public void testDeleteAccountMetadataByKeyForAllUsersNullUserIdError() throws Exception {
-
- try (Connection dbConnection = DAOUtils.getConnection(DB_NAME)) {
- PowerMockito.mockStatic(DatabaseUtil.class);
- PowerMockito.when(DatabaseUtil.getDBConnection())
- .thenReturn(dbConnection);
- accountMetadataService.removeAccountMetadataByKeyForAllUsers(null,
- AccountMetadataDAOTestData.SAMPLE_KEY);
- }
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/AccountMetadataDAOTestData.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/AccountMetadataDAOTestData.java
deleted file mode 100644
index fa79385e..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/AccountMetadataDAOTestData.java
+++ /dev/null
@@ -1,86 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.util;
-
-
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Implementation of AccountMetadataDAOTestData class.
- */
-public class AccountMetadataDAOTestData {
-
- public static final String SAMPLE_ACCOUNT_ID = "account-1";
- public static final String SAMPLE_USER_ID = "ann@gold.com";
- public static final String SAMPLE_KEY = "bnr-permission";
- public static final String SAMPLE_VALUE = "active";
- public static final String GLOBAL = "GLOBAL";
-
- public static final Map SAMPLE_ACCOUNT_ATTRIBUTES_MAP = new HashMap() {
- {
- put("disclosure-option", "pre-approved");
- put("other-accounts-availability", "true");
- put("secondary-account-instruction", "active");
- put("secondary-account-privilege", "inactive");
- }
- };
-
- public static final Map SAMPLE_USER_ID_ATTRIBUTE_VALUE_MAP = new HashMap() {
- {
- put("sample_user_id_1", "active");
- put("sample_user_id_2", "inactive");
- put("sample_user_id_3", "active");
- put("sample_user_id_4", "inactive");
- }
- };
-
- /**
- * Implementation of AccountMetadataServiceTests class.
- */
- public static final class DataProviders {
-
- public static final Object[][] METADATA_DATA_HOLDER = new Object[][]{
-
- {
- SAMPLE_ACCOUNT_ID,
- SAMPLE_USER_ID,
- "disclosure-option",
- "pre-approved",
- }
- };
-
- public static final Object[][] GLOBAL_METADATA_DATA_HOLDER = new Object[][]{
-
- {
- SAMPLE_ACCOUNT_ID,
- GLOBAL,
- "disclosure-option",
- "pre-approved",
- }
- };
-
- public static final Object[][] GET_METADATA_DATA_HOLDER = new Object[][]{
-
- {
- SAMPLE_ACCOUNT_ID,
- SAMPLE_USER_ID,
- }
- };
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/DAOUtils.java b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/DAOUtils.java
deleted file mode 100644
index 83ae7020..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/java/com/wso2/openbanking/accelerator/account/metadata/service/util/DAOUtils.java
+++ /dev/null
@@ -1,64 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.account.metadata.service.util;
-
-import org.apache.commons.dbcp.BasicDataSource;
-import org.apache.commons.lang3.StringUtils;
-
-import java.nio.file.Paths;
-import java.sql.Connection;
-import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.Map;
-
-/**
- * Implementation of DAOUtils class.
- */
-public class DAOUtils {
-
- private static Map dataSourceMap = new HashMap<>();
-
- public static void initializeDataSource(String databaseName, String scriptPath) throws Exception {
- BasicDataSource dataSource = new BasicDataSource();
- dataSource.setDriverClassName("org.h2.Driver");
- dataSource.setUsername("username");
- dataSource.setPassword("password");
- dataSource.setUrl("jdbc:h2:mem:" + databaseName);
-
- try (Connection connection = dataSource.getConnection()) {
- connection.createStatement().executeUpdate("RUNSCRIPT FROM '" + scriptPath + "'");
- }
- dataSourceMap.put(databaseName, dataSource);
- }
-
- public static Connection getConnection(String database) throws SQLException {
- if (dataSourceMap.get(database) != null) {
- return dataSourceMap.get(database).getConnection();
- }
- throw new RuntimeException("Invalid datasource.");
- }
-
- public static String getFilePath(String fileName) {
- if (StringUtils.isNotBlank(fileName)) {
- return Paths.get(System.getProperty("user.dir"), "src", "test", "resources", fileName)
- .toString();
- }
- return null;
- }
-}
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/dbScripts/h2.sql b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/dbScripts/h2.sql
deleted file mode 100644
index e79fb9a7..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/dbScripts/h2.sql
+++ /dev/null
@@ -1,8 +0,0 @@
-CREATE TABLE IF NOT EXISTS OB_ACCOUNT_METADATA (
- ACCOUNT_ID VARCHAR(100) NOT NULL,
- USER_ID VARCHAR(100) NOT NULL,
- METADATA_KEY VARCHAR(100) NOT NULL,
- METADATA_VALUE VARCHAR(100) NOT NULL,
- LAST_UPDATED_TIMESTAMP TIMESTAMP NOT NULL,
- PRIMARY KEY (USER_ID,ACCOUNT_ID,METADATA_KEY)
-);
diff --git a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/testng.xml b/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/testng.xml
deleted file mode 100644
index af4222bb..00000000
--- a/open-banking-accelerator/components/account-metadata/com.wso2.openbanking.accelerator.account.metadata.service/src/test/resources/testng.xml
+++ /dev/null
@@ -1,28 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/pom.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/pom.xml
deleted file mode 100644
index 3e35d80f..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/pom.xml
+++ /dev/null
@@ -1,219 +0,0 @@
-
-
-
-
- 4.0.0
-
-
- open-banking-accelerator
- com.wso2.openbanking.accelerator
- 3.2.0-SNAPSHOT
- ../../pom.xml
-
- com.wso2.openbanking.accelerator.ciba
- bundle
- WSO2 Open Banking - Common component
-
-
- com.wso2.openbanking.accelerator
- com.wso2.openbanking.accelerator.common
- provided
-
-
- com.wso2.openbanking.accelerator
- com.wso2.openbanking.accelerator.identity
- provided
-
-
- org.wso2.carbon.identity.inbound.auth.oauth2
- org.wso2.carbon.identity.oauth
- ${identity.inbound.auth.oauth.ciba.updated.version}
-
-
- org.wso2.carbon.identity.inbound.auth.oauth2
- org.wso2.carbon.identity.oauth.ciba
- ${identity.inbound.auth.oauth.ciba.updated.version}
-
-
- org.powermock
- powermock-module-testng
-
-
- org.powermock
- powermock-api-mockito
-
-
- com.wso2.openbanking.accelerator
- com.wso2.openbanking.accelerator.consent.service
-
-
- org.springframework
- spring-test
-
-
- org.springframework
- spring-core
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- org.jacoco
- jacoco-maven-plugin
-
-
-
- **/*GrantHandler.class
-
-
-
-
- default-prepare-agent
-
- prepare-agent
-
-
-
- default-prepare-agent-integration
-
- prepare-agent-integration
-
-
-
- default-report
-
- report
-
-
-
- default-report-integration
-
- report-integration
-
-
-
- default-check
-
- check
-
-
-
-
- BUNDLE
-
-
- INSTRUCTION
- COVEREDRATIO
- 0.86
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- src/test/resources/testng.xml
-
-
-
-
- com.github.spotbugs
- spotbugs-maven-plugin
-
- Max
- Low
- true
- false
- ${project.build.directory}/spotbugs
- ${project.basedir}/src/main/resources/findbugs-exclude.xml
- ${project.basedir}/src/main/resources/findbugs-include.xml
- false
-
-
- com.h3xstream.findsecbugs
- findsecbugs-plugin
- ${com.h3xstream.findsecbugs.version}
-
-
-
-
-
- analyze-compile
- compile
-
- check
-
-
-
-
-
- org.apache.felix
- maven-bundle-plugin
- true
-
-
-
- ${project.artifactId}
-
-
- com.wso2.openbanking.accelerator.identity.internal
-
-
- com.nimbusds.jwt; version="${nimbusds.osgi.version.range}",
- com.wso2.openbanking.accelerator.common.exception; version="${project.version}",
- com.wso2.openbanking.accelerator.common.util; version="${project.version}",
- com.wso2.openbanking.accelerator.consent.mgt.service.impl; version="${project.version}",
- net.minidev.json; version="${json-smart}",
- org.apache.commons.logging; version="${commons.logging.version}",
- org.wso2.carbon.identity.oauth.ciba.grant; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.oauth2; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.oauth2.dto; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.oauth2.model; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.oauth2.token; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.openidconnect; version="${identity.inbound.auth.oauth.version.range}",
- org.wso2.carbon.identity.openidconnect.model; version="${identity.inbound.auth.oauth.version.range}",
-
-
- !com.wso2.openbanking.accelerator.identity.internal,
- com.wso2.openbanking.accelerator.ciba
-
- *
- <_dsannotations>*
-
-
-
-
-
-
- 6.4.111.52
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/CIBAConstants.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/CIBAConstants.java
deleted file mode 100644
index 62c25ffc..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/CIBAConstants.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-/**
- * CIBA Test Constants class.
- */
-public class CIBAConstants {
-
- public static final String INVALID_REQUEST = "invalid_request";
- public static final String INTENT_CLAIM = "openbanking_intent_id";
- public static final String VALUE_TAG = "value";
- public static final String CONSENT_ID_PREFIX = "OB_CONSENT_ID_";
-
- //Error Messages
- public static final String PARSE_ERROR_MESSAGE =
- "Request object invalid: Unable to parse the request object as json";
- public static final String EMPTY_CONTENT_ERROR = "Request object invalid: Empty value for intent";
- public static final String MESSAGE_CONTEXT_EMPTY_ERROR = "OAuth Token Request Message Context is empty";
- public static final String SCOPE_ADDING_ERROR = "Error while adding consent ID to scopes";
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java
deleted file mode 100644
index 7b0251dc..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBARequestObjectValidationExtension.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-import com.wso2.openbanking.accelerator.common.util.Generated;
-import net.minidev.json.JSONObject;
-import org.apache.commons.lang.StringUtils;
-import org.wso2.carbon.identity.oauth2.RequestObjectException;
-import org.wso2.carbon.identity.oauth2.model.OAuth2Parameters;
-import org.wso2.carbon.identity.openidconnect.CIBARequestObjectValidatorImpl;
-import org.wso2.carbon.identity.openidconnect.model.RequestObject;
-
-import java.text.ParseException;
-
-/**
- * The extension of RequestObjectValidatorImpl to enforce Open Banking specific validations of the
- * request object.
- */
-public class OBCIBARequestObjectValidationExtension extends CIBARequestObjectValidatorImpl {
-
- /**
- * Validations related to clientId, response type, exp, redirect URL, mandatory params,
- * issuer, audience are done. Called after signature validation.
- *
- * @param initialRequestObject request object
- * @param oAuth2Parameters oAuth2Parameters
- * @throws RequestObjectException - RequestObjectException
- */
- @Override
- public boolean validateRequestObject(RequestObject initialRequestObject, OAuth2Parameters oAuth2Parameters)
- throws RequestObjectException {
-
- JSONObject intent;
- try {
- intent = initialRequestObject.getClaimsSet().getJSONObjectClaim(CIBAConstants.INTENT_CLAIM);
- } catch (ParseException e) {
- throw new RequestObjectException(CIBAConstants.INVALID_REQUEST,
- CIBAConstants.PARSE_ERROR_MESSAGE, e);
- }
- if (StringUtils.isEmpty(intent.getAsString(CIBAConstants.VALUE_TAG))) {
- throw new RequestObjectException(CIBAConstants.INVALID_REQUEST, CIBAConstants.EMPTY_CONTENT_ERROR);
- }
-
- return validateIAMConstraints(initialRequestObject, oAuth2Parameters);
- }
-
- /**
- * Validate IAM related logic.
- * @param requestObject
- * @param oAuth2Parameters
- * @return is IAM related constraints are validate
- * @throws RequestObjectException
- */
- @Generated(message = "super methods cannot be mocked")
- boolean validateIAMConstraints(RequestObject requestObject,
- OAuth2Parameters oAuth2Parameters) throws RequestObjectException {
-
- return super.validateRequestObject(requestObject, oAuth2Parameters);
- }
-
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBASignatureAlgorithmEnforcementValidator.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBASignatureAlgorithmEnforcementValidator.java
deleted file mode 100644
index b01a769e..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCIBASignatureAlgorithmEnforcementValidator.java
+++ /dev/null
@@ -1,54 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-import com.wso2.openbanking.accelerator.identity.token.util.TokenFilterException;
-import com.wso2.openbanking.accelerator.identity.token.validators.SignatureAlgorithmEnforcementValidator;
-import com.wso2.openbanking.accelerator.identity.util.IdentityCommonConstants;
-import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
-
-import javax.servlet.http.HttpServletResponse;
-
-/**
- * CIBA Signature Algorithm Enforcer class
- */
-public class OBCIBASignatureAlgorithmEnforcementValidator extends SignatureAlgorithmEnforcementValidator {
-
- /**
- * CIBA and FAPI related validations for Signature Algorithm.
- * @param requestSigningAlgorithm the algorithm of signed message
- * @param registeredSigningAlgorithm the algorithm registered during client authentication
- * @throws TokenFilterException
- */
- @Override
- public void validateInboundSignatureAlgorithm(String requestSigningAlgorithm, String registeredSigningAlgorithm)
- throws TokenFilterException {
-
- super.validateInboundSignatureAlgorithm(requestSigningAlgorithm, registeredSigningAlgorithm);
- if (OAuthServerConfiguration.getInstance().isFapiCiba()) {
- if (!(IdentityCommonConstants.ALG_ES256.equals(requestSigningAlgorithm) ||
- IdentityCommonConstants.ALG_PS256.equals(requestSigningAlgorithm))) {
- String message = "FAPI unsupported signing algorithm " + requestSigningAlgorithm
- + " used to sign the JWT";
- throw new TokenFilterException(HttpServletResponse.SC_UNAUTHORIZED, IdentityCommonConstants
- .OAUTH2_INVALID_CLIENT_MESSAGE, message);
- }
- }
- }
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCibaGrantHandler.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCibaGrantHandler.java
deleted file mode 100644
index f656bc7c..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/java/com.wso2.openbanking.accelerator.ciba/OBCibaGrantHandler.java
+++ /dev/null
@@ -1,69 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-import com.wso2.openbanking.accelerator.common.exception.ConsentManagementException;
-import com.wso2.openbanking.accelerator.consent.mgt.service.impl.ConsentCoreServiceImpl;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.carbon.identity.oauth.ciba.grant.CibaGrantHandler;
-import org.wso2.carbon.identity.oauth2.IdentityOAuth2Exception;
-import org.wso2.carbon.identity.oauth2.token.OAuthTokenReqMessageContext;
-
-import java.util.Arrays;
-
-/**
- * OB specific CIBA grant handler.
- */
-public class OBCibaGrantHandler extends CibaGrantHandler {
-
- private static final ConsentCoreServiceImpl consentCoreService = new ConsentCoreServiceImpl();
- private static Log log = LogFactory.getLog(CibaGrantHandler.class);
-
- public void setConsentIdScope(OAuthTokenReqMessageContext tokReqMsgCtx, String authReqId)
- throws IdentityOAuth2Exception {
- String[] scopesArray;
- String[] tokenRequestMessageContextArray = tokReqMsgCtx.getScope();
- if (tokenRequestMessageContextArray != null) {
- scopesArray = Arrays.copyOf(tokenRequestMessageContextArray, tokenRequestMessageContextArray.length + 1);
- } else {
- throw new IdentityOAuth2Exception(CIBAConstants.MESSAGE_CONTEXT_EMPTY_ERROR);
- }
- try {
- scopesArray[scopesArray.length - 1] = CIBAConstants.CONSENT_ID_PREFIX + consentCoreService.
- getConsentIdByConsentAttributeNameAndValue("auth_req_id", authReqId).get(0);
- } catch (ConsentManagementException e) {
- throw new IdentityOAuth2Exception(CIBAConstants.SCOPE_ADDING_ERROR, e);
- }
- tokReqMsgCtx.setScope(scopesArray);
-
- }
-
- @Override
- public boolean validateGrant(OAuthTokenReqMessageContext tokReqMsgCtx) throws IdentityOAuth2Exception {
- if (!super.validateGrant(tokReqMsgCtx)) {
- log.error("Successful in validating grant.Validation failed for the token request made by client: "
- + tokReqMsgCtx.getOauth2AccessTokenReqDTO().getClientId());
- return false;
- } else {
- setConsentIdScope(tokReqMsgCtx, super.getAuthReqId(tokReqMsgCtx));
- return true;
- }
- }
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-exclude.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-exclude.xml
deleted file mode 100644
index c4f8e532..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-exclude.xml
+++ /dev/null
@@ -1,21 +0,0 @@
-
-
-
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-include.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-include.xml
deleted file mode 100644
index 649d044e..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/main/resources/findbugs-include.xml
+++ /dev/null
@@ -1,23 +0,0 @@
-
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java
deleted file mode 100644
index 74133c1a..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBARequestObjectValidationExtensionTest.java
+++ /dev/null
@@ -1,93 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-import com.nimbusds.jwt.JWTClaimsSet;
-import net.minidev.json.JSONObject;
-import org.mockito.Mockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.testng.PowerMockTestCase;
-import org.testng.annotations.Test;
-import org.wso2.carbon.identity.oauth2.RequestObjectException;
-import org.wso2.carbon.identity.oauth2.model.OAuth2Parameters;
-import org.wso2.carbon.identity.openidconnect.model.RequestObject;
-
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-/**
- * Test class for OBCIBARequestObjectValidationExtension.
- */
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({JWTClaimsSet.class, OAuth2Parameters.class, RequestObject.class, JSONObject.class})
-public class OBCIBARequestObjectValidationExtensionTest extends PowerMockTestCase {
-
- private final String dummyString = "dummyString";
-
- @Test(expectedExceptions = RequestObjectException.class, description = "Empty intent key")
- public void validateRequestObjectInvalidIntentKeyTest() throws Exception {
-
- OBCIBARequestObjectValidationExtensionMock obcibaRequestObjectValidationExtensionMock =
- new OBCIBARequestObjectValidationExtensionMock();
-
- JSONObject intent = mock(JSONObject.class);
-
- RequestObject requestObject = mock(RequestObject.class);
- OAuth2Parameters oAuth2Parameters = mock(OAuth2Parameters.class);
- JWTClaimsSet claimsSet = Mockito.mock(JWTClaimsSet.class);
-
- Mockito.when(requestObject.getClaimsSet()).thenReturn(claimsSet);
- Mockito.when(claimsSet.getJSONObjectClaim(Mockito.anyString())).thenReturn(intent);
-
- when(intent.getAsString(dummyString)).thenReturn(dummyString);
-
- obcibaRequestObjectValidationExtensionMock.validateRequestObject(requestObject, oAuth2Parameters);
-
- }
-
- @Test(description = "success scenario")
- public void validateRequestObjectValidObjectTest() throws Exception {
-
- OBCIBARequestObjectValidationExtensionMock obcibaRequestObjectValidationExtensionMock =
- new OBCIBARequestObjectValidationExtensionMock();
-
- JSONObject intent = mock(JSONObject.class);
-
- RequestObject requestObject = mock(RequestObject.class);
- OAuth2Parameters oAuth2Parameters = mock(OAuth2Parameters.class);
- JWTClaimsSet claimsSet = Mockito.mock(JWTClaimsSet.class);
-
- Mockito.when(requestObject.getClaimsSet()).thenReturn(claimsSet);
- Mockito.when(claimsSet.getJSONObjectClaim(Mockito.anyString())).thenReturn(intent);
-
- when(intent.getAsString("value")).thenReturn(dummyString);
-
- obcibaRequestObjectValidationExtensionMock.validateRequestObject(requestObject, oAuth2Parameters);
-
- }
-}
-
-class OBCIBARequestObjectValidationExtensionMock extends OBCIBARequestObjectValidationExtension {
-
- @Override
- boolean validateIAMConstraints(RequestObject requestObject,
- OAuth2Parameters oAuth2Parameters) throws RequestObjectException {
- return Mockito.anyBoolean();
- }
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBASignatureAlgorithmEnforcementValidatorTest.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBASignatureAlgorithmEnforcementValidatorTest.java
deleted file mode 100644
index 8de0c7ce..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/OBCIBASignatureAlgorithmEnforcementValidatorTest.java
+++ /dev/null
@@ -1,124 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-import com.wso2.openbanking.accelerator.identity.internal.IdentityExtensionsDataHolder;
-import com.wso2.openbanking.accelerator.identity.token.DefaultTokenFilter;
-import com.wso2.openbanking.accelerator.identity.token.TokenFilter;
-import com.wso2.openbanking.accelerator.identity.token.validators.OBIdentityFilterValidator;
-import com.wso2.openbanking.accelerator.identity.util.IdentityCommonConstants;
-import com.wso2.openbanking.accelerator.identity.util.IdentityCommonUtil;
-import org.apache.http.HttpStatus;
-import org.json.JSONObject;
-import org.mockito.Mockito;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PowerMockIgnore;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.testng.PowerMockTestCase;
-import org.springframework.mock.web.MockHttpServletRequest;
-import org.springframework.mock.web.MockHttpServletResponse;
-import org.testng.annotations.BeforeMethod;
-import org.testng.annotations.Test;
-import org.wso2.carbon.identity.oauth.config.OAuthServerConfiguration;
-
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import javax.servlet.FilterChain;
-import javax.servlet.ServletOutputStream;
-
-import static org.testng.Assert.assertEquals;
-
-@PowerMockIgnore("jdk.internal.reflect.*")
-@PrepareForTest({IdentityCommonUtil.class, OAuthServerConfiguration.class})
-public class OBCIBASignatureAlgorithmEnforcementValidatorTest extends PowerMockTestCase {
-
-
-
- MockHttpServletResponse response;
- MockHttpServletRequest request;
- FilterChain filterChain;
-
- @BeforeMethod
- public void beforeMethod() {
-
- request = new MockHttpServletRequest();
- response = new MockHttpServletResponse();
- filterChain = Mockito.spy(FilterChain.class);
-
- }
-
- //Enable this test if you are building CIBA components along with this.
- @Test(description = "Test when registered algorithm and signed algorithm differ")
- public void fapiUnsupportedSignatureAlgorithmValidationTest() throws Exception {
- Map configMap = new HashMap<>();
- PowerMockito.mockStatic(IdentityCommonUtil.class);
- PowerMockito.mockStatic(OAuthServerConfiguration.class);
-
- OAuthServerConfiguration oAuthServerConfiguration = Mockito.mock(OAuthServerConfiguration.class);
- configMap.put(IdentityCommonConstants.ENABLE_TRANSPORT_CERT_AS_HEADER, true);
- configMap.put(IdentityCommonConstants.CLIENT_CERTIFICATE_ENCODE, false);
- IdentityExtensionsDataHolder.getInstance().setConfigurationMap(configMap);
-
- OBCIBASignatureAlgorithmEnforcementValidator validator =
- Mockito.spy(OBCIBASignatureAlgorithmEnforcementValidator.class);
-
- request.setParameter(IdentityCommonConstants.OAUTH_JWT_ASSERTION, TestConstants.CLIENT_ASSERTION);
- request.addHeader(TestConstants.CERTIFICATE_HEADER, TestConstants.CERTIFICATE_CONTENT);
-
- Mockito.doReturn("RS256").when(validator)
- .getRegisteredSigningAlgorithm("iYpRm64b2vmvmKDhdL6KZD9z6fca");
- Mockito.doReturn("RS256").when(validator)
- .getRequestSigningAlgorithm(TestConstants.CLIENT_ASSERTION);
-
- List validators = new ArrayList<>();
- validators.add(validator);
-
- TokenFilter filter = Mockito.spy(TokenFilter.class);
- Mockito.doReturn(new DefaultTokenFilter()).when(filter).getDefaultTokenFilter();
- Mockito.doReturn(validators).when(filter).getValidators();
- PowerMockito.when(IdentityCommonUtil.getRegulatoryFromSPMetaData("iYpRm64b2vmvmKDhdL6KZD9z6fca"))
- .thenReturn(true);
- PowerMockito.when(IdentityCommonUtil.getMTLSAuthHeader()).thenReturn(TestConstants.CERTIFICATE_HEADER);
- PowerMockito.when(OAuthServerConfiguration.getInstance()).thenReturn(oAuthServerConfiguration);
- Mockito.when(oAuthServerConfiguration.isFapiCiba()).thenReturn(true);
- filter.doFilter(request, response, filterChain);
-
- Map responseMap = getResponse(response.getOutputStream());
- assertEquals(response.getStatus(), HttpStatus.SC_UNAUTHORIZED);
- assertEquals(responseMap.get(IdentityCommonConstants.OAUTH_ERROR), "invalid_client");
- assertEquals(responseMap.get(IdentityCommonConstants.OAUTH_ERROR_DESCRIPTION),
- "FAPI unsupported signing algorithm RS256 used to sign the JWT");
- }
-
- public static Map getResponse(ServletOutputStream outputStream) {
-
- Map response = new HashMap<>();
- JSONObject outputStreamMap = new JSONObject(outputStream);
- JSONObject targetStream = new JSONObject(outputStreamMap.get(TestConstants.TARGET_STREAM).toString());
- response.put(IdentityCommonConstants.OAUTH_ERROR,
- targetStream.get(IdentityCommonConstants.OAUTH_ERROR).toString());
- response.put(IdentityCommonConstants.OAUTH_ERROR_DESCRIPTION,
- targetStream.get(IdentityCommonConstants.OAUTH_ERROR_DESCRIPTION).toString());
- return response;
- }
-
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/TestConstants.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/TestConstants.java
deleted file mode 100644
index adbe8927..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/java/com/wso2/openbanking/accelerator/ciba/TestConstants.java
+++ /dev/null
@@ -1,66 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.ciba;
-
-public class TestConstants {
-
- public static final String CLIENT_ASSERTION = "eyJraWQiOiJqeVJVY3l0MWtWQ2xjSXZsVWxjRHVrVlozdFUiLCJhbGciOiJQUzI1" +
- "NiJ9.eyJzdWIiOiJpWXBSbTY0YjJ2bXZtS0RoZEw2S1pEOXo2ZmNhIiwiYXVkIjoiaHR0cHM6Ly9sb2NhbGhvc3Q6OTQ0My9vYXV0a" +
- "DIvdG9rZW4iLCJpc3MiOiJpWXBSbTY0YjJ2bXZtS0RoZEw2S1pEOXo2ZmNhIiwiZXhwIjoxNjEwNjMxNDEyLCJpYXQiOjE2MTA2MDE" +
- "0MTIsImp0aSI6IjE2MTA2MDE0MTI5MDAifQ.tmMTlCL-VABhFTA6QQ6UPvUydKuzynidepAa8oZGEBfVyAsiW5IF01NKYD0ynpXXJC" +
- "Q6hcbWK0FEGity67p6DeI9LT-xAnaKwZY7H8rbuxWye2vhanM0jVa1vggsmwWYyOR4k55ety9lP1MkcGZpaK48qoaqsX_X7GCSGXzq" +
- "BncTEPYfCpVUQtS4ctwoCl06TFbY2Lfm9E24z1rfmU9xPc7au6LpKRLMMHQ8QXuc-FhnWdgEFv_3tAai2ovVmrqEfwj6Z6Ew5bFeI9" +
- "jtCR4TSol47hzDwldx5rH7m2OPUx66yEtGrM7UU62fC-4nxplZ69fjlHN4KQ62PxEaCQs0_A";
-
- public static final String CERTIFICATE_HEADER = "x-wso2-mutual-auth-cert";
- public static final String CERTIFICATE_CONTENT = "-----BEGIN CERTIFICATE-----" +
- "MIIFODCCBCCgAwIBAgIEWcWGxDANBgkqhkiG9w0BAQsFADBTMQswCQYDVQQGEwJH" +
- "QjEUMBIGA1UEChMLT3BlbkJhbmtpbmcxLjAsBgNVBAMTJU9wZW5CYW5raW5nIFBy" +
- "ZS1Qcm9kdWN0aW9uIElzc3VpbmcgQ0EwHhcNMTkwNTE2MDg0NDQ2WhcNMjAwNjE2" +
- "MDkxNDQ2WjBhMQswCQYDVQQGEwJHQjEUMBIGA1UEChMLT3BlbkJhbmtpbmcxGzAZ" +
- "BgNVBAsTEjAwMTU4MDAwMDFIUVFyWkFBWDEfMB0GA1UEAxMWc0Zna2k3Mk9pcXda" +
- "TkZPWmc2T2FqaTCCASIwDQYJKoZIhvcNAQEBBQADggEPADCCAQoCggEBANoVwx4E" +
- "iWnQs89lj8vKSy/xTbZU2AHS9tFNz7wVa+rkpFyLVPtQW8AthG4hlfrBYMne7/P9" +
- "c1Fi/q+n7eomWvJJo44GV44GJhegM6yyRaIcQdpxe9x9G4twWK4cY+VU3TfE6Dbd" +
- "DdmAt7ai4KFbbpB33N8RwXoeGZdwxZFNPmfaoZZbz5p9+aSMQf1UyExcdlPXah77" +
- "PDZDwAnyy5kYXUPS59S78+p4twqZXyZu9hd+Su5Zod5UObRJ4F5LQzZPS1+KzBje" +
- "JM0o8qoRRZTZkLNnmmQw503KXp/LCLrSbFU2ZLGy3bQpKFFc5I6tZiy67ELNzLWo" +
- "DzngEbApwhX+jtsCAwEAAaOCAgQwggIAMA4GA1UdDwEB/wQEAwIHgDAgBgNVHSUB" +
- "Af8EFjAUBggrBgEFBQcDAQYIKwYBBQUHAwIwgeAGA1UdIASB2DCB1TCB0gYLKwYB" +
- "BAGodYEGAWQwgcIwKgYIKwYBBQUHAgEWHmh0dHA6Ly9vYi50cnVzdGlzLmNvbS9w" +
- "b2xpY2llczCBkwYIKwYBBQUHAgIwgYYMgYNVc2Ugb2YgdGhpcyBDZXJ0aWZpY2F0" +
- "ZSBjb25zdGl0dXRlcyBhY2NlcHRhbmNlIG9mIHRoZSBPcGVuQmFua2luZyBSb290" +
- "IENBIENlcnRpZmljYXRpb24gUG9saWNpZXMgYW5kIENlcnRpZmljYXRlIFByYWN0" +
- "aWNlIFN0YXRlbWVudDBtBggrBgEFBQcBAQRhMF8wJgYIKwYBBQUHMAGGGmh0dHA6" +
- "Ly9vYi50cnVzdGlzLmNvbS9vY3NwMDUGCCsGAQUFBzAChilodHRwOi8vb2IudHJ1" +
- "c3Rpcy5jb20vb2JfcHBfaXNzdWluZ2NhLmNydDA6BgNVHR8EMzAxMC+gLaArhilo" +
- "dHRwOi8vb2IudHJ1c3Rpcy5jb20vb2JfcHBfaXNzdWluZ2NhLmNybDAfBgNVHSME" +
- "GDAWgBRQc5HGIXLTd/T+ABIGgVx5eW4/UDAdBgNVHQ4EFgQU5eqvEZ6ZdQS5bq/X" +
- "dzP5XY/fUXUwDQYJKoZIhvcNAQELBQADggEBAIg8bd/bIh241ewS79lXU058VjCu" +
- "JC+4QtcI2XiGV3dBpg10V6Kb6E/h8Gru04uVZW1JK52ivVb5NYs6r8txRsTBIaA8" +
- "Cr03LJqEftclL9NbkPZnpEkUfqCBfujNQF8XWaQgXIIA+io1UzV1TG3K9XCa/w2S" +
- "sTANKfF8qK5kRsy6z9OGPUE+Oi3DUt+E9p5LCq6n5Bkp9YRGmyYRPs8JMkJmq3sf" +
- "wtXOy27LE4exJRuZsF1CA78ObaRytuE3DJcnIRdhOcjWieS/MxZD7bzuuAPu5ySX" +
- "i2/qxT3AlWtHtxrz0mKSC3rlgYAHCzCAHoASWKpf5tnB3TodPVZ6DYOu7oI=" +
- "-----END CERTIFICATE-----";
-
- public static final String TARGET_STREAM = "targetStream";
-
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/resources/testng.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/resources/testng.xml
deleted file mode 100644
index 5b2f8ba3..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.ciba/src/test/resources/testng.xml
+++ /dev/null
@@ -1,29 +0,0 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/pom.xml b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/pom.xml
deleted file mode 100644
index 870e3fdd..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/pom.xml
+++ /dev/null
@@ -1,306 +0,0 @@
-
-
-
-
- 4.0.0
-
-
- open-banking-accelerator
- com.wso2.openbanking.accelerator
- 3.2.11-SNAPSHOT
- ../../pom.xml
-
-
- com.wso2.openbanking.accelerator.common
- bundle
- WSO2 Open Banking - Common component
-
-
- org.wso2.orbit.org.bouncycastle
- bcpkix-jdk18on
-
-
- org.wso2.orbit.org.bouncycastle
- bcprov-jdk18on
-
-
- org.apache.ws.commons.axiom.wso2
- axiom
-
-
- commons-logging
- commons-logging
-
-
- org.wso2.securevault
- org.wso2.securevault
-
-
- org.wso2.carbon.identity.inbound.auth.oauth2
- org.wso2.carbon.identity.oauth
-
-
- org.wso2.orbit.org.bouncycastle
- bcprov-jdk15on
-
-
-
-
- org.wso2.carbon.identity.framework
- org.wso2.carbon.identity.application.mgt
-
-
- org.wso2.orbit.org.bouncycastle
- bcprov-jdk15on
-
-
-
-
- org.hibernate
- hibernate-validator
-
-
- commons-beanutils
- commons-beanutils
-
-
-
- org.wso2.eclipse.osgi
- org.eclipse.osgi.services
-
-
- org.eclipse.osgi
- org.eclipse.osgi
-
-
- org.wso2.carbon
- org.wso2.carbon.core
-
-
- org.wso2.orbit.com.hazelcast
- hazelcast
-
-
- org.wso2.orbit.org.bouncycastle
- bcprov-jdk15on
-
-
-
-
- org.testng
- testng
- test
-
-
- org.mockito
- mockito-all
- test
-
-
- org.powermock
- powermock-module-testng
-
-
- org.powermock
- powermock-api-mockito
-
-
- io.jsonwebtoken
- jjwt
-
-
- org.wso2.orbit.com.nimbusds
- nimbus-jose-jwt
-
-
- net.minidev
- json-smart
-
-
-
-
-
- com.github.spotbugs
- spotbugs-maven-plugin
- 4.2.3
-
- Max
- Low
- false
- true
- ${project.build.directory}/spotbugs
- ${project.basedir}/src/main/resources/findbugs-include.xml
-
-
- com.h3xstream.findsecbugs
- findsecbugs-plugin
- ${com.h3xstream.findsecbugs.version}
-
-
-
-
-
- analyze-compile
- compile
-
- check
-
-
-
-
-
- org.apache.maven.plugins
- maven-compiler-plugin
-
-
- org.jacoco
- jacoco-maven-plugin
-
-
-
- **/*Constants.class
- **/*Component.class
- **/*DataHolder.class
- **/*Enum.class
- **/*Exception.class
- **/*Discoverer.class
- **/*AudienceValidator.class
- **/*OpenBankingBaseCache.class
- **/*OpenBankingBaseCacheKey.class
- **/*OpenBankingIdentityBaseCache.class
- **/*JWKSetCache.class
- **/*JWKSetCacheKey.class
- **/*ApplicationIdentityService.class
- **/*JWKRetriever.class
- **/*OpenBankingErrorCodes.class
- **/*IdentityConstants.class
- **/*ServerIdentityRetriever.class
-
- **/DatabaseUtil.class
- **/JDBCPersistenceManager.class
- **/CertValidationErrors.class
- **/JDBCRetentionDataPersistenceManager.class
- **/*Type*/**
-
-
-
-
- default-prepare-agent
-
- prepare-agent
-
-
-
- default-prepare-agent-integration
-
- prepare-agent-integration
-
-
-
- default-report
-
- report
-
-
-
- default-report-integration
-
- report-integration
-
-
-
- default-check
-
- check
-
-
-
-
- BUNDLE
-
-
- INSTRUCTION
- COVEREDRATIO
- 0.77
-
-
-
-
-
-
-
-
-
- org.apache.maven.plugins
- maven-surefire-plugin
-
-
- src/test/resources/testng.xml
-
-
-
-
- com.github.spotbugs
- spotbugs-maven-plugin
-
- Max
- Low
- true
- ${project.build.directory}/spotbugs
- ${project.basedir}/src/main/resources/findbugs-exclude.xml
-
-
-
- analyze-compile
- compile
-
- check
-
-
-
-
-
- org.apache.felix
- maven-bundle-plugin
- true
-
-
-
- ${project.artifactId}
-
-
- com.wso2.openbanking.accelerator.common.internal
-
-
- org.osgi.framework;version="${osgi.framework.imp.pkg.version.range}",
- org.osgi.service.component;version="${osgi.service.component.imp.pkg.version.range}"
-
-
- !com.wso2.openbanking.accelerator.common.internal,
- com.wso2.openbanking.accelerator.common.*;version="${project.version}",
-
- *
- <_dsannotations>*
-
-
-
-
-
-
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCache.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCache.java
deleted file mode 100644
index 1c41b245..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCache.java
+++ /dev/null
@@ -1,212 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.common.caching;
-
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingException;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
-import java.util.concurrent.TimeUnit;
-
-import javax.cache.Cache;
-import javax.cache.CacheBuilder;
-import javax.cache.CacheConfiguration;
-import javax.cache.CacheManager;
-import javax.cache.Caching;
-
-/**
- * Abstract cache manager for Open Banking.
- *
- * @param Extended Cache Key
- * @param Cache Value
- */
-public abstract class OpenBankingBaseCache {
-
- private static final String BASE_CACHE_KEY = "OB_BASE_CACHE";
- private final String cacheName;
-
- private static final Log log = LogFactory.getLog(OpenBankingBaseCache.class);
-
- /**
- * On Demand Retriever for caching.
- */
- public interface OnDemandRetriever {
-
- Object get() throws OpenBankingException;
- }
-
- /**
- * Initialize With unique cache name.
- *
- * @param cacheName unique cache name.
- */
- public OpenBankingBaseCache(String cacheName) {
-
- this.cacheName = cacheName;
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Base Cache initialized for %s", cacheName.replaceAll("[\r\n]", "")));
- }
- }
-
- /**
- * Get from cache or invoke ondemand retriever and store.
- *
- * @param key cache key.
- * @param onDemandRetriever on demand retriever.
- * @return cached object.
- * @throws OpenBankingException if an error occurs while retrieving the object
- */
- public V getFromCacheOrRetrieve(K key, OnDemandRetriever onDemandRetriever) throws OpenBankingException {
-
- Cache cache = getBaseCache();
-
- if (cache.containsKey(key)) {
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Found cache entry `%s` in cache %s",
- key.toString().replaceAll("[\r\n]", ""), cacheName.replaceAll("[\r\n]", "")));
- }
- return cache.get(key);
- } else {
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Cache Entry `%s` not available in cache %s",
- key.toString().replaceAll("[\r\n]", ""), cacheName.replaceAll("[\r\n]", "")));
- }
-
- V value = (V) onDemandRetriever.get();
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("On demand retrieved `%s` for %s",
- key.toString().replaceAll("[\r\n]", ""), cacheName.replaceAll("[\r\n]", "")));
- }
-
- removeFromCache(key);
- addToCache(key, value);
- return value;
- }
-
- }
-
- /**
- * Get from cache.
- *
- * @param key cache key.
- * @return cached object.
- */
- public V getFromCache(K key) {
-
- Cache cache = getBaseCache();
-
- if (cache.containsKey(key)) {
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("Found cache entry `%s` in cache %s",
- key.toString().replaceAll("[\r\n]", ""), cacheName.replaceAll("[\r\n]", "")));
- }
- return cache.get(key);
- } else {
-
- return null;
- }
-
- }
-
- /**
- * Add Object to cache.
- *
- * @param key cache key.
- * @param value cache value.
- */
- public void addToCache(K key, V value) {
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("`%s` added into cache %s", key.toString().replaceAll("[\r\n]", ""),
- cacheName.replaceAll("[\r\n]", "")));
- }
-
- Cache cache = getBaseCache();
- cache.put(key, value);
- }
-
- /**
- * Remove Object from Cache.
- *
- * @param key cache key.
- */
- public void removeFromCache(K key) {
-
- if (log.isDebugEnabled()) {
- log.debug(String.format("`%s` removed from cache %s", key.toString().replaceAll("[\r\n]", ""),
- cacheName.replaceAll("[\r\n]", "")));
- }
-
- Cache cache = getBaseCache();
- cache.remove(key);
- }
-
- /**
- * Get Cache for instance.
- *
- * @return
- */
- private Cache getBaseCache() {
-
- CacheManager cacheManager = Caching.getCacheManager(BASE_CACHE_KEY);
-
- Iterable> availableCaches = cacheManager.getCaches();
- for (Cache cache : availableCaches) {
- if (cache.getName().equalsIgnoreCase(
- cache.getName().startsWith("$__local__$.") ? "$__local__$." + cacheName : cacheName)) {
- return cacheManager.getCache(cacheName);
- }
- }
-
- CacheConfiguration.Duration accessExpiry = new CacheConfiguration.Duration(TimeUnit.MINUTES,
- getCacheAccessExpiryMinutes());
-
- CacheConfiguration.Duration modifiedExpiry = new CacheConfiguration.Duration(TimeUnit.MINUTES,
- getCacheModifiedExpiryMinutes());
-
- // Build Cache on OB base cache.
- CacheBuilder cacheBuilder = cacheManager.createCacheBuilder(cacheName);
-
- return cacheBuilder.setExpiry(CacheConfiguration.ExpiryType.ACCESSED, accessExpiry)
- .setExpiry(CacheConfiguration.ExpiryType.MODIFIED, modifiedExpiry)
- .build();
-
- }
-
-
- /**
- * Get Cache expiry time upon access in minutes.
- *
- * @return integer denoting number of minutes.
- */
- public abstract int getCacheAccessExpiryMinutes();
-
- /**
- * Get Cache expiry time upon modification in minutes.
- *
- * @return integer denoting number of minutes.
- */
- public abstract int getCacheModifiedExpiryMinutes();
-
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCacheKey.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCacheKey.java
deleted file mode 100644
index b6ca634d..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/caching/OpenBankingBaseCacheKey.java
+++ /dev/null
@@ -1,38 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.common.caching;
-
-/**
- * Abstract class for Open Banking Cache Key.
- */
-public class OpenBankingBaseCacheKey {
-
- public OpenBankingBaseCacheKey() {
-
- }
-
- public OpenBankingBaseCacheKey(String cacheKey) {
-
- }
-
- public static OpenBankingBaseCacheKey of(String cacheKey) {
- return new OpenBankingBaseCacheKey(cacheKey);
- }
-
-}
diff --git a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java b/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java
deleted file mode 100644
index 32486797..00000000
--- a/open-banking-accelerator/components/com.wso2.openbanking.accelerator.common/src/main/java/com/wso2/openbanking/accelerator/common/config/OpenBankingConfigParser.java
+++ /dev/null
@@ -1,1483 +0,0 @@
-/**
- * Copyright (c) 2023, WSO2 LLC. (https://www.wso2.com).
- *
- * WSO2 LLC. 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 com.wso2.openbanking.accelerator.common.config;
-
-import com.wso2.openbanking.accelerator.common.constant.OpenBankingConstants;
-import com.wso2.openbanking.accelerator.common.exception.OpenBankingRuntimeException;
-import com.wso2.openbanking.accelerator.common.util.CarbonUtils;
-import edu.umd.cs.findbugs.annotations.SuppressFBWarnings;
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
-import org.apache.axiom.om.impl.builder.StAXOMBuilder;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.wso2.securevault.SecretResolver;
-import org.wso2.securevault.SecretResolverFactory;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.LinkedHashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.Stack;
-import java.util.stream.Collectors;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-
-import static java.util.Map.Entry.comparingByKey;
-
-/**
- * Config parser for open-banking.xml.
- */
-public class OpenBankingConfigParser {
-
- // To enable attempted thread-safety using double-check locking
- private static final Object lock = new Object();
- private static final Log log = LogFactory.getLog(OpenBankingConfigParser.class);
- private static final Map configuration = new HashMap<>();
- private static final Map> obExecutors = new HashMap<>();
- private static final Map> dataPublishingStreams = new HashMap<>();
- private static final Map> dataPublishingValidationMap = new HashMap<>();
- private static final Map> dcrRegistrationConfigs = new HashMap<>();
- private static final Map> authorizeSteps = new HashMap<>();
- private static final Map> allowedScopes = new HashMap<>();
- private static final Map> allowedAPIs = new HashMap<>();
- private static final Map revocationValidators = new HashMap<>();
- private static final List serviceActivatorSubscribers = new ArrayList<>();
- private static final Map> keyManagerAdditionalProperties
- = new HashMap<>();
- private static Map obEventExecutors = new HashMap<>();
- private static OpenBankingConfigParser parser;
- private static String configFilePath;
- private static SecretResolver secretResolver;
- private OMElement rootElement;
-
- private Map authWorkerConfig = new HashMap<>();
-
- /**
- * Private Constructor of config parser.
- */
- private OpenBankingConfigParser() {
-
- buildConfiguration();
- }
-
- /**
- * Singleton getInstance method to create only one object.
- *
- * @return OpenBankingConfigParser object
- */
- public static OpenBankingConfigParser getInstance() {
-
- if (parser == null) {
- synchronized (lock) {
- if (parser == null) {
- parser = new OpenBankingConfigParser();
- }
- }
- }
- return parser;
- }
-
- /**
- * Method to get an instance of ConfigParser when custom file path is provided.
- *
- * This method is deprecated as it allows custom absolute file paths which could result in
- * path traversal attacks. Do not use this method unless the custom path is trusted.
- *
- * @param filePath Custom file path
- * @return OpenBankingConfigParser object
- * @Deprecated use OpenBankingConfigParser.getInstance()
- */
- @Deprecated
- public static OpenBankingConfigParser getInstance(String filePath) {
-
- configFilePath = filePath;
- return getInstance();
- }
-
- /**
- * Method to obtain map of configs.
- *
- * @return Config map
- */
- public Map getConfiguration() {
-
- return configuration;
- }
-
- /**
- * Method to read the configuration (in a recursive manner) as a model and put them in the configuration map.
- */
- @SuppressFBWarnings("PATH_TRAVERSAL_IN")
- // Suppressed content - new FileInputStream(configFilePath)
- // Suppression reason - False Positive : Method for passing configFilePath is deprecated and is used for testing
- // purposes only. Therefore, it can be assumed that configFilePath is a trusted filepath
- // Suppressed warning count - 1
- private void buildConfiguration() {
-
- InputStream inStream = null;
- StAXOMBuilder builder;
- String warningMessage = "";
- try {
- if (configFilePath != null) {
- File openBankingConfigXml = new File(configFilePath);
- if (openBankingConfigXml.exists()) {
- inStream = new FileInputStream(openBankingConfigXml);
- }
- } else {
- File openBankingConfigXml = new File(CarbonUtils.getCarbonConfigDirPath(),
- OpenBankingConstants.OB_CONFIG_FILE);
- if (openBankingConfigXml.exists()) {
- inStream = new FileInputStream(openBankingConfigXml);
- }
- }
- if (inStream == null) {
- String message =
- "open-banking configuration not found at: " + configFilePath + " . Cause - " + warningMessage;
- if (log.isDebugEnabled()) {
- log.debug(message.replaceAll("[\r\n]", ""));
- }
- throw new FileNotFoundException(message);
- }
- builder = new StAXOMBuilder(inStream);
- builder.setDoDebug(false);
- rootElement = builder.getDocumentElement();
- Stack nameStack = new Stack<>();
- secretResolver = SecretResolverFactory.create(rootElement, true);
- readChildElements(rootElement, nameStack);
- buildOBExecutors();
- buildDataPublishingStreams();
- buildDCRParameters();
- buildConsentAuthSteps();
- buildAllowedScopes();
- buildAllowedSubscriptions();
- buildServiceActivatorSubscribers();
- buildKeyManagerProperties();
- buildOBEventExecutors();
- buildWorkers();
- } catch (IOException | XMLStreamException | OMException e) {
- throw new OpenBankingRuntimeException("Error occurred while building configuration from open-banking.xml",
- e);
- } finally {
- try {
- if (inStream != null) {
- inStream.close();
- }
- } catch (IOException e) {
- log.error("Error closing the input stream for open-banking.xml", e);
- }
- }
- }
-
- private void buildOBExecutors() {
-
- OMElement gatewayElement = rootElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.GATEWAY_CONFIG_TAG));
-
- if (gatewayElement != null) {
-
- OMElement openBankingGatewayExecutors = gatewayElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.GATEWAY_EXECUTOR_CONFIG_TAG));
-
- if (openBankingGatewayExecutors != null) {
- //obtaining each consent type element under OpenBankingGatewayExecutors tag
- Iterator consentTypeElement = openBankingGatewayExecutors.getChildElements();
- while (consentTypeElement.hasNext()) {
- OMElement consentType = (OMElement) consentTypeElement.next();
- String consentTypeName = consentType.getLocalName();
- Map executors = new HashMap<>();
- //obtaining each Executor element under each consent type
- Iterator obExecutor = consentType.getChildrenWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.EXECUTOR_CONFIG_TAG));
- if (obExecutor != null) {
- while (obExecutor.hasNext()) {
- OMElement executorElement = obExecutor.next();
- //Retrieve class name and priority from executor config
- String obExecutorClass = executorElement.getAttributeValue(new QName("class"));
- String obExecutorPriority = executorElement.getAttributeValue(new QName("priority"));
-
- if (StringUtils.isEmpty(obExecutorClass)) {
- //Throwing exceptions since we cannot proceed without invalid executor names
- throw new OpenBankingRuntimeException("Executor class is not defined " +
- "correctly in open-banking.xml");
- }
- int priority = Integer.MAX_VALUE;
- if (!StringUtils.isEmpty(obExecutorPriority)) {
- priority = Integer.parseInt(obExecutorPriority);
- }
- executors.put(priority, obExecutorClass);
- }
- }
- //Ordering the executors based on the priority number
- LinkedHashMap priorityMap = executors.entrySet()
- .stream()
- .sorted(comparingByKey())
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
- LinkedHashMap::new));
- obExecutors.put(consentTypeName, priorityMap);
- }
- }
- }
- }
-
- protected void buildKeyManagerProperties() {
-
- OMElement keyManagerElement = rootElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.KEY_MANAGER_CONFIG_TAG));
-
- if (keyManagerElement != null) {
- OMElement keyManagerProperties = keyManagerElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.KEY_MANAGER_ADDITIONAL_PROPERTIES_CONFIG_TAG));
-
- if (keyManagerProperties != null) {
- Iterator properties = keyManagerProperties.getChildrenWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.PROPERTY_CONFIG_TAG));
- if (properties != null) {
- while (properties.hasNext()) {
- OMElement propertyElement = properties.next();
-
- //Retrieve attributes from key manager config
- Map property = new HashMap<>();
- property.put("priority", propertyElement.getAttributeValue(new QName("priority")));
- property.put("label", propertyElement.getAttributeValue(new QName("label")));
- property.put("type", propertyElement.getAttributeValue(new QName("type")));
- property.put("tooltip", propertyElement.getAttributeValue(new QName("tooltip")));
- property.put("default", propertyElement.getAttributeValue(new QName("default")));
- property.put("required", propertyElement.getAttributeValue(new QName("required")));
- property.put("mask", propertyElement.getAttributeValue(new QName("mask")));
- property.put("multiple", propertyElement.getAttributeValue(new QName("multiple")));
- property.put("values", propertyElement.getAttributeValue(new QName("values")));
- String propertyName = propertyElement.getAttributeValue(new QName("name"));
-
- if (StringUtils.isBlank(propertyName)) {
- //Throwing exceptions since we cannot proceed without property names
- throw new OpenBankingRuntimeException("Additional property name is not defined " +
- "correctly in open-banking.xml");
- }
-
- keyManagerAdditionalProperties.put(propertyName, property);
- }
- }
- }
- }
- }
-
- protected void buildDataPublishingStreams() {
-
- OMElement dataPublishingElement = rootElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.DATA_PUBLISHING_CONFIG_TAG));
-
- if (dataPublishingElement != null) {
- OMElement thriftElement = dataPublishingElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.THRIFT_CONFIG_TAG));
-
- if (thriftElement != null) {
- OMElement streams = thriftElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.STREAMS_CONFIG_TAG));
-
- if (streams != null) {
- Iterator dataStreamElement = streams.getChildElements();
- while (dataStreamElement.hasNext()) {
- OMElement dataStream = (OMElement) dataStreamElement.next();
- String dataStreamName = dataStream.getLocalName();
- Map attributes = new HashMap<>();
- //obtaining attributes under each stream
- Iterator attribute = dataStream.getChildrenWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.ATTRIBUTE_CONFIG_TAG));
- if (attribute != null) {
- while (attribute.hasNext()) {
- OMElement attributeElement = attribute.next();
- //Retrieve attribute name and priority from config
- String attributeName = attributeElement.getAttributeValue(new QName("name"));
- String attributePriority = attributeElement.getAttributeValue(new QName("priority"));
- String isRequired = attributeElement.getAttributeValue(new QName("required"));
- String type = attributeElement.getAttributeValue(new QName("type"));
-
- if (StringUtils.isEmpty(attributeName)) {
- //Throwing exceptions since we cannot proceed without valid attribute names
- throw new OpenBankingRuntimeException(
- "Data publishing attribute name is not defined " +
- "correctly in open-banking.xml");
- }
- int priority = Integer.MAX_VALUE;
- if (!StringUtils.isEmpty(attributePriority)) {
- priority = Integer.parseInt(attributePriority);
- }
- boolean required = false;
- if (!StringUtils.isEmpty(isRequired)) {
- required = Boolean.parseBoolean(isRequired);
- }
-
- String attributeType = "string";
- if (!StringUtils.isEmpty(type)) {
- attributeType = type;
- }
-
- Map metadata = new HashMap<>();
- metadata.put(OpenBankingConstants.REQUIRED, required);
- metadata.put(OpenBankingConstants.ATTRIBUTE_TYPE, attributeType);
-
- attributes.put(priority, attributeName);
- String attributeKey = dataStreamName + "_" + attributeName;
- dataPublishingValidationMap.put(attributeKey, metadata);
- }
- }
- //Ordering the attributes based on the priority number
- LinkedHashMap priorityMap = attributes.entrySet()
- .stream()
- .sorted(comparingByKey())
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
- LinkedHashMap::new));
- dataPublishingStreams.put(dataStreamName, priorityMap);
- }
- }
- }
- }
- }
-
- private void buildDCRParameters() {
-
- OMElement dcrElement = rootElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.DCR_CONFIG_TAG));
-
- if (dcrElement != null) {
- OMElement registrationElement = dcrElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.DCR_REGISTRATION_CONFIG_TAG));
-
- if (registrationElement != null) {
- //obtaining each parameter type element under RegistrationRequestPrams tag
- Iterator parameterTypeElement = registrationElement.getChildElements();
- while (parameterTypeElement.hasNext()) {
- OMElement parameterType = (OMElement) parameterTypeElement.next();
- String parameterTypeName = parameterType.getLocalName();
- Map parameterValues = new HashMap<>();
- //obtaining each element under each parameter type
- Iterator childValues = parameterType.getChildElements();
- while (childValues.hasNext()) {
- OMElement child = (OMElement) childValues.next();
- if (OpenBankingConstants.DCR_REGISTRATION_PARAM_ALLOWED_VALUE_TAG
- .equalsIgnoreCase(child.getLocalName())) {
-
- OMElement allowedValuesElement = parameterType.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.DCR_REGISTRATION_PARAM_ALLOWED_VALUE_TAG));
-
- List values = new ArrayList<>();
- if (allowedValuesElement != null) {
- Iterator allowedValues = allowedValuesElement.getChildElements();
- while (allowedValues.hasNext()) {
- OMElement value = (OMElement) allowedValues.next();
- values.add(value.getText());
- }
- parameterValues.put(child.getLocalName(), values);
- }
- } else {
- parameterValues.put(child.getLocalName(), child.getText());
- }
- }
- dcrRegistrationConfigs.put(parameterTypeName, parameterValues);
- }
- }
- }
-
- }
-
- private void buildConsentAuthSteps() {
-
- OMElement consentElement = rootElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.CONSENT_CONFIG_TAG));
-
- if (consentElement != null) {
- OMElement consentAuthorizeSteps = consentElement.getFirstChildWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME,
- OpenBankingConstants.AUTHORIZE_STEPS_CONFIG_TAG));
-
- if (consentAuthorizeSteps != null) {
- //obtaining each step type element under AuthorizeSteps tag
- Iterator stepTypeElement = consentAuthorizeSteps.getChildElements();
- while (stepTypeElement.hasNext()) {
- OMElement stepType = (OMElement) stepTypeElement.next();
- String consentTypeName = stepType.getLocalName();
- Map executors = new HashMap<>();
- //obtaining each step under each consent type
- Iterator obExecutor = stepType.getChildrenWithName(
- new QName(OpenBankingConstants.OB_CONFIG_QNAME, OpenBankingConstants.STEP_CONFIG_TAG));
- if (obExecutor != null) {
- while (obExecutor.hasNext()) {
- OMElement executorElement = obExecutor.next();
- //Retrieve class name and priority from executor config
- String obExecutorClass = executorElement.getAttributeValue(new QName("class"));
- String obExecutorPriority = executorElement.getAttributeValue(new QName("priority"));
-
- if (StringUtils.isEmpty(obExecutorClass)) {
- //Throwing exceptions since we cannot proceed without invalid executor names
- throw new OpenBankingRuntimeException("Executor class is not defined " +
- "correctly in open-banking.xml");
- }
- int priority = Integer.MAX_VALUE;
- if (!StringUtils.isEmpty(obExecutorPriority)) {
- priority = Integer.parseInt(obExecutorPriority);
- }
- executors.put(priority, obExecutorClass);
- }
- }
- //Ordering the executors based on the priority number
- LinkedHashMap priorityMap = executors.entrySet()
- .stream()
- .sorted(comparingByKey())
- .collect(Collectors.toMap(Map.Entry::getKey, Map.Entry::getValue, (e1, e2) -> e2,
- LinkedHashMap::new));
- authorizeSteps.put(consentTypeName, priorityMap);
- }
- }
- }
- }
-
- /**
- * Method to read text configs from xml when root element is given.
- *
- * @param serverConfig XML root element object
- * @param nameStack stack of config names
- */
- private void readChildElements(OMElement serverConfig, Stack nameStack) {
-
- for (Iterator childElements = serverConfig.getChildElements(); childElements.hasNext(); ) {
- OMElement element = (OMElement) childElements.next();
- nameStack.push(element.getLocalName());
- if (elementHasText(element)) {
- String key = getKey(nameStack);
- Object currentObject = configuration.get(key);
- String value = replaceSystemProperty(element.getText());
- if (secretResolver != null && secretResolver.isInitialized() &&
- secretResolver.isTokenProtected(key)) {
- value = secretResolver.resolve(key);
- }
- if (currentObject == null) {
- configuration.put(key, value);
- } else if (currentObject instanceof ArrayList) {
- ArrayList list = (ArrayList) currentObject;
- if (!list.contains(value)) {
- list.add(value);
- configuration.put(key, list);
- }
- } else {
- if (!value.equals(currentObject)) {
- ArrayList