Class 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.