Package org.pjdbc.drivers
Class DataMaskingDriver
java.lang.Object
org.pjdbc.sql.AbstractDriver
org.pjdbc.sql.AbstractProxyDriver
org.pjdbc.drivers.DataMaskingDriver
- All Implemented Interfaces:
Driver
@DriverCapability(prefix="mask",
description="Masks sensitive data in query results",
capabilities={"masking","security"})
@DriverParameter(name="columns",type=STRING,description="Semicolon-separated column name patterns (regex) to mask") @DriverParameter(name="strategy",type=STRING,description="Masking strategy",defaultValue="PARTIAL",enumValues={"FULL","PARTIAL","EMAIL","REDACT","HASH"}) @DriverParameter(name="mask",type=STRING,description="Mask character",defaultValue="*") @DriverParameter(name="showFirst",type=INTEGER,description="Characters to show at start for PARTIAL",defaultValue="0",min=0L) @DriverParameter(name="showLast",type=INTEGER,description="Characters to show at end for PARTIAL",defaultValue="4",min=0L)
public class DataMaskingDriver
extends AbstractProxyDriver
DataMaskingDriver masks sensitive data in query results on-the-fly.
URL format: jdbc:mask[param=value,...]:jdbc:target:...
Masking Strategies:
- FULL - Replace entire value with mask characters (e.g., "********")
- PARTIAL - Show first/last N characters (e.g., "****1234")
- EMAIL - Mask email preserving first char and domain (e.g., "j***@example.com")
- REDACT - Replace with "[REDACTED]"
- HASH - Replace with hash prefix (e.g., "a1b2c3d4...")
Example URLs:
jdbc:mask[columns=ssn;credit_card]:jdbc:postgresql://localhost/mydb jdbc:mask[columns=.*email.*,strategy=EMAIL]:jdbc:postgresql://localhost/mydb jdbc:mask[columns=password;secret,strategy=REDACT]:jdbc:postgresql://localhost/mydb jdbc:mask[columns=card_number,showLast=4,showFirst=0]:jdbc:mysql://localhost/db
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classConfiguration holder for masking parameters.static enumMasking strategy enumeration. -
Driver Parameters
URL format:
jdbc:mask[param=value,...]:<target-url>Parameter Type Default Constraints Description columnsstring - - Semicolon-separated column name patterns (regex) to mask strategystring PARTIALone of: "FULL", "PARTIAL", "EMAIL", "REDACT", "HASH" Masking strategy maskstring *- Mask character showFirstinteger 0≥ 0 Characters to show at start for PARTIAL showLastinteger 4≥ 0 Characters to show at end for PARTIAL Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubName(String subname) protected booleanacceptsSubProtocol(String subprotocol) connect(String url, Properties info) protected CallableStatementproxyCallableStatement(CallableStatement delegate, Connection conn) protected ConnectionproxyConnection(Connection delegate, String url, Properties info, Driver driver) protected PreparedStatementproxyPreparedStatement(PreparedStatement delegate, Connection conn) proxyResultSet(Statement stmt, ResultSet delegate) protected StatementproxyStatement(Statement delegate, Connection conn) Methods inherited from class org.pjdbc.sql.AbstractProxyDriver
getPropertyInfo, isCompositionValidationEnabled, isValidateParametersEnabled, proxyCallableStatement, proxyConnection, proxyConnection, proxyPreparedStatementMethods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Constructor Details
-
DataMaskingDriver
public DataMaskingDriver()
-
-
Method Details
-
acceptsSubProtocol
- Specified by:
acceptsSubProtocolin classAbstractDriver
-
acceptsSubName
- Overrides:
acceptsSubNamein classAbstractProxyDriver
-
connect
- Specified by:
connectin interfaceDriver- Overrides:
connectin classAbstractProxyDriver- Throws:
SQLException
-
proxyConnection
protected Connection proxyConnection(Connection delegate, String url, Properties info, Driver driver) throws SQLException - Overrides:
proxyConnectionin classAbstractProxyDriver- Throws:
SQLException
-
proxyStatement
- Overrides:
proxyStatementin classAbstractProxyDriver- Throws:
SQLException
-
proxyPreparedStatement
protected PreparedStatement proxyPreparedStatement(PreparedStatement delegate, Connection conn) throws SQLException - Overrides:
proxyPreparedStatementin classAbstractProxyDriver- Throws:
SQLException
-
proxyCallableStatement
protected CallableStatement proxyCallableStatement(CallableStatement delegate, Connection conn) throws SQLException - Overrides:
proxyCallableStatementin classAbstractProxyDriver- Throws:
SQLException
-
proxyResultSet
- Overrides:
proxyResultSetin classAbstractProxyDriver- Throws:
SQLException
-