mirror of
https://github.com/floci-io/floci.git
synced 2026-11-22 21:50:46 -05:00
fix(cognito): report EXTERNAL_PROVIDER status for federated users (#7553)
Federated users provisioned via the hosted UI were reported with UserStatus CONFIRMED. AWS reports EXTERNAL_PROVIDER for users that sign in with a third-party identity provider. - Set user status to EXTERNAL_PROVIDER in provisionFederatedUser - Update test assertion accordingly Closes #7545 Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> fix(cognito): preserve status of linked and permanent-password federated users Addresses qodo review: provisionFederatedUser no longer overwrites EXTERNAL_PROVIDER on linked local profiles or federated profiles that had a permanent password assigned. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> fix(cognito): track auto-provisioned status to preserve linked users on re-sign-in Use a persisted federatedAutoProvisioned flag instead of overwriting federatedProviderName, so linked profiles and permanent-password users keep their status across repeated federated sign-ins. Addresses pgermosen review. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com> test(cognito): add re-sign-in status preservation tests Covers linked profile re-sign-in and permanent-password profile re-sign-in. Addresses pgermosen review. Signed-off-by: Matheus Oliveira <matheus.6148@gmail.com>
This commit is contained in:
1 parent
cb07f9f773
commit
ad8c35888f
3 files changed
+58
-2
No files matched your search
@@ -3101,13 +3101,25 @@ public class CognitoService implements ResourceProvider {
|
||||
user.setUsername(targetUsername);
|
||||
user.setUserPoolId(userPoolId);
|
||||
user.getAttributes().put("sub", UUID.randomUUID().toString());
|
||||
user.setFederatedAutoProvisioned(true);
|
||||
}
|
||||
// Determine whether this is a linked local profile or a federated profile
|
||||
// with a permanent password before reconciliation overwrites identities.
|
||||
boolean linkedOrPermanent = existing.isPresent()
|
||||
&& (!user.isFederatedAutoProvisioned()
|
||||
|| (user.getPasswordHash() != null && !user.isTemporaryPassword()));
|
||||
user.getAttributes().putAll(mappedAttributes);
|
||||
user.setFederatedProviderName(provider.getProviderName());
|
||||
user.setFederatedSubject(subject);
|
||||
updateFederatedIdentity(user, provider, subject, issuer);
|
||||
user.setEnabled(true);
|
||||
user.setUserStatus("CONFIRMED");
|
||||
// Preserve the status of linked local profiles and of federated profiles
|
||||
// that had a permanent password assigned; only auto-provisioned passwordless
|
||||
// federated profiles get EXTERNAL_PROVIDER.
|
||||
if (!linkedOrPermanent) {
|
||||
user.setUserStatus("EXTERNAL_PROVIDER");
|
||||
user.setFederatedAutoProvisioned(true);
|
||||
}
|
||||
user.setLastModifiedDate(System.currentTimeMillis() / 1000L);
|
||||
userStore.put(userKey(userPoolId, user.getUsername()), user);
|
||||
LOG.infov("Reconciled federated user {0} from provider {1} in pool {2}",
|
||||
|
||||
@@ -37,6 +37,7 @@ public class CognitoUser {
|
||||
private boolean webAuthnMfaEnabled;
|
||||
private String federatedProviderName;
|
||||
private String federatedSubject;
|
||||
private boolean federatedAutoProvisioned;
|
||||
|
||||
public CognitoUser() {
|
||||
long now = System.currentTimeMillis() / 1000L;
|
||||
@@ -152,4 +153,9 @@ public class CognitoUser {
|
||||
public void setFederatedSubject(String federatedSubject) {
|
||||
this.federatedSubject = federatedSubject;
|
||||
}
|
||||
|
||||
public boolean isFederatedAutoProvisioned() { return federatedAutoProvisioned; }
|
||||
public void setFederatedAutoProvisioned(boolean federatedAutoProvisioned) {
|
||||
this.federatedAutoProvisioned = federatedAutoProvisioned;
|
||||
}
|
||||
}
|
||||
@@ -333,7 +333,7 @@ class CognitoFederationServiceTest {
|
||||
CognitoUser user = cognitoService.adminGetUser(pool.getId(), storedCode.userId());
|
||||
|
||||
assertEquals(pool.getId(), user.getUserPoolId());
|
||||
assertEquals("CONFIRMED", user.getUserStatus());
|
||||
assertEquals("EXTERNAL_PROVIDER", user.getUserStatus());
|
||||
assertTrue(user.isEnabled());
|
||||
assertFalse(user.getUsername().isBlank());
|
||||
assertNotNull(user.getAttributes().get("sub"));
|
||||
@@ -543,6 +543,44 @@ class CognitoFederationServiceTest {
|
||||
.noneMatch(u -> "Google_google-subject".equals(u.getUsername())));
|
||||
}
|
||||
|
||||
@Test
|
||||
void googleProvisioningPreservesLinkedUserProfileStatusOnResignIn() throws Exception {
|
||||
IdentityProvider provider = createProvider("Google", "Google", Map.of("client_id", "google-client"), Map.of());
|
||||
cognitoService.adminCreateUser(pool.getId(), "alice", Map.of("email", "alice@example.test"), "Password123!");
|
||||
cognitoService.adminLinkProviderForUser(pool.getId(), "alice", "Google", "google-subject");
|
||||
|
||||
// First federated sign-in.
|
||||
CognitoUser first = cognitoService.provisionFederatedUser(pool.getId(), provider, "google-subject", null,
|
||||
Map.of("email", "updated@example.test"));
|
||||
String statusAfterFirst = first.getUserStatus();
|
||||
|
||||
// Second federated sign-in.
|
||||
CognitoUser second = cognitoService.provisionFederatedUser(pool.getId(), provider, "google-subject", null,
|
||||
Map.of("email", "updated2@example.test"));
|
||||
|
||||
assertEquals("alice", second.getUsername());
|
||||
assertEquals(statusAfterFirst, second.getUserStatus(),
|
||||
"Linked profile status must be preserved across repeated federated sign-ins");
|
||||
}
|
||||
|
||||
@Test
|
||||
void googleProvisioningPreservesPermanentPasswordStatusOnResignIn() throws Exception {
|
||||
IdentityProvider provider = createProvider("Google", "Google", Map.of("client_id", "google-client"), Map.of());
|
||||
CognitoUser first = cognitoService.provisionFederatedUser(pool.getId(), provider, "google-subject", null,
|
||||
Map.of("email", "user@example.test"));
|
||||
cognitoService.adminSetUserPassword(pool.getId(), first.getUsername(), "PermanentPass1!", true);
|
||||
|
||||
CognitoUser afterPassword = cognitoService.adminGetUser(pool.getId(), first.getUsername());
|
||||
assertEquals("CONFIRMED", afterPassword.getUserStatus());
|
||||
|
||||
// Re-sign-in via federation must not revert to EXTERNAL_PROVIDER.
|
||||
CognitoUser second = cognitoService.provisionFederatedUser(pool.getId(), provider, "google-subject", null,
|
||||
Map.of("email", "user2@example.test"));
|
||||
|
||||
assertEquals("CONFIRMED", second.getUserStatus(),
|
||||
"Permanent-password profile must keep CONFIRMED across federated re-sign-in");
|
||||
}
|
||||
|
||||
@Test
|
||||
void googleProvisioningReconcilesUserLinkedWithGeneratedUsername() throws Exception {
|
||||
IdentityProvider provider = createProvider("Google", "Google", Map.of("client_id", "google-client"), Map.of());
|
||||
|
||||
Reference in new issue
Block a user