@@ -3173,7 +3173,7 @@ private List<String> doGetUserList(String claim, String claimValue, String profi
31733173 }
31743174
31753175 try {
3176- if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain)) {
3176+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain, userManager )) {
31773177 if (log.isDebugEnabled()) {
31783178 log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
31793179 + extractedDomain + ". Hence returning empty user list.");
@@ -3266,6 +3266,23 @@ private List<String> doGetUserList(String claim, String claimValue, String profi
32663266
32673267 // For all the user stores append the domain name to the claim and pass it recursively (Including PRIMARY).
32683268 String domainName = ((AbstractUserStoreManager) userStoreManager).getMyDomainName();
3269+
3270+ try {
3271+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), domainName, userStoreManager)) {
3272+ if (log.isDebugEnabled()) {
3273+ log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
3274+ + domainName + ". Hence skipping the user store.");
3275+ }
3276+ continue;
3277+ }
3278+ } catch (org.wso2.carbon.user.api.UserStoreException e) {
3279+ handleGetUserListFailure(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getCode(),
3280+ String.format(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getMessage(),
3281+ e.getMessage()), claim, claimValue, profileName);
3282+ throw new UserStoreException(
3283+ "Error occurred while retrieving claim for claim URI: " + claim, e);
3284+ }
3285+
32693286 String claimValueWithDomain;
32703287 if (StringUtils.equalsIgnoreCase(domainName, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
32713288 claimValueWithDomain = domainName + CarbonConstants.DOMAIN_SEPARATOR + claimValue;
@@ -3433,7 +3450,7 @@ private List<User> doGetUserListWithID(String claim, String claimValue, String p
34333450 }
34343451
34353452 try {
3436- if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain)) {
3453+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain, userManager )) {
34373454 if (log.isDebugEnabled()) {
34383455 log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
34393456 + extractedDomain + ". Hence returning empty user list.");
@@ -3528,6 +3545,23 @@ private List<User> doGetUserListWithID(String claim, String claimValue, String p
35283545
35293546 // For all the user stores append the domain name to the claim and pass it recursively (Including PRIMARY).
35303547 String domainName = ((AbstractUserStoreManager) userStoreManager).getMyDomainName();
3548+
3549+ try {
3550+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), domainName, userStoreManager)) {
3551+ if (log.isDebugEnabled()) {
3552+ log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
3553+ + domainName + ". Hence skipping the user store.");
3554+ }
3555+ continue;
3556+ }
3557+ } catch (org.wso2.carbon.user.api.UserStoreException e) {
3558+ handleGetUserListFailureWithID(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getCode(),
3559+ String.format(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getMessage(),
3560+ e.getMessage()), claim, claimValue, profileName);
3561+ throw new UserStoreException(
3562+ "Error occurred while retrieving claim for claim URI: " + claim, e);
3563+ }
3564+
35313565 String claimValueWithDomain;
35323566 if (StringUtils.equalsIgnoreCase(domainName, UserCoreConstants.PRIMARY_DEFAULT_DOMAIN_NAME)) {
35333567 claimValueWithDomain = domainName + CarbonConstants.DOMAIN_SEPARATOR + claimValue;
@@ -3580,7 +3614,7 @@ private List<String> doGetUserList(String claim, String claimValue, String profi
35803614 }
35813615
35823616 try {
3583- if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain)) {
3617+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain, userManager )) {
35843618 if (log.isDebugEnabled()) {
35853619 log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
35863620 + extractedDomain + ". Hence returning empty user list.");
@@ -3665,6 +3699,22 @@ private List<String> doGetUserList(String claim, String claimValue, String profi
36653699 // For all the user stores append the domain name to the claim and pass it recursively (Including PRIMARY).
36663700 String domainName = ((AbstractUserStoreManager) userStoreManager).getMyDomainName();
36673701
3702+ try {
3703+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), domainName, userStoreManager)) {
3704+ if (log.isDebugEnabled()) {
3705+ log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
3706+ + domainName + ". Hence skipping the user store.");
3707+ }
3708+ continue;
3709+ }
3710+ } catch (org.wso2.carbon.user.api.UserStoreException e) {
3711+ handleGetUserListFailure(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getCode(),
3712+ String.format(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getMessage(),
3713+ e.getMessage()), claim, claimValue, limit, offset, profileName);
3714+ throw new UserStoreException(
3715+ "Error occurred while retrieving claim for claim URI: " + claim, e);
3716+ }
3717+
36683718 try {
36693719 property = claimManager.getAttributeName(domainName, claim);
36703720 } catch (org.wso2.carbon.user.api.UserStoreException e) {
@@ -17415,7 +17465,7 @@ private void mapAttributesToLocalIdentityClaims(List<ExpressionCondition> expres
1741517465 }
1741617466
1741717467 // Check if the claim is an identity store managed claim and map the attribute name to claim URI.
17418- if (isIdentityStoreManagedClaim(mappedClaim.getClaim(), userStoreDomain)) {
17468+ if (isIdentityStoreManagedClaim(mappedClaim.getClaim(), userStoreDomain, null )) {
1741917469 expressionCondition.setAttributeName(mappedClaim.getClaim().getClaimUri());
1742017470 if (log.isDebugEnabled()) {
1742117471 log.debug("Obtained the ClaimURI " + mappedClaim.getClaim().getClaimUri() +
@@ -17432,9 +17482,27 @@ private void mapAttributesToLocalIdentityClaims(List<ExpressionCondition> expres
1743217482 * to store identity claims.
1743317483 * @param localClaim Claim to be checked.
1743417484 * @param userStoreDomain User store domain.
17485+ * @param userStoreManager User store manager to check the configuration. If null, uses the current user store manager.
1743517486 * @return True if the claim is an identity store managed claim, false otherwise.
1743617487 */
17437- private boolean isIdentityStoreManagedClaim(org.wso2.carbon.user.api.Claim localClaim, String userStoreDomain) {
17488+ private boolean isIdentityStoreManagedClaim(org.wso2.carbon.user.api.Claim localClaim, String userStoreDomain,
17489+ UserStoreManager userStoreManager) {
17490+
17491+ RealmConfiguration realmConfigToCheck = realmConfig;
17492+ if (userStoreManager instanceof AbstractUserStoreManager) {
17493+ realmConfigToCheck = ((AbstractUserStoreManager) userStoreManager).getRealmConfiguration();
17494+ }
17495+
17496+ // If StoreIdentityClaims property is enabled, all claims should be stored in user store.
17497+ // This overrides all other claim configurations.
17498+ if (Boolean.parseBoolean(
17499+ realmConfigToCheck.getUserStoreProperty(UserStoreConfigConstants.STORE_IDENTITY_CLAIMS))) {
17500+ if (log.isDebugEnabled()) {
17501+ log.debug("StoreIdentityClaims property is enabled for domain: " + userStoreDomain +
17502+ ". All claims will be stored in user store.");
17503+ }
17504+ return false;
17505+ }
1743817506
1743917507 if (localClaim == null) {
1744017508 return false;
@@ -17460,7 +17528,9 @@ private boolean isIdentityStoreManagedClaim(org.wso2.carbon.user.api.Claim local
1746017528 if (CollectionUtils.isEmpty(excludedUserStores)) {
1746117529 return false;
1746217530 }
17463- return excludedUserStores.contains(userStoreDomain);
17531+
17532+ return excludedUserStores.stream()
17533+ .anyMatch(excludedDomain -> excludedDomain.equalsIgnoreCase(userStoreDomain));
1746417534 }
1746517535
1746617536 /**
@@ -17523,7 +17593,7 @@ private List<User> doGetUserListWithID(String claim, String claimValue, String p
1752317593 }
1752417594
1752517595 try {
17526- if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain)) {
17596+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), extractedDomain, userManager )) {
1752717597 if (log.isDebugEnabled()) {
1752817598 log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
1752917599 + extractedDomain + ". Hence returning empty user list.");
@@ -17607,6 +17677,22 @@ private List<User> doGetUserListWithID(String claim, String claimValue, String p
1760717677 // For all the user stores append the domain name to the claim and pass it recursively (Including PRIMARY).
1760817678 String domainName = ((AbstractUserStoreManager) userStoreManager).getMyDomainName();
1760917679
17680+ try {
17681+ if (isIdentityStoreManagedClaim(claimManager.getClaim(claim), domainName, userStoreManager)) {
17682+ if (log.isDebugEnabled()) {
17683+ log.debug("The claim: " + claim + " is an identity store managed claim for the domain: "
17684+ + domainName + ". Hence skipping the user store.");
17685+ }
17686+ continue;
17687+ }
17688+ } catch (org.wso2.carbon.user.api.UserStoreException e) {
17689+ handleGetUserListFailure(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getCode(),
17690+ String.format(ErrorMessages.ERROR_CODE_ERROR_DURING_PRE_GET_USER_LIST.getMessage(),
17691+ e.getMessage()), claim, claimValue, limit, offset, profileName);
17692+ throw new UserStoreException(
17693+ "Error occurred while retrieving claim for claim URI: " + claim, e);
17694+ }
17695+
1761017696 try {
1761117697 property = claimManager.getAttributeName(domainName, claim);
1761217698 } catch (org.wso2.carbon.user.api.UserStoreException e) {
0 commit comments