Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support storing multiple mobile numbers and email addresses per user #857

Merged
merged 59 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
59 commits
Select commit Hold shift + click to select a range
a6f6325
support multiple mobile numbers per user
lashinijay Apr 19, 2024
d97eaab
support multiple mobile numbers per user
lashinijay Apr 19, 2024
3968a6a
add method descriptions
lashinijay Apr 24, 2024
f52b461
fix validation when mobile number update on verification is turned off
lashinijay Apr 29, 2024
5e09068
fix validation when mobile number update on verification is turned off
lashinijay May 20, 2024
2811945
add multiple email addresses and verified email addresses per user su…
lashinijay May 29, 2024
63e822d
fix the logic for when verification on update is disabled
lashinijay May 29, 2024
b5ab7c7
fix imports
lashinijay May 29, 2024
e79adba
Merge branch 'refs/heads/support-multiple-email-addresses' into mulit…
lashinijay May 30, 2024
d63a79b
improvements for support multiple mobile numbers and email address co…
lashinijay May 30, 2024
a32a375
drop email addresses and mobile numbers claim when multiple mobile an…
lashinijay May 30, 2024
5cc6909
logic improvements
lashinijay May 30, 2024
4c19b27
add supportMultiEmailsAndMobileNumbers config as a governance config
lashinijay Jun 3, 2024
88e24a9
code refactoring
lashinijay Jun 4, 2024
4b619b7
code refactoring
lashinijay Jun 4, 2024
b24c93c
code refactoring
lashinijay Jun 4, 2024
0afcb52
address comments
lashinijay Jun 6, 2024
caa6430
address comments
lashinijay Jun 4, 2024
ad92924
update unit tests
lashinijay Jun 6, 2024
a633496
Update components/org.wso2.carbon.identity.recovery/src/test/java/org…
lashinijay Jun 6, 2024
d8f0d29
fix deleting primary email address and mobile number flow
lashinijay Jul 8, 2024
d11d300
Merge master
PasinduYeshan Sep 10, 2024
852bc40
Add mobile number verification handler tests.
PasinduYeshan Sep 12, 2024
8478c07
Add mobile number verification handler tests.
PasinduYeshan Sep 12, 2024
233f288
Remove governance config and get it from IdentityUtil.
PasinduYeshan Sep 12, 2024
6fbbd8c
Change utils methods and add unit tests for tests.
PasinduYeshan Sep 12, 2024
8deef4a
Change util methods.
PasinduYeshan Sep 12, 2024
f5705ed
Fix requiring multi attribute claims in normal flow issue in mobile v…
PasinduYeshan Sep 14, 2024
e6bbcc6
Change logic to automatically add primary to all numbers list when ve…
PasinduYeshan Sep 14, 2024
5041a4a
Change email update logic and refactor code - add few todos.
PasinduYeshan Sep 15, 2024
05dc2de
Add user email verification handler test
PasinduYeshan Sep 18, 2024
a81c82e
Add missing user email verification handler test cases.
PasinduYeshan Sep 18, 2024
d6a5683
Add connector config update tests
PasinduYeshan Sep 18, 2024
2e56b75
Rename test variables.
PasinduYeshan Sep 18, 2024
5ce0934
Refactor Test Class with Annotations.
PasinduYeshan Sep 18, 2024
ef46d0a
Add unit tests - UserSelfRegistrationManager
PasinduYeshan Sep 19, 2024
64af0f5
Fix issues in multi email mobile scenarios.
PasinduYeshan Sep 21, 2024
81568b9
Add more unit tests.
PasinduYeshan Sep 21, 2024
f1a6daf
Add more unit tests for Utils.
PasinduYeshan Sep 22, 2024
5be64f3
Add more unit tests for Utils.
PasinduYeshan Sep 23, 2024
f3a49a1
Add more unit tests for UserSelfRegistrationManager
PasinduYeshan Sep 24, 2024
35ad822
Add more unit tests for UserSelfRegistrationManager, Utils
PasinduYeshan Sep 26, 2024
09c229d
Add more unit tests for UserEmailVerificationHandler
PasinduYeshan Sep 26, 2024
10bf7cc
Add more unit tests for MobileNumberVerificationHandler
PasinduYeshan Sep 26, 2024
0eb3a2d
Refactor code
PasinduYeshan Sep 27, 2024
0ade20a
Introduce ON_VERIFIED_LIST_UPDATE recovery scenarios to handle verifi…
PasinduYeshan Sep 30, 2024
88e1bd4
Update unit tests to cover new recovery scenarios.
PasinduYeshan Sep 30, 2024
5b45640
Add unit tests for ResendConfirmationManager.
PasinduYeshan Sep 30, 2024
0188c6d
Add unit tests for JDBCRecoveryDataStore.
PasinduYeshan Oct 1, 2024
89ed1b1
Add more unit tests.
PasinduYeshan Oct 1, 2024
97d5614
Refine unit tests.
PasinduYeshan Oct 1, 2024
744c4e8
Refine unit tests.
PasinduYeshan Oct 2, 2024
0c1a4da
Merge branch 'master' into feature/icrc
PasinduYeshan Oct 2, 2024
c0c2343
Add missing theadlocal logic.
PasinduYeshan Oct 2, 2024
4254b8f
Merge remote-tracking branch 'origin/feature/icrc' into feature/icrc
PasinduYeshan Oct 2, 2024
6943e3c
Refactor code.
PasinduYeshan Oct 2, 2024
4a4d010
Change SMS notification handler.
PasinduYeshan Oct 3, 2024
0f770f0
Merge master
PasinduYeshan Oct 8, 2024
1929c98
Change SMS notification handler to local.
PasinduYeshan Oct 8, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,9 @@ private String getRecoveryScenarioFromProperties(List<PropertyDTO> propertyDTOS)
RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_EMAIL_LINK.toString().equals(recoveryScenario) ||
RecoveryScenarios.ADMIN_FORCED_PASSWORD_RESET_VIA_OTP.toString().equals(recoveryScenario) ||
RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) ||
RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario)) {
RecoveryScenarios.EMAIL_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario) ||
RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) ||
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario)) {
return recoveryScenario;
}

Expand All @@ -293,7 +295,8 @@ private NotificationResponseBean doResendConfirmationCode(String recoveryScenari

UserRecoveryData userRecoveryData = null;
// Currently this me/resend-code API supports resend code during mobile verification scenario only.
if (RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario)) {
if (RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) ||
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario)) {
userRecoveryData = Utils.getUserRecoveryData(resendCodeRequestDTO, recoveryScenario);
}
if (userRecoveryData == null) {
Expand All @@ -312,6 +315,18 @@ private NotificationResponseBean doResendConfirmationCode(String recoveryScenari
resendCodeRequestDTO);
}

if (RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario) &&
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE
.equals(userRecoveryData.getRecoveryScenario()) &&
RecoverySteps.VERIFY_MOBILE_NUMBER.equals(userRecoveryData.getRecoveryStep())) {

notificationResponseBean = setNotificationResponseBean(resendConfirmationManager,
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString(),
RecoverySteps.VERIFY_MOBILE_NUMBER.toString(),
IdentityRecoveryConstants.NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE,
resendCodeRequestDTO);
}

return notificationResponseBean;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,13 +187,29 @@ private NotificationResponseBean doResendConfirmationCode(String recoveryScenari
notificationResponseBean = setNotificationResponseBean(resendConfirmationManager,
RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE.toString(), RecoverySteps.VERIFY_EMAIL.toString(),
IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_VERIFY_EMAIL_ON_UPDATE, resendCodeRequestDTO);
} else if (RecoveryScenarios.EMAIL_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario) &&
RecoveryScenarios.EMAIL_VERIFICATION_ON_VERIFIED_LIST_UPDATE
.equals(userRecoveryData.getRecoveryScenario()) &&
RecoverySteps.VERIFY_EMAIL.equals(userRecoveryData.getRecoveryStep())) {
notificationResponseBean = setNotificationResponseBean(resendConfirmationManager,
RecoveryScenarios.EMAIL_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString(),
RecoverySteps.VERIFY_EMAIL.toString(),
IdentityRecoveryConstants.NOTIFICATION_TYPE_RESEND_VERIFY_EMAIL_ON_UPDATE, resendCodeRequestDTO);
} else if (RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString().equals(recoveryScenario) &&
RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.equals(userRecoveryData.getRecoveryScenario()) &&
RecoverySteps.VERIFY_MOBILE_NUMBER.equals(userRecoveryData.getRecoveryStep())) {
notificationResponseBean = setNotificationResponseBean(resendConfirmationManager,
RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.toString(),
RecoverySteps.VERIFY_MOBILE_NUMBER.toString(),
IdentityRecoveryConstants.NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE, resendCodeRequestDTO);
} else if (RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString().equals(recoveryScenario) &&
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE
.equals(userRecoveryData.getRecoveryScenario()) &&
RecoverySteps.VERIFY_MOBILE_NUMBER.equals(userRecoveryData.getRecoveryStep())) {
notificationResponseBean = setNotificationResponseBean(resendConfirmationManager,
RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE.toString(),
RecoverySteps.VERIFY_MOBILE_NUMBER.toString(),
IdentityRecoveryConstants.NOTIFICATION_TYPE_VERIFY_MOBILE_ON_UPDATE, resendCodeRequestDTO);
}

return notificationResponseBean;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import org.mockito.MockitoAnnotations;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Test;
import org.wso2.carbon.base.CarbonBaseConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
Expand Down Expand Up @@ -165,23 +166,68 @@ public void testMeResendCodePost() throws IdentityRecoveryException {
Mockito.when(userRecoveryData.getRecoveryStep()).thenReturn(
RecoverySteps.getRecoveryStep("VERIFY_MOBILE_NUMBER"));

assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 201);
assertEquals(meApiService.meResendCodePost(
meResendCodeRequestDTO(RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.name())).getStatus(),
201);

assertEquals(meApiService.meResendCodePost(
meResendCodeRequestDTOWithInvalidScenarioProperty()).getStatus(), 400);

mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString()))
.thenReturn(null);
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
assertEquals(meApiService.meResendCodePost(
meResendCodeRequestDTO(RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.name())).getStatus(),
400);

Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(RecoveryScenarios.
getRecoveryScenario("ASK_PASSWORD"));
assertEquals(meApiService.meResendCodePost(meResendCodeRequestDTO()).getStatus(), 400);
assertEquals(meApiService.meResendCodePost(
meResendCodeRequestDTO(RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE.name())).getStatus(),
400);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}

@DataProvider(name = "recoveryScenarioProvider")
public Object[][] recoveryScenarioProvider() {
return new Object[][] {
{RecoveryScenarios.EMAIL_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_EMAIL, 400},
{RecoveryScenarios.EMAIL_VERIFICATION_ON_VERIFIED_LIST_UPDATE, RecoverySteps.VERIFY_EMAIL, 400},
{RecoveryScenarios.MOBILE_VERIFICATION_ON_UPDATE, RecoverySteps.VERIFY_MOBILE_NUMBER, 201},
{RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE,
RecoverySteps.VERIFY_MOBILE_NUMBER, 201},
{RecoveryScenarios.MOBILE_VERIFICATION_ON_VERIFIED_LIST_UPDATE, RecoverySteps.VERIFY_MOBILE_NUMBER, 201}
};
}

@Test(dataProvider = "recoveryScenarioProvider")
public void testMeResendCodePostRecoveryScenarios(RecoveryScenarios recoveryScenario, RecoverySteps recoveryStep,
int expectedStatusCode) throws IdentityRecoveryException {

try {
String carbonHome = Paths.get(System.getProperty("user.dir"), "src", "test", "resources").toString();
System.setProperty(CarbonBaseConstants.CARBON_HOME, carbonHome);
PrivilegedCarbonContext.startTenantFlow();
PrivilegedCarbonContext.getThreadLocalCarbonContext().setUsername(USERNAME);
PrivilegedCarbonContext.getThreadLocalCarbonContext().setTenantId(-1234);
Mockito.when(resendConfirmationManager.resendConfirmationCode(isNull(), anyString(), anyString(),
anyString(), isNull())).thenReturn(notificationResponseBean);
mockedUtils.when(() -> Utils.getUserRecoveryData(any(ResendCodeRequestDTO.class), anyString()))
.thenReturn(userRecoveryData);
mockedUtils.when(Utils::getResendConfirmationManager).thenReturn(resendConfirmationManager);
Mockito.when(userRecoveryData.getRecoveryScenario()).thenReturn(recoveryScenario);
Mockito.when(userRecoveryData.getRecoveryStep()).thenReturn(recoveryStep);

assertEquals(meApiService.meResendCodePost(
meResendCodeRequestDTO(recoveryScenario.name())).getStatus(),
expectedStatusCode);
} finally {
PrivilegedCarbonContext.endTenantFlow();
}
}

private SelfRegistrationUserDTO buildSelfRegistartion() {
private SelfRegistrationUserDTO buildSelfRegistration() {

SelfRegistrationUserDTO selfRegistrationUserDTO = new SelfRegistrationUserDTO();
selfRegistrationUserDTO.setUsername("TestUser");
Expand Down Expand Up @@ -212,11 +258,11 @@ private SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO() {
SelfUserRegistrationRequestDTO selfUserRegistrationRequestDTO = new SelfUserRegistrationRequestDTO();
List<ClaimDTO> listClaimDTO = new ArrayList<>();
listClaimDTO.add(buildClaimDTO());
buildSelfRegistartion().setClaims(listClaimDTO);
buildSelfRegistration().setClaims(listClaimDTO);
List<PropertyDTO> listPropertyDTOs = new ArrayList<>();
listPropertyDTOs.add(buildSelfUserRegistrationRequestDTO());
selfUserRegistrationRequestDTO.setProperties(listPropertyDTOs);
selfUserRegistrationRequestDTO.setUser(buildSelfRegistartion());
selfUserRegistrationRequestDTO.setUser(buildSelfRegistration());
return selfUserRegistrationRequestDTO;
}

Expand All @@ -227,11 +273,11 @@ private MeCodeValidationRequestDTO createMeCodeValidationRequestDTO() {
return codeValidationRequestDTO;
}

private MeResendCodeRequestDTO meResendCodeRequestDTO() {
private MeResendCodeRequestDTO meResendCodeRequestDTO(String recoveryScenario) {

MeResendCodeRequestDTO meResendCodeRequestDTO = new MeResendCodeRequestDTO();
List<PropertyDTO> listProperty = new ArrayList<>();
listProperty.add(buildPropertyDTO("RecoveryScenario", "MOBILE_VERIFICATION_ON_UPDATE"));
listProperty.add(buildPropertyDTO("RecoveryScenario", recoveryScenario));
meResendCodeRequestDTO.setProperties(listProperty);
return meResendCodeRequestDTO;
}
Expand Down
Loading
Loading