Skip to content

Commit

Permalink
Improve role user list to support legacy and new runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
WSO2 committed May 8, 2024
1 parent 31bf43d commit f5544a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.GET_ROLE_ID_BY_NAME_SQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.GET_ROLE_NAME_BY_ID_SQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.GET_USER_LIST_OF_ROLE_SQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.GET_USER_LIST_OF_ROLE_SQL_MSSQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.IS_ROLE_EXIST_SQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.IS_ROLE_ID_EXIST_SQL;
import static org.wso2.carbon.identity.role.mgt.core.dao.SQLQueries.REMOVE_GROUP_FROM_ROLE_SQL;
Expand Down Expand Up @@ -1122,10 +1123,15 @@ public List<UserBasicInfo> getUserListOfRole(String roleID, String tenantDomain)
}

List<String> disabledDomainName = getDisabledDomainNames();
String sql = GET_USER_LIST_OF_ROLE_SQL;

try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false)) {
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection,
GET_USER_LIST_OF_ROLE_SQL, RoleTableColumns.UM_ID)) {
String databaseProductName = connection.getMetaData().getDatabaseProductName();
if (MICROSOFT.equals(databaseProductName)) {
sql = GET_USER_LIST_OF_ROLE_SQL_MSSQL;
}
try (NamedPreparedStatement statement = new NamedPreparedStatement(connection, sql,
RoleTableColumns.UM_ID)) {
statement.setString(RoleTableColumns.UM_ROLE_NAME, roleName);
statement.setInt(RoleTableColumns.UM_TENANT_ID, tenantId);
try (ResultSet resultSet = statement.executeQuery()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public class SQLQueries {
public static final String GET_USER_LIST_OF_ROLE_SQL =
"SELECT UM_USER_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_USER_ROLE, UM_DOMAIN WHERE "
+ "UM_ROLE_ID=(SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=:UM_ROLE_NAME; AND "
+ "UM_TENANT_ID=:UM_TENANT_ID; LIMIT 1) AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=:UM_TENANT_ID; "
+ "AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID";
public static final String GET_USER_LIST_OF_ROLE_SQL_MSSQL =
"SELECT UM_USER_NAME, UM_DOMAIN_NAME FROM UM_HYBRID_USER_ROLE, UM_DOMAIN WHERE "
+ "UM_ROLE_ID=(SELECT TOP 1 UM_ID FROM UM_HYBRID_ROLE WHERE UM_ROLE_NAME=:UM_ROLE_NAME; AND "
+ "UM_TENANT_ID=:UM_TENANT_ID;) AND UM_HYBRID_USER_ROLE.UM_TENANT_ID=:UM_TENANT_ID; "
+ "AND UM_HYBRID_USER_ROLE.UM_DOMAIN_ID=UM_DOMAIN.UM_DOMAIN_ID";

Expand Down

0 comments on commit f5544a3

Please sign in to comment.