Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support editing shared user profile and return aggregated profile for shared user #400

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all 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 @@ -163,6 +163,7 @@
org.wso2.carbon.user.core.listener;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.service;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.util;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.user.core.model;version="${carbon.kernel.package.import.version.range}",
org.wso2.carbon.identity.event.handler; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.event.event; version="${carbon.identity.package.import.version.range}",
org.wso2.carbon.identity.event; version="${carbon.identity.package.import.version.range}",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.wso2.carbon.identity.event.handler.AbstractEventHandler;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingService;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingServiceImpl;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.listener.SharedUserDeleteOperationEventListener;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.listener.SharedUserOperationEventListener;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.listener.SharingOrganizationCreatorUserEventHandler;
import org.wso2.carbon.identity.organization.management.role.management.service.RoleManager;
Expand Down Expand Up @@ -61,6 +62,8 @@ protected void activate(ComponentContext componentContext) {
null);
bundleContext.registerService(UserOperationEventListener.class.getName(),
new SharedUserOperationEventListener(), null);
bundleContext.registerService(UserOperationEventListener.class.getName(),
new SharedUserDeleteOperationEventListener(), null);
bundleContext.registerService(AbstractEventHandler.class.getName(),
new SharingOrganizationCreatorUserEventHandler(), null);
LOG.info("OrganizationUserSharingServiceComponent activated successfully.");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
/*
* Copyright (c) 2024, WSO2 LLC. (http://www.wso2.com).
*
* WSO2 LLC. licenses this file to you under the Apache License,
* Version 2.0 (the "License"); you may not use this file except
* in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

package org.wso2.carbon.identity.organization.management.organization.user.sharing.listener;

import org.wso2.carbon.identity.core.AbstractIdentityUserOperationEventListener;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingService;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.OrganizationUserSharingServiceImpl;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.internal.OrganizationUserSharingDataHolder;
import org.wso2.carbon.identity.organization.management.organization.user.sharing.util.OrganizationSharedUserUtil;
import org.wso2.carbon.identity.organization.management.service.exception.OrganizationManagementException;
import org.wso2.carbon.user.core.UserStoreException;
import org.wso2.carbon.user.core.UserStoreManager;
import org.wso2.carbon.user.core.common.AbstractUserStoreManager;

import static org.wso2.carbon.identity.organization.management.service.util.Utils.getOrganizationId;
import static org.wso2.carbon.identity.organization.management.service.util.Utils.getTenantDomain;

/**
* Shared user delete operation event listener.
*/
public class SharedUserDeleteOperationEventListener extends AbstractIdentityUserOperationEventListener {

private final OrganizationUserSharingService organizationUserSharingService =
new OrganizationUserSharingServiceImpl();

@Override
public int getExecutionOrderId() {

return 129;
}

@Override
public boolean doPreDeleteUserWithID(String userID, UserStoreManager userStoreManager) throws UserStoreException {

if (!isEnable() || userStoreManager == null) {
return true;
}
try {
// The organization where the user identity is managed. Clear all the associations of the user.
String associatedOrgId = OrganizationSharedUserUtil
.getUserManagedOrganizationClaim((AbstractUserStoreManager) userStoreManager, userID);
if (associatedOrgId != null) {
// User is associated only for shared users. Hence, delete the user association.
return organizationUserSharingService.deleteUserAssociation(userID, associatedOrgId);
}

String orgId = getOrganizationId();
if (orgId == null) {
orgId = OrganizationUserSharingDataHolder.getInstance().getOrganizationManager()
.resolveOrganizationId(getTenantDomain());
}
// Delete all the user associations of the user.
return organizationUserSharingService.unshareOrganizationUsers(userID, orgId);
} catch (OrganizationManagementException e) {
throw new UserStoreException(e.getMessage(), e.getErrorCode(), e);
}
}
}
Loading
Loading