Skip to content

Commit

Permalink
Merge pull request #4015 from Yasasr1/remove-identity-claims-4.10.x
Browse files Browse the repository at this point in the history
Fix sending Identity claim attributes to the userstores to fetch data
  • Loading branch information
Yasasr1 authored Jun 28, 2024
2 parents b271930 + 1a9f7cf commit 40a6e5f
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2289,13 +2289,42 @@ public final Map<String, String> getUserClaimValues(String userName, String[] cl
if (claims == null) {
claims = new String[0];
}
Map<String, String> finalValues = new HashMap<>();
String[] allClaims = claims.clone();

// #################### <PreListeners> ###################################################
try {
for (UserOperationEventListener listener : UMListenerServiceComponent.getUserOperationEventListeners()) {
if (listener instanceof AbstractUserOperationEventListener) {
AbstractUserOperationEventListener newListener = (AbstractUserOperationEventListener) listener;
if (!newListener
.doPreGetUserClaimValues(userStore.getDomainFreeName(), claims, profileName, finalValues,
this)) {
handleGetUserClaimValuesFailure(
ErrorMessages.ERROR_CODE_ERROR_IN_PRE_GET_CLAIM_VALUES.getCode(),
String.format(ErrorMessages.ERROR_CODE_ERROR_IN_PRE_GET_CLAIM_VALUES.getMessage(),
UserCoreErrorConstants.POST_LISTENER_TASKS_FAILED_MESSAGE), userName, claims,
profileName);
break;
}
}
}
} catch (UserStoreException ex) {
handleGetUserClaimValuesFailure(ErrorMessages.ERROR_CODE_ERROR_IN_PRE_GET_CLAIM_VALUES.getCode(),
String.format(ErrorMessages.ERROR_CODE_ERROR_IN_PRE_GET_CLAIM_VALUES.getMessage(),
ex.getMessage()), userName, claims, profileName);
throw ex;
}
// #################### </PreListeners> ###################################################

claims = removeNullElements(claims);

Map<String, String> finalValues;
try {
if (isUniqueIdEnabled) {
finalValues = doGetUserClaimValuesWithID(userID, claims, userStore.getDomainName(), profileName);
} else {
finalValues = doGetUserClaimValues(userStore.getDomainFreeName(), claims, userStore.getDomainName(), profileName);
finalValues = doGetUserClaimValues(userStore.getDomainFreeName(), claims, userStore.getDomainName(),
profileName);
}
} catch (UserStoreException ex) {
handleGetUserClaimValuesFailure(ErrorMessages.ERROR_CODE_ERROR_WHILE_GETTING_CLAIM_VALUES.getCode(),
Expand All @@ -2304,14 +2333,14 @@ public final Map<String, String> getUserClaimValues(String userName, String[] cl
throw ex;
}

// #################### <Listeners> #####################################################
// #################### <PostListeners> #####################################################
try {
for (UserOperationEventListener listener : UMListenerServiceComponent.getUserOperationEventListeners()) {
if (listener instanceof AbstractUserOperationEventListener) {
AbstractUserOperationEventListener newListener = (AbstractUserOperationEventListener) listener;
if (!newListener
.doPostGetUserClaimValues(userStore.getDomainFreeName(), claims, profileName, finalValues,
this)) {
.doPostGetUserClaimValues(userStore.getDomainFreeName(), allClaims, profileName,
finalValues, this)) {
handleGetUserClaimValuesFailure(
ErrorMessages.ERROR_CODE_ERROR_IN_POST_GET_CLAIM_VALUES.getCode(),
String.format(ErrorMessages.ERROR_CODE_ERROR_IN_POST_GET_CLAIM_VALUES.getMessage(),
Expand All @@ -2327,11 +2356,22 @@ public final Map<String, String> getUserClaimValues(String userName, String[] cl
ex.getMessage()), userName, claims, profileName);
throw ex;
}
// #################### </Listeners> #####################################################
// #################### </PostListeners> #####################################################

return finalValues;
}

/**
* Removes all null elements from the given String array.
*
* @param array Array The input String array.
* @return A new String array containing only non-null elements.
*/
private static String[] removeNullElements(String[] array) {

return Arrays.stream(array).filter(Objects::nonNull).toArray(String[]::new);
}

/**
* This method is responsible for calling the relevant methods when there is a failure while trying to get the
* user list.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ public enum ErrorMessages {
ERROR_CODE_ERROR_WHILE_GETTING_CLAIM_URI("33001", "Un-expected error while getting claim uri, %s"),
ERROR_CODE_ERROR_WHILE_GETTING_CLAIM_VALUES("33002", "Un-expected error while getting claim values, %s"),
ERROR_CODE_ERROR_IN_POST_GET_CLAIM_VALUES("33003", "Un-expected error during post get claim values, %s"),
ERROR_CODE_ERROR_IN_PRE_GET_CLAIM_VALUES("33005", "Un-expected error during pre get claim values, %s"),

// Error code related with Add ClaimValues
ERROR_CODE_DUPLICATE_ERROR_WHILE_ADDING_CLAIM_MAPPINGS("33004", "Duplicate entries are found when adding " +
Expand Down

0 comments on commit 40a6e5f

Please sign in to comment.