Skip to content

Commit a9f93bf

Browse files
Merge pull request #895 from ThaminduR/fix-21290
Change execution order to ensure the account is locked in case of a notification sending failure
2 parents 5a1aad8 + 7001b6b commit a9f93bf

File tree

1 file changed

+28
-27
lines changed

1 file changed

+28
-27
lines changed

components/org.wso2.carbon.identity.recovery/src/main/java/org/wso2/carbon/identity/recovery/handler/UserSelfRegistrationHandler.java

Lines changed: 28 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,34 @@ public void handleEvent(Event event) throws IdentityEventException {
135135
return;
136136
}
137137

138+
// If account lock on creation is enabled, lock the account by persisting the account lock claim.
139+
if (isAccountLockOnCreation || isEnableConfirmationOnCreation) {
140+
HashMap<String, String> userClaims = new HashMap<>();
141+
if (isAccountLockOnCreation) {
142+
// Need to lock user account.
143+
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM, Boolean.TRUE.toString());
144+
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_REASON_CLAIM,
145+
IdentityMgtConstants.LockedReason.PENDING_SELF_REGISTRATION.toString());
146+
}
147+
if (Utils.isAccountStateClaimExisting(tenantDomain)) {
148+
userClaims.put(IdentityRecoveryConstants.ACCOUNT_STATE_CLAIM_URI,
149+
IdentityRecoveryConstants.PENDING_SELF_REGISTRATION);
150+
}
151+
try {
152+
userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
153+
if (log.isDebugEnabled()) {
154+
if (isAccountLockOnCreation) {
155+
log.debug("Locked user account: " + user.getUserName());
156+
}
157+
if (isEnableConfirmationOnCreation) {
158+
log.debug("Send verification notification for user account: " + user.getUserName());
159+
}
160+
}
161+
} catch (UserStoreException e) {
162+
throw new IdentityEventException("Error while lock user account :" + user.getUserName(), e);
163+
}
164+
}
165+
138166
boolean isSelfRegistrationConfirmationNotify = Boolean.parseBoolean(Utils.getSignUpConfigs
139167
(IdentityRecoveryConstants.ConnectorConfig.SELF_REGISTRATION_NOTIFY_ACCOUNT_CONFIRMATION, user.getTenantDomain()));
140168

@@ -166,33 +194,6 @@ public void handleEvent(Event event) throws IdentityEventException {
166194
} catch (IdentityRecoveryException e) {
167195
throw new IdentityEventException("Error while sending self sign up notification ", e);
168196
}
169-
if (isAccountLockOnCreation || isEnableConfirmationOnCreation) {
170-
HashMap<String, String> userClaims = new HashMap<>();
171-
if (isAccountLockOnCreation) {
172-
// Need to lock user account.
173-
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM, Boolean.TRUE.toString());
174-
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_REASON_CLAIM,
175-
IdentityMgtConstants.LockedReason.PENDING_SELF_REGISTRATION.toString());
176-
}
177-
if (Utils.isAccountStateClaimExisting(tenantDomain)) {
178-
userClaims.put(IdentityRecoveryConstants.ACCOUNT_STATE_CLAIM_URI,
179-
IdentityRecoveryConstants.PENDING_SELF_REGISTRATION);
180-
}
181-
try {
182-
userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
183-
if (log.isDebugEnabled()) {
184-
if (isAccountLockOnCreation) {
185-
log.debug("Locked user account: " + user.getUserName());
186-
}
187-
if (isEnableConfirmationOnCreation) {
188-
log.debug("Send verification notification for user account: " + user.getUserName());
189-
}
190-
}
191-
} catch (UserStoreException e) {
192-
throw new IdentityEventException("Error while lock user account :" + user.getUserName(), e);
193-
}
194-
}
195-
196197
}
197198
}
198199

0 commit comments

Comments
 (0)