Class PostgresqlUtil
java.lang.Object
dk.cloudcreate.essentials.components.foundation.postgresql.PostgresqlUtil
-
Field Summary
FieldsModifier and TypeFieldDescriptionThis list incorporates a broad range of reserved names, including those specific to PostgreSQL as well as standard SQL keywords, that cannot be used as COLUMN, TABLE and INDEX names. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidcheckIsValidTableOrColumnName(String tableOrColumnName) Validates whether the provided table or column name is valid according to PostgreSQL naming conventions and does not conflict with reserved keywords.
This method callscheckIsValidTableOrColumnName(String, String)with a null context.
The method provided is designed as an initial layer of defense against SQL injection by applying naming conventions intended to reduce the risk of malicious input.
However, Essentials components as well ascheckIsValidTableOrColumnName(String)does not offer exhaustive protection, nor does it assure the complete security of the resulting SQL against SQL injection threats.
The responsibility for implementing protective measures against SQL Injection lies exclusively with the users/developers using the Essentials components and its supporting classes.
Users must ensure thorough sanitization and validation of API input parameters, column, table, and index names.
Insufficient attention to these practices may leave the application vulnerable to SQL injection, potentially endangering the security and integrity of the database.static voidcheckIsValidTableOrColumnName(String tableOrColumnName, String context) Validates whether the provided table or column name is valid according to PostgreSQL naming conventions and does not conflict with reserved keywords.
The method provided is designed as an initial layer of defense against SQL injection by applying naming conventions intended to reduce the risk of malicious input.
However, Essentials components as well ascheckIsValidTableOrColumnName(String, String)does not offer exhaustive protection, nor does it assure the complete security of the resulting SQL against SQL injection threats.
The responsibility for implementing protective measures against SQL Injection lies exclusively with the users/developers using the Essentials components and its supporting classes.
Users must ensure thorough sanitization and validation of API input parameters, column, table, and index names.
Insufficient attention to these practices may leave the application vulnerable to SQL injection, potentially endangering the security and integrity of the database.static intgetServiceMajorVersion(org.jdbi.v3.core.Handle handle) Read the major Postgresql server version
-
Field Details
-
RESERVED_NAMES
This list incorporates a broad range of reserved names, including those specific to PostgreSQL as well as standard SQL keywords, that cannot be used as COLUMN, TABLE and INDEX names. Developers should use this list cautiously and always cross-reference against the current version of PostgreSQL they are working with, as database systems frequently update their list of reserved keywords.
The primary goal of this list is to avoid naming conflicts and ensure compatibility with SQL syntax, in an attempt to reduce errors and potential SQL injection vulnerabilities.
-
-
Constructor Details
-
PostgresqlUtil
public PostgresqlUtil()
-
-
Method Details
-
getServiceMajorVersion
public static int getServiceMajorVersion(org.jdbi.v3.core.Handle handle) Read the major Postgresql server version- Parameters:
handle- the jdbi handle that will be used for querying- Returns:
- the major version (12, 13, 14, 15, etc.)
-
checkIsValidTableOrColumnName
Validates whether the provided table or column name is valid according to PostgreSQL naming conventions and does not conflict with reserved keywords.
The method provided is designed as an initial layer of defense against SQL injection by applying naming conventions intended to reduce the risk of malicious input.
However, Essentials components as well ascheckIsValidTableOrColumnName(String, String)does not offer exhaustive protection, nor does it assure the complete security of the resulting SQL against SQL injection threats.
The responsibility for implementing protective measures against SQL Injection lies exclusively with the users/developers using the Essentials components and its supporting classes.
Users must ensure thorough sanitization and validation of API input parameters, column, table, and index names.
Insufficient attention to these practices may leave the application vulnerable to SQL injection, potentially endangering the security and integrity of the database.
The method checks if the
tableOrColumnName:- Is not null, empty, and does not consist solely of whitespace.
- Does not match any PostgreSQL reserved keyword (case-insensitive check).
- Contains only characters valid for PostgreSQL identifiers: letters, digits, and underscores, and does not start with a digit.
- Parameters:
tableOrColumnName- the table or column name to validate.context- optional context that will be included in any error message. null value means no context is provided- Throws:
InvalidTableOrColumnNameException- if the provided name is null, empty, matches a reserved keyword, or contains invalid characters.
-
checkIsValidTableOrColumnName
Validates whether the provided table or column name is valid according to PostgreSQL naming conventions and does not conflict with reserved keywords.
This method callscheckIsValidTableOrColumnName(String, String)with a null context.
The method provided is designed as an initial layer of defense against SQL injection by applying naming conventions intended to reduce the risk of malicious input.
However, Essentials components as well ascheckIsValidTableOrColumnName(String)does not offer exhaustive protection, nor does it assure the complete security of the resulting SQL against SQL injection threats.
The responsibility for implementing protective measures against SQL Injection lies exclusively with the users/developers using the Essentials components and its supporting classes.
Users must ensure thorough sanitization and validation of API input parameters, column, table, and index names.
Insufficient attention to these practices may leave the application vulnerable to SQL injection, potentially endangering the security and integrity of the database.
The method checks if the
tableOrColumnName:- Is not null, empty, and does not consist solely of whitespace.
- Does not match any PostgreSQL reserved keyword (case-insensitive check).
- Contains only characters valid for PostgreSQL identifiers: letters, digits, and underscores, and does not start with a digit.
- Parameters:
tableOrColumnName- the table or column name to validate.- Throws:
InvalidTableOrColumnNameException- if the provided name is null, empty, matches a reserved keyword, or contains invalid characters.
-