Skip to content

Commit

Permalink
Merge pull request #40 from imesh94/fix/secondary-user-config
Browse files Browse the repository at this point in the history
Improvements to secondary user scenarios
  • Loading branch information
Akila94 authored Nov 8, 2024
2 parents 6466678 + 167a125 commit e4d3d74
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -670,6 +670,23 @@ public boolean getSecondaryUserAccountsEnabled() {
}
}

/**
* Get secondary user accounts selectable without account metadata status.
* This indicates whether the secondary user accounts can be selected when there is no account metadata
* available for the given account and user combination.
*
* @return boolean
*/
public boolean isSecondaryAccountsSelectableWithoutAccountMetadata() {

Object config = getConfigElementFromKey(CommonConstants.SELECTABLE_WITHOUT_ACCOUNT_METADATA);
if (config != null) {
return Boolean.parseBoolean((String) config);
} else {
return false;
}
}

/**
* Get Disclosure Options Management enabled status.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public class CommonConstants {

// Secondary user account config constants
public static final String SECONDARY_USER_ACCOUNTS_ENABLED = "SecondaryUserAccounts.Enable";
public static final String SELECTABLE_WITHOUT_ACCOUNT_METADATA =
"SecondaryUserAccounts.SelectableWithoutAccountMetadata";

// Disclosure Options Management config constants
public static final String DISCLOSURE_OPTIONS_MANAGEMENT_ENABLED = "DisclosureOptionsManagement.Enable";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,13 @@ public void testIsSecondaryAccountsEnabled() {
Assert.assertTrue(openBankingCDSConfigParser.getSecondaryUserAccountsEnabled());
}

@Test(priority = 8)
public void testIsSecondaryAccountsSelectableWithoutAccountMetadata() {
String dummyConfigFile = absolutePathForTestResources + "/open-banking-cds.xml";
OpenBankingCDSConfigParser openBankingCDSConfigParser = OpenBankingCDSConfigParser.getInstance(dummyConfigFile);
Assert.assertFalse(openBankingCDSConfigParser.isSecondaryAccountsSelectableWithoutAccountMetadata());
}

@Test(priority = 8)
public void testIsCeasingSecondaryUserSharingEnabled() {
String dummyConfigFile = absolutePathForTestResources + "/open-banking-cds.xml";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@
</BNR>
<SecondaryUserAccounts>
<Enable>true</Enable>
<SelectableWithoutAccountMetadata>false</SelectableWithoutAccountMetadata>
<CeasingSecondaryUserSharingEnabled>true</CeasingSecondaryUserSharingEnabled>
</SecondaryUserAccounts>
<DisclosureOptionsManagement>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ public void execute(ConsentPersistData consentPersistData) throws ConsentExcepti
// bind user consented non-primary accounts with the created consent
bindNonPrimaryAccountsToConsentWithGivenPermissions(consentCoreService, consentResource,
consentData, nonPrimaryAccountIDsMapWithPermissions);

} else if (!nonPrimaryAccountIDsMapWithPermissions.isEmpty()) {
// bind user consented non-primary accounts with the created consent
bindNonPrimaryAccountsToConsentWithGivenPermissions(consentCoreService, consentResource,
consentData, nonPrimaryAccountIDsMapWithPermissions);

} else {
// case where no specific non-primary account permissions provided
bindUserAccountsToConsent(consentCoreService, consentResource, consentData, accountIdList);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import com.wso2.openbanking.accelerator.consent.extensions.common.ResponseStatus;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.wso2.openbanking.cds.common.config.OpenBankingCDSConfigParser;
import org.wso2.openbanking.cds.consent.extensions.common.CDSConsentExtensionConstants;
import org.wso2.openbanking.cds.consent.extensions.validate.utils.CDSConsentValidatorUtil;

Expand All @@ -38,6 +39,7 @@ public class CDSConsentExtensionsUtil {

private static final Log log = LogFactory.getLog(CDSConsentValidatorUtil.class);
private static AccountMetadataService accountMetadataService = AccountMetadataServiceImpl.getInstance();
private static OpenBankingCDSConfigParser cdsConfigParser = OpenBankingCDSConfigParser.getInstance();

/**
* Get secondary user instruction data.
Expand All @@ -57,7 +59,7 @@ public static Boolean isUserEligibleForSecondaryAccountDataSharing(String accoun
return CDSConsentExtensionConstants.ACTIVE_STATUS
.equalsIgnoreCase(accountMetadata.get(CDSConsentExtensionConstants.INSTRUCTION_STATUS));
} else {
return false;
return cdsConfigParser.isSecondaryAccountsSelectableWithoutAccountMetadata();
}
} catch (OpenBankingException e) {
log.error("Error occurred while retrieving account metadata for account id : " + accountId, e);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,11 @@
{% else %}
<Enable>false</Enable>
{% endif %}
{% if open_banking_cds.secondary_user_accounts.selectable_without_account_metadata is defined %}
<SelectableWithoutAccountMetadata>{{open_banking_cds.secondary_user_accounts.selectable_without_account_metadata}}</SelectableWithoutAccountMetadata>
{% else %}
<SelectableWithoutAccountMetadata>false</SelectableWithoutAccountMetadata>
{% endif %}
{% if open_banking_cds.secondary_user_accounts.ceasing_secondary_user_sharing_enable is defined %}
<CeasingSecondaryUserSharingEnabled>{{open_banking_cds.secondary_user_accounts.ceasing_secondary_user_sharing_enable}}</CeasingSecondaryUserSharingEnabled>
{% else %}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -961,6 +961,7 @@ validate_accounts_on_retrieval=true

[open_banking_cds.secondary_user_accounts]
enable = true
selectable_without_account_metadata = false
ceasing_secondary_user_sharing_enable = true

[open_banking_cds.disclosure_options_management]
Expand Down

0 comments on commit e4d3d74

Please sign in to comment.