Skip to content

Commit

Permalink
Merge pull request #5068 from shashimalcse/fix-admin-role-name
Browse files Browse the repository at this point in the history
Fix admin role retrieving for permission assign
  • Loading branch information
shashimalcse authored Oct 26, 2023
2 parents 1782ee1 + 9b37283 commit 8790666
Showing 1 changed file with 8 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8790666

Please sign in to comment.