Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import org.apache.commons.lang.ArrayUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.tomcat.jdbc.pool.DataSourceProxy;
import org.wso2.carbon.CarbonConstants;
import org.wso2.carbon.base.ServerConfiguration;
import org.wso2.carbon.user.api.RealmConfiguration;
Expand Down Expand Up @@ -53,6 +54,7 @@
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.UUID;

import static org.wso2.carbon.user.core.constants.UserCoreDBConstants.CASE_INSENSITIVE_SQL_STATEMENT_PARAMETER_PLACEHOLDER;
Expand All @@ -79,6 +81,8 @@ public class HybridRoleManager {
private static final String CASE_INSENSITIVE_USERNAME = "CaseInsensitiveUsername";

private static final String DB2 = "db2";
private static final String POSTGRE_SQL = "PostgreSQL";
Comment thread
ImalshaD marked this conversation as resolved.
private static final String POSTGRES_SCHEMA = "postgresSchema";

private static boolean hybridRoleAudienceTableExists = false;

Expand Down Expand Up @@ -1533,6 +1537,15 @@ private boolean isTableExists(String tableName) {
}
String schemaName = connection.getSchema();
String catalogName = connection.getCatalog();

// For PostgreSQL, use the configured schema if available. This handles cases where tables reside in a
// non-default schema that differs from the first entry in the database user's search path.
if (POSTGRE_SQL.equalsIgnoreCase(connection.getMetaData().getDatabaseProductName())) {
String postgresSchema = getPostgresSchema();
if (org.apache.commons.lang.StringUtils.isNotBlank(postgresSchema)) {
Comment thread
ImalshaD marked this conversation as resolved.
schemaName = postgresSchema.trim();
}
Comment thread
ImalshaD marked this conversation as resolved.
}
Comment thread
ImalshaD marked this conversation as resolved.
try (ResultSet resultSet = metaData.getTables(catalogName, schemaName, tableName, new String[]{"TABLE"})) {
if (resultSet.next()) {
return true;
Expand All @@ -1545,4 +1558,17 @@ private boolean isTableExists(String tableName) {
}
return false;
}

private String getPostgresSchema() {

String customSchema = null;
if (!(dataSource instanceof DataSourceProxy)) {
return null;
}
Properties properties = ((DataSourceProxy) dataSource).getDbProperties();
if (properties != null) {
customSchema = properties.getProperty(POSTGRES_SCHEMA);
}
return customSchema;
}
Comment thread
ImalshaD marked this conversation as resolved.
}
Loading