From 9b372839a132d89b072ec6ac403a6645888f9aaa Mon Sep 17 00:00:00 2001 From: Thilina Shashimal Senarath Date: Thu, 26 Oct 2023 13:52:44 +0530 Subject: [PATCH] Fix admin role retrieving for permission assign --- .../AdminRolePermissionsUpdateListener.java | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/AdminRolePermissionsUpdateListener.java b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/AdminRolePermissionsUpdateListener.java index 504caa9ebcb2..dca49987fad1 100644 --- a/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/AdminRolePermissionsUpdateListener.java +++ b/components/application-mgt/org.wso2.carbon.identity.application.mgt/src/main/java/org/wso2/carbon/identity/application/mgt/listener/AdminRolePermissionsUpdateListener.java @@ -37,6 +37,7 @@ import org.wso2.carbon.identity.role.v2.mgt.core.exception.IdentityRoleManagementException; import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission; import org.wso2.carbon.user.api.UserStoreException; +import org.wso2.carbon.user.core.util.UserCoreUtil; import java.util.ArrayList; import java.util.List; @@ -154,18 +155,19 @@ private String getAdminRoleId(String tenantDomain) throws IdentityApplicationMan if (realm == null) { throw new IdentityApplicationManagementException("Error while retrieving user realm"); } - String adminUserName; + String adminRoleName; try { - adminUserName = realm.getRealmConfiguration().getAdminUserName(); + adminRoleName = realm.getRealmConfiguration().getAdminRoleName(); } catch (UserStoreException e) { - throw new IdentityApplicationManagementException("Error while retrieving admin username"); + throw new IdentityApplicationManagementException("Error while retrieving admin role name"); } - if (StringUtils.isBlank(adminUserName)) { - throw new IdentityApplicationManagementException("Admin username not found"); + if (StringUtils.isBlank(adminRoleName)) { + throw new IdentityApplicationManagementException("Admin role name not found"); } try { return ApplicationManagementServiceComponentHolder.getInstance() - .getRoleManagementServiceV2().getRoleIdByName(adminUserName, ORGANIZATION, orgId, tenantDomain); + .getRoleManagementServiceV2().getRoleIdByName(UserCoreUtil.removeDomainFromName(adminRoleName), + ORGANIZATION, orgId, tenantDomain); } catch (IdentityRoleManagementException e) { throw new IdentityApplicationManagementException("Error while retrieving role id for admin role in " + "tenant domain : " + tenantDomain, e);