Skip to content
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import org.json.JSONObject;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.context.PrivilegedCarbonContext;
import org.wso2.carbon.identity.action.execution.api.model.ActionExecutionStatus;
import org.wso2.carbon.identity.application.authentication.framework.util.FrameworkUtils;
import org.wso2.carbon.identity.application.common.IdentityApplicationManagementException;
import org.wso2.carbon.identity.application.common.model.ServiceProvider;
Expand Down Expand Up @@ -5931,13 +5932,44 @@ private void updateUserClaims(User user, Map<String, String> oldClaimList,

if (isExecutableUserProfileUpdate) {

Map<String, String> multiValuedClaimsToModify =
SCIMCommonUtils.getSimpleMultiValuedClaimsToModify(oldClaimList, simpleMultiValuedClaimsToBeAdded,
simpleMultiValuedClaimsToBeRemoved);
userClaimsToBeModifiedIncludingMultiValueClaims.putAll(multiValuedClaimsToModify);
populateMultiValuedClaimsToModify(oldClaimList, simpleMultiValuedClaimsToBeAdded,
simpleMultiValuedClaimsToBeRemoved, userClaimsToBeModifiedIncludingMultiValueClaims);

preUpdateProfileActionExecutor.execute(user, userClaimsToBeModifiedIncludingMultiValueClaims,
userClaimsToBeDeleted);
ActionExecutionStatus<?> actionExecutionStatus = preUpdateProfileActionExecutor.executeAndGetStatus(user,
userClaimsToBeModifiedIncludingMultiValueClaims, userClaimsToBeDeleted);
Comment thread
Lashen1227 marked this conversation as resolved.
if (actionExecutionStatus != null) {
Comment thread
Lashen1227 marked this conversation as resolved.

Map<String, String> userClaimsToBeAddedFromAction = (HashMap<String, String>)
actionExecutionStatus.getResponseContext().get("userClaimsToBeAdded");
Map<String, String> userClaimsToBeModifiedFromAction = (HashMap<String, String>)
actionExecutionStatus.getResponseContext().get("userClaimsToBeModified");
Map<String, String> userClaimsToBeDeletedFromAction = (HashMap<String, String>)
actionExecutionStatus.getResponseContext().get("userClaimsToBeRemoved");
Map<String, List<String>> simpleMultiValuedClaimsToBeAddedFromAction = (HashMap<String, List<String>>)
actionExecutionStatus.getResponseContext().get("multiValuedClaimsToBeAdded");
Map<String, List<String>> simpleMultiValuedClaimsToBeRemovedFromAction = (HashMap<String, List<String>>)
actionExecutionStatus.getResponseContext().get("multiValuedClaimsToBeRemoved");

if (userClaimsToBeAddedFromAction != null) {
userClaimsToBeAdded.putAll(userClaimsToBeAddedFromAction);
userClaimsToBeModified.putAll(userClaimsToBeAddedFromAction);
}
if (userClaimsToBeModifiedFromAction != null) {
userClaimsToBeModified.putAll(userClaimsToBeModifiedFromAction);
}
if (userClaimsToBeDeletedFromAction != null) {
userClaimsToBeDeleted.putAll(userClaimsToBeDeletedFromAction);
userClaimsToBeModified.keySet().removeAll(userClaimsToBeDeletedFromAction.keySet());
}
if (simpleMultiValuedClaimsToBeAddedFromAction != null) {
simpleMultiValuedClaimsToBeAdded.putAll(simpleMultiValuedClaimsToBeAddedFromAction);
}
if (simpleMultiValuedClaimsToBeRemovedFromAction != null) {
simpleMultiValuedClaimsToBeRemoved.putAll(simpleMultiValuedClaimsToBeRemovedFromAction);
}
populateMultiValuedClaimsToModify(oldClaimList, simpleMultiValuedClaimsToBeAdded,
simpleMultiValuedClaimsToBeRemoved, userClaimsToBeModifiedIncludingMultiValueClaims);
}
}

if (log.isDebugEnabled()) {
Expand Down Expand Up @@ -5983,6 +6015,27 @@ private void updateUserClaims(User user, Map<String, String> oldClaimList,
}
}

/**
* Populate both modifiable single and multi-valued claims.
*
* @param oldClaimList User claim list for the user's existing state.
* @param simpleMultiValuedClaimsToBeAdded Map of simple multi-valued claims to be added.
* @param simpleMultiValuedClaimsToBeRemoved Map of simple multi-valued claims to be removed.
* @param userClaimsToBeModifiedIncludingMultiValueClaims Map of both single and multi valued claims to be modified.
* @return Map with the same keys and values as lists of strings, splitting multi-valued claims if necessary.
*/
private void populateMultiValuedClaimsToModify(Map<String, String> oldClaimList, Map<String, List<String>>
simpleMultiValuedClaimsToBeAdded, Map<String,
List<String>> simpleMultiValuedClaimsToBeRemoved,
Map<String, String> userClaimsToBeModifiedIncludingMultiValueClaims)
{

Map<String, String> multiValuedClaimsToModify =
SCIMCommonUtils.getSimpleMultiValuedClaimsToModify(oldClaimList, simpleMultiValuedClaimsToBeAdded,
simpleMultiValuedClaimsToBeRemoved);
userClaimsToBeModifiedIncludingMultiValueClaims.putAll(multiValuedClaimsToModify);
}

/**
* Convert the claim values to list of strings.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,18 @@ public class PreUpdateProfileActionExecutor {
public void execute(User user, Map<String, String> userClaimsToBeModified,
Map<String, String> userClaimsToBeDeleted) throws UserStoreException {

executeAndGetStatus(user, userClaimsToBeModified, userClaimsToBeDeleted);
}

// Triggers the execution of pre update profile extension at profile update with PUT and returns execution status.
public ActionExecutionStatus<?> executeAndGetStatus(User user, Map<String, String> userClaimsToBeModified,
Map<String, String> userClaimsToBeDeleted)
throws UserStoreException {

ActionExecutorService actionExecutorService = SCIMCommonComponentHolder.getActionExecutorService();

if (!actionExecutorService.isExecutionEnabled(ActionType.PRE_UPDATE_PROFILE)) {
return;
return null;
Comment thread
Lashen1227 marked this conversation as resolved.
}

LOG.debug("Executing pre update profile action for user: " + user.getId());
Expand All @@ -96,7 +104,7 @@ public void execute(User user, Map<String, String> userClaimsToBeModified,
actionExecutorService.execute(ActionType.PRE_UPDATE_PROFILE, flowContext,
IdentityContext.getThreadLocalIdentityContext().getTenantDomain());

handleActionExecutionStatus(actionExecutionStatus);
return handleActionExecutionStatus(actionExecutionStatus);
} catch (ActionExecutionException e) {
throw new UserActionExecutionServerException(UserActionError.PRE_UPDATE_PROFILE_ACTION_SERVER_ERROR,
"Error while executing pre update profile action.", e);
Expand All @@ -119,12 +127,12 @@ private UserActionRequestDTO buildUserActionRequestDTO(User user, Map<String, St
return userActionRequestDTOBuilder.build();
}

private void handleActionExecutionStatus(ActionExecutionStatus<?> actionExecutionStatus)
private ActionExecutionStatus<?> handleActionExecutionStatus(ActionExecutionStatus<?> actionExecutionStatus)
throws UserStoreException {

switch (actionExecutionStatus.getStatus()) {
case SUCCESS:
Comment thread
Lashen1227 marked this conversation as resolved.
return;
return actionExecutionStatus;
case FAILED:
Failure failure = (Failure) actionExecutionStatus.getResponse();
throw new UserActionExecutionClientException(UserActionError.PRE_UPDATE_PROFILE_ACTION_EXECUTION_FAILED,
Expand Down
Loading