Skip to content

Commit

Permalink
Change role v2 implementation to use UM_HYBRID_ROLE for DB queries
Browse files Browse the repository at this point in the history
  • Loading branch information
ZiyamSanthosh committed Jan 9, 2024
1 parent 92f5a89 commit b24fe0c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2619,12 +2619,11 @@ private int getAudienceRefByID(String roleId, String tenantDomain) throws Identi

int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
int refId;
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false);
NamedPreparedStatement statement = new NamedPreparedStatement(connection, GET_AUDIENCE_REF_BY_ID_SQL)) {

statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
statement.setString(RoleConstants.RoleTableColumns.ATTR_VALUE, roleId);
statement.setInt(RoleConstants.RoleTableColumns.UM_TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.UM_UUID, roleId);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
refId = resultSet.getInt(1);
Expand Down Expand Up @@ -2784,12 +2783,11 @@ public boolean isExistingRoleID(String roleId, String tenantDomain) throws Ident

boolean isExist = false;
int tenantId = IdentityTenantUtil.getTenantId(tenantDomain);
try (Connection connection = IdentityDatabaseUtil.getDBConnection(false);
try (Connection connection = IdentityDatabaseUtil.getUserDBConnection(false);
NamedPreparedStatement statement = new NamedPreparedStatement(connection, IS_ROLE_ID_EXIST_SQL)) {

statement.setInt(RoleConstants.RoleTableColumns.TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.ATTR_NAME, RoleConstants.ID_URI);
statement.setString(RoleConstants.RoleTableColumns.ATTR_VALUE, roleId);
statement.setInt(RoleConstants.RoleTableColumns.UM_TENANT_ID, tenantId);
statement.setString(RoleConstants.RoleTableColumns.UM_UUID, roleId);
try (ResultSet resultSet = statement.executeQuery()) {
if (resultSet.next()) {
isExist = resultSet.getInt(1) > 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public class SQLQueries {
"UM_HYBRID_ROLE INNER JOIN UM_HYBRID_ROLE_AUDIENCE ON UM_HYBRID_ROLE.UM_AUDIENCE_REF_ID = " +
"UM_HYBRID_ROLE_AUDIENCE.UM_ID WHERE UM_HYBRID_ROLE.UM_UUID=:UM_UUID;";

public static final String GET_AUDIENCE_REF_BY_ID_SQL = "SELECT AUDIENCE_REF_ID FROM IDN_SCIM_GROUP WHERE " +
"TENANT_ID=:TENANT_ID; AND ATTR_NAME=:ATTR_NAME; AND ATTR_VALUE=:ATTR_VALUE;";
public static final String GET_AUDIENCE_REF_BY_ID_SQL = "SELECT UM_AUDIENCE_REF_ID FROM UM_HYBRID_ROLE WHERE " +
"UM_TENANT_ID=:UM_TENANT_ID; AND UM_UUID=:UM_UUID;";

public static final String ADD_IDP_GROUPS_SQL = "INSERT INTO UM_IDP_GROUP_ROLE (UM_ROLE_ID, UM_GROUP_ID, " +
"UM_TENANT_ID) VALUES ((SELECT UM_ID FROM UM_HYBRID_ROLE WHERE UM_UUID=:UM_UUID; AND " +
Expand Down Expand Up @@ -241,8 +241,8 @@ public class SQLQueries {
public static final String GET_ROLE_NAME_BY_ID_SQL = "SELECT UM_ROLE_NAME FROM UM_HYBRID_ROLE WHERE "
+ "UM_TENANT_ID=:UM_TENANT_ID; AND UM_UUID=:UM_UUID;";

public static final String IS_ROLE_ID_EXIST_SQL = "SELECT COUNT(ID) FROM IDN_SCIM_GROUP WHERE "
+ "TENANT_ID=:TENANT_ID; AND ATTR_NAME=:ATTR_NAME; AND ATTR_VALUE=:ATTR_VALUE;";
public static final String IS_ROLE_ID_EXIST_SQL = "SELECT COUNT(UM_ID) FROM UM_HYBRID_ROLE WHERE "
+ "UM_TENANT_ID=:UM_TENANT_ID; AND UM_UUID=:UM_UUID;";

public static final String REMOVE_GROUP_FROM_ROLE_SQL =
"DELETE FROM UM_HYBRID_GROUP_ROLE WHERE " + "UM_GROUP_NAME=:UM_GROUP_NAME; AND "
Expand Down

0 comments on commit b24fe0c

Please sign in to comment.