Skip to content

Commit

Permalink
Add method to get shared hybrid roles for a given main role ID
Browse files Browse the repository at this point in the history
  • Loading branch information
dewniMW committed Feb 27, 2024
1 parent dc1db69 commit 7f37c0d
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission;
import org.wso2.carbon.identity.role.v2.mgt.core.model.Role;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleDTO;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;

import java.util.List;
Expand Down Expand Up @@ -449,4 +450,16 @@ Map<String, String> getMainRoleToSharedRoleMappingsBySubOrg(List<String> roleIds
*/
List<String> getAssociatedApplicationByRoleId(String roleId, String tenantDomain)
throws IdentityRoleManagementException;

/**
* Get shared hybrid roles for the given main role ID.
*
* @param roleId The main role ID.
* @param tenantId The tenant ID.
* @throws IdentityRoleManagementException IdentityRoleManagementException.
*/
default List<RoleDTO> getSharedHybridRoles(String roleId, int tenantId) throws IdentityRoleManagementException {

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission;
import org.wso2.carbon.identity.role.v2.mgt.core.model.Role;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleDTO;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;
import org.wso2.carbon.user.core.UserCoreConstants;

Expand Down Expand Up @@ -897,6 +898,12 @@ public List<String> getAssociatedApplicationByRoleId(String roleId, String tenan
return roleDAO.getAssociatedApplicationIdsByRoleId(roleId, tenantDomain);
}

@Override
public List<RoleDTO> getSharedHybridRoles(String roleId, int mainTenantId) throws IdentityRoleManagementException {

return roleDAO.getSharedHybridRoles(roleId, mainTenantId);
}

/**
* Get user from tenant domain.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import org.wso2.carbon.identity.role.v2.mgt.core.model.Permission;
import org.wso2.carbon.identity.role.v2.mgt.core.model.Role;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleBasicInfo;
import org.wso2.carbon.identity.role.v2.mgt.core.model.RoleDTO;
import org.wso2.carbon.identity.role.v2.mgt.core.model.UserBasicInfo;

import java.util.List;
Expand Down Expand Up @@ -460,4 +461,16 @@ List<String> getAssociatedApplicationIdsByRoleId(String roleId, String tenantDom
* @throws IdentityRoleManagementException IdentityRoleManagementException.
*/
int getRoleAudienceRefId(String audience, String audienceId) throws IdentityRoleManagementException;

/**
* Get shared hybrid roles for the given main role ID.
*
* @param roleId The main role ID.
* @param tenantId The tenant ID.
* @throws IdentityRoleManagementException IdentityRoleManagementException.
*/
default List<RoleDTO> getSharedHybridRoles(String roleId, int tenantId) throws IdentityRoleManagementException {

return null;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3558,4 +3558,28 @@ private IdpGroup convertToIdpGroup(IdPGroup idpGroup) {
convertedGroup.setGroupName(idpGroup.getIdpGroupName());
return convertedGroup;
}

@Override
public List<RoleDTO> getSharedHybridRoles(String roleId, int mainTenantId) throws IdentityRoleManagementException {

List<RoleDTO> hybridRoles = new ArrayList<>();
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(true);
NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_SHARED_ROLES_SQL)) {
statement.setInt(RoleConstants.RoleTableColumns.UM_TENANT_ID, mainTenantId);
statement.setString(RoleConstants.RoleTableColumns.UM_UUID, roleId);
try (ResultSet resultSet = statement.executeQuery()) {
while (resultSet.next()) {
String name = resultSet.getString(1);
int tenantId = resultSet.getInt(2);
int audienceRefId = resultSet.getInt(3);
String id = resultSet.getString(4);
hybridRoles.add(new RoleDTO(name, id, audienceRefId, tenantId));
}
}
} catch (SQLException e) {
String errorMessage = "Error while retrieving shared roles of role id : " + roleId;
throw new IdentityRoleManagementServerException(UNEXPECTED_SERVER_ERROR.getCode(), errorMessage, e);
}
return hybridRoles;
}
}

0 comments on commit 7f37c0d

Please sign in to comment.