Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
bhagyasakalanka committed May 17, 2024
2 parents 8faf784 + 02b24a7 commit 0aa61ac
Show file tree
Hide file tree
Showing 40 changed files with 119 additions and 41 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.user.governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WSO2 Carbon - User Rest Governance API</name>
<description>WSO2 Carbon - User Rest Governance API</description>
Expand Down
4 changes: 2 additions & 2 deletions components/org.wso2.carbon.identity.api.user.recovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.user.recovery</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<packaging>jar</packaging>
<name>WSO2 Carbon - Identity Management Recovery Rest API</name>
<description>WSO2 Carbon - Identity Management Recovery Rest API</description>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.captcha/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.governance/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.piicontroller/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.recovery/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public class AuditConstants {
public static final String ACTION_PASSWORD_RECOVERY = "Password recovery";
public static final String ACTION_USERNAME_RECOVERY = "Username recovery";
public static final String ACTION_PASSWORD_RESET = "Password reset";
public static final String ACTION_ACCOUNT_STATUS_NOTIFY = "Account status notify";
public static final String NOTIFICATION_TEMPLATE_TYPE = "Notification template";
public static final String USER_STORE_DOMAIN = "UserStoreDomain";
public static final String RECOVERY_SCENARIO = "RecoveryScenario";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,12 @@ public class IdentityRecoveryConstants {
// Self sign up properties.
public static final String SIGNUP_PROPERTY_REGISTRATION_OPTION = "registrationOption";

public static final String ADMIN_INITIATED = "AdminInitiated";
// Properties related to password recovery failure due to account status.
public static final String ERROR_KEY = "error-key";
public static final String NOTIFICATION_TYPE_ACCOUNT_STATUS_NOTIFY = "passwordRecoveryFailureNotify";
public static final String ACCOUNT_STATUS_LOCKED = "password.recovery.failed.account.locked";
public static final String ACCOUNT_STATUS_DISABLED = "password.recovery.failed.account.disabled";
public static final String IGNORE_IF_TEMPLATE_NOT_FOUND = "ignoreIfTemplateNotFound";

private IdentityRecoveryConstants() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.nio.charset.StandardCharsets;
import java.security.NoSuchAlgorithmException;
import java.util.Base64;
import java.util.HashMap;
import java.util.Map;

Expand Down Expand Up @@ -157,12 +159,15 @@ IdentityEventConstants.Event.PRE_SEND_RECOVERY_NOTIFICATION, new UserRecoveryDat
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_FEDERATED_USER,
user.getUserName());
}
String eventName = Utils.resolveEventName(notificationChannel);
if (Utils.isAccountDisabled(user)) {
// If the NotifyUserAccountStatus is disabled, notify with an empty NotificationResponseBean.
if (getNotifyUserAccountStatus()) {
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_DISABLED_ACCOUNT,
user.getUserName());
}
triggerAccountStatusNotification(user, notificationChannel,
IdentityRecoveryConstants.ACCOUNT_STATUS_DISABLED, eventName, properties);
return new NotificationResponseBean(user);
} else if (Utils.isAccountLocked(user)) {
// Check user in PENDING_SR or PENDING_AP status.
Expand All @@ -172,6 +177,8 @@ IdentityEventConstants.Event.PRE_SEND_RECOVERY_NOTIFICATION, new UserRecoveryDat
throw Utils.handleClientException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_LOCKED_ACCOUNT,
user.getUserName());
}
triggerAccountStatusNotification(user, notificationChannel,
IdentityRecoveryConstants.ACCOUNT_STATUS_LOCKED, eventName, properties);
return new NotificationResponseBean(user);
}
UserRecoveryDataStore userRecoveryDataStore = JDBCRecoveryDataStore.getInstance();
Expand All @@ -189,7 +196,6 @@ IdentityEventConstants.Event.PRE_SEND_RECOVERY_NOTIFICATION, new UserRecoveryDat
NotificationResponseBean notificationResponseBean = new NotificationResponseBean(user);
if (isNotificationInternallyManage) {
// Manage notifications by the identity server.
String eventName = Utils.resolveEventName(notificationChannel);
triggerNotification(user, notificationChannel, IdentityRecoveryConstants.NOTIFICATION_TYPE_PASSWORD_RESET,
secretKey, eventName, properties, recoveryDataDO);
} else {
Expand Down Expand Up @@ -1028,6 +1034,55 @@ private void triggerNotification(User user, String notificationChannel, String t

}

/**
* Trigger notification to send account status information.
*
* @param user User
* @param notificationChannel Notification channel
* @param status Account status
* @param eventName Event name
* @param metaProperties Meta properties to be sent with the notification.
* @throws IdentityRecoveryException Error while triggering notification.
*/
private void triggerAccountStatusNotification(User user, String notificationChannel,
String status, String eventName, Property[] metaProperties)
throws IdentityRecoveryException {

HashMap<String, Object> properties = new HashMap<>();
properties.put(IdentityEventConstants.EventProperty.USER_NAME, user.getUserName());
properties.put(IdentityEventConstants.EventProperty.TENANT_DOMAIN, user.getTenantDomain());
properties.put(IdentityEventConstants.EventProperty.USER_STORE_DOMAIN, user.getUserStoreDomain());
properties.put(IdentityEventConstants.EventProperty.NOTIFICATION_CHANNEL, notificationChannel);
if (StringUtils.isNotBlank(status)) {
properties.put(IdentityRecoveryConstants.ERROR_KEY,
Base64.getUrlEncoder().encodeToString(status.getBytes(StandardCharsets.UTF_8)));
}
// This property is used to ignore throwing an error if the template is not found. This allows to preserve the
// backward compatibility for the tenants without the specific email template.
properties.put(IdentityRecoveryConstants.IGNORE_IF_TEMPLATE_NOT_FOUND, true);

if (metaProperties != null) {
for (Property metaProperty : metaProperties) {
if (StringUtils.isNotBlank(metaProperty.getValue()) && StringUtils.isNotBlank(metaProperty.getKey())) {
properties.put(metaProperty.getKey(), metaProperty.getValue());
}
}
}
properties.put(IdentityRecoveryConstants.TEMPLATE_TYPE,
IdentityRecoveryConstants.NOTIFICATION_TYPE_ACCOUNT_STATUS_NOTIFY);
Event identityMgtEvent = new Event(eventName, properties);
try {
IdentityRecoveryServiceDataHolder.getInstance().getIdentityEventService().handleEvent(identityMgtEvent);
auditAccountStatusNotify(notificationChannel, user, null,
FrameworkConstants.AUDIT_SUCCESS);
} catch (IdentityEventException e) {
auditAccountStatusNotify(notificationChannel, user,
e.getMessage(), FrameworkConstants.AUDIT_FAILED);
throw Utils.handleServerException(IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_TRIGGER_NOTIFICATION,
user.getUserName(), e);
}
}

private void publishEvent(User user, String notify, String code, String password, Property[] metaProperties,
String eventName, UserRecoveryData userRecoveryData) throws
IdentityRecoveryException {
Expand Down Expand Up @@ -1143,6 +1198,23 @@ private void auditPasswordRecovery(String action, String notificationChannel, Us
Utils.createAuditMessage(action, user.getUserName(), dataObject, result);
}

private void auditAccountStatusNotify(String notificationChannel, User user, String errorMsg, String result) {

JSONObject dataObject = new JSONObject();
dataObject.put(AuditConstants.REMOTE_ADDRESS_KEY, MDC.get(AuditConstants.REMOTE_ADDRESS_QUERY_KEY));
dataObject.put(AuditConstants.USER_AGENT_KEY, MDC.get(AuditConstants.USER_AGENT_QUERY_KEY));
dataObject.put(AuditConstants.NOTIFICATION_CHANNEL, notificationChannel);
dataObject.put(AuditConstants.SERVICE_PROVIDER_KEY, MDC.get(AuditConstants.SERVICE_PROVIDER_QUERY_KEY));
dataObject.put(AuditConstants.USER_STORE_DOMAIN, user.getUserStoreDomain());
dataObject.put(AuditConstants.TENANT_DOMAIN, user.getTenantDomain());
dataObject.put(AuditConstants.NOTIFICATION_TEMPLATE_TYPE, IdentityRecoveryConstants.NOTIFICATION_TYPE_ACCOUNT_STATUS_NOTIFY);

if (AUDIT_FAILED.equals(result)) {
dataObject.put(AuditConstants.ERROR_MESSAGE_KEY, errorMsg);
}
Utils.createAuditMessage(AuditConstants.ACTION_ACCOUNT_STATUS_NOTIFY, user.getUserName(), dataObject, result);
}

private void auditPasswordReset(User user, String action, String errorMsg, String result, String recoveryScenario,
String recoveryStep) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
2 changes: 1 addition & 1 deletion components/org.wso2.carbon.identity.user.endpoint/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
<parent>
<artifactId>identity-governance</artifactId>
<groupId>org.wso2.carbon.identity.governance</groupId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<parent>
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
<groupId>org.wso2.carbon.identity.governance</groupId>
<artifactId>identity-governance</artifactId>
<relativePath>../../pom.xml</relativePath>
<version>1.9.12-SNAPSHOT</version>
<version>1.9.15-SNAPSHOT</version>
</parent>

<modelVersion>4.0.0</modelVersion>
Expand Down
Loading

0 comments on commit 0aa61ac

Please sign in to comment.