Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
RushanNanayakkara committed Mar 8, 2024
2 parents 2d7cadc + 95517ca commit ab716d9
Show file tree
Hide file tree
Showing 42 changed files with 200 additions and 63 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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.user.governance</artifactId>
<version>1.9.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../..</relativePath>
</parent>

<artifactId>org.wso2.carbon.identity.api.user.recovery</artifactId>
<version>1.9.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,11 +171,21 @@ public void setReCaptchaScoreThreshold(double reCaptchaScoreThreshold) {
this.reCaptchaScoreThreshold = reCaptchaScoreThreshold;
}

/**
* Get the recaptcha score used as the threshold for printing warn logs.
*
* @return Recaptcha score threshold used for warning.
*/
public double getReCaptchaWarnScoreThreshold() {

return reCaptchaWarnScoreThreshold;
}

/**
* Set the recaptcha score used as the threshold for printing warn logs.
*
* @param reCaptchaWarnScoreThreshold Recaptcha score threshold used for warning.
*/
public void setReCaptchaWarnScoreThreshold(double reCaptchaWarnScoreThreshold) {

this.reCaptchaWarnScoreThreshold = reCaptchaWarnScoreThreshold;
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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,24 @@ default NotificationTemplate getNotificationTemplate(String notificationChannel,
return null;
}

/**
* Return the notification template from the tenant registry which matches the given channel and template name.
*
* @param notificationChannel Notification Channel Name (Eg: SMS or EMAIL).
* @param templateType Display name of the template.
* @param locale Locale.
* @param tenantDomain Tenant Domain.
* @param applicationUuid Application UUID.
* @return Return {@link org.wso2.carbon.identity.governance.model.NotificationTemplate} object.
* @throws NotificationTemplateManagerException If an error occurred while getting the notification template.
*/
default NotificationTemplate getNotificationTemplate(String notificationChannel, String templateType, String locale,
String tenantDomain, String applicationUuid)
throws NotificationTemplateManagerException {

return null;
}

/**
* Add the notification template to the registry.
*
Expand All @@ -55,6 +73,19 @@ default void addNotificationTemplate(NotificationTemplate notificationTemplate,

}

/**
* Add the notification template to the registry.
*
* @param notificationTemplate Notification template.
* @param tenantDomain Tenant domain.
* @param applicationUuid Application UUID.
* @throws NotificationTemplateManagerException If an error occurred while adding the notification template.
*/
default void addNotificationTemplate(NotificationTemplate notificationTemplate, String tenantDomain,
String applicationUuid) throws NotificationTemplateManagerException {

}

/**
* Add a new notification template to the registry to the corresponding notification channel root directory.
*
Expand Down Expand Up @@ -91,4 +122,19 @@ default List<NotificationTemplate> getDefaultNotificationTemplates(String notifi

return null;
}

/**
* Add a new notification template to the registry to the corresponding notification channel root directory.
*
* @param displayName Notification template display name.
* @param notificationChannel Notification channel (Eg: SMS, EMAIL).
* @param tenantDomain Tenant domain.
* @param applicationUuid Application UUID.
* @throws NotificationTemplateManagerException If an error occurred while adding the template to the registry.
*/
default void addNotificationTemplateType(String displayName, String notificationChannel,
String tenantDomain, String applicationUuid)
throws NotificationTemplateManagerException {

}
}
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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,8 @@ public enum ErrorMessages {
+ "recovery request"),
ERROR_CODE_USERNAME_RECOVERY_VALIDATION_FAILED("UNR-10003",
"Username recovery validation failed for user account : '%s'"),
ERROR_CODE_USERNAME_RECOVERY_MULTIPLE_DOMAINS("UNR-10004", "Multiple domains found in the " +
"given claim set"),

// UAR - User Account Recovery.
ERROR_CODE_INVALID_RECOVERY_CODE("UAR-10001", "Invalid recoveryCode : '%s'"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@
import org.wso2.carbon.user.core.model.OperationalCondition;
import org.wso2.carbon.user.core.model.OperationalOperation;
import org.wso2.carbon.user.core.service.RealmService;
import org.wso2.carbon.user.core.util.UserCoreUtil;

import java.util.ArrayList;
import java.util.Arrays;
Expand Down Expand Up @@ -298,27 +299,19 @@ public String getUsernameByClaims(Map<String, String> claims, String tenantDomai
}
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try {
List<String> userStoreDomainNames = getDomainNames(tenantId);
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager) getUserStoreManager(tenantId);
RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService();
ClaimManager claimManager = (ClaimManager) realmService.getTenantUserRealm(tenantId).getClaimManager();
ArrayList<org.wso2.carbon.user.core.common.User> resultedUserList = new ArrayList<>();

for (String domain : userStoreDomainNames) {
List<ExpressionCondition> expressionConditionList =
getExpressionConditionList(claims, domain, claimManager);
if (expressionConditionList.isEmpty()) {
continue;
}
Condition operationalCondition = getOperationalCondition(expressionConditionList);
/* Get the users list that matches with the condition
limit : 2, offset : 1, sortBy : null, sortOrder : null */
resultedUserList.addAll(abstractUserStoreManager.getUserListWithID(operationalCondition, domain,
UserCoreConstants.DEFAULT_PROFILE, 2, 1, null, null));
if (resultedUserList.size() > 1) {
log.warn("Multiple users matched for given claims set: " + claims.keySet());
throw Utils.handleClientException(
IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_MULTIPLE_MATCHING_USERS, null);
AbstractUserStoreManager abstractUserStoreManager = (AbstractUserStoreManager)
getUserStoreManager(tenantId);
String userstoreDomain = extractDomainFromClaims(claims, abstractUserStoreManager);
if (userstoreDomain != null) {
populateUserListFromClaimsForDomain(tenantId, claims, userstoreDomain, resultedUserList,
abstractUserStoreManager);
} else {
// If a userstore domain is not specified in the request, consider all userstores.
List<String> userStoreDomainNames = getDomainNames(tenantId);
for (String domain : userStoreDomainNames) {
populateUserListFromClaimsForDomain(tenantId, claims, domain, resultedUserList,
abstractUserStoreManager);
}
}
// Return empty when no users are found.
Expand All @@ -333,11 +326,84 @@ public String getUsernameByClaims(Map<String, String> claims, String tenantDomai
Arrays.toString(claims.keySet().toArray()));
}
throw new IdentityRecoveryException(e.getErrorCode(), "Error occurred while retrieving users.", e);
} catch (UserStoreException e) {
} catch (UserStoreException | IdentityRecoveryServerException e) {
throw new IdentityRecoveryException(e.getMessage(), e);
}
}

/**
* Extract and remove the userstore domain from the claim set.
*
* @param claims List of UserClaims.
* @param abstractUserStoreManager Abstract user store manager.
* @return Userstore domain of the claims.
* @throws IdentityRecoveryClientException Error if multiple domains are present.
*/
private String extractDomainFromClaims(Map<String, String> claims,
AbstractUserStoreManager abstractUserStoreManager)
throws IdentityRecoveryClientException {

String domain = null;
for (Map.Entry<String, String> entry : claims.entrySet()) {
if (StringUtils.isNotBlank(entry.getValue()) && entry.getValue().contains(UserCoreConstants.DOMAIN_SEPARATOR)) {
String extractedDomain = IdentityUtil.extractDomainFromName(entry.getValue());
// Some claims (Eg:- Birth date) can have "/" in claim values. Skip such claims where
// secondaryUserStoreManager for the extracted domain is null.
UserStoreManager secondaryUserStoreManager = abstractUserStoreManager.
getSecondaryUserStoreManager(extractedDomain);
if (secondaryUserStoreManager != null) {
if (domain == null) {
domain = extractedDomain;
} else if (!domain.equalsIgnoreCase(extractedDomain)) {
log.warn("Multiple domains found for the given claim set: " + claims.keySet());
throw Utils.handleClientException(
IdentityRecoveryConstants.ErrorMessages.
ERROR_CODE_USERNAME_RECOVERY_MULTIPLE_DOMAINS, null);
}
// Remove domain from claim value.
entry.setValue(UserCoreUtil.removeDomainFromName(entry.getValue()));
}
}
}
return domain;
}

/**
* Get the users for the given claim set and userstore domain and populate the user list.
*
* @param tenantId Tenant ID.
* @param claims List of UserClaims.
* @param userstoreDomain Userstore domain of the claims.
* @param userList List of users.
* @param abstractUserStoreManager Abstract user store manager.
* @throws IdentityRecoveryClientException Error if multiple users exist for the given claims set.
* @throws UserStoreException Error while getting the attribute name of a claim.
*/
private void populateUserListFromClaimsForDomain(int tenantId, Map<String, String> claims, String userstoreDomain,
ArrayList<org.wso2.carbon.user.core.common.User> userList,
AbstractUserStoreManager abstractUserStoreManager)
throws UserStoreException, IdentityRecoveryClientException {

RealmService realmService = IdentityRecoveryServiceDataHolder.getInstance().getRealmService();
ClaimManager claimManager = (ClaimManager) realmService.getTenantUserRealm(tenantId).getClaimManager();

List<ExpressionCondition> expressionConditionList =
getExpressionConditionList(claims, userstoreDomain, claimManager);

if (!expressionConditionList.isEmpty()) {
Condition operationalCondition = getOperationalCondition(expressionConditionList);
// Get the user list that matches the condition limit : 2, offset : 1, sortBy : null, sortOrder : null
userList.addAll(abstractUserStoreManager.getUserListWithID(operationalCondition, userstoreDomain,
UserCoreConstants.DEFAULT_PROFILE, 2, 1, null, null));

if (userList.size() > 1) {
log.warn("Multiple users matched for given claims set: " + claims.keySet());
throw Utils.handleClientException(
IdentityRecoveryConstants.ErrorMessages.ERROR_CODE_MULTIPLE_MATCHING_USERS, null);
}
}
}

/**
* Get the expression conditions for the claim set.
*
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.6-SNAPSHOT</version>
<version>1.9.10-SNAPSHOT</version>
<relativePath>../../pom.xml</relativePath>
</parent>

Expand Down
Loading

0 comments on commit ab716d9

Please sign in to comment.