Skip to content

Commit

Permalink
Change execution order to ensure the account is locked in case of a n…
Browse files Browse the repository at this point in the history
…otification error
  • Loading branch information
ThaminduR committed Dec 16, 2024
1 parent 2262d06 commit d8ec2df
Showing 1 changed file with 27 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,33 @@ public void handleEvent(Event event) throws IdentityEventException {
if (IdentityEventConstants.Event.POST_ADD_USER.equals(event.getEventName())) {
UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();

if (isAccountLockOnCreation || isEnableConfirmationOnCreation) {
HashMap<String, String> userClaims = new HashMap<>();
if (isAccountLockOnCreation) {
// Need to lock user account.
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM, Boolean.TRUE.toString());
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_REASON_CLAIM,
IdentityMgtConstants.LockedReason.PENDING_SELF_REGISTRATION.toString());
}
if (Utils.isAccountStateClaimExisting(tenantDomain)) {
userClaims.put(IdentityRecoveryConstants.ACCOUNT_STATE_CLAIM_URI,
IdentityRecoveryConstants.PENDING_SELF_REGISTRATION);
}
try {
userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
if (log.isDebugEnabled()) {
if (isAccountLockOnCreation) {
log.debug("Locked user account: " + user.getUserName());
}
if (isEnableConfirmationOnCreation) {
log.debug("Send verification notification for user account: " + user.getUserName());
}
}
} catch (UserStoreException e) {
throw new IdentityEventException("Error while lock user account :" + user.getUserName(), e);
}
}

try {
// Get the user preferred notification channel.
String preferredChannel = resolveNotificationChannel(eventProperties, userName, tenantDomain,
Expand Down Expand Up @@ -166,33 +193,6 @@ public void handleEvent(Event event) throws IdentityEventException {
} catch (IdentityRecoveryException e) {
throw new IdentityEventException("Error while sending self sign up notification ", e);
}
if (isAccountLockOnCreation || isEnableConfirmationOnCreation) {
HashMap<String, String> userClaims = new HashMap<>();
if (isAccountLockOnCreation) {
// Need to lock user account.
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_CLAIM, Boolean.TRUE.toString());
userClaims.put(IdentityRecoveryConstants.ACCOUNT_LOCKED_REASON_CLAIM,
IdentityMgtConstants.LockedReason.PENDING_SELF_REGISTRATION.toString());
}
if (Utils.isAccountStateClaimExisting(tenantDomain)) {
userClaims.put(IdentityRecoveryConstants.ACCOUNT_STATE_CLAIM_URI,
IdentityRecoveryConstants.PENDING_SELF_REGISTRATION);
}
try {
userStoreManager.setUserClaimValues(user.getUserName(), userClaims, null);
if (log.isDebugEnabled()) {
if (isAccountLockOnCreation) {
log.debug("Locked user account: " + user.getUserName());
}
if (isEnableConfirmationOnCreation) {
log.debug("Send verification notification for user account: " + user.getUserName());
}
}
} catch (UserStoreException e) {
throw new IdentityEventException("Error while lock user account :" + user.getUserName(), e);
}
}

}
}

Expand Down

0 comments on commit d8ec2df

Please sign in to comment.