From a941e04f05f1bbf3a9d7235a3fa54b6bfd4ee866 Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Sun, 19 Jan 2025 20:31:21 +0530 Subject: [PATCH 1/4] govern shared profile update based on SharedProfileValueResolvingMethod value --- .../pom.xml | 6 +- .../OrganizationUserSharingDataHolder.java | 25 ++- ...ganizationUserSharingServiceComponent.java | 22 ++- ...rProfileUpdateGovernanceEventListener.java | 186 ++++++++++++++++++ pom.xml | 4 +- 5 files changed, 238 insertions(+), 5 deletions(-) create mode 100644 components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharedUserProfileUpdateGovernanceEventListener.java diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml index 773512790..38fc10717 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml @@ -1,6 +1,6 @@ + + + + + + + + + + \ No newline at end of file From 5ed7b4a7a3cd920230b781d81210d5c4ed381d02 Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Mon, 20 Jan 2025 00:45:28 +0530 Subject: [PATCH 3/4] fix formatting --- .../sharing/internal/OrganizationUserSharingDataHolder.java | 1 - .../src/test/resources/testng.xml | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingDataHolder.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingDataHolder.java index 79a2ca80a..17b2574a7 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingDataHolder.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/main/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/OrganizationUserSharingDataHolder.java @@ -40,7 +40,6 @@ public class OrganizationUserSharingDataHolder { private RoleManager roleManager; private ClaimMetadataManagementService claimManagementService; - public static OrganizationUserSharingDataHolder getInstance() { return instance; diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/resources/testng.xml b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/resources/testng.xml index 59f82c567..f32857d80 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/resources/testng.xml +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/resources/testng.xml @@ -24,4 +24,4 @@ - \ No newline at end of file + From 28563694d05cb65cf3f5f135ac3a3af90ee6997c Mon Sep 17 00:00:00 2001 From: AnuradhaSK Date: Mon, 20 Jan 2025 13:31:05 +0530 Subject: [PATCH 4/4] add more test and exclude unwanted tests for jacoco report --- .../pom.xml | 7 +++++ ...fileUpdateGovernanceEventListenerTest.java | 26 +++++++++++++++++++ 2 files changed, 33 insertions(+) diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml index 38fc10717..72c546b08 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/pom.xml @@ -170,6 +170,13 @@ org.jacoco jacoco-maven-plugin ${jacoco.version} + + + org/wso2/carbon/identity/organization/management/organization/user/sharing/constant/*.class + org/wso2/carbon/identity/organization/management/organization/user/sharing/internal/*.class + org/wso2/carbon/identity/organization/management/organization/user/sharing/models/*.class + + diff --git a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharedUserProfileUpdateGovernanceEventListenerTest.java b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharedUserProfileUpdateGovernanceEventListenerTest.java index c793186c1..750bd4a70 100644 --- a/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharedUserProfileUpdateGovernanceEventListenerTest.java +++ b/components/org.wso2.carbon.identity.organization.management.organization.user.sharing/src/test/java/org/wso2/carbon/identity/organization/management/organization/user/sharing/listener/SharedUserProfileUpdateGovernanceEventListenerTest.java @@ -20,6 +20,7 @@ import org.mockito.Mock; import org.mockito.MockedStatic; +import org.mockito.Mockito; import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.DataProvider; @@ -30,6 +31,8 @@ import org.wso2.carbon.identity.claim.metadata.mgt.exception.ClaimMetadataException; import org.wso2.carbon.identity.claim.metadata.mgt.model.LocalClaim; import org.wso2.carbon.identity.claim.metadata.mgt.util.ClaimConstants; +import org.wso2.carbon.identity.core.model.IdentityEventListenerConfig; +import org.wso2.carbon.identity.core.util.IdentityUtil; import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingService; import org.wso2.carbon.identity.organization.management.organization.user.sharing.internal.OrganizationUserSharingDataHolder; import org.wso2.carbon.identity.organization.management.organization.user.sharing.models.UserAssociation; @@ -83,6 +86,8 @@ public class SharedUserProfileUpdateGovernanceEventListenerTest { OrganizationUserSharingService organizationUserSharingService; @Mock private UserStoreManager userStoreManager; + @Mock + IdentityEventListenerConfig identityEventListenerConfig; private MockedStatic organizationManagementUtilMockedStatic; MockedStatic privilegedCarbonContext; @@ -278,6 +283,27 @@ public void testDoPreSetUserClaimValueWithID(String userID, String claimURI, Str } } + @Test + public void testSharedUserProfileUpdateGovernanceEventListenerDisabledState() throws Exception { + + try (MockedStatic identityUtil = Mockito.mockStatic(IdentityUtil.class)) { + + identityUtil.when(() -> IdentityUtil.readEventListenerProperty(anyString(), anyString())) + .thenReturn(identityEventListenerConfig); + when(identityEventListenerConfig.getEnable()).thenReturn("false"); + + SharedUserProfileUpdateGovernanceEventListener sharedUserProfileUpdateGovernanceEventListener = + new SharedUserProfileUpdateGovernanceEventListener(); + assertTrue(sharedUserProfileUpdateGovernanceEventListener.doPreSetUserClaimValueWithID( + SHARED_USER_OF_USER_1_IN_L1_ORG, GIVEN_NAME_CLAIM, "John", DEFAULT_PROFILE, userStoreManager)); + + Map claimMapWithFromOriginResolvedClaim = new HashMap<>(); + claimMapWithFromOriginResolvedClaim.put(GIVEN_NAME_CLAIM, "John"); + assertTrue(sharedUserProfileUpdateGovernanceEventListener.doPreSetUserClaimValuesWithID(USER_1_IN_ROOT, + claimMapWithFromOriginResolvedClaim, DEFAULT_PROFILE, userStoreManager)); + } + } + private void setUpClaims() throws ClaimMetadataException { Map claimPropertiesWithFromOriginResolvingMethod = new HashMap<>();