Search code examples
wso2wso2-api-managerwso2-identity-server

Unable to delete Consent Purposes


I'm trying to delete a consent purpose that I created. I understand that I cannot delete a consent purpose if there are users associated with it.

I have already deleted all the users from the database, but when I print all the consents with the REST API there is a register of a user (but the database is empty).

How can I delete the user record that no longer exists in the database but is still related to consent? How can I clean all the data related with the consents? How can I revoke all the consents? Am I missing something?

WSO2 IS v5.10.0 WSO2 Doc - https://docs.wso2.com/display/IS590/apidocs/Consent-management-apis/index.html#!/operations#Consent#consentsGet

I have been trying the WSO2 REST API to solve this issue, but without success. When I try to delete a purpose with the WSO2 REST API - {"code":"CM_00079","message":"Bad Request","description":"Purpose Id: 29 is associated with one or more receipt(s)."}


Solution

  • Here you had to face this issue because of deleting users directly from the database/user store. It's not recommended to delete users directly from the database. If you use user deletion REST API/SOAP API, in addition to clearing user data from the userstore, it will invoke different user deletion pre-listeners/post-listeners and clear out the other associates/bindings to the deleting user which are stored in different tables/different DBs. Clearing the consent recipient data is such a case and there are many more (eg: deleting the user from assigned roles).

    Since you have removed the user directly from DB, the consent associated with the deleted user has not been cleared. To delete the consent data of the user, clear the records in the following tables stored in Identity DB in the same order(due to foreign key constraints):

    1. CM_SP_PURPOSE_PURPOSE_CAT_ASSC
    2. CM_SP_PURPOSE_PII_CAT_ASSOC
    3. CM_SP_PURPOSE_ASSOC
    4. CM_RECEIPT_SP_ASSOC
    5. CM_RECEIPT

    Then try the REST API request to delete the consent purpose.