Package org.pjdbc.drivers
Class UserMapDriver
java.lang.Object
org.pjdbc.sql.AbstractDriver
org.pjdbc.sql.AbstractProxyDriver
org.pjdbc.drivers.UserMapDriver
- All Implemented Interfaces:
Driver
@DriverCapability(prefix="mapuser",
description="Maps application usernames to database credentials",
capabilities={"security","transformation"})
@DriverSideEffects(filesystem=true)
public class UserMapDriver
extends AbstractProxyDriver
Maps application usernames to database credentials.
UserMapDriver enables multi-tenant or role-based database access by translating application-level usernames to actual database credentials. This is useful for:
- Hiding real database credentials from application code
- Implementing role-based access with different database users
- Multi-tenant scenarios where each tenant maps to different credentials
User mappings are loaded from a properties file on the classpath:
org.pjdbc.UserMapDriver.UserMapFile
Properties file format:
app_user1=db_user/db_password app_user2=other_user/other_password
URL format: jdbc:mapuser:jdbc:target:...
Example:
// Connect with app credentials, which get mapped to DB credentials
Properties info = new Properties();
info.setProperty("user", "app_user1");
info.setProperty("password", "ignored");
Connection conn = DriverManager.getConnection("jdbc:mapuser:jdbc:postgresql://localhost/db", info);
Security: Error messages are intentionally generic to prevent user enumeration attacks. Missing users and invalid mappings produce the same error.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected booleanacceptsSubProtocol(String subprotocol) connect(String url, Properties info) Methods inherited from class org.pjdbc.sql.AbstractProxyDriver
acceptsSubName, getPropertyInfo, isCompositionValidationEnabled, isValidateParametersEnabled, proxyCallableStatement, proxyCallableStatement, proxyConnection, proxyConnection, proxyConnection, proxyPreparedStatement, proxyPreparedStatement, proxyResultSet, proxyStatementMethods inherited from class org.pjdbc.sql.AbstractDriver
acceptsProtocol, acceptsURL, getMajorVersion, getMinorVersion, getParentLogger, getUrlParameter, getUrlParameter, getUrlParameters, jdbcCompliant, parseUrl, protocol, subname, subprotocol, validateParameters
-
Constructor Details
-
UserMapDriver
public UserMapDriver()
-
-
Method Details
-
acceptsSubProtocol
- Specified by:
acceptsSubProtocolin classAbstractDriver
-
connect
- Specified by:
connectin interfaceDriver- Overrides:
connectin classAbstractProxyDriver- Throws:
SQLException
-